Make 05 tests pass
This commit is contained in:
parent
f1149c3915
commit
13d8e6b65f
2 changed files with 33 additions and 21 deletions
|
@ -1,6 +1,18 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function (number1, number2) {
|
||||
if (number1 < 0 || number2 < 0) return 'ERROR'
|
||||
if (typeof number1 !== 'number' || typeof number2 !== 'number') return 'ERROR'
|
||||
|
||||
};
|
||||
let sum = 0
|
||||
|
||||
const start = Math.min(number1, number2)
|
||||
const end = Math.max(number1, number2)
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
sum += i
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = sumAll;
|
||||
module.exports = sumAll
|
||||
|
|
|
@ -2,21 +2,21 @@ const sumAll = require('./sumAll')
|
|||
|
||||
describe('sumAll', () => {
|
||||
test('sums numbers within the range', () => {
|
||||
expect(sumAll(1, 4)).toEqual(10);
|
||||
});
|
||||
test.skip('works with large numbers', () => {
|
||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||
});
|
||||
test.skip('works with larger number first', () => {
|
||||
expect(sumAll(123, 1)).toEqual(7626);
|
||||
});
|
||||
test.skip('returns ERROR with negative numbers', () => {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||
});
|
||||
});
|
||||
expect(sumAll(1, 4)).toEqual(10)
|
||||
})
|
||||
test('works with large numbers', () => {
|
||||
expect(sumAll(1, 4000)).toEqual(8002000)
|
||||
})
|
||||
test('works with larger number first', () => {
|
||||
expect(sumAll(123, 1)).toEqual(7626)
|
||||
})
|
||||
test('returns ERROR with negative numbers', () => {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR')
|
||||
})
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, '90')).toEqual('ERROR')
|
||||
})
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue