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

26 lines
804 B
JavaScript
Raw Normal View History

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