31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
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);
|
|
});
|
|
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);
|
|
});
|
|
});
|