From 2b9cdf054b630d52aa88ad926da00e9a7b718067 Mon Sep 17 00:00:00 2001 From: Brian Bixby Date: Mon, 12 Feb 2018 17:45:21 -0800 Subject: [PATCH 1/3] initial commit --- package-lock.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} From ff6f4a088b38ca589ac98092ea729a750c5b4cab Mon Sep 17 00:00:00 2001 From: Brian Bixby Date: Mon, 12 Feb 2018 19:42:57 -0800 Subject: [PATCH 2/3] all tests are done, just need read me --- lab-brian/.eslintignore | 5 ++ lab-brian/.eslintrc.json | 27 ++++++ lab-brian/.gitignore | 145 ++++++++++++++++++++++++++++++ lab-brian/README.md | 2 + lab-brian/index.js | 7 ++ lab-brian/lib/arithmetic.js | 15 ++++ lab-brian/lib/greet.js | 7 ++ lab-brian/test/arithmetic-test.js | 57 ++++++++++++ lab-brian/test/greet-test.js | 23 +++++ package-lock.json | 3 - 10 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 lab-brian/.eslintignore create mode 100644 lab-brian/.eslintrc.json create mode 100644 lab-brian/.gitignore create mode 100644 lab-brian/README.md create mode 100644 lab-brian/index.js create mode 100644 lab-brian/lib/arithmetic.js create mode 100644 lab-brian/lib/greet.js create mode 100644 lab-brian/test/arithmetic-test.js create mode 100644 lab-brian/test/greet-test.js delete mode 100644 package-lock.json diff --git a/lab-brian/.eslintignore b/lab-brian/.eslintignore new file mode 100644 index 0000000..82ff623 --- /dev/null +++ b/lab-brian/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* \ No newline at end of file diff --git a/lab-brian/.eslintrc.json b/lab-brian/.eslintrc.json new file mode 100644 index 0000000..b96d606 --- /dev/null +++ b/lab-brian/.eslintrc.json @@ -0,0 +1,27 @@ +{ + "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" ], + "linebreak-style": ["error", "unix"] + } +} \ No newline at end of file diff --git a/lab-brian/.gitignore b/lab-brian/.gitignore new file mode 100644 index 0000000..4745950 --- /dev/null +++ b/lab-brian/.gitignore @@ -0,0 +1,145 @@ +# 401 JS +db +**.env +temp +build + +# Created by https://www.gitignore.io/api/vim,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 + +### 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/vim,osx,node,linux,windows diff --git a/lab-brian/README.md b/lab-brian/README.md new file mode 100644 index 0000000..eba7780 --- /dev/null +++ b/lab-brian/README.md @@ -0,0 +1,2 @@ +### Documentation +In your README.md file, describe the exported values of each module defined in your `lib` directory. Every function description should include it's airty (expected number of parameters), the expected data for each parameter (data-type and limitations), and the expected output behavior (for both valid and invalid use). Feel free to include any additional information that you would like. \ No newline at end of file diff --git a/lab-brian/index.js b/lab-brian/index.js new file mode 100644 index 0000000..0cc3eb5 --- /dev/null +++ b/lab-brian/index.js @@ -0,0 +1,7 @@ +'use strict'; + +// const greet = require('./lib/greet.js'); +// const arithmetic = require('./lib/arithmetic.js'); + +// greet('brian'); +// arithmetic(2); \ No newline at end of file diff --git a/lab-brian/lib/arithmetic.js b/lab-brian/lib/arithmetic.js new file mode 100644 index 0000000..2b058ab --- /dev/null +++ b/lab-brian/lib/arithmetic.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = exports = {}; + +exports.add = function(a,b) { + if(!a || !b) throw new Error('parameter not provided'); + if(typeof a !== 'number' || typeof b !== 'number') return null; + return a+b; +}; + +exports.sub = function(a,b) { + if(!a || !b) throw new Error('parameter not provided'); + if(typeof a !== 'number' || typeof b !== 'number') return null; + return a-b; +}; \ No newline at end of file diff --git a/lab-brian/lib/greet.js b/lab-brian/lib/greet.js new file mode 100644 index 0000000..0c6f96a --- /dev/null +++ b/lab-brian/lib/greet.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function(name) { + if(!name) throw new Error('name not provided'); + if(typeof name !== 'string') return null; + return `hello ${name}`; +}; \ No newline at end of file diff --git a/lab-brian/test/arithmetic-test.js b/lab-brian/test/arithmetic-test.js new file mode 100644 index 0000000..b63e77a --- /dev/null +++ b/lab-brian/test/arithmetic-test.js @@ -0,0 +1,57 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +describe('Arithmetic Module', function() { + describe('#add', function() { + it('should throw a missing a parameter error', function() { + assert.throws(function() { + arithmetic.add(7); + }, 'error not thrown'); + }); + + it('should throw a missing a parameter error', function() { + assert.throws(function() { + arithmetic.add(); + }, 'error not thrown'); + }); + + it('it should return null', function() { + var result = arithmetic.add(5, '5'); + assert.ok(result === null, 'not equal to null'); + }); + + it('it should return 10', function() { + var result = arithmetic.add(5, 5); + assert.ok(result === 10, 'not equal to 10'); + }); + + }); + + describe('#sub', function() { + it('should throw a missing parameter error', function() { + assert.throws(function() { + arithmetic.sub(5); + }, 'error not thrown'); + }); + + it('should throw a missing parameter error', function() { + assert.throws(function() { + arithmetic.sub(); + }, 'error not thrown'); + }); + + it('it should return null', function() { + var result = arithmetic.sub(5, '5'); + assert.ok(result === null, 'not equal to null'); + }); + + it('it should return 10', function() { + var result = arithmetic.sub(15, 5); + assert.ok(result === 10, 'not equal to 10'); + }); + + }); + +}); \ No newline at end of file diff --git a/lab-brian/test/greet-test.js b/lab-brian/test/greet-test.js new file mode 100644 index 0000000..936565d --- /dev/null +++ b/lab-brian/test/greet-test.js @@ -0,0 +1,23 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + it('it should return null', function() { + var result = greet(5); + assert.ok(result === null, 'not equal to null'); + }); + + it('it should return hello world', function() { + var result = greet('world'); + assert.ok(result === 'hello world', 'not equal to hello world'); + }); + + it('should throw a missing name error', function() { + assert.throws(function() { + greet(); + }, 'error not thrown'); + }); + +}); diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 48e341a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "lockfileVersion": 1 -} From bca6933ac2425bc2f85f4e6de0f68f83bd6a33d0 Mon Sep 17 00:00:00 2001 From: Brian Bixby Date: Mon, 12 Feb 2018 19:59:46 -0800 Subject: [PATCH 3/3] done --- lab-brian/README.md | 12 +++++++++++- lab-brian/index.js | 9 +++++---- lab-brian/lib/arithmetic.js | 4 ++-- lab-brian/lib/greet.js | 3 ++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lab-brian/README.md b/lab-brian/README.md index eba7780..d893db7 100644 --- a/lab-brian/README.md +++ b/lab-brian/README.md @@ -1,2 +1,12 @@ ### Documentation -In your README.md file, describe the exported values of each module defined in your `lib` directory. Every function description should include it's airty (expected number of parameters), the expected data for each parameter (data-type and limitations), and the expected output behavior (for both valid and invalid use). Feel free to include any additional information that you would like. \ No newline at end of file +In your README.md file, describe the exported values of each module defined in your `lib` directory. Every function description should include it's airty (expected number of parameters), the expected data for each parameter (data-type and limitations), and the expected output behavior (for both valid and invalid use). Feel free to include any additional information that you would like. + + +#Questions +I have 2 exported files from my lib directory and 3 exported functions. + +Greet has an airity of 1 with a expected input data-type of string. The expected output data-type is a string (hello plus the input string) if there is a valid input of a string, if there is no input parameter then an error will be thrown and if the input type is not a string then the function will return a null value. + +Arithmetic.add has an airity of 2 with expected input data-types of integers. The expected output data-type is an integer(the sum of both parameters) if there is valid inputs of integers, if there is an incorrect number of input parameters then an error will be thrown and if either input type is not an integer then the function will return a null value. + +Arithmetic.sub has an airity of 2 with expected input data-types of integers. The expected output data-type is an integer(the difference of parameter a - parameter b) if there is valid inputs of integers, if there is an incorrect number of input parameters then an error will be thrown and if either input type is not an integer then the function will return a null value. \ No newline at end of file diff --git a/lab-brian/index.js b/lab-brian/index.js index 0cc3eb5..f89ae62 100644 --- a/lab-brian/index.js +++ b/lab-brian/index.js @@ -1,7 +1,8 @@ 'use strict'; -// const greet = require('./lib/greet.js'); -// const arithmetic = require('./lib/arithmetic.js'); +const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); -// greet('brian'); -// arithmetic(2); \ No newline at end of file +console.log(greet('brian')); +// console.log(arithmetic.add(2, 4, 6)); +console.log(arithmetic.sub(2, 4)); \ No newline at end of file diff --git a/lab-brian/lib/arithmetic.js b/lab-brian/lib/arithmetic.js index 2b058ab..067e3aa 100644 --- a/lab-brian/lib/arithmetic.js +++ b/lab-brian/lib/arithmetic.js @@ -3,13 +3,13 @@ module.exports = exports = {}; exports.add = function(a,b) { - if(!a || !b) throw new Error('parameter not provided'); + if(arguments.length !== 2) throw new Error('parameter not provided'); if(typeof a !== 'number' || typeof b !== 'number') return null; return a+b; }; exports.sub = function(a,b) { - if(!a || !b) throw new Error('parameter not provided'); + if(arguments.length !== 2) throw new Error('parameter not provided'); if(typeof a !== 'number' || typeof b !== 'number') return null; return a-b; }; \ No newline at end of file diff --git a/lab-brian/lib/greet.js b/lab-brian/lib/greet.js index 0c6f96a..599e3f3 100644 --- a/lab-brian/lib/greet.js +++ b/lab-brian/lib/greet.js @@ -1,7 +1,8 @@ 'use strict'; module.exports = function(name) { - if(!name) throw new Error('name not provided'); + if(arguments.length !== 1) throw new Error('name not provided'); if(typeof name !== 'string') return null; + return `hello ${name}`; }; \ No newline at end of file