forked from cdepair/darts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
darts_spec.rb
177 lines (140 loc) · 4.19 KB
/
darts_spec.rb
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
require './darts.rb'
describe Darts do
describe 'score' do
it 'should return a score of 6 for 3, 0' do
Darts.new(3,0).score.should == 6
end
it 'should return a score of 20 for 0, 3' do
Darts.new(0,3).score.should == 20
end
it 'should return a score of 60 for 0, 4.026' do
Darts.new(0,4.026).score.should == 60
end
it 'should return a score of 40 for 0, 6.6' do
Darts.new(0,6.6).score.should == 40
end
it 'should return a score of 50 for 0, 0.3' do
Darts.new(0,0.3).score.should == 50
end
it 'should return a score of 25 for 0, 0.6' do
Darts.new(0,0.6).score.should == 25
end
it 'should return a score of 50 for 0, 0' do
Darts.new(0,0).score.should == 50
end
it 'should return a score of 0 for 15, 15' do
Darts.new(15,15).score.should == 0
end
end
describe 'get_theta' do
it 'should return the correct theta for 1, 3' do
Darts.new(1,3).get_theta.should be_within(0.01).of 71.57
end
it 'should return the correct theta for 1, 4' do
Darts.new(1,4).get_theta.should be_within(0.01).of 75.96
end
it 'should return the correct theta for 0, 4' do
Darts.new(0,4).get_theta.should == 90
end
it 'should return the correct theta for 0, -4' do
Darts.new(0,-4).get_theta.should == 270
end
it 'should return the correct theta for 4, 0' do
Darts.new(4,0).get_theta.should == 0
end
it 'should return the correct theta for -4, 0' do
Darts.new(-4,0).get_theta.should == 180
end
it 'should return a theta of bullseye for 0, 0' do
Darts.new(0,0).get_theta.should == 'bullseye'
end
end
describe 'distance_from_bullseye' do
it 'should give the correct distance to the bullseye for 1, 3' do
Darts.new(1,3).distance_from_bullseye.should be_within(0.01).of 3.16
end
it 'should give the correct distance to the bullseye for 3, 4' do
Darts.new(3,4).distance_from_bullseye.should be_within(0).of 5
end
it 'should give the correct distance to the bullseye for 0, 0' do
Darts.new(0,0).distance_from_bullseye.should be_within(0).of 0
end
it 'should give the correct distance to the bullseye for -3, -4' do
Darts.new(-3,-4).distance_from_bullseye.should be_within(0).of 5
end
end
describe 'slice' do
before do
@darts = Darts.new(1,1)
end
it 'should return 6 for a theta of 1' do
@darts.theta = 1
@darts.slice.should == 6
end
it 'should return 13 for a theta of 11' do
@darts.theta = 11
@darts.slice.should == 13
end
it 'should return 4 for a theta of 28' do
@darts.theta = 28
@darts.slice.should == 4
end
it 'should return 20 for a theta of 90' do
@darts.theta = 90
@darts.slice.should == 20
end
it 'should return 11 for a theta of 180' do
@darts.theta = 180
@darts.slice.should == 11
end
it 'should return 3 for a theta of 270' do
@darts.theta = 270
@darts.slice.should == 3
end
it 'should return 6 for a theta of 359' do
@darts.theta = 359
@darts.slice.should == 6
end
it 'should return 6 for a theta of 360' do
@darts.theta = 360
@darts.slice.should == 6
end
it 'should return 6 for a theta of 720' do
@darts.theta = 720
@darts.slice.should == 6
end
end
describe 'ring' do
before do
@darts = Darts.new(1,1)
end
it 'should return ring 1 for 0.4' do
@darts.distance = 0.4
@darts.ring.should == 1
end
it 'should return ring 2 for 1.25' do
@darts.distance = 1.25
@darts.ring.should == 2
end
it 'should return ring 3 for 4.025' do
@darts.distance = 4.025
@darts.ring.should == 3
end
it 'should return ring 4 for 4.2' do
@darts.distance = 4.2
@darts.ring.should == 4
end
it 'should return ring 5 for 6.525' do
@darts.distance = 6.525
@darts.ring.should == 5
end
it 'should return ring 6 for 6.7' do
@darts.distance = 6.7
@darts.ring.should == 6
end
it 'should return ring 7 for 6.8' do
@darts.distance = 6.8
@darts.ring.should == 7
end
end
end