@@ -16,28 +16,65 @@ 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+ test ( "given an empty array, returns -Infinity" , ( ) => {
20+ const maxElement = [ ] ;
21+ const currentOutput = findMax ( maxElement ) ;
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, returns that number" , ( ) => {
30+ const maxElement = [ 1 ] ;
31+ const currentOutput = findMax ( maxElement ) ;
32+ const targetOutput = 1 ;
33+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
34+ } ) ;
2435
2536// Given an array with both positive and negative numbers
2637// When passed to the max function
2738// Then it should return the largest number overall
28-
39+ test ( "given an array with one both positive and negative numbers , return largest number" , ( ) => {
40+ const maxElement = [ 2 , - 4 , 8 , - 1 ] ;
41+ const currentOutput = findMax ( maxElement ) ;
42+ const targetOutput = 8 ;
43+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
44+ } ) ;
2945// Given an array with just negative numbers
3046// When passed to the max function
3147// Then it should return the closest one to zero
32-
48+ test ( "given an array with negative numbers, returns the closest to zero" , ( ) => {
49+ const maxElement = [ - 1 , - 4 , - 12 ] ;
50+ const currentOutput = findMax ( maxElement ) ;
51+ const targetOutput = - 1 ;
52+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
53+ } ) ;
3354// Given an array with decimal numbers
3455// When passed to the max function
3556// Then it should return the largest decimal number
36-
57+ test ( "given an array with decimal numbers returns the largest decimal number" , ( ) => {
58+ const maxElement = [ 2.5 , 4.5 , 9.8 ] ;
59+ const currentOutput = findMax ( maxElement ) ;
60+ const targetOutput = 9.8 ;
61+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
62+ } ) ;
3763// Given an array with non-number values
3864// When passed to the max function
3965// Then it should return the max and ignore non-numeric values
40-
66+ test ( "given an array with one non-number return the max and ignore non-numeric value, " , ( ) => {
67+ const maxElement = [ "hello" , 4 , 8 , 10 ] ;
68+ const currentOutput = findMax ( maxElement ) ;
69+ const targetOutput = 10 ;
70+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
71+ } ) ;
4172// Given an array with only non-number values
4273// When passed to the max function
4374// Then it should return the least surprising value given how it behaves for all other inputs
75+ test ( "given an array with only non-number values returns -Infinity" , ( ) => {
76+ const maxElement = [ "history" , "nation" ] ;
77+ const currentOutput = findMax ( maxElement ) ;
78+ const targetOutput = - Infinity ;
79+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
80+ } ) ;
0 commit comments