Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lab-shannon/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
26 changes: 26 additions & 0 deletions lab-shannon/.eslintrc
Original file line number Diff line number Diff line change
@@ -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" ]
}
}
121 changes: 121 additions & 0 deletions lab-shannon/.gitignore
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions lab-shannon/README.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions lab-shannon/lib/arithmetic.js
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions lab-shannon/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const Greet = module.exports = {};

Greet.hello = function(name) {
if (typeof name !== `string`){
return null;
}

return `hello ${name}`
}
15 changes: 15 additions & 0 deletions lab-shannon/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
22 changes: 22 additions & 0 deletions lab-shannon/test/arithmetic.test.js
Original file line number Diff line number Diff line change
@@ -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);
})
})
});
12 changes: 12 additions & 0 deletions lab-shannon/test/greet.test.js
Original file line number Diff line number Diff line change
@@ -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);
})
})