Skip to content

Commit 17d8641

Browse files
committed
added test cases to reflect the function
1 parent 8953ba6 commit 17d8641

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Sprint-2/implement/tally.test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,42 @@ const tally = require("./tally.js");
1919
// Given a function called tally
2020
// When passed an array of items
2121
// Then it should return an object containing the count for each unique item
22+
test("tally returns an object containing the count for each unique item", () => {
23+
expect(tally(["a", "a", "b", "c"])).toEqual({
24+
a: 2,
25+
b: 1,
26+
c: 1,
27+
});
28+
});
2229

2330
// Given an empty array
2431
// When passed to tally
2532
// Then it should return an empty object
26-
test.todo("tally on an empty array returns an empty object");
33+
test("tally on an empty array returns an empty object", () => {
34+
expect(tally([])).toEqual({});
35+
});
36+
37+
// Given an array with a single item
38+
// When passed to tally
39+
// Then it should return a count of 1 for that item
40+
test("tally on an array with one item returns count of 1", () => {
41+
expect(tally(["a"])).toEqual({
42+
a: 1,
43+
});
44+
});
2745

2846
// Given an array with duplicate items
2947
// When passed to tally
3048
// Then it should return counts for each unique item
49+
test("tally counts duplicate items correctly", () => {
50+
expect(tally(["a", "a", "a"])).toEqual({
51+
a: 3,
52+
});
53+
});
3154

3255
// Given an invalid input like a string
3356
// When passed to tally
3457
// Then it should throw an error
58+
test("tally throws an error for invalid input", () => {
59+
expect(() => tally("abc")).toThrow("Input must be an array");
60+
});

0 commit comments

Comments
 (0)