@@ -16,28 +16,63 @@ const findMax = require("./max.js");
1616// When passed to the max function
1717// Then it should return -Infinity
1818// Delete this test.todo and replace it with a test.
19- test . todo ( "given an empty array, returns -Infinity" ) ;
19+
20+ test ( "given an empty array, it should return -Infinity" , ( ) => {
21+ const currentOutput = findMax ( [ ] ) ;
22+ const targetOutput = - Infinity ;
23+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
24+ } ) ;
2025
2126// Given an array with one number
2227// When passed to the max function
2328// Then it should return that number
29+ test ( "Given an array with one number, it should return that number" , ( ) => {
30+ const currentOutput = findMax ( [ 1 ] ) ;
31+ const targetOutput = 1 ;
32+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
33+ } ) ;
2434
2535// Given an array with both positive and negative numbers
2636// When passed to the max function
2737// Then it should return the largest number overall
38+ test ( "Given an array with both positive and negative numbers it should return the largest number overall" , ( ) => {
39+ const currentOutput = findMax ( [ - 2 , 2 , 3 , - 3 ] ) ;
40+ const targetOutput = 3 ;
41+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
42+ } ) ;
2843
2944// Given an array with just negative numbers
3045// When passed to the max function
3146// Then it should return the closest one to zero
47+ test ( "Given an array with just negative numbers, it should returnthe closest one to zero" , ( ) => {
48+ const currentOutput = findMax ( [ - 1 , - 2 , - 3 , - 4 ] ) ;
49+ const targetOutput = - 1 ;
50+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
51+ } ) ;
3252
3353// Given an array with decimal numbers
3454// When passed to the max function
3555// Then it should return the largest decimal number
56+ test ( "given an array with decimal numbers, it should return the largest decimal number" , ( ) => {
57+ const currentOutput = findMax ( [ 0.2 , 0.45 , 5.3 , 1.5 ] ) ;
58+ const targetOutput = 5.3 ;
59+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
60+ } ) ;
3661
3762// Given an array with non-number values
3863// When passed to the max function
3964// Then it should return the max and ignore non-numeric values
65+ test ( "given an array with non-number values, it should return the max and ignore non-numeric values" , ( ) => {
66+ const currentOutput = findMax ( [ "a" , "!" , 3 , 5 , "0" ] ) ;
67+ const targetOutput = 5 ;
68+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
69+ } ) ;
4070
4171// Given an array with only non-number values
4272// When passed to the max function
4373// Then it should return the least surprising value given how it behaves for all other inputs
74+ test ( "given an array with only non-number values, it should return the least surprising value given how it behaves for all other inputs" , ( ) => {
75+ const currentOutput = findMax ( [ "2" , "3" , "$" , "%" ] ) ;
76+ const targetOutput = "3" ;
77+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
78+ } ) ;
0 commit comments