-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdarts.spec.js
73 lines (63 loc) · 2 KB
/
darts.spec.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { solve } from './darts';
describe('Return the correct amount earned by a dart landing in a given point in the target problem', () => {
test('A dart lands outside the target', () => {
const x = -9;
const y = 9;
const expected = 0;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands just in the border of the target', () => {
const x = 0;
const y = 10;
const expected = 1;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands in the outer circle', () => {
const x = 4;
const y = 4;
const expected = 1;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands right in the border between outer and middle circles', () => {
const x = 5;
const y = 0;
const expected = 5;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands in the middle circle', () => {
const x = 0.8;
const y = -0.8;
const expected = 5;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands right in the border between middle and inner circles', () => {
const x = 0;
const y = -1;
const expected = 10;
expect(solve(x, y)).toEqual(expected);
});
test('A dart lands in the inner circle', () => {
const x = -0.1;
const y = -0.1;
const expected = 10;
expect(solve(x, y)).toEqual(expected);
});
test('A dart whose coordinates sum to > 1 but whose radius to origin is <= 1 is scored in the inner circle', () => {
const x = 0.4;
const y = 0.8;
const expected = 10;
expect(solve(x, y)).toEqual(expected);
});
test('A dart whose coordinates sum to > 5 but whose radius to origin is <= 5 is scored in the middle circle', () => {
const x = 2;
const y = 4;
const expected = 5;
expect(solve(x, y)).toEqual(expected);
});
test('A dart whose coordinates sum to > 10 but whose radius to origin is <= 10 is scored in the outer circle', () => {
const x = 4;
const y = 8;
const expected = 1;
expect(solve(x, y)).toEqual(expected);
});
});