Skip to content

Commit 67e1d52

Browse files
Implement tests for describeMedian function to validate median calculation and error handling
1 parent 1f79607 commit 67e1d52

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎Sprint-1/implement/describe-median.test.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ const describeMedian = require("./describe-median.js");
2121
// When passed to describeMedian
2222
// Then it should return "The median is " followed by the median
2323
// Delete this test.todo and replace it with a test.
24-
test.todo('given [1, 2, 3], returns "The median is 2"');
24+
test('given [1, 2, 3], returns "The median is 2"', () => {
25+
expect(describeMedian([1, 2, 3])).toEqual("The median is 2");
26+
});
2527

2628
// Given an empty array
2729
// When passed to describeMedian
2830
// Then it should return "Could not calculate a median: calculateMedian requires a non-empty array"
29-
31+
test('given empty array, returns "Could not calculate a median: calculateMedian requires a non-empty array"', () => {
32+
expect(describeMedian([])).toEqual(
33+
"Could not calculate a median: calculateMedian requires a non-empty array"
34+
);
35+
});
3036
// Given something that isn't an array of numbers, e.g. "banana"
3137
// When passed to describeMedian
3238
// Then it should return "Could not calculate a median: calculateMedian requires an array of numbers"
39+
test('given something that isnt an array of numbers, returns "Could not calculate a median: calculateMedian requires an array of numbers"', () => {
40+
expect(describeMedian("Non-array")).toEqual(
41+
"Could not calculate a median: calculateMedian requires an array of numbers"
42+
);
43+
});

0 commit comments

Comments
 (0)