From 0ae8c6bdfa185437be0192caf44ca28e12cc2ed8 Mon Sep 17 00:00:00 2001 From: KatherineHanson Date: Mon, 11 Sep 2017 15:33:13 -0700 Subject: [PATCH 1/4] added greet module --- .eslintignore | 0 .eslintrc | 1 + .gitignore | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 8 ++++ lib/greet.js | 12 +++++ package.json | 26 +++++++++++ 6 files changed, 174 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 index.js create mode 100644 lib/greet.js create mode 100644 package.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..e69de29 diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.eslintrc @@ -0,0 +1 @@ + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ec7bce --- /dev/null +++ b/.gitignore @@ -0,0 +1,127 @@ +# Created by https://www.gitignore.io/api/osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### 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 ### +*.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 + +### 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,node,linux,windows diff --git a/index.js b/index.js new file mode 100644 index 0000000..12a9d30 --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +'use strict'; + +// assign to name of file you're referring to +const greet = require('./lib/greet.js'); + +console.log(greet()); +console.log(greet(3)); +console.log(greet('world')); diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..49a6d7f --- /dev/null +++ b/lib/greet.js @@ -0,0 +1,12 @@ +'use strict'; + +// Export a function that takes in a name and returns "hello" + name + +module.exports = function(name){ + if(typeof name === 'string') { + return `hello ${name}`; + } + else { + return null; + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..b312844 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "01-node-ecosystem", + "version": "1.0.0", + "description": "01-node-ecosystem lab", + "main": "index.js", + "directories": { + "lib": "lib" + }, + "scripts": { + "test": "jest --runInBand" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/KatherineHanson/01-node-ecosystem.git" + }, + "author": "Katherine Hanson", + "license": "ISC", + "bugs": { + "url": "https://github.com/KatherineHanson/01-node-ecosystem/issues" + }, + "homepage": "https://github.com/KatherineHanson/01-node-ecosystem#readme", + "devDependencies": {}, + "dependencies": { + "jest": "^21.0.2" + } +} From c8a43956f1c3a5550e8503b97e7295e204f7a301 Mon Sep 17 00:00:00 2001 From: KatherineHanson Date: Mon, 11 Sep 2017 15:41:05 -0700 Subject: [PATCH 2/4] added greet module tests --- __test__/greet.test.js | 18 ++++++++++++++++++ index.js | 4 ---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 __test__/greet.test.js diff --git a/__test__/greet.test.js b/__test__/greet.test.js new file mode 100644 index 0000000..c82fb9f --- /dev/null +++ b/__test__/greet.test.js @@ -0,0 +1,18 @@ +'use strict'; + +const greet = require('../lib/greet.js'); + +test('greet() should return null', () => { + let result = greet(); + expect(result).toEqual(null); +}); + +test('greet(3) should return null', () => { + let result = greet(3); + expect(result).toEqual(null); +}); + +test('greet(\'world\') should return "hello world"', () => { + let result = greet('world'); + expect(result).toEqual('hello world'); +}); diff --git a/index.js b/index.js index 12a9d30..ec291d9 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,3 @@ // assign to name of file you're referring to const greet = require('./lib/greet.js'); - -console.log(greet()); -console.log(greet(3)); -console.log(greet('world')); From 0d96fae6c0b9980c4523b2e737939ce2aab60048 Mon Sep 17 00:00:00 2001 From: KatherineHanson Date: Mon, 11 Sep 2017 16:37:04 -0700 Subject: [PATCH 3/4] finished arithmetic module and testing functionality --- __test__/arithmetic.test.js | 33 +++++++++++++++++++++++++++++++++ index.js | 3 +++ lib/arithmetic.js | 22 ++++++++++++++++++++++ lib/greet.js | 2 +- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 __test__/arithmetic.test.js create mode 100644 lib/arithmetic.js diff --git a/__test__/arithmetic.test.js b/__test__/arithmetic.test.js new file mode 100644 index 0000000..0e311be --- /dev/null +++ b/__test__/arithmetic.test.js @@ -0,0 +1,33 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); + +test('arithmetic.add() should return null', () => { + let result = arithmetic.add(); + expect(result).toEqual(null); +}); + +test('arithmetic.sub() should return null', () => { + let result = arithmetic.sub(); + expect(result).toEqual(null); +}); + +test('arithmetic.add(2,\'hi\') should return null', () => { + let result = arithmetic.add(2,'hi'); + expect(result).toEqual(null); +}); + +test('arithmetic.sub(2,\'hi\') should return null', () => { + let result = arithmetic.add(2,'hi'); + expect(result).toEqual(null); +}); + +test('arithmetic.add(2,3) should return 5', () => { + let result = arithmetic.add(2,3); + expect(result).toEqual(5); +}); + +test('arithmetic.sub(2,3) should return -1', () => { + let result = arithmetic.sub(2,3); + expect(result).toEqual(-1); +}); diff --git a/index.js b/index.js index ec291d9..717fd51 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,7 @@ 'use strict'; // assign to name of file you're referring to + const greet = require('./lib/greet.js'); + +const arithmetic = require('./lib/arithmetic.js'); diff --git a/lib/arithmetic.js b/lib/arithmetic.js new file mode 100644 index 0000000..b6bb6c5 --- /dev/null +++ b/lib/arithmetic.js @@ -0,0 +1,22 @@ +'use strict'; + +// Export an object that has add and sub methods that implement addition and subtraction + +module.exports = { + add: function(num1,num2) { + if(typeof num1 === 'number' && typeof num2 === 'number'){ + return num1 + num2; + } + else { + return null; + } + }, + sub: function(num1,num2) { + if(typeof num1 === 'number' && typeof num2 === 'number'){ + return num1 - num2; + } + else { + return null; + } + } +}; diff --git a/lib/greet.js b/lib/greet.js index 49a6d7f..26b553b 100644 --- a/lib/greet.js +++ b/lib/greet.js @@ -2,7 +2,7 @@ // Export a function that takes in a name and returns "hello" + name -module.exports = function(name){ +module.exports = name => { if(typeof name === 'string') { return `hello ${name}`; } From 34e25c62366fdf48bfd9fee425799b1408b076b4 Mon Sep 17 00:00:00 2001 From: KatherineHanson Date: Mon, 11 Sep 2017 17:20:15 -0700 Subject: [PATCH 4/4] Completed README.md --- README.md | 61 ++++++++++++----------------------------------- lib/arithmetic.js | 4 ++-- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 328a88c..bf59c93 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,21 @@ ![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` -* Open a pull request to this repository -* Submit on canvas a question and observation, how long you spent, and a link to your pull request - -## Resources -* [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) -* [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) -* [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) - -## Configuration -Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files. -* **README.md** - contains documentation -* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file -* **.eslintrc** - contains the course linter configuratoin -* **.eslintignore** - contains the course linter ignore configuration -* **lib/** - contains module definitions -* **__test__/** - contains unit tests - -## Feature Tasks +## Exported Values #### Greet Module -Create a NodeJS module in the lib/ directory named `greet.js` that exports a single function. -* The `greet` function should have a single parameter (arity of one) that should expect a string as it's input -* The `greet` function should return the input name, concatenated with "hello ": eg. ("hello susan") -* The `greet` function should return `null` if the input is not a string +Exports a single function +* The `greet` function has an arity of one +* The data type for this parameter is string +* If the parameter is a string, the `greet` function returns the parameter concatenated with `'hello '`, for example `hello katherine` +* Else the `greet` function returns `null` #### Arithmetic Module -Create a NodeJS module in the lib/ directory named `arithmetic.js` that exports an object. This module should have `add` and `sub` methods that implament addition and subtraction. -* The `add` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the sum of the 2 numbers -* The `sub` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the second paramiter subtracted from the first paramiter - -## Testing -#### Greet Module Tests -* Write a test that expects the greet module to return `null` when you supply non string values -* Write a test the expects the greet module to return `'hello world'` - * This should happen when invoked with `'world'` as the first argument - -#### Arithmetic Module Tests -* Test each method for proper use (invoded with number arguments) -* Test each method for inproper use (invoded with one or more non-numner arguments) - -## Documentation -In your README.md describe the exported values of each module defined in your lib/ directory. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md. +Exports an object. This module has `add` and `sub` methods that implement addition and subtraction +* The `add` method has an arity of two + * The data type for these parameters is number + * If both parameters are numbers, the function returns the two numbers' sum, for example `5` for `(2,3)` + * Else the function returns `null` +* The `sub` method has an arity of two + * The data type for these parameters is number + * If both parameters are numbers, the function returns the difference of the second parameter subtracted from the first parameter, for example `-1` for `(2,3)` + * Else the function returns `null` diff --git a/lib/arithmetic.js b/lib/arithmetic.js index b6bb6c5..4a88464 100644 --- a/lib/arithmetic.js +++ b/lib/arithmetic.js @@ -3,7 +3,7 @@ // Export an object that has add and sub methods that implement addition and subtraction module.exports = { - add: function(num1,num2) { + add: (num1,num2) => { if(typeof num1 === 'number' && typeof num2 === 'number'){ return num1 + num2; } @@ -11,7 +11,7 @@ module.exports = { return null; } }, - sub: function(num1,num2) { + sub: (num1,num2) => { if(typeof num1 === 'number' && typeof num2 === 'number'){ return num1 - num2; }