odin-default-js-exercises/05_sumAll/solution/sumAll-solution.spec.js

26 lines
804 B
JavaScript
Raw Normal View History

2023-02-01 23:53:54 +00:00
const sumAll = require('./sumAll-solution');
2022-02-20 19:07:44 +00:00
2023-02-01 23:53:54 +00:00
describe('sumAll', () => {
test('sums numbers within the range', () => {
2023-01-21 17:53:41 +00:00
expect(sumAll(1, 4)).toEqual(10);
});
2023-02-01 23:58:58 +00:00
test('works with large numbers', () => {
2023-01-21 17:53:41 +00:00
expect(sumAll(1, 4000)).toEqual(8002000);
});
2023-02-01 23:58:58 +00:00
test('works with larger number first', () => {
2023-01-21 17:53:41 +00:00
expect(sumAll(123, 1)).toEqual(7626);
});
2023-02-01 23:58:58 +00:00
test('returns ERROR with negative numbers', () => {
2023-02-01 23:53:54 +00:00
expect(sumAll(-10, 4)).toEqual('ERROR');
2023-01-21 17:53:41 +00:00
});
2023-02-01 23:58:58 +00:00
test('returns ERROR with non-integer parameters', () => {
2023-02-01 23:53:54 +00:00
expect(sumAll(2.5, 4)).toEqual('ERROR');
2023-01-21 17:53:41 +00:00
});
2023-02-01 23:58:58 +00:00
test('returns ERROR with non-number parameters', () => {
2023-02-01 23:53:54 +00:00
expect(sumAll(10, '90')).toEqual('ERROR');
2023-01-21 17:53:41 +00:00
});
2023-02-01 23:58:58 +00:00
test('returns ERROR with non-number parameters', () => {
2023-02-01 23:53:54 +00:00
expect(sumAll(10, [90, 1])).toEqual('ERROR');
2023-01-21 17:53:41 +00:00
});
2022-02-20 19:07:44 +00:00
});