From b4092626496d207b0005e0cbae21f80927ac71bb Mon Sep 17 00:00:00 2001 From: Nicholas Carignan Date: Mon, 27 Nov 2017 15:44:09 -0800 Subject: [PATCH 1/4] greet and arithmetic tests pass --- lab-nicholas/.eslintignore | 5 ++ lab-nicholas/.eslintrc | 26 ++++++++ lab-nicholas/.gitignore | 80 ++++++++++++++++++++++++ lab-nicholas/README.md | 1 + lab-nicholas/__test__/arithmetic.test.js | 32 ++++++++++ lab-nicholas/__test__/greet.test.js | 18 ++++++ lab-nicholas/lib/arithmetic.js | 17 +++++ lab-nicholas/lib/greet.js | 10 +++ lab-nicholas/package.json | 14 +++++ 9 files changed, 203 insertions(+) create mode 100644 lab-nicholas/.eslintignore create mode 100644 lab-nicholas/.eslintrc create mode 100644 lab-nicholas/.gitignore create mode 100644 lab-nicholas/README.md create mode 100644 lab-nicholas/__test__/arithmetic.test.js create mode 100644 lab-nicholas/__test__/greet.test.js create mode 100644 lab-nicholas/lib/arithmetic.js create mode 100644 lab-nicholas/lib/greet.js create mode 100644 lab-nicholas/package.json diff --git a/lab-nicholas/.eslintignore b/lab-nicholas/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-nicholas/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-nicholas/.eslintrc b/lab-nicholas/.eslintrc new file mode 100644 index 0000000..840d336 --- /dev/null +++ b/lab-nicholas/.eslintrc @@ -0,0 +1,26 @@ +{ + "env": { + "browser": true, + "node": true, + "commonjs": true, + "jest": true, + "es6": true + }, + "globals": { + "err": true, + "req": true, + "res": true, + "next": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "comma-dangle": ["error", "always-multiline"], + "semi": [ "error", "always" ] + } +} diff --git a/lab-nicholas/.gitignore b/lab-nicholas/.gitignore new file mode 100644 index 0000000..2c116a4 --- /dev/null +++ b/lab-nicholas/.gitignore @@ -0,0 +1,80 @@ + +# Created by https://www.gitignore.io/api/node,linux + +### 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 + + +# End of https://www.gitignore.io/api/node,linux diff --git a/lab-nicholas/README.md b/lab-nicholas/README.md new file mode 100644 index 0000000..f94ee80 --- /dev/null +++ b/lab-nicholas/README.md @@ -0,0 +1 @@ +# Jest Practice diff --git a/lab-nicholas/__test__/arithmetic.test.js b/lab-nicholas/__test__/arithmetic.test.js new file mode 100644 index 0000000..5e92bab --- /dev/null +++ b/lab-nicholas/__test__/arithmetic.test.js @@ -0,0 +1,32 @@ + +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); + +describe('arithmetic.js', () => { + describe('arithmetic.sum', () => { + test('arithmetic.sum should return the sum of the parameters', () => { + expect(arithmetic.sum(2, 4)).toEqual(6); + expect(arithmetic.sum(3, 7)).toEqual(10); + }); + + test('arithmetic.sum should return null if any input is NaN', () => { + expect(arithmetic.sum('', '')).toEqual(null); + expect(arithmetic.sum(3, 'pineapple')).toEqual(null); + }); + + }); + + describe('arithmetic.sub', () => { + test('arithmetic.sub should return the difference of the parameters', () => { + expect(arithmetic.sub(6, 4)).toEqual(2); + expect(arithmetic.sub(17, 7)).toEqual(10); + }); + + test('arithmetic.sub should return null if any input is NaN', () => { + expect(arithmetic.sub('', '')).toEqual(null); + expect(arithmetic.sub(3, 'pineapple')).toEqual(null); + }); + + }); +}); diff --git a/lab-nicholas/__test__/greet.test.js b/lab-nicholas/__test__/greet.test.js new file mode 100644 index 0000000..380ab26 --- /dev/null +++ b/lab-nicholas/__test__/greet.test.js @@ -0,0 +1,18 @@ +'use strict'; + +const greet = require('../lib/greet.js'); + +describe('greet.js', () => { + describe('greet.greet', () => { + test('greet.greet should return hello ', () => { + expect(greet.greet('Demi')).toEqual('Hello Demi'); + expect(greet.greet('Sam')).toEqual('Hello Sam'); + }); + + test('greet.greet should return null if error', () => { + expect(greet.greet('')).toEqual(null); + expect(greet.greet(355641)).toEqual(null); + }); + + }); +}); diff --git a/lab-nicholas/lib/arithmetic.js b/lab-nicholas/lib/arithmetic.js new file mode 100644 index 0000000..08c00f0 --- /dev/null +++ b/lab-nicholas/lib/arithmetic.js @@ -0,0 +1,17 @@ +'use strict'; + +const Arithmetic = module.exports = {}; + +Arithmetic.sum = (a, b) => { + if(typeof a !== 'number' || typeof b !== 'number'){ + return null; + } + return a+b; +}; + +Arithmetic.sub = (a, b) => { + if(typeof a !== 'number' || typeof b !== 'number' ){ + return null; + } + return a-b; +}; diff --git a/lab-nicholas/lib/greet.js b/lab-nicholas/lib/greet.js new file mode 100644 index 0000000..4396561 --- /dev/null +++ b/lab-nicholas/lib/greet.js @@ -0,0 +1,10 @@ +'use strict'; + +const Greet = module.exports = {}; + +Greet.greet = (name) => { + if(name === '' || typeof name !== 'string'){ + return null; + } + return `Hello ${name}`; +}; diff --git a/lab-nicholas/package.json b/lab-nicholas/package.json new file mode 100644 index 0000000..c11efa8 --- /dev/null +++ b/lab-nicholas/package.json @@ -0,0 +1,14 @@ +{ + "name": "lab-nicholas", + "version": "1.0.0", + "description": "jest lab", + "main": "index.js", + "scripts": { + "test": "jest" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "jest": "^21.2.1" + } +} From 31b7ce1df2579716468bbfcbc681567e620dfcf7 Mon Sep 17 00:00:00 2001 From: Nicholas Carignan Date: Mon, 27 Nov 2017 15:47:09 -0800 Subject: [PATCH 2/4] added hello world string --- lab-nicholas/__test__/greet.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lab-nicholas/__test__/greet.test.js b/lab-nicholas/__test__/greet.test.js index 380ab26..aa18ef5 100644 --- a/lab-nicholas/__test__/greet.test.js +++ b/lab-nicholas/__test__/greet.test.js @@ -7,6 +7,7 @@ describe('greet.js', () => { test('greet.greet should return hello ', () => { expect(greet.greet('Demi')).toEqual('Hello Demi'); expect(greet.greet('Sam')).toEqual('Hello Sam'); + expect(greet.greet('World')).toEqual('Hello World'); }); test('greet.greet should return null if error', () => { From 76e71015cf1569eddd9d1c58c08329e81fb75422 Mon Sep 17 00:00:00 2001 From: Nicholas Carignan Date: Tue, 5 Dec 2017 09:33:54 -0800 Subject: [PATCH 3/4] README.md added --- README.md | 53 ------------------------------------------ lab-nicholas/README.md | 9 ++++++- 2 files changed, 8 insertions(+), 54 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 61783ab..0000000 --- a/README.md +++ /dev/null @@ -1,53 +0,0 @@ -![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. -* Features without unit tests behind them will not be graded. - -## 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 -#### 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 - -#### 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. diff --git a/lab-nicholas/README.md b/lab-nicholas/README.md index f94ee80..151e922 100644 --- a/lab-nicholas/README.md +++ b/lab-nicholas/README.md @@ -1 +1,8 @@ -# Jest Practice +# arithmetic.js +##arithmetic.sum +arithmetic.sum takes in two numbers, 'a' and 'b' and returns their sum. there is input validation to make sure they are both numbers and 'null' is returned if there is an error. +##arithmetic.sub +arithmetic.sub takes in two numbers, 'a' and 'b' and returns their difference. there is input validation to make sure they are both numbers and 'null' is returned if there is an error. +#greet.js +##greet.greet +greet.greet takes in a string 'name' and returns the concatenated string 'Hello '. There is input validation to make sure 'name' is a string and not empty. It returns 'null if there is an error' From 6cfd0a2070bd998de24f74964dc3d549b44dd32c Mon Sep 17 00:00:00 2001 From: Nicholas Carignan Date: Wed, 6 Dec 2017 14:19:25 -0800 Subject: [PATCH 4/4] coolio --- lab-nicholas/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab-nicholas/README.md b/lab-nicholas/README.md index 151e922..90ef26e 100644 --- a/lab-nicholas/README.md +++ b/lab-nicholas/README.md @@ -1,5 +1,5 @@ # arithmetic.js -##arithmetic.sum +##arithmetic.sum arithmetic.sum takes in two numbers, 'a' and 'b' and returns their sum. there is input validation to make sure they are both numbers and 'null' is returned if there is an error. ##arithmetic.sub arithmetic.sub takes in two numbers, 'a' and 'b' and returns their difference. there is input validation to make sure they are both numbers and 'null' is returned if there is an error.