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

fixing test to use problem.js instead of solution.js #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
21 changes: 16 additions & 5 deletions w03/w3-r-sum-of-numbers/problem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Given two integers, which can be positive and negative,
/* Given two integers, which can be positive and negative,
find the sum of all the numbers between and including a and b,
and return the sum. If both numbers are equal return a or b.

Note! a and b are not ordered!

Example:
Example:
getSum(1, 0) == 1 // 1 + 0 = 1
getSum(1, 2) == 3 // 1 + 2 = 3
getSum(0, 1) == 1 // 0 + 1 = 1
Expand All @@ -14,13 +14,24 @@ getSum(-1, 2) == 2 // -1 + 0 + 1 + 2 = 2
*/

function getSum( a, b ) {
if(a === b){
return a;
}
if(b < a){
let temp = b;
b = a;
a = temp;
}
var answer = 0;
for (i = a; i <= b; i++) {
answer += i;
}
return answer;

} // END FUNCTION


module.exports = {
getSum:getSum,
attendance:"WORD UP"
}


};
26 changes: 13 additions & 13 deletions w03/w3-r-sum-of-numbers/test/r-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var expect = require("chai").expect;

var getSum = require("../solution").getSum;
console.log(getSum.toString(), "TYLRERERKJERHKEJRHKJ")
var getSum = require("../problem").getSum;
console.log(getSum.toString(), "TYLRERERKJERHKEJRHKJ");
describe("getSum warmup", function() {
it("should return the same number if a and b are equal", function () {
expect(getSum(1, 1)).to.be.equal(1)
expect(getSum(7, 7)).to.be.equal(7)
expect(getSum(2928, 2928)).to.be.equal(2928)
})
expect(getSum(1, 1)).to.be.equal(1);
expect(getSum(7, 7)).to.be.equal(7);
expect(getSum(2928, 2928)).to.be.equal(2928);
});

it("should return the addition of each number between and including a & b", function () {
expect(getSum(-1, 2)).to.be.equal(2)
expect(getSum(-10, 2)).to.be.equal(-52)
expect(getSum(77, -77)).to.be.equal(0)
expect(getSum(5, -7)).to.be.equal(-13)
expect(getSum(34554, 2)).to.be.equal(597006734)
})
})
expect(getSum(-1, 2)).to.be.equal(2);
expect(getSum(-10, 2)).to.be.equal(-52);
expect(getSum(77, -77)).to.be.equal(0);
expect(getSum(5, -7)).to.be.equal(-13);
expect(getSum(34554, 2)).to.be.equal(597006734);
});
});