From 9f2b10ef07af0678ace8abb81e2f1f60de39cd37 Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 15:51:22 -0700 Subject: [PATCH 1/6] getting my file set up --- .eslintignore | 1 + .eslintrc | 35 ++++++++++++++++++++++++ .gitignore | 68 +++++++++++++++++++++++++++++++++++++++++++++++ __test__/greet.js | 0 index.js | 0 lib/greet.js | 0 6 files changed, 104 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 __test__/greet.js create mode 100644 index.js create mode 100644 lib/greet.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..4b63a5d --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +**/*/vendor/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..90447e4 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,35 @@ +{ + "globals" : { + "rawData": true, + "app": true, + "Handlebars": true, + "page": true, + "$": true, + "marked": true, + "hljs": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 6, + "ecmaFeatures": {"impliedStrict": true} + }, + "env": { + "browser": true, + "jquery": true, + "node": true, + "es6": true + }, + "rules": { + "semi": [2, "always"], + "eqeqeq": ["error", "always"], + "no-template-curly-in-string": "error", + "no-console": "off", + "no-undefined": "off", + "indent": ["error", 2], + "quotes": ["warn", "single", {"allowTemplateLiterals": true}], + "no-multi-spaces": ["warn", {"exceptions": { "VariableDeclarator": true }}], + "no-trailing-spaces": "warn", + "new-cap": "warn", + "no-redeclare": ["error", { "builtinGlobals": true }] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3583e8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +# Created by https://www.gitignore.io/api/osx,linux,node,vim + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +### 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-* + + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ + +# auto-generated tag files +tags + +###### Personal +.tern-project diff --git a/__test__/greet.js b/__test__/greet.js new file mode 100644 index 0000000..e69de29 diff --git a/index.js b/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..e69de29 From 039472a9459926e83d5a30139bbcce2078f18e1f Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 16:49:25 -0700 Subject: [PATCH 2/6] finished my arithmetic and greet test --- README.md | 51 -------------------------- __test__/arithmetic.test.js | 35 ++++++++++++++++++ __test__/greet.test.js | 19 ++++++++++ index.js | 8 ++++ __test__/greet.js => lib/arithmetic.js | 0 lib/greet.js | 8 ++++ package.json | 23 ++++++++++++ 7 files changed, 93 insertions(+), 51 deletions(-) create mode 100644 __test__/arithmetic.test.js create mode 100644 __test__/greet.test.js rename __test__/greet.js => lib/arithmetic.js (100%) create mode 100644 package.json diff --git a/README.md b/README.md index 328a88c..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,52 +1 @@ -![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem -=== -## Submission Instructions -* Work in a fork of this repository -* Work in a branch on your fork -* Write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` -* Open a pull request to this repository -* Submit on canvas a question and observation, how long you spent, and a link to your pull request - -## Resources -* [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) -* [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) -* [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) - -## Configuration -Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files. -* **README.md** - contains documentation -* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file -* **.eslintrc** - contains the course linter configuratoin -* **.eslintignore** - contains the course linter ignore configuration -* **lib/** - contains module definitions -* **__test__/** - contains unit tests - -## Feature Tasks -#### Greet Module -Create a NodeJS module in the lib/ directory named `greet.js` that exports a single function. -* The `greet` function should have a single parameter (arity of one) that should expect a string as it's input -* The `greet` function should return the input name, concatenated with "hello ": eg. ("hello susan") -* The `greet` function should return `null` if the input is not a string - -#### Arithmetic Module -Create a NodeJS module in the lib/ directory named `arithmetic.js` that exports an object. This module should have `add` and `sub` methods that implament addition and subtraction. -* The `add` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the sum of the 2 numbers -* The `sub` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the second paramiter subtracted from the first paramiter - -## Testing -#### Greet Module Tests -* Write a test that expects the greet module to return `null` when you supply non string values -* Write a test the expects the greet module to return `'hello world'` - * This should happen when invoked with `'world'` as the first argument - -#### Arithmetic Module Tests -* Test each method for proper use (invoded with number arguments) -* Test each method for inproper use (invoded with one or more non-numner arguments) - -## Documentation -In your README.md describe the exported values of each module defined in your lib/ directory. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md. diff --git a/__test__/arithmetic.test.js b/__test__/arithmetic.test.js new file mode 100644 index 0000000..cca8595 --- /dev/null +++ b/__test__/arithmetic.test.js @@ -0,0 +1,35 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); + +// arithmetic.add() +test('arithmetic.add(5, 3) should return 8', () => { + let result = arithmetic.add(5, 3); + expect(result).toEqual(8); +}); + +test('arithmetic.add(5, "3") should return null', () => { + let result = arithmetic.add(5, '3'); + expect(result).toEqual(null); +}); + +test('arithmetic.add("5", 3) should return null', () => { + let result = arithmetic.add('5', 3); + expect(result).toEqual(null); +}); + +// arithmetic.sub() +test('arithmetic.sub(5, 3) should return 2', () => { + let result = arithmetic.sub(5, 3); + expect(result).toEqual(2); +}); + +test('arithmetic.sub(5, "3") should return null', () => { + let result = arithmetic.sub(5, '3'); + expect(result).toEqual(null); +}); + +test('arithmetic.sub("5", 3) should return null', () => { + let result = arithmetic.sub('5', 3); + expect(result).toEqual(null); +}); \ No newline at end of file diff --git a/__test__/greet.test.js b/__test__/greet.test.js new file mode 100644 index 0000000..8a7a5fb --- /dev/null +++ b/__test__/greet.test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greet = require('../lib/greet.js'); + +test('greet() should return null', () => { + let result = greet(); + expect(result).toEqual(null); +}); + +test('greet(6) should return null', () => { + let result = greet(6); + expect(result).toEqual(null); +}); + +test('greet(\'ron\') should return "hello ron"', () => { + let result = greet('ron'); + expect(result).toEqual('hello ron'); +}); + diff --git a/index.js b/index.js index e69de29..27cec62 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,8 @@ +'use strict'; + +const greet = require('./lib/greet.js'); + +console.log(greet()); +console.log(greet('ron')); + + diff --git a/__test__/greet.js b/lib/arithmetic.js similarity index 100% rename from __test__/greet.js rename to lib/arithmetic.js diff --git a/lib/greet.js b/lib/greet.js index e69de29..1e59aaf 100644 --- a/lib/greet.js +++ b/lib/greet.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = (name) => { + if (typeof name === 'string') + return `hello ${name}`; + else + return null; +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6550679 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "01-node-ecosystem", + "version": "1.0.0", + "description": "First lab of 401", + "main": "index.js", + "dependencies": { + "jest": "^21.0.2" + }, + "devDependencies": {}, + "scripts": { + "test": "jest --runInBand" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ronbarrantes/01-node-ecosystem.git" + }, + "author": "Ron Barrantes", + "license": "MIT", + "bugs": { + "url": "https://github.com/ronbarrantes/01-node-ecosystem/issues" + }, + "homepage": "https://github.com/ronbarrantes/01-node-ecosystem#readme" +} From b223b7ff8bdb693be7c9bd95bf89695556b99689 Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 17:06:20 -0700 Subject: [PATCH 3/6] arithmetic functions working --- index.js | 7 +++++++ lib/arithmetic.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/index.js b/index.js index 27cec62..7a8428d 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,15 @@ 'use strict'; const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); console.log(greet()); console.log(greet('ron')); +console.log(arithmetic.add(1,2)); +console.log(arithmetic.sub(1,2)); + +console.log(arithmetic.add(1,'2')); +console.log(arithmetic.sub('1',2)); + diff --git a/lib/arithmetic.js b/lib/arithmetic.js index e69de29..d03f285 100644 --- a/lib/arithmetic.js +++ b/lib/arithmetic.js @@ -0,0 +1,20 @@ +'use strict'; + +const arithmetic = {}; + +arithmetic.add = (a, b) => { + if (typeof a === 'number' && typeof b === 'number') + return a + b; + else + return null; +}; + + +arithmetic.sub = (a, b) => { + if (typeof a === 'number' && typeof b === 'number') + return a - b; + else + return null; +}; + +module.exports = arithmetic; \ No newline at end of file From a8c3d3815659cc73ecaa21268e9a0752a071d65f Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 17:38:43 -0700 Subject: [PATCH 4/6] finish up the README.md --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 8b13789..41079ea 100644 --- a/README.md +++ b/README.md @@ -1 +1,44 @@ +# 01 Node Ecosystem +Greet and Arithmetic are functions that facilitate adding or subtracting two numbers or greeting someone. + +## how to use + +Please remember to require `greet` and `arithmetic` from the `lib/` directory at the top of your `index.js` + +### greet() +- takes in an argument as a string, and returns `hello + ` +- if argument is not a string or null it will return `null` + +``` +console.log(greet('world')); +console.log(greet(6)); + +>> hello world +>> null +``` + + +### arithmetic.add() +- takes in only two numbers as it's arguments and returns the sum of the numbers +- if any argument is not a number it will return `null` + +``` +console.log(arithmetic.add(2, 3)); +console.log(arithmetic.add('2', '3')); + +>> 5 +>> null +``` + +### arithmetic.sub() +- takes in only two numbers as it's arguments and returns the difference of the numbers +- if any argument is not a number it will return `null` + +``` +console.log(arithmetic.sub(9, 3)); +console.log(arithmetic.sub('9', '3')); + +>> 6 +>> null +``` \ No newline at end of file From 36d4d6522c5f3c7fae0e9981d7f85935fca6287d Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 17:46:43 -0700 Subject: [PATCH 5/6] redid file structure --- .eslintignore => lab-ron/.eslintignore | 0 .eslintrc => lab-ron/.eslintrc | 0 .gitignore => lab-ron/.gitignore | 0 README.md => lab-ron/README.md | 0 {__test__ => lab-ron/__test__}/arithmetic.test.js | 0 {__test__ => lab-ron/__test__}/greet.test.js | 0 index.js => lab-ron/index.js | 0 {lib => lab-ron/lib}/arithmetic.js | 0 {lib => lab-ron/lib}/greet.js | 0 package.json => lab-ron/package.json | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename .eslintignore => lab-ron/.eslintignore (100%) rename .eslintrc => lab-ron/.eslintrc (100%) rename .gitignore => lab-ron/.gitignore (100%) rename README.md => lab-ron/README.md (100%) rename {__test__ => lab-ron/__test__}/arithmetic.test.js (100%) rename {__test__ => lab-ron/__test__}/greet.test.js (100%) rename index.js => lab-ron/index.js (100%) rename {lib => lab-ron/lib}/arithmetic.js (100%) rename {lib => lab-ron/lib}/greet.js (100%) rename package.json => lab-ron/package.json (100%) diff --git a/.eslintignore b/lab-ron/.eslintignore similarity index 100% rename from .eslintignore rename to lab-ron/.eslintignore diff --git a/.eslintrc b/lab-ron/.eslintrc similarity index 100% rename from .eslintrc rename to lab-ron/.eslintrc diff --git a/.gitignore b/lab-ron/.gitignore similarity index 100% rename from .gitignore rename to lab-ron/.gitignore diff --git a/README.md b/lab-ron/README.md similarity index 100% rename from README.md rename to lab-ron/README.md diff --git a/__test__/arithmetic.test.js b/lab-ron/__test__/arithmetic.test.js similarity index 100% rename from __test__/arithmetic.test.js rename to lab-ron/__test__/arithmetic.test.js diff --git a/__test__/greet.test.js b/lab-ron/__test__/greet.test.js similarity index 100% rename from __test__/greet.test.js rename to lab-ron/__test__/greet.test.js diff --git a/index.js b/lab-ron/index.js similarity index 100% rename from index.js rename to lab-ron/index.js diff --git a/lib/arithmetic.js b/lab-ron/lib/arithmetic.js similarity index 100% rename from lib/arithmetic.js rename to lab-ron/lib/arithmetic.js diff --git a/lib/greet.js b/lab-ron/lib/greet.js similarity index 100% rename from lib/greet.js rename to lab-ron/lib/greet.js diff --git a/package.json b/lab-ron/package.json similarity index 100% rename from package.json rename to lab-ron/package.json From 88ac0a80ac6432c37d38c76a525d22cc63161684 Mon Sep 17 00:00:00 2001 From: Ron Barrantes Date: Mon, 11 Sep 2017 17:49:40 -0700 Subject: [PATCH 6/6] readded the original README.md --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..328a88c --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem +=== + +## Submission Instructions +* Work in a fork of this repository +* Work in a branch on your fork +* Write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` +* Open a pull request to this repository +* Submit on canvas a question and observation, how long you spent, and a link to your pull request + +## Resources +* [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) +* [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) +* [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) + +## Configuration +Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files. +* **README.md** - contains documentation +* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file +* **.eslintrc** - contains the course linter configuratoin +* **.eslintignore** - contains the course linter ignore configuration +* **lib/** - contains module definitions +* **__test__/** - contains unit tests + +## Feature Tasks +#### Greet Module +Create a NodeJS module in the lib/ directory named `greet.js` that exports a single function. +* The `greet` function should have a single parameter (arity of one) that should expect a string as it's input +* The `greet` function should return the input name, concatenated with "hello ": eg. ("hello susan") +* The `greet` function should return `null` if the input is not a string + +#### Arithmetic Module +Create a NodeJS module in the lib/ directory named `arithmetic.js` that exports an object. This module should have `add` and `sub` methods that implament addition and subtraction. +* The `add` method should have an arity of two (define two paramiters) + * If either parameter is a non-number the function should return null + * Else return the sum of the 2 numbers +* The `sub` method should have an arity of two (define two paramiters) + * If either parameter is a non-number the function should return null + * Else return the second paramiter subtracted from the first paramiter + +## Testing +#### Greet Module Tests +* Write a test that expects the greet module to return `null` when you supply non string values +* Write a test the expects the greet module to return `'hello world'` + * This should happen when invoked with `'world'` as the first argument + +#### Arithmetic Module Tests +* Test each method for proper use (invoded with number arguments) +* Test each method for inproper use (invoded with one or more non-numner arguments) + +## Documentation +In your README.md describe the exported values of each module defined in your lib/ directory. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md.