From cf54e33a9abc027fca0f18a1bb0d43844e517c13 Mon Sep 17 00:00:00 2001 From: Shannon Dillon Date: Mon, 27 Nov 2017 15:38:38 -0800 Subject: [PATCH 1/5] write and pass tests for hello function --- lab-shannon/.eslintignore | 5 ++ lab-shannon/.eslintrc | 26 +++++++ lab-shannon/.gitignore | 121 +++++++++++++++++++++++++++++++++ lab-shannon/README.md | 1 + lab-shannon/lib/greet.js | 11 +++ lab-shannon/package.json | 15 ++++ lab-shannon/test/greet.test.js | 12 ++++ 7 files changed, 191 insertions(+) create mode 100644 lab-shannon/.eslintignore create mode 100644 lab-shannon/.eslintrc create mode 100644 lab-shannon/.gitignore create mode 100644 lab-shannon/README.md create mode 100644 lab-shannon/lib/greet.js create mode 100644 lab-shannon/package.json create mode 100644 lab-shannon/test/greet.test.js diff --git a/lab-shannon/.eslintignore b/lab-shannon/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-shannon/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-shannon/.eslintrc b/lab-shannon/.eslintrc new file mode 100644 index 0000000..840d336 --- /dev/null +++ b/lab-shannon/.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-shannon/.gitignore b/lab-shannon/.gitignore new file mode 100644 index 0000000..581450e --- /dev/null +++ b/lab-shannon/.gitignore @@ -0,0 +1,121 @@ + +# Created by https://www.gitignore.io/api/node,macos,windows,visualstudiocode + +### 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 + + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history + +### 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/node,macos,windows,visualstudiocode diff --git a/lab-shannon/README.md b/lab-shannon/README.md new file mode 100644 index 0000000..0260d94 --- /dev/null +++ b/lab-shannon/README.md @@ -0,0 +1 @@ +A program to greet users and perform simple addition/subtraction. The greet function takes one parameter of type 'string'; it returns ____. The arithmetic function takes ____ parameters of type ____; it returns ____. diff --git a/lab-shannon/lib/greet.js b/lab-shannon/lib/greet.js new file mode 100644 index 0000000..665ae0b --- /dev/null +++ b/lab-shannon/lib/greet.js @@ -0,0 +1,11 @@ +'use strict'; + +const Greet = module.exports = {}; + +Greet.hello = function(name) { + if (typeof name !== `string`){ + return `null`; + } + + return `hello ${name}` +} diff --git a/lab-shannon/package.json b/lab-shannon/package.json new file mode 100644 index 0000000..be4ac27 --- /dev/null +++ b/lab-shannon/package.json @@ -0,0 +1,15 @@ +{ + "name": "lab-shannon", + "version": "1.0.0", + "description": "lab day 1 testing greet and arithmetic functions", + "main": "index.js", + "directories": { + "lib": "lib", + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "shannon", + "license": "MIT" +} diff --git a/lab-shannon/test/greet.test.js b/lab-shannon/test/greet.test.js new file mode 100644 index 0000000..c9f90c4 --- /dev/null +++ b/lab-shannon/test/greet.test.js @@ -0,0 +1,12 @@ +'use strict'; + +const greet = require(`../lib/greet`); + +describe(`test greet.hello function`, () => { + test(`greet.hello should return 'hello {name}' when no errors are present`, () => { + expect(greet.hello(`world`)).toEqual(`hello world`); + }) + test(`if a non-string is passes as an argument to greet.hello null should be returned`, () => { + expect(greet.hello(28)).toEqual(`null`); + }) +}) From cbbdd6942d371d42e44ced4eab09863b91762ded Mon Sep 17 00:00:00 2001 From: Shannon Dillon Date: Mon, 27 Nov 2017 15:54:26 -0800 Subject: [PATCH 2/5] write and pass tests for arithmetic.add function --- lab-shannon/README.md | 2 +- lab-shannon/lib/arithmetic.js | 11 +++++++++++ lab-shannon/test/arithmetic.test.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lab-shannon/lib/arithmetic.js create mode 100644 lab-shannon/test/arithmetic.test.js diff --git a/lab-shannon/README.md b/lab-shannon/README.md index 0260d94..7c1c3db 100644 --- a/lab-shannon/README.md +++ b/lab-shannon/README.md @@ -1 +1 @@ -A program to greet users and perform simple addition/subtraction. The greet function takes one parameter of type 'string'; it returns ____. The arithmetic function takes ____ parameters of type ____; it returns ____. +A program to greet users and perform simple addition/subtraction. The greet function takes one parameter of type 'string'; it returns the string `hello` concatenated with the name argument. If the argument provided is not a valid string `null` is returned. The arithmetic add function takes two parameters of type number; it returns the sum of the numbers or `null` if one of the arguments provided is not a number. The arithmetic subtract function takes two parameters of type number; it returns the difference between the numbers or `null` if one of the arguments provided is not a number. diff --git a/lab-shannon/lib/arithmetic.js b/lab-shannon/lib/arithmetic.js new file mode 100644 index 0000000..be3a5d9 --- /dev/null +++ b/lab-shannon/lib/arithmetic.js @@ -0,0 +1,11 @@ +'use strict'; + +const Arithmetic = module.exports = {}; + +Arithmetic.add = function(num1, num2){ + if (typeof num1 !== `number` || typeof num2 !== `number`){ + return `null`; + } + + return num1 + num2; +} diff --git a/lab-shannon/test/arithmetic.test.js b/lab-shannon/test/arithmetic.test.js new file mode 100644 index 0000000..2ef1d98 --- /dev/null +++ b/lab-shannon/test/arithmetic.test.js @@ -0,0 +1,14 @@ +'use strict'; + +const arithmetic = require(`../lib/arithmetic`); + +describe(`test the arithmetic functions`, () => { + describe(`the arithmetic.add function should return the sum of the arguments provided`, () => { + test(`the arithmetic.add function should return the sum of the arguments provided`, () => { + expect(arithmetic.add(2,7)).toBe(9); + }) + test(`the arithmetic.add function should return null if one or more of the arguments provided is not a number`, () => { + expect(arithmetic.add(`pie`, 2)).toBe(`null`); + }) + }) +}); From 094981d59fc22dccf111ade62f29d98d8c000c3f Mon Sep 17 00:00:00 2001 From: Shannon Dillon Date: Mon, 27 Nov 2017 16:08:31 -0800 Subject: [PATCH 3/5] write and pass tests for arithmetic.sub --- lab-shannon/README.md | 2 +- lab-shannon/lib/arithmetic.js | 7 +++++++ lab-shannon/test/arithmetic.test.js | 14 +++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lab-shannon/README.md b/lab-shannon/README.md index 7c1c3db..a1e35c7 100644 --- a/lab-shannon/README.md +++ b/lab-shannon/README.md @@ -1 +1 @@ -A program to greet users and perform simple addition/subtraction. The greet function takes one parameter of type 'string'; it returns the string `hello` concatenated with the name argument. If the argument provided is not a valid string `null` is returned. The arithmetic add function takes two parameters of type number; it returns the sum of the numbers or `null` if one of the arguments provided is not a number. The arithmetic subtract function takes two parameters of type number; it returns the difference between the numbers or `null` if one of the arguments provided is not a number. +A program to greet users and perform simple addition/subtraction operations. The greet function takes one parameter of type 'string'; it returns the string `hello` concatenated with the string provided. If the argument provided is not a valid string `null` is returned. The arithmetic add function takes two parameters of type number; it returns the sum of the numbers or `null` if one of the arguments provided is not a number. The arithmetic subtract function takes two parameters of type number; it returns the difference between the numbers or `null` if one of the arguments provided is not a number. diff --git a/lab-shannon/lib/arithmetic.js b/lab-shannon/lib/arithmetic.js index be3a5d9..06f9b8f 100644 --- a/lab-shannon/lib/arithmetic.js +++ b/lab-shannon/lib/arithmetic.js @@ -9,3 +9,10 @@ Arithmetic.add = function(num1, num2){ return num1 + num2; } + +Arithmetic.sub = function(num1, num2){ + if (typeof num1 !== `number` || typeof num2 !== `number`){ + return `null`; + } + return num1 - num2; +} diff --git a/lab-shannon/test/arithmetic.test.js b/lab-shannon/test/arithmetic.test.js index 2ef1d98..0e28aac 100644 --- a/lab-shannon/test/arithmetic.test.js +++ b/lab-shannon/test/arithmetic.test.js @@ -3,12 +3,20 @@ const arithmetic = require(`../lib/arithmetic`); describe(`test the arithmetic functions`, () => { - describe(`the arithmetic.add function should return the sum of the arguments provided`, () => { - test(`the arithmetic.add function should return the sum of the arguments provided`, () => { + describe(`the arithmetic.add function should return the sum of the arguments provided if both arguments are valid numbers`, () => { + test(`the arithmetic.add function should return the sum of the arguments provided if both arguments are valid numbers`, () => { expect(arithmetic.add(2,7)).toBe(9); }) - test(`the arithmetic.add function should return null if one or more of the arguments provided is not a number`, () => { + test(`the arithmetic.add function should return 'null' if one or more of the arguments provided is not a number`, () => { expect(arithmetic.add(`pie`, 2)).toBe(`null`); }) }) + describe(`the arithmetic.sub function should return the difference between the arguments provided if both arguments are valid numbers`, () => { + test(`the arithmetic.sub function should return the difference between the arguments provided if both arguments are valid numbers`, () => { + expect(arithmetic.sub(9,4)).toBe(5); + }) + test(`the arithmetic.sub function should return 'null' if one or more of the arguments provided is not a number`, () => { + expect(arithmetic.sub(`potato`, 7)).toBe(`null`); + }) + }) }); From bf542183783722f2d9e8e80db3c059a21d107e14 Mon Sep 17 00:00:00 2001 From: Shannon Dillon Date: Mon, 27 Nov 2017 16:35:47 -0800 Subject: [PATCH 4/5] refactor code a bit --- lab-shannon/README.md | 8 +++++++- lab-shannon/test/arithmetic.test.js | 2 +- lab-shannon/test/greet.test.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lab-shannon/README.md b/lab-shannon/README.md index a1e35c7..28a54d0 100644 --- a/lab-shannon/README.md +++ b/lab-shannon/README.md @@ -1 +1,7 @@ -A program to greet users and perform simple addition/subtraction operations. The greet function takes one parameter of type 'string'; it returns the string `hello` concatenated with the string provided. If the argument provided is not a valid string `null` is returned. The arithmetic add function takes two parameters of type number; it returns the sum of the numbers or `null` if one of the arguments provided is not a number. The arithmetic subtract function takes two parameters of type number; it returns the difference between the numbers or `null` if one of the arguments provided is not a number. +A program to greet users and perform simple addition/subtraction operations. It contains three functions: greet.hello, arithmetic.add, and arithmetic.sub. + +The greet.hello function takes one parameter of type 'string'; it returns the string `hello` concatenated with the argument provided. If the argument provided is not a valid string `null` is returned instead. + +The arithmetic.add function takes two parameters of type number; it returns the sum of the numbers or `null` if one of the arguments provided is not a number. + +The arithmetic.sub function takes two parameters of type number; it returns the difference between the numbers or `null` if one of the arguments provided is not a number. diff --git a/lab-shannon/test/arithmetic.test.js b/lab-shannon/test/arithmetic.test.js index 0e28aac..584601c 100644 --- a/lab-shannon/test/arithmetic.test.js +++ b/lab-shannon/test/arithmetic.test.js @@ -16,7 +16,7 @@ describe(`test the arithmetic functions`, () => { expect(arithmetic.sub(9,4)).toBe(5); }) test(`the arithmetic.sub function should return 'null' if one or more of the arguments provided is not a number`, () => { - expect(arithmetic.sub(`potato`, 7)).toBe(`null`); + expect(arithmetic.sub(`sweet potato`, 7)).toBe(`null`); }) }) }); diff --git a/lab-shannon/test/greet.test.js b/lab-shannon/test/greet.test.js index c9f90c4..f8ba366 100644 --- a/lab-shannon/test/greet.test.js +++ b/lab-shannon/test/greet.test.js @@ -6,7 +6,7 @@ describe(`test greet.hello function`, () => { test(`greet.hello should return 'hello {name}' when no errors are present`, () => { expect(greet.hello(`world`)).toEqual(`hello world`); }) - test(`if a non-string is passes as an argument to greet.hello null should be returned`, () => { + test(`if a non-string is passed as an argument to greet.hello 'null' should be returned`, () => { expect(greet.hello(28)).toEqual(`null`); }) }) From cee35100d86fb86bf5f5e179c33b7d591155b1d6 Mon Sep 17 00:00:00 2001 From: Shannon Dillon Date: Tue, 28 Nov 2017 13:59:53 -0800 Subject: [PATCH 5/5] change string 'null' to actual value null --- lab-shannon/lib/arithmetic.js | 4 ++-- lab-shannon/lib/greet.js | 2 +- lab-shannon/test/arithmetic.test.js | 4 ++-- lab-shannon/test/greet.test.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lab-shannon/lib/arithmetic.js b/lab-shannon/lib/arithmetic.js index 06f9b8f..c8198e7 100644 --- a/lab-shannon/lib/arithmetic.js +++ b/lab-shannon/lib/arithmetic.js @@ -4,7 +4,7 @@ const Arithmetic = module.exports = {}; Arithmetic.add = function(num1, num2){ if (typeof num1 !== `number` || typeof num2 !== `number`){ - return `null`; + return null; } return num1 + num2; @@ -12,7 +12,7 @@ Arithmetic.add = function(num1, num2){ Arithmetic.sub = function(num1, num2){ if (typeof num1 !== `number` || typeof num2 !== `number`){ - return `null`; + return null; } return num1 - num2; } diff --git a/lab-shannon/lib/greet.js b/lab-shannon/lib/greet.js index 665ae0b..2b9b242 100644 --- a/lab-shannon/lib/greet.js +++ b/lab-shannon/lib/greet.js @@ -4,7 +4,7 @@ const Greet = module.exports = {}; Greet.hello = function(name) { if (typeof name !== `string`){ - return `null`; + return null; } return `hello ${name}` diff --git a/lab-shannon/test/arithmetic.test.js b/lab-shannon/test/arithmetic.test.js index 584601c..a0efce9 100644 --- a/lab-shannon/test/arithmetic.test.js +++ b/lab-shannon/test/arithmetic.test.js @@ -8,7 +8,7 @@ describe(`test the arithmetic functions`, () => { expect(arithmetic.add(2,7)).toBe(9); }) test(`the arithmetic.add function should return 'null' if one or more of the arguments provided is not a number`, () => { - expect(arithmetic.add(`pie`, 2)).toBe(`null`); + expect(arithmetic.add(`pie`, 2)).toBe(null); }) }) describe(`the arithmetic.sub function should return the difference between the arguments provided if both arguments are valid numbers`, () => { @@ -16,7 +16,7 @@ describe(`test the arithmetic functions`, () => { expect(arithmetic.sub(9,4)).toBe(5); }) test(`the arithmetic.sub function should return 'null' if one or more of the arguments provided is not a number`, () => { - expect(arithmetic.sub(`sweet potato`, 7)).toBe(`null`); + expect(arithmetic.sub(`sweet potato`, 7)).toBe(null); }) }) }); diff --git a/lab-shannon/test/greet.test.js b/lab-shannon/test/greet.test.js index f8ba366..af5c901 100644 --- a/lab-shannon/test/greet.test.js +++ b/lab-shannon/test/greet.test.js @@ -7,6 +7,6 @@ describe(`test greet.hello function`, () => { expect(greet.hello(`world`)).toEqual(`hello world`); }) test(`if a non-string is passed as an argument to greet.hello 'null' should be returned`, () => { - expect(greet.hello(28)).toEqual(`null`); + expect(greet.hello(28)).toEqual(null); }) })