@@ -23,28 +23,86 @@ const calculateMean = require("./mean.js");
2323// When passed to calculateMean
2424// Then it should return their mean
2525// Delete this test.todo and replace it with a test.
26- test . todo ( "given [1, 2, 6], returns 3" ) ;
26+ describe ( "calculateMean" , ( ) => {
27+ it ( "return [1, 2, 6]" , ( ) => {
28+ expect ( calculateMean ( [ 1 , 2 , 6 ] ) ) . toEqual ( 3 ) ;
29+ } ) ;
2730
28- // Given an array with a single number
29- // When passed to calculateMean
30- // Then it should return that number
31+ // Given an array with a single number
32+ // When passed to calculateMean
33+ // Then it should return that number
34+ it ( "returns for [6]" , ( ) => {
35+ expect ( calculateMean ( [ 6 ] ) ) . toEqual ( 6 ) ;
36+ } ) ;
3137
32- // Given an array containing negative or decimal numbers
33- // When passed to calculateMean
34- // Then it should return the correct mean
38+ // Given an array containing negative or decimal numbers
39+ // When passed to calculateMean
40+ // Then it should return the correct mean
41+ it ( "returns for 10, 20.5, -10, 30.5]" , ( ) => {
42+ expect ( calculateMean ( [ 10 , 20.5 , - 10 , 30.5 ] ) ) . toEqual ( 12.75 ) ;
43+ } ) ;
3544
36- // Given an empty array
37- // When passed to calculateMean
38- // Then it should throw Error("calculateMean requires a non-empty array")
45+ // Given an empty array
46+ // When passed to calculateMean
47+ // Then it should throw Error("calculateMean requires a non-empty array")
3948
40- // Given a value that isn't an array, e.g. "banana", 42, null or {}
41- // When passed to calculateMean
42- // Then it should throw Error("calculateMean requires an array of numbers")
49+ it ( "returns for []" , ( ) => {
50+ ( ) =>
51+ expect ( calculateMean ( [ ] ) ) . toThrow (
52+ new Error ( "calculateMean requires a non-empty array" )
53+ ) ;
54+ } ) ;
4355
44- // Given no argument at all
45- // When passed to calculateMean
46- // Then it should throw Error("calculateMean requires an array of numbers")
56+ // Given a value that isn't an array, e.g. "banana", 42, null or {}
57+ // When passed to calculateMean
58+ // Then it should throw Error("calculateMean requires an array of numbers")
4759
48- // Given an array containing a non-number value, e.g. [1, "2", 3]
49- // When passed to calculateMean
50- // Then it should throw Error("calculateMean requires an array of numbers")
60+ it ( "returns for 'banana'" , ( ) => {
61+ ( ) =>
62+ expect ( calculateMean ( "banana" ) ) . toThrow (
63+ new Error ( "calculateMean requires an array of numbers" )
64+ ) ;
65+ } ) ;
66+
67+ it ( "returns for 42" , ( ) => {
68+ ( ) =>
69+ expect ( calculateMean ( 42 ) ) . toThrow (
70+ new Error ( "calculateMean requires an array of numbers" )
71+ ) ;
72+ } ) ;
73+
74+ it ( "returns for null" , ( ) => {
75+ ( ) =>
76+ expect ( calculateMean ( null ) ) . toThrow (
77+ new Error ( "calculateMean requires an array of numbers" )
78+ ) ;
79+ } ) ;
80+
81+ it ( "returns for {}" , ( ) => {
82+ ( ) =>
83+ expect ( calculateMean ( { } ) ) . toThrow (
84+ new Error ( "calculateMean requires an array of numbers" )
85+ ) ;
86+ } ) ;
87+
88+ // Given no argument at all
89+ // When passed to calculateMean
90+ // Then it should throw Error("calculateMean requires an array of numbers")
91+
92+ it ( "returns for ''" , ( ) => {
93+ ( ) =>
94+ expect ( calculateMean ( "" ) ) . toThrow (
95+ new Error ( "calculateMean requires an array of numbers" )
96+ ) ;
97+ } ) ;
98+
99+ // Given an array containing a non-number value, e.g. [1, "2", 3]
100+ // When passed to calculateMean
101+ // Then it should throw Error("calculateMean requires an array of numbers")
102+ it ( "returns for [1, '2', 3]" , ( ) => {
103+ ( ) =>
104+ expect ( calculateMean ( [ 1 , "2" , 3 ] ) ) . toThrow (
105+ new Error ( "calculateMean requires an array of numbers" )
106+ ) ;
107+ } ) ;
108+ } ) ;
0 commit comments