-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathReturnOnInvestment.test.js
More file actions
35 lines (27 loc) · 1.02 KB
/
ReturnOnInvestment.test.js
File metadata and controls
35 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { returnOnInvestment } from '../ReturnOnInvestment'
describe('returnOnInvestment', () => {
test('positive ROI when gain exceeds cost', () => {
expect(returnOnInvestment(1000, 500)).toBe(100)
})
test('zero ROI when gain equals cost', () => {
expect(returnOnInvestment(500, 500)).toBe(0)
})
test('negative ROI when gain is less than cost', () => {
expect(returnOnInvestment(200, 500)).toBe(-60)
})
test('total loss when gain is zero', () => {
expect(returnOnInvestment(0, 500)).toBe(-100)
})
test('throws RangeError for zero cost', () => {
expect(() => returnOnInvestment(1000, 0)).toThrow(RangeError)
})
test('throws RangeError for negative cost', () => {
expect(() => returnOnInvestment(1000, -100)).toThrow(RangeError)
})
test('throws TypeError for non-number gain', () => {
expect(() => returnOnInvestment('1000', 500)).toThrow(TypeError)
})
test('throws TypeError for non-number cost', () => {
expect(() => returnOnInvestment(1000, '500')).toThrow(TypeError)
})
})