challenge-algorithms-v2.0/06-sum/index.test.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-10-30 02:25:47 +00:00
import { sum } from '.';
2022-10-30 02:25:47 +00:00
describe('sum', () => {
it('Dever retornar 0 quando passamos o array vazio', () => {
2022-10-27 19:21:02 +00:00
expect(sum([])).toBe(0);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 1 quando passamos o array [1]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([1])).toBe(1);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 3 quando passamos o array [1, 2]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([1, 2])).toBe(3);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 6 quando passamos o array [1, 2, 3]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([1, 2, 3])).toBe(6);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 10 quando passamos o array [1, 2, 3, 4]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([1, 2, 3, 4])).toBe(10);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 15 quando passamos o array [1, 2, 3, 4, 5]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([1, 2, 3, 4, 5])).toBe(15);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 27 quando passamos o array [4, 6, 12, 5]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([4, 6, 12, 5])).toBe(27);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 3886 quando passamos o array [9, 234, 312, 999, 21 , 2311]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([9, 234, 312, 999, 21, 2311])).toBe(3886);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar 73098 quando passamos o array [533, 234, 23423, 32, 48876]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([533, 234, 23423, 32, 48876])).toBe(73098);
});
// Criar um teste para numeros negativos
2022-10-30 02:25:47 +00:00
it('Dever retornar -51 quando passamos o array [-1, 5, -10, -45]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([-1, 5, -10, -45])).toBe(-51);
});
2022-10-30 02:25:47 +00:00
it('Dever retornar -40 quando passamos o array [-2, -7, -31]', () => {
2022-10-27 19:21:02 +00:00
expect(sum([-2, -7, -31])).toBe(-40);
});
});