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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.idea/
42 changes: 26 additions & 16 deletions sketch.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
function sum(a, b) {
return a + b;
return a + b;
}

function sayHelloTo(username){
return "Hello, " + username + "!";
function sayHelloTo(username) {
return "Hello, " + username + "!";
}

function sub(a, b){
return a - b;
function sub(a, b) {
return a - b;
}

function prod(a, b) {
return a * b;
return a * b;
}

function answer() {
return 42;
return 42;
}

function digital_root(n) {
return (n-1)%9+1;
return (n - 1) % 9 + 1;
}

function sum42(a, b) {
return a + b + 42;
return a + b + 42;
}

function findGcd(a, b) {
if (!b) {
return a;
}

return findGcd(b, a % b);
}

module.exports = {
sum: sum,
sub: sub,
prod: prod,
sum42: sum42,
digital_root: digital_root,
hello: sayHelloTo,
answer: answer
sum: sum,
sub: sub,
prod: prod,
sum42: sum42,
digital_root: digital_root,
hello: sayHelloTo,
answer: answer,
gcd: findGcd
}
52 changes: 7 additions & 45 deletions sketch.test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,21 @@
const { sum, prod, digital_root, sum42 } = require('./sketch');
const {sum, prod, digital_root, sum42, gcd} = require('./sketch');

// test('adds 1 + 2 to equal 3', () => {
// expect(sum(1, 2)).toBe(3);
// });

/**
* Sum to be defined
*/

test('Sum function exists', () => {
expect(sum).toBeDefined();
});

test('adds 1 + 2 to equal 3', sumTest);

function sumTest() {
expect(sum(1, 2)).toBe(3);
expect(sum(1, 2)).toBe(3);
}

function helloTest() {
expect(sayHelloTo("Dan")).toBe("Hello, Dan!");
expect(sayHelloTo("Dan")).toBe("Hello, Dan!");
}

/**
* Prod to be defined
*/

test('Prod function exists',()=>{
expect(prod).toBeDefined();
});

/**
* prod function output
*/

test('prod calculates 2 * 10 = 20', () => {
expect(prod(2, 10)).toBe(20);
});

/**
* Digital Root to be defined
*/

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

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

test('Sum42 function exists', () => {
expect(sum42).toBeDefined();
});
test('GCD of 40 and 20', gcdSimpleTest);

test('Sum42 3 + 1 should be 46', () => {
expect(sum42(3, 1)).toBe(46);
});
function gcdSimpleTest() {
expect(gcd(20, 40)).toBe(20);
}