diff options
Diffstat (limited to 'test/triangle_spec.rb')
| -rw-r--r-- | test/triangle_spec.rb | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/test/triangle_spec.rb b/test/triangle_spec.rb index 2600d6f..8dd2605 100644 --- a/test/triangle_spec.rb +++ b/test/triangle_spec.rb @@ -12,6 +12,23 @@ RSpec.describe Ruby2D::Triangle do expect(triangle.color.a).to eq(1) end + it "creates a triangle with options" do + triangle = Triangle.new( + x1: 10, y1: 20, x2: 30, y2: 40, x3: 50, y3: 60, z: 70, + color: 'gray', opacity: 0.5 + ) + + expect(triangle.x1).to eq(10) + expect(triangle.y1).to eq(20) + expect(triangle.x2).to eq(30) + expect(triangle.y2).to eq(40) + expect(triangle.x3).to eq(50) + expect(triangle.y3).to eq(60) + expect(triangle.z).to eq(70) + expect(triangle.color.r).to eq(2/3.0) + expect(triangle.opacity).to eq(0.5) + end + it "creates a new triangle with one color via string" do triangle = Triangle.new(color: 'black') expect(triangle.color).to be_a(Ruby2D::Color) @@ -41,16 +58,42 @@ RSpec.describe Ruby2D::Triangle do it "throws an error when array of 2 strings is passed" do expect do Triangle.new(color: ['red', 'green']) - end.to raise_error("Triangles require 3 colors, one for each vertex. 2 were given.") + end.to raise_error("`Ruby2D::Triangle` requires 3 colors, one for each vertex. 2 were given.") end it "throws an error when array of 4 strings is passed" do expect do Triangle.new(color: ['red', 'green', 'blue', 'fuchsia']) - end.to raise_error("Triangles require 3 colors, one for each vertex. 4 were given.") + end.to raise_error("`Ruby2D::Triangle` requires 3 colors, one for each vertex. 4 were given.") + end + end + + describe "attributes" do + it "can be set and read" do + triangle = Triangle.new + triangle.x1 = 10 + triangle.y1 = 20 + triangle.x2 = 30 + triangle.y2 = 40 + triangle.x3 = 50 + triangle.y3 = 60 + triangle.z = 70 + triangle.color = 'gray' + triangle.opacity = 0.5 + + expect(triangle.x1).to eq(10) + expect(triangle.y1).to eq(20) + expect(triangle.x2).to eq(30) + expect(triangle.y2).to eq(40) + expect(triangle.x3).to eq(50) + expect(triangle.y3).to eq(60) + expect(triangle.z).to eq(70) + expect(triangle.color.r).to eq(2/3.0) + expect(triangle.opacity).to eq(0.5) end end + # TODO: This test should be more precise, like `Renderable#contains?` describe "#contains?" do triangle = Triangle.new( x1: 0, y1: 0, |
