diff --git a/lab-nicole/.eslintignore b/lab-nicole/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-nicole/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-nicole/.eslintrc.json b/lab-nicole/.eslintrc.json new file mode 100644 index 0000000..886827f --- /dev/null +++ b/lab-nicole/.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"] + } +} diff --git a/lab-nicole/.gitignore b/lab-nicole/.gitignore new file mode 100644 index 0000000..4745950 --- /dev/null +++ b/lab-nicole/.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-nicole/index.js b/lab-nicole/index.js new file mode 100644 index 0000000..fc7450b --- /dev/null +++ b/lab-nicole/index.js @@ -0,0 +1,10 @@ +'use strict'; + +const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); + +console.log('greet module', greet); +greet('nicole'); +console.log('arithmetic module', arithmetic); +console.log(arithmetic.add(9, 3)); +console.log(arithmetic.sub(3, 1)); \ No newline at end of file diff --git a/lab-nicole/lib/arithmetic.js b/lab-nicole/lib/arithmetic.js new file mode 100644 index 0000000..88b2f65 --- /dev/null +++ b/lab-nicole/lib/arithmetic.js @@ -0,0 +1,16 @@ +'use strict'; + +module.exports = exports = {}; + +exports.add = function(a, b) { + if (arguments.length !== 2) throw new Error('there were not two arguments passed in'); + if (typeof a !== 'number' || typeof b !== 'number') return null; + return a + b; +} + + +exports.sub = function(a, b) { + if (arguments.length !== 2) throw new Error('there was not two arguments passed in'); + if (typeof a !== 'number' || typeof b !== 'number') return null; + return a - b; +} \ No newline at end of file diff --git a/lab-nicole/lib/greet.js b/lab-nicole/lib/greet.js new file mode 100644 index 0000000..554c70e --- /dev/null +++ b/lab-nicole/lib/greet.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function (name) { + if (arguments.length !== 1) throw new Error('did not receive just one argument'); + if (typeof name !== 'string') return null; + return `hello ${name}`; +} \ No newline at end of file diff --git a/lab-nicole/readme.md b/lab-nicole/readme.md new file mode 100644 index 0000000..e79be47 --- /dev/null +++ b/lab-nicole/readme.md @@ -0,0 +1,7 @@ +## Day 1 - Module Tests + +This file has 2 exported modules, the arithmetic and the greet module. + +Greet is a singular function with an arity of 1, an expected data type of string, and an expected output of printing 'hello ' plus the passed in string argument. If the argument passed in is not a string, it will return null. If there is more or less than one argument passed in, an error will be thrown with the corresponding error message. + +Arithmetic has two functions, add and sub. For both add and sub, they have an arity of two. If more or less than 2 arguments are passed in, the functions will throw an error with a corresponding error message. The data types they expect are numbers. If either argument passed is not a number, then the functions will return null. \ No newline at end of file diff --git a/lab-nicole/test/arithmetic-test.js b/lab-nicole/test/arithmetic-test.js new file mode 100644 index 0000000..98b7953 --- /dev/null +++ b/lab-nicole/test/arithmetic-test.js @@ -0,0 +1,27 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +describe('Arithmetic Module', function() { + describe('#Add', function() { + it('should return the sum of the two numbers passed in to it', function() { + assert.ok(arithmetic.add(5, 7) === 12, '5 + 7 was not equal to 12'); + assert.ok(arithmetic.add(-4, 2) === -2, '-4 and 2 did not equal -2'); + }) + it('should return null if either agument passed was not a number', function() { + assert.ok(arithmetic.add('woo', 8) === null, 'passed in a string, did not return null'); + assert.ok(arithmetic.add(2, true) === null, 'passed in a boolean, did not return null'); + }) + }) + describe('#Sub', function() { + it('should return the subtraction of the two numbers passed in to it', function () { + assert.ok(arithmetic.sub(9, 3) === 6, '9 and 3 did not equal 6'); + assert.ok(arithmetic.sub(-4, 3) === -7, '-4 and 3 did not equal -7'); + }) + it('should return null if either agument passed was not a number', function() { + assert.ok(arithmetic.sub('hi', 0) === null, 'passed in string, did not return null'); + assert.ok(arithmetic.sub(1, false) === null, 'passed in boolean, did not return null'); + }) + }) +}) \ No newline at end of file diff --git a/lab-nicole/test/greet-test.js b/lab-nicole/test/greet-test.js new file mode 100644 index 0000000..12661ba --- /dev/null +++ b/lab-nicole/test/greet-test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + describe('#Greet', function() { + it('should have one argument', function() { + assert.ok(greet.length === 1, 'number of arguments not equal to 1'); + }); + it('should return hello world', function() { + assert.ok(greet('world') === 'hello world', 'not equal to hello world'); + }); + it('should return null if input is not a string', function() { + assert.ok(greet(7) === null, 'passing function a number does not return null'); + }); + }); + +}) \ No newline at end of file