Skip to content

Commit f8ce3aa

Browse files
authored
Update tally.test.js
1 parent 896e52b commit f8ce3aa

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,36 @@ 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("tally counts the frequency of each unique item", () => {
24+
expect(tally(["a", "a", "b", "c"])).toEqual({
25+
a: 2,
26+
b: 1,
27+
c: 1,
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+
});
2738

2839
// Given an array with duplicate items
2940
// When passed to tally
3041
// Then it should return counts for each unique item
3142

43+
test("tally counts duplicate items correctly", () => {
44+
expect(tally(["a", "a", "a"])).toEqual({
45+
a: 3,
46+
});
47+
});
48+
3249
// Given an invalid input like a string
3350
// When passed to tally
3451
// Then it should throw an error
52+
53+
test("tally throws an error when passed invalid input", () => {
54+
expect(() => tally("a")).toThrow();
55+
});

0 commit comments

Comments
 (0)