Skip to content

Commit 12e8cb0

Browse files
committed
added a test for adding decimal and throwing and error if non number value is found
1 parent dab9188 commit 12e8cb0

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,20 @@ test("should return the number when given negative numbers ", () => {
3737
// Given an array with decimal/float numbers
3838
// When passed to the sum function
3939
// Then it should return the correct total sum
40+
test("should return the number when given decimal number", () => {
41+
expect(sum([2.5, 3.4, 5.7, 2])).toEqual(13.6);
42+
expect(sum([1, 1.5, 2.5, 6.3])).toEqual(11.3);
43+
expect(sum([2.3, 2.7, 7.4, 5.5])).toEqual(17.9);
44+
});
4045

4146
// Given an array containing a value that isn't a number
4247
// When passed to the sum function
4348
// Then it should throw Error("sum requires an array of numbers")
49+
test("should throw an error when argument is passed that is non number", () => {
50+
expect(() => sum([1, 2, "hi", 3, "hey"])).toThrow(
51+
"sum requires an array of numbers"
52+
);
53+
});
4454

4555
// Given something that isn't an array at all, such as "hey", 42 or no argument
4656
// When passed to the sum function

0 commit comments

Comments
 (0)