Skip to content

Commit 520c9fc

Browse files
authored
Add tests for tally function with various inputs
1 parent 058fc4e commit 520c9fc

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎Sprint-2/implement/tally.test.js‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,40 @@ const tally = require("./tally.js");
2020
// When passed an array of items
2121
// Then it should return an object containing the count for each unique item
2222

23+
test("returns an object containing the count for each unique item", () => {
24+
expect(tally([1, 2, 2, 3, 3, 3])).toEqual({
25+
1: 1,
26+
2: 2,
27+
3: 3,
28+
});
29+
});
30+
2331
// Given an empty array
2432
// When passed to tally
2533
// Then it should return an empty object
26-
test.todo("tally on an empty array returns an empty object");
34+
35+
test("tally on an empty array returns an empty object", () => {
36+
expect(tally([])).toEqual({});
37+
});
38+
2739

2840
// Given an array with duplicate items
2941
// When passed to tally
3042
// Then it should return counts for each unique item
3143

44+
test("counts duplicate items", () => {
45+
expect(tally(["a", "a", "b", "c"])).toEqual({
46+
a: 2,
47+
b: 1,
48+
c: 1,
49+
});
50+
});
51+
3252
// Given an invalid input like a string
3353
// When passed to tally
3454
// Then it should throw an error
55+
56+
test("throws an error for invalid input", () => {
57+
expect(() => tally("abc")).toThrow();
58+
});
59+

0 commit comments

Comments
 (0)