diff options
| author | lstrzebinczyk <[email protected]> | 2017-05-27 20:56:35 +0200 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-06-03 20:30:43 -0400 |
| commit | 3a694ffebcff71305d79c6e8c15246d671ce3888 (patch) | |
| tree | 0c5ea151fa8ad76aa2e4feb447d6fe9efef1c409 /test/quad_spec.rb | |
| parent | 65187cd5126227778146ec33c2857a391fbab620 (diff) | |
| download | ruby2d-3a694ffebcff71305d79c6e8c15246d671ce3888.tar.gz ruby2d-3a694ffebcff71305d79c6e8c15246d671ce3888.zip | |
Use named arguments (#65)
Diffstat (limited to 'test/quad_spec.rb')
| -rw-r--r-- | test/quad_spec.rb | 79 |
1 files changed, 20 insertions, 59 deletions
diff --git a/test/quad_spec.rb b/test/quad_spec.rb index a6cfca4..249d8a7 100644 --- a/test/quad_spec.rb +++ b/test/quad_spec.rb @@ -3,13 +3,7 @@ require 'ruby2d' RSpec.describe Ruby2D::Quad do describe '#new' do it "creates a quad with white color by default" do - quad = Quad.new( - 300, 200, - 350, 200, - 300, 250, - 250, 250 - ) - + 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) @@ -18,48 +12,28 @@ RSpec.describe Ruby2D::Quad do end it 'creates a new quad with one color via string' do - quad = Quad.new( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - "red" - ) - + 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( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - [0.1, 0.3, 0.5, 0.7] - ) - + 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( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - ["red", "green", "blue", "black"] - ) - + 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( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - [[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]] + 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) @@ -67,25 +41,13 @@ RSpec.describe Ruby2D::Quad do it "throws an error when array of 3 strings is passed" do expect do - Quad.new( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - ["red", "green", "blue"] - ) + 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( - 300, 200, - 350, 200, - 300, 250, - 250, 250, - ["red", "green", "blue", "black", "fuchsia"] - ) + 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 @@ -93,22 +55,21 @@ RSpec.describe Ruby2D::Quad do describe '#contains?' do it "returns true if point is inside quad" do quad = Quad.new( - -25, 0, - 0, -25, - 25, 0, - 0, 25 + 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( - -25, 0, - 0, -25, - 25, 0, - 0, 25 + 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 |
