Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more math functions #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions .idea/UnitTestingCI.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

175 changes: 175 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
"license": "MIT",
"devDependencies": {
"jest": "^22.1.4"
}
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/js6450/UnitTestingCI.git"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these URLs should point to Open-Source-Studio-at-ITP rather than js6450?

},
"bugs": {
"url": "https://github.com/js6450/UnitTestingCI/issues"
},
"homepage": "https://github.com/js6450/UnitTestingCI#readme"
}
42 changes: 42 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ function anomalyCode(x) {
return '5' + x - x;
}

var numArray = [];
var arrayLen = 10;

function setArray(arrayLen){
for(var i = 0; i < arrayLen; i++){
numArray[i] = randInt(0, 100);
}

return numArray;
}

function randInt(min, max){
return Math.round(Math.random(min, max));
}

function factorize(num){
var totalProduct = 1;

for(var i = 1; i < num + 1; i++){
totalProduct *= i;
}

return totalProduct
}

class Point3D{
constructor(x, y, z){
this.x = x;
this.y = y;
this.z = z;
}
}

function inDist(p1, p2, d){
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z) < d * d;
}

function nOfFibonacci(x) {
let n = parseInt(x, 10);
return (!n || n < 1) ? -1 : (n < 3 ? 1 : (nOfFibonacci(n-1) + nOfFibonacci(n-2)));
Expand All @@ -43,5 +80,10 @@ module.exports = {
sayHelloTo: sayHelloTo,
answer: answer,
anomalyCode: anomalyCode,
setArray: setArray,
randInt: randInt,
factorize: factorize,
Point3D: Point3D,
inDist: inDist,
nOfFibonacci: nOfFibonacci
}
37 changes: 29 additions & 8 deletions sketch.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, setArray, randInt, factorize, Point3D, inDist } = require('./sketch');
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, nOfFibonacci } = require('./sketch');
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -59,7 +60,7 @@ test('prod calculates 2 * 10 = 20', () => {

test('digital root of 265 should equal 4', () => {
expect(digital_root(265)).toBe(4);
})
});

test('Sum42 function exists', () => {
expect(sum42).toBeDefined();
Expand All @@ -71,31 +72,51 @@ test('Sum42 3 + 1 should be 46', () => {

test('Sub function exists', () => {
expect(sub).toBeDefined();
})
});

test('Sub 10 - 3 should be 7', () => {
expect(sub(10,3)).toBe(7);
})
});

test('anomalyCode function exists', () => {
expect(anomalyCode(1)).toBeDefined();
})
});

test('anomalyCode one should be 50', () => {
expect(anomalyCode(7)).toBe(50);
})
});

test('anomalyCode ten should be 500', () => {
expect(anomalyCode(78)).toBe(500);
})
});

test('anomalyCode hundred should be 5000', () => {
expect(anomalyCode(789)).toBe(5000);
})
});

test('anomalyCode thousand should be 50000', () => {
expect(anomalyCode(7891)).toBe(50000);
})
});

test('randInt generates random Integer', () => {
expect(Number.isInteger(randInt(1, 5))).toBe(true);
});

test('array length should match number of elements actually created', () =>{
expect(setArray(5).length).toBe(5);
});

test('factorize 5! should be 120', () => {
expect(factorize(5)).toBe(120);
});

test('Point3D object exists', () => {
expect(Point3D).toBeDefined();
});

test('intDist point (0, 0, 0) and (1, 1, 1) are within distance of 2', () => {
expect(inDist(new Point3D(0, 0, 0), new Point3D(1, 1, 1), 2)).toBe(true);
});

test('the 20th number of fibonacci should be 6765', () => {
expect(nOfFibonacci(20)).toBe(6765);
Expand Down