Skip to content

Commit 4e5a380

Browse files
committed
Add tests for various scenarios in max function
1 parent 5201774 commit 4e5a380

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎Sprint-1/implement/max.test.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,41 @@ test("given an empty array, returns -Infinity", () => {
2424
// When passed to the max function
2525
// Then it should return that number
2626

27+
test("given an array with one number, returns the number", () => {
28+
expected(findMax([12])).toBe(12);
29+
});
30+
2731
// Given an array with both positive and negative numbers
2832
// When passed to the max function
2933
// Then it should return the largest number overall
34+
test("given an array with both positive and negative numbers, returns the highest number", () => {
35+
expect(findMax([20, -21, 30])).toBe(30);
36+
});
3037

3138
// Given an array with just negative numbers
3239
// When passed to the max function
3340
// Then it should return the closest one to zero
41+
test("given an array with just negative numbers, return the number closest to zero", () => {
42+
expect(findMax([-12, -7, -20])).toBe(-7);
43+
});
3444

3545
// Given an array with decimal numbers
3646
// When passed to the max function
3747
// Then it should return the largest decimal number
48+
test("given an array with decimal numbers, return the largest decimal number", () => {
49+
expect(findMax([1.2, 1.3, 1.8])).toBe(1.8);
50+
});
3851

3952
// Given an array with non-number values
4053
// When passed to the max function
4154
// Then it should return the max and ignore non-numeric values
55+
test("given an array with non-number values, return the max and ignore the non-numerical values", () => {
56+
expect(findMax(["boy", 2, "hi", 20, 24])).toBe(24);
57+
});
4258

4359
// Given an array with only non-number values
4460
// When passed to the max function
4561
// Then it should return the least surprising value given how it behaves for all other inputs
62+
test("given an array with only non-number values, return the least surprising value", () => {
63+
expect(findMax(["a", "c", "e"])).toBe(-Infinity);
64+
});

0 commit comments

Comments
 (0)