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..28a54d0 --- /dev/null +++ b/lab-shannon/README.md @@ -0,0 +1,7 @@ +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/lib/arithmetic.js b/lab-shannon/lib/arithmetic.js new file mode 100644 index 0000000..c8198e7 --- /dev/null +++ b/lab-shannon/lib/arithmetic.js @@ -0,0 +1,18 @@ +'use strict'; + +const Arithmetic = module.exports = {}; + +Arithmetic.add = function(num1, num2){ + if (typeof num1 !== `number` || typeof num2 !== `number`){ + return null; + } + + 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/lib/greet.js b/lab-shannon/lib/greet.js new file mode 100644 index 0000000..2b9b242 --- /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/arithmetic.test.js b/lab-shannon/test/arithmetic.test.js new file mode 100644 index 0000000..a0efce9 --- /dev/null +++ b/lab-shannon/test/arithmetic.test.js @@ -0,0 +1,22 @@ +'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 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`, () => { + 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(`sweet potato`, 7)).toBe(null); + }) + }) +}); diff --git a/lab-shannon/test/greet.test.js b/lab-shannon/test/greet.test.js new file mode 100644 index 0000000..af5c901 --- /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 passed as an argument to greet.hello 'null' should be returned`, () => { + expect(greet.hello(28)).toEqual(null); + }) +})