CS2613/tests/Q2/spec/objectSum.spec.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-10-26 10:10:09 -03:00
let sum=require ("../objectSum.js");
describe("objectSum",
function() {
it("List of numbers",
function() {
let obj = [1, 2, 3]
expect(sum.objectSum(obj)).toBe(6);
});
it("Skip non numbers",
function() {
let obj = [1, 2, "jellyfish", 3]
expect(sum.objectSum(obj)).toBe(6);
});
it("Recursive arrays",
function() {
let obj = [1, 2, [-6, 2, -2], 3]
expect(sum.objectSum(obj)).toBe(0);
2022-10-26 10:18:05 -03:00
});
it("Lists",
function() {
let obj = {a: 1, b: 2, c: 3}
expect(sum.objectSum(obj)).toBe(6);
});
it("Recursive lists",
function() {
let obj = [1, 2, {thing: [-6, -12], other: 6}]
expect(sum.objectSum(obj)).toBe(-9);
});
2022-10-26 10:10:09 -03:00
});