-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle_spec.rb
60 lines (50 loc) · 1.18 KB
/
triangle_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
# p. 196 of TDD by example
require 'triangle'
describe Triangle do
before(:each) do
end
it "type should return 1 for an equialateral triangle" do
@t = Triangle.new(1,1,1)
@t.type.should == 1
end
it "type should return 2 for an isosceles triangle" do
@t = Triangle.new(1,1,2)
@t.type.should == 2
end
it "type should return 3 for a scalar triangle" do
@t = Triangle.new(1,2,3)
@t.type.should == 3
end
it "should raise an error if malformed with a zero side" do
@t = Triangle.new(0,2,3)
begin
@t.type
true.should == false
rescue RuntimeError
end
end
it "should raise an error if malformed with a nil parameter" do
@t = Triangle.new(1,2,nil)
begin
@t.type
true.should == false
rescue RuntimeError
end
end
it "should raise an error if malformed with a negative number side" do
@t = Triangle.new(1,2,-3)
begin
@t.type
true.should == false
rescue RuntimeError
end
end
it "should raise an error if malformed with non-numeric side" do
@t = Triangle.new(1,'a',3)
begin
@t.type
true.should == false
rescue RuntimeError
end
end
end