Skip to content

Commit 396a9c0

Browse files
committed
I have modified the files and tested them with Jest and got a Pass
1 parent f8bcc92 commit 396a9c0

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

Sprint-1/implement/dedupe.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2]
1616
// Given an empty array
1717
// When passed to the dedupe function
1818
// Then it should return an empty array
19-
test.todo("given an empty array, it returns an empty array");
19+
test("given an empty array, it returns an empty array", () => {
20+
expect(dedupe([])).toEqual([]);
21+
});
2022

2123
// Given an array with no duplicates
2224
// When passed to the dedupe function
2325
// Then it should return a copy of the original array
26+
test("given an array with no duplicates, it returns the same array", () => {
27+
expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]);
28+
});
2429

2530
// Given an array with strings or numbers
2631
// When passed to the dedupe function
2732
// Then it should remove the duplicate values, preserving the first occurence of each element
33+
test("removes duplicates and keeps first occurrence", () => {
34+
expect(dedupe(['a','a','a','b','b','c'])).toEqual(['a','b','c']);
35+
expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]);
36+
});
2837

Sprint-1/implement/max.test.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,48 @@ 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+
test("given an empty array, returns null", () => {
20+
expect(findMax([])).toBe(null);
21+
});
2022

2123
// Given an array with one number
2224
// When passed to the max function
2325
// Then it should return that number
26+
test("given an array with one number , returns that number", () => {
27+
expect(findMax([7])).toBe(7);
28+
});
2429

2530
// Given an array with both positive and negative numbers
2631
// When passed to the max function
2732
// Then it should return the largest number overall
33+
test("given positive and negative numbers, returns the largest number", () => {
34+
expect(findMax([-10, 0, 5, -3, 8])).toBe(8);
35+
});
2836

2937
// Given an array with just negative numbers
3038
// When passed to the max function
3139
// Then it should return the closest one to zero
40+
test("given only negative numbers, returns the largest negative number", () => {
41+
expect(findMax([-10, -4, -2, -30])).toBe(-2);
42+
});
3243

3344
// Given an array with decimal numbers
3445
// When passed to the max function
3546
// Then it should return the largest decimal number
47+
test("given decimal numbers, returns the largest decimal number", () => {
48+
expect(findMax([1.2, 3.7, 2.5])).toBe(3.7);
49+
});
3650

3751
// Given an array with non-number values
3852
// When passed to the max function
3953
// Then it should return the max and ignore non-numeric values
54+
test("ignores non-number values and returns the max", () => {
55+
expect(findMax(["hey", 10, "hi", 60, 10])).toBe(60);
56+
});
4057

4158
// Given an array with only non-number values
4259
// When passed to the max function
4360
// Then it should return the least surprising value given how it behaves for all other inputs
44-
61+
test("given only non-number values, returns null", () => {
62+
expect(findMax(["hey", "hi", null, undefined, NaN])).toBe(null);
63+
});

Sprint-1/implement/sum.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,43 @@ const sum = require("./sum.js");
1313
// Given an empty array
1414
// When passed to the sum function
1515
// Then it should return 0
16-
test.todo("given an empty array, returns 0")
16+
test("given an empty array, returns 0", () => {
17+
expect(sum([])).toBe(0);
18+
});
1719

1820
// Given an array with just one number
1921
// When passed to the sum function
2022
// Then it should return that number
23+
test("given an array with one number, returns that number", () => {
24+
expect(sum([7])).toBe(7);
25+
});
2126

2227
// Given an array containing negative numbers
2328
// When passed to the sum function
2429
// Then it should still return the correct total sum
30+
test("given negative numbers, returns the correct total", () => {
31+
expect(sum([-10, -3, -2])).toBe(-15);
32+
});
2533

2634
// Given an array with decimal/float numbers
2735
// When passed to the sum function
2836
// Then it should return the correct total sum
37+
test("given decimal numbers, returns the correct total", () => {
38+
expect(sum([1.5, 2.5, 3])).toBe(7);
39+
});
2940

3041
// Given an array containing non-number values
3142
// When passed to the sum function
3243
// Then it should ignore the non-numerical values and return the sum of the numerical elements
44+
test("ignores non-number values and returns the sum", () => {
45+
expect(sum(["hey", 10, "hi", 60, 10])).toBe(80);
46+
});
47+
3348

3449
// Given an array with only non-number values
3550
// When passed to the sum function
3651
// Then it should return the least surprising value given how it behaves for all other inputs
52+
test("given only non-number values, returns 0", () => {
53+
expect(sum(["hey", "hi", null, undefined, NaN])).toBe(0);
54+
});
3755

0 commit comments

Comments
 (0)