forked from ruby2d/ruby2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quad_spec.rb
79 lines (69 loc) · 2.3 KB
/
quad_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
require 'ruby2d'
RSpec.describe Ruby2D::Quad do
describe '#new' do
it "creates a quad with white color by default" do
quad = Quad.new
expect(quad.color).to be_a(Ruby2D::Color)
expect(quad.color.r).to eq(1)
expect(quad.color.g).to eq(1)
expect(quad.color.b).to eq(1)
expect(quad.color.a).to eq(1)
end
it 'creates a new quad with one color via string' do
quad = Quad.new(color: "red")
expect(quad.color).to be_a(Ruby2D::Color)
end
it "creates a new triangle with one color via array of numbers" do
quad = Quad.new(color: [0.1, 0.3, 0.5, 0.7])
expect(quad.color).to be_a(Ruby2D::Color)
end
it "creates a new quad with 4 colors via array of 4 strings" do
quad = Quad.new(color: ["red", "green", "blue", "black"])
expect(quad.color).to be_a(Ruby2D::Color::Set)
end
it "creates a new quad with 4 colors via array of 4 arrays of arrays of numbers" do
quad = Quad.new(
color: [
[0.1, 0.3, 0.5, 0.7],
[0.2, 0.4, 0.6, 0.8],
[0.3, 0.5, 0.7, 0.9],
[0.4, 0.6, 0.8, 1.0]
]
)
expect(quad.color).to be_a(Ruby2D::Color::Set)
end
it "throws an error when array of 3 strings is passed" do
expect do
Quad.new(color: ["red", "green", "blue"])
end.to raise_error("Quads require 4 colors, one for each vertex. 3 were given.")
end
it "throws an error when array of 5 strings is passed" do
expect do
Quad.new(color: ["red", "green", "blue", "black", "fuchsia"])
end.to raise_error("Quads require 4 colors, one for each vertex. 5 were given.")
end
end
describe '#contains?' do
it "returns true if point is inside quad" do
quad = Quad.new(
x1: -25, y1: 0,
x2: 0, y2: -25,
x3: 25, y3: 0,
x4: 0, y4: 25
)
expect(quad.contains?(0, 0)).to be true
end
it "returns true if point is not inside quad" do
quad = Quad.new(
x1: -25, y1: 0,
x2: 0, y2: -25,
x3: 25, y3: 0,
x4: 0, y4: 25
)
expect(quad.contains?( 20, 20)).to be false
expect(quad.contains?(-20, 20)).to be false
expect(quad.contains?( 20, -20)).to be false
expect(quad.contains?(-20, -20)).to be false
end
end
end