From fd2380d7b8a376c7981ee4d54499e0c782ae0b57 Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 13:43:54 -0700 Subject: [PATCH 1/6] Adds greet module. --- lab-nathan/.eslintignore | 5 ++ lab-nathan/.eslintrc | 21 +++++ lab-nathan/.gitignore | 136 ++++++++++++++++++++++++++++++ README.md => lab-nathan/README.md | 0 lab-nathan/index.js | 0 lab-nathan/lib/greet.js | 5 ++ 6 files changed, 167 insertions(+) create mode 100644 lab-nathan/.eslintignore create mode 100644 lab-nathan/.eslintrc create mode 100644 lab-nathan/.gitignore rename README.md => lab-nathan/README.md (100%) create mode 100644 lab-nathan/index.js create mode 100644 lab-nathan/lib/greet.js diff --git a/lab-nathan/.eslintignore b/lab-nathan/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-nathan/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-nathan/.eslintrc b/lab-nathan/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/lab-nathan/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/lab-nathan/.gitignore b/lab-nathan/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/lab-nathan/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows diff --git a/README.md b/lab-nathan/README.md similarity index 100% rename from README.md rename to lab-nathan/README.md diff --git a/lab-nathan/index.js b/lab-nathan/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-nathan/lib/greet.js b/lab-nathan/lib/greet.js new file mode 100644 index 0000000..4d9854d --- /dev/null +++ b/lab-nathan/lib/greet.js @@ -0,0 +1,5 @@ +'use strict'; + +module.export = function(name) { + return typeof name === 'string'? `hello ${name}!` : null; +} \ No newline at end of file From 3066cf3c97c301a86e3f13f1f18245a2d3b84239 Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 14:00:33 -0700 Subject: [PATCH 2/6] Adds arithmetic module. --- lab-nathan/lib/arithmetic.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lab-nathan/lib/arithmetic.js diff --git a/lab-nathan/lib/arithmetic.js b/lab-nathan/lib/arithmetic.js new file mode 100644 index 0000000..59b8096 --- /dev/null +++ b/lab-nathan/lib/arithmetic.js @@ -0,0 +1,20 @@ +'use strict'; + +let arithmetic = {}; +module.export = arithmetic; + +arithmetic.add = function(a, b) { + if (typeof a !== 'number' || typeof b !== 'number') { + throw new Error('Cannot add non-numbers.'); + } + + return a + b; +}; + +arithmetic.subtract = function(a, b) { + if (typeof a !== 'number' || typeof b !== 'number') { + throw new Error('Cannot subract non-numbers.'); + } + + return a - b; +}; \ No newline at end of file From 9c9669fce398e16252a6e2925c187892d77abb0f Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 14:13:06 -0700 Subject: [PATCH 3/6] Write greet test. --- lab-nathan/lib/arithmetic.js | 2 +- lab-nathan/lib/greet.js | 4 ++-- lab-nathan/test/greet-test.js | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lab-nathan/test/greet-test.js diff --git a/lab-nathan/lib/arithmetic.js b/lab-nathan/lib/arithmetic.js index 59b8096..ddc2b0f 100644 --- a/lab-nathan/lib/arithmetic.js +++ b/lab-nathan/lib/arithmetic.js @@ -1,7 +1,7 @@ 'use strict'; let arithmetic = {}; -module.export = arithmetic; +module.exports = arithmetic; arithmetic.add = function(a, b) { if (typeof a !== 'number' || typeof b !== 'number') { diff --git a/lab-nathan/lib/greet.js b/lab-nathan/lib/greet.js index 4d9854d..fa2e13e 100644 --- a/lab-nathan/lib/greet.js +++ b/lab-nathan/lib/greet.js @@ -1,5 +1,5 @@ 'use strict'; -module.export = function(name) { +module.exports = function(name) { return typeof name === 'string'? `hello ${name}!` : null; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/lab-nathan/test/greet-test.js b/lab-nathan/test/greet-test.js new file mode 100644 index 0000000..4db853c --- /dev/null +++ b/lab-nathan/test/greet-test.js @@ -0,0 +1,13 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + describe('#', function() { + it('should return hello world!', function() { + let result = greet('world'); + assert.ok(result === 'hello world!', 'unexpected result.'); + }); + }); +}); \ No newline at end of file From 194103f41e6f827f372a51171d1aba87077303eb Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 14:16:15 -0700 Subject: [PATCH 4/6] Adds arithmetic tests. --- lab-nathan/test/arithmetic-test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lab-nathan/test/arithmetic-test.js diff --git a/lab-nathan/test/arithmetic-test.js b/lab-nathan/test/arithmetic-test.js new file mode 100644 index 0000000..10f25a2 --- /dev/null +++ b/lab-nathan/test/arithmetic-test.js @@ -0,0 +1,19 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +describe('Arithmetic Module', function() { + describe('#add', function() { + it('should return 10', function() { + return arithmetic.add(3, 7); + }); + }); + + describe('#subtract', function() { + it('should return 10', function() { + return arithmetic.subtract(30, 20); + }); + }); +}); + From 130ad8158af70cc62a9245ee349eefd24f00c446 Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 14:32:16 -0700 Subject: [PATCH 5/6] Adds bonus tests. --- lab-nathan/README.md | 60 ++---------------------------- lab-nathan/test/arithmetic-test.js | 18 ++++++++- lab-nathan/test/greet-test.js | 7 +++- 3 files changed, 26 insertions(+), 59 deletions(-) diff --git a/lab-nathan/README.md b/lab-nathan/README.md index a3aca54..b1e5d66 100644 --- a/lab-nathan/README.md +++ b/lab-nathan/README.md @@ -1,59 +1,7 @@ -![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem -=== +# Greet and Arithmetic -## Submission Instructions - * work in a fork of this repository - * work in a branch on your fork - * write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` - * submit a pull request to this repository - * submit a link to your pull request on canvas - * submit a question, observation, and how long you spent on canvas +This project contains two node modules, greet and arithmetic. -## Resources -* [node assert docs](https://nodejs.org/dist/latest-v4.x/docs/api/assert.html) -* [mocha docs](http://mochajs.org/#getting-started) +The Greet module is a function which accepts a name parameter and returns "hello [name]!". -## Requirements - -#### Configuration - -* include the following: - * **README.md** - contains documentation about your lab - * **.gitignore** - contains a robust `.gitignore` file - * **.eslintrc** - contains the provided `.eslintrc` file - * **.eslintignore** - contains the provided `.eslintignore` file - * **.package.json** - contains all necessary dependencies and developer dependencies - * **lib/** - should contain your modules - * **test/** - should contain your unit tests - -#### Feature Tasks -* create a node.js module (`greet.js`) that exports a single function - * the `greet` function should have a single parameter that should expect a string as it's input - * the `greet` function should return the input name, concatenated with "hello " - * the `greet` function should return `null` if the input is not a string -* create a node.js module named `arithmetic.js` - * this module should have `add` and `sub` methods - * the `add` method should contain 2 parameters - * these parameters should be numbers and the method should return the sum of the 2 numbers - * the `sub` method should contain 2 parameters - * these parameters should be numbers and the method should return the first number minus the second number -* decide on the expected behavior for non-number inputs - -#### Testing -* write a test the expects the greet module to return "hello world!" - * this should happen when invoked with "world!" as a parameter -* write a test for the `add` and `subtract` methods on the arithmetic module - * this should ensure that your functions work with number inputs - -#### Documentation -* write a description of your project (this should be in your `README.md` file) - -###### BONUS 1pt -* write a test that expects the greet module to return null when you use non string values -* write a test that ensures the functions work as expected with non number inputs - -## Rubric -* 2pts configuration -* 3pts feature tasks -* 3pts tests -* 2pts documentation +The Arithmetic module is an object containing two methods, add and subtract. They both accept two parameters and return the result. \ No newline at end of file diff --git a/lab-nathan/test/arithmetic-test.js b/lab-nathan/test/arithmetic-test.js index 10f25a2..5dfbdd0 100644 --- a/lab-nathan/test/arithmetic-test.js +++ b/lab-nathan/test/arithmetic-test.js @@ -6,13 +6,27 @@ const assert = require('assert'); describe('Arithmetic Module', function() { describe('#add', function() { it('should return 10', function() { - return arithmetic.add(3, 7); + let result = arithmetic.add(3, 7); + assert.ok(result === 10); + }); + + it('should throw error with non-number inputs.', function() { + assert.throws(function() { + arithmetic.add('a', 4); + }); }); }); describe('#subtract', function() { it('should return 10', function() { - return arithmetic.subtract(30, 20); + let result = arithmetic.subtract(30, 20); + assert.ok(result === 10); + }); + + it('should throw error with non-number inputs.', function() { + assert.throws(function() { + arithmetic.subtract('a', 20); + }); }); }); }); diff --git a/lab-nathan/test/greet-test.js b/lab-nathan/test/greet-test.js index 4db853c..e54dd7d 100644 --- a/lab-nathan/test/greet-test.js +++ b/lab-nathan/test/greet-test.js @@ -7,7 +7,12 @@ describe('Greet Module', function() { describe('#', function() { it('should return hello world!', function() { let result = greet('world'); - assert.ok(result === 'hello world!', 'unexpected result.'); + assert.ok(result === 'hello world!'); + }); + + it('should return null with a non-string input', function() { + let result = greet(0); + assert.ok(result === null); }); }); }); \ No newline at end of file From 1d2fe1d12763a3a38c6e26e5c731314a6481c734 Mon Sep 17 00:00:00 2001 From: Nathan Harrenstein Date: Mon, 17 Jul 2017 14:35:07 -0700 Subject: [PATCH 6/6] Readds readme. --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..75b6a5b --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem +=== + +## Submission Instructions + * work in a fork of this repository + * work in a branch on your fork + * write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` + * submit a pull request to this repository + * submit a link to your pull request on canvas + * submit a question, observation, and how long you spent on canvas + +## Resources +* [node assert docs](https://nodejs.org/dist/latest-v4.x/docs/api/assert.html) +* [mocha docs](http://mochajs.org/#getting-started) + +## Requirements + +#### Configuration + +* include the following: + * **README.md** - contains documentation about your lab + * **.gitignore** - contains a robust `.gitignore` file + * **.eslintrc** - contains the provided `.eslintrc` file + * **.eslintignore** - contains the provided `.eslintignore` file + * **.package.json** - contains all necessary dependencies and developer dependencies + * **lib/** - should contain your modules + * **test/** - should contain your unit tests + +#### Feature Tasks +* create a node.js module (`greet.js`) that exports a single function + * the `greet` function should have a single parameter that should expect a string as it's input + * the `greet` function should return the input name, concatenated with "hello " + * the `greet` function should return `null` if the input is not a string +* create a node.js module named `arithmetic.js` + * this module should have `add` and `sub` methods + * the `add` method should contain 2 parameters + * these parameters should be numbers and the method should return the sum of the 2 numbers + * the `sub` method should contain 2 parameters + * these parameters should be numbers and the method should return the first number minus the second number +* decide on the expected behavior for non-number inputs + +#### Testing +* write a test the expects the greet module to return "hello world!" + * this should happen when invoked with "world!" as a parameter +* write a test for the `add` and `subtract` methods on the arithmetic module + * this should ensure that your functions work with number inputs + +#### Documentation +* write a description of your project (this should be in your `README.md` file) + +###### BONUS 1pt +* write a test that expects the greet module to return null when you use non string values +* write a test that ensures the functions work as expected with non number inputs + +## Rubric +* 2pts configuration +* 3pts feature tasks +* 3pts tests +* 2pts documentation \ No newline at end of file