@@ -22,25 +22,31 @@ const describeMedian = require("./describe-median.js");
2222// Then it should return "The median is " followed by the median
2323// Delete this test.todo and replace it with a test.
2424describe ( "describeMedian" , ( ) => {
25- it ( "returns for [1, 2, 3, 4]" , ( ) => {
26- const array = [ 1 , 2 , 3 , 4 ]
27- const result = describeMedian ( array ) ;
28- expect ( result ) . toBe ( ' The median is 2.5' )
29- } )
30-
31- // Given an empty array
32- // When passed to describeMedian
33- // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array"
34- it ( "returns for []" , ( ) => {
25+ it ( "returns for [1, 2, 3, 4]" , ( ) => {
26+ const array = [ 1 , 2 , 3 , 4 ] ;
27+ const result = describeMedian ( array ) ;
28+ expect ( result ) . toBe ( " The median is 2.5" ) ;
29+ } ) ;
30+
31+ // Given an empty array
32+ // When passed to describeMedian
33+ // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array"
34+ it ( "returns for []" , ( ) => {
3535 expect ( ( ) => describeMedian ( [ ] ) ) . toThrow (
36- new Error ( "Could not calculate a median: calculateMedian requires a non-empty array" ) )
37- } )
38-
39- // Given something that isn't an array of numbers, e.g. "banana"
40- // When passed to describeMedian
41- // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers"
42- it ( "returns for ['banana', 'apple', 'orange']" , ( ) => {
43- expect ( ( ) => describeMedian ( [ 'banana' , 'apple' , 'orange' ] ) ) . toThrow (
44- new Error ( "Could not calculate a median: calculateMedian requires an array of numbers" ) )
45- } )
46- } )
36+ new Error (
37+ "Could not calculate a median: calculateMedian requires a non-empty array"
38+ )
39+ ) ;
40+ } ) ;
41+
42+ // Given something that isn't an array of numbers, e.g. "banana"
43+ // When passed to describeMedian
44+ // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers"
45+ it ( "returns for ['banana', 'apple', 'orange']" , ( ) => {
46+ expect ( ( ) => describeMedian ( [ "banana" , "apple" , "orange" ] ) ) . toThrow (
47+ new Error (
48+ "Could not calculate a median: calculateMedian requires an array of numbers"
49+ )
50+ ) ;
51+ } ) ;
52+ } ) ;
0 commit comments