Make 05 tests pass

This commit is contained in:
marleyrae 2023-06-19 16:12:59 -07:00
parent f1149c3915
commit 13d8e6b65f
2 changed files with 33 additions and 21 deletions

View file

@ -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 // Do not edit below this line
module.exports = sumAll; module.exports = sumAll

View file

@ -2,21 +2,21 @@ const sumAll = require('./sumAll')
describe('sumAll', () => { describe('sumAll', () => {
test('sums numbers within the range', () => { test('sums numbers within the range', () => {
expect(sumAll(1, 4)).toEqual(10); expect(sumAll(1, 4)).toEqual(10)
}); })
test.skip('works with large numbers', () => { test('works with large numbers', () => {
expect(sumAll(1, 4000)).toEqual(8002000); expect(sumAll(1, 4000)).toEqual(8002000)
}); })
test.skip('works with larger number first', () => { test('works with larger number first', () => {
expect(sumAll(123, 1)).toEqual(7626); expect(sumAll(123, 1)).toEqual(7626)
}); })
test.skip('returns ERROR with negative numbers', () => { test('returns ERROR with negative numbers', () => {
expect(sumAll(-10, 4)).toEqual('ERROR'); expect(sumAll(-10, 4)).toEqual('ERROR')
}); })
test.skip('returns ERROR with non-number parameters', () => { test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, "90")).toEqual('ERROR'); expect(sumAll(10, '90')).toEqual('ERROR')
}); })
test.skip('returns ERROR with non-number parameters', () => { test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, [90, 1])).toEqual('ERROR'); expect(sumAll(10, [90, 1])).toEqual('ERROR')
}); })
}); })