@@ -19,16 +19,43 @@ const tally = require("./tally.js");
19
19
// Given a function called tally
20
20
// When passed an array of items
21
21
// Then it should return an object containing the count for each unique item
22
+ describe ( "edge cases of the tally function" , ( ) => {
23
+ test ( "When passed an array of items as a parameter into tally" , ( ) => {
24
+ const currentOutput = tally ( [ 1 , 2 , 4 , 5 , 6 ] ) ;
25
+ const targetOutput = { 1 : 1 , 2 : 1 , 4 : 1 , 5 : 1 , 6 : 1 } ;
26
+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
27
+ } ) ;
28
+ } ) ;
22
29
23
30
// Given an empty array
24
31
// When passed to tally
25
32
// Then it should return an empty object
26
- test . todo ( "tally on an empty array returns an empty object" ) ;
33
+ describe ( "edge cases of the tally function" , ( ) => {
34
+ test ( "tally on an empty array returns an empty object" , ( ) => {
35
+ const currentOutput = tally ( [ ] ) ;
36
+ const targetOutput = { } ;
37
+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
38
+ } ) ;
39
+ } ) ;
27
40
28
41
// Given an array with duplicate items
29
42
// When passed to tally
30
43
// Then it should return counts for each unique item
44
+ describe ( "edge cases of the tally function" , ( ) => {
45
+ test ( "When passed an array with duplicate items of items as a parameter into tally" , ( ) => {
46
+ const currentOutput = tally ( [ 1 , 2 , 2 , 6 , 6 , 6 , 1 ] ) ;
47
+ const targetOutput = { 1 : 2 , 2 : 2 , 6 : 3 } ;
48
+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
49
+ } ) ;
50
+ } ) ;
31
51
32
52
// Given an invalid input like a string
33
53
// When passed to tally
34
54
// Then it should throw an error
55
+ describe ( "edge cases of the tally function" , ( ) => {
56
+ test ( "tally gets not an array then it trow an error" , ( ) => {
57
+ // const currentOutput = tally("string");
58
+ // const targetOutput = Error;
59
+ expect ( ( ) => tally ( "string" ) ) . toThrow ( "This is not an array" ) ;
60
+ } ) ;
61
+ } ) ;
0 commit comments