@@ -20,15 +20,35 @@ 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 on an empty array returns an empty object" , ( ) => {
24+ expect ( tally ( [ ] ) ) . toEqual ( { } ) ;
25+ } ) ;
26+
2327// Given an empty array
2428// When passed to tally
2529// Then it should return an empty object
26- test . todo ( "tally on an empty array returns an empty object" ) ;
30+ test ( "tally on an array with duplicate items returns counts for each unique item" , ( ) => {
31+ expect ( tally ( [ "a" ] ) ) . toEqual ( { a : 1 } ) ;
32+ expect ( tally ( [ "a" , "a" , "a" ] ) ) . toEqual ( { a : 3 } ) ;
33+ expect ( tally ( [ "a" , "a" , "b" , "c" ] ) ) . toEqual ( { a : 2 , b : 1 , c : 1 } ) ;
34+ } ) ;
2735
2836// Given an array with duplicate items
2937// When passed to tally
3038// Then it should return counts for each unique item
3139
40+ test ( "tally on an array with duplicate items returns counts for each unique item" , ( ) => {
41+ expect ( tally ( [ "a" ] ) ) . toEqual ( { a : 1 } ) ;
42+ expect ( tally ( [ "a" , "a" , "a" ] ) ) . toEqual ( { a : 3 } ) ;
43+ expect ( tally ( [ "a" , "a" , "b" , "c" ] ) ) . toEqual ( { a : 2 , b : 1 , c : 1 } ) ;
44+ } ) ;
45+
46+
3247// Given an invalid input like a string
3348// When passed to tally
3449// Then it should throw an error
50+ test ( "tally on an array with duplicate items returns counts for each unique item" , ( ) => {
51+ expect ( tally ( [ "a" ] ) ) . toEqual ( { a : 1 } ) ;
52+ expect ( tally ( [ "a" , "a" , "a" ] ) ) . toEqual ( { a : 3 } ) ;
53+ expect ( tally ( [ "a" , "a" , "b" , "c" ] ) ) . toEqual ( { a : 2 , b : 1 , c : 1 } ) ;
54+ } ) ;
0 commit comments