Skip to content

Commit 8a4b703

Browse files
committed
added the test for the max function
1 parent f6f580c commit 8a4b703

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

Sprint-1/implement/max.test.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,75 @@ 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+
20+
test("given an empty array, returns -Infinity", () => {
21+
const currentOutput = findMax([]);
22+
const targetOutput = -Infinity;
23+
24+
expect(currentOutput).toEqual(targetOutput);
25+
});
2026

2127
// Given an array with one number
2228
// When passed to the max function
2329
// Then it should return that number
2430

31+
test("given an array with one number, returns that number", () => {
32+
const currentOutput = findMax([42]);
33+
const targetOutput = 42;
34+
35+
expect(currentOutput).toEqual(targetOutput);
36+
});
37+
38+
2539
// Given an array with both positive and negative numbers
2640
// When passed to the max function
2741
// Then it should return the largest number overall
2842

43+
test("given an array with positive and negative numbers, returns the largest", () => {
44+
const currentOutput = findMax([-25, 5, 20, -3, 15]);
45+
const targetOutput = 20;
46+
47+
expect(currentOutput).toEqual(targetOutput);
48+
});
2949
// Given an array with just negative numbers
3050
// When passed to the max function
3151
// Then it should return the closest one to zero
3252

53+
test("given an array of only negative numbers, returns the closest to zero", () => {
54+
const currentOutput = findMax([-50, -3, -20, -10]);
55+
const targetOutput = -3;
56+
57+
expect(currentOutput).toEqual(targetOutput);
58+
});
59+
3360
// Given an array with decimal numbers
3461
// When passed to the max function
3562
// Then it should return the largest decimal number
3663

64+
test("given an array of decimal numbers, returns the largest decimal", () => {
65+
const currentOutput = findMax([1.1, 3.5, 2.9, 3.4]);
66+
const targetOutput = 3.5;
67+
68+
expect(currentOutput).toEqual(targetOutput);
69+
});
70+
3771
// Given an array with non-number values
3872
// When passed to the max function
3973
// Then it should return the max and ignore non-numeric values
4074

75+
test("given an array with non-number values, returns correct max (ignoring non-numbers)", () => {
76+
const currentOutput = findMax([10, "hi", 50, true, 3]);
77+
const targetOutput = 50;
78+
79+
expect(currentOutput).toEqual(targetOutput);
80+
});
81+
4182
// Given an array with only non-number values
4283
// When passed to the max function
4384
// Then it should return the least surprising value given how it behaves for all other inputs
85+
test("given an array with only non-number values, returns -Infinity", () => {
86+
const currentOutput = findMax(["a", null, undefined, {}, [], true]);
87+
const targetOutput = -Infinity;
88+
89+
expect(currentOutput).toEqual(targetOutput);
90+
});

0 commit comments

Comments
 (0)