Class | TestLogoTurtle |
In: |
LogoTurtle.rb
|
Parent: | Test::Unit::TestCase |
DELTA | = | 0.000000000001 | Constant delta for approximative testing |
Test methods to retrieve lines and to convert instances
# File LogoTurtle.rb, line 480 def testget a = LogoTurtle.new a.forward(200); a.right(90); a.forward(200) loopcount = 0 a.getLines { |line| assert_equal("black", line.color); loopcount += 1 } assert_equal(2, loopcount) assert_equal([0.0, 0.0, 0.0, "black", "white", true, true, [], []], LogoTurtle.new.to_a) assert_equal("0.0;0.0;0.0;black;white;true;true;;", LogoTurtle.new.to_s) end
Test initialization of LogoTurtle instances
# File LogoTurtle.rb, line 380 def testinit a = LogoTurtle.new() assert_equal(0, a.posx) assert_equal(0, a.posy) assert_equal(0, a.direction) assert_equal("black", a.color) assert_equal("white", a.background) b = LogoTurtle.new(-2.5, -0.5, -45, "anycolor", "anyothercolor") assert_equal(-2.5, b.posx) assert_equal(-0.5, b.posy) assert_equal(-45, b.direction) assert_equal("anycolor", b.color) assert_equal("anyothercolor", b.background) c = LogoTurtle.new("a", "b", "c", 1, [2, 3]) assert_equal(0.0, c.posx) assert_equal(0.0, c.posy) assert_equal(0.0, c.direction) assert_equal("1", c.color) assert_equal("23", c.background) end
Test movement methods for LogoTurtle instances
# File LogoTurtle.rb, line 403 def testmovement a = LogoTurtle.new(-100.0, -100.0, 45.0) a.right(495) assert_in_delta(180.0, a.direction, DELTA) a.left(-90) assert_in_delta(270.0, a.direction, DELTA) a.forward(100) assert_in_delta(-200.0, a.posx, DELTA) assert_in_delta(-100.0, a.posy, DELTA) a.left(90+360+360) assert_in_delta(180.0, a.direction, DELTA) a.backward(100) assert_in_delta(-200.0, a.posx, DELTA) assert_in_delta(0, a.posy, DELTA) a.move(-12.34, 56.78) assert_in_delta(-112.34, a.posx, DELTA) assert_in_delta(-43.22, a.posy, DELTA) a.turn(45) assert_in_delta(90.0, a.direction, DELTA) a.home assert_in_delta(-100.0, a.posx, DELTA) assert_in_delta(-100.0, a.posy, DELTA) b = LogoTurtle.new b.right("asdf") b.forward("asdf") b.left("asdf") b.backward("asdf") assert_in_delta(0.0, b.posx, DELTA) assert_in_delta(0.0, b.posy, DELTA) assert_in_delta(0.0, b.direction, DELTA) end
Test private methods used by LogoTurtle instances
# File LogoTurtle.rb, line 493 def testprivate assert_in_delta(0, LogoTurtle.new().normalize(0), DELTA) assert_in_delta(0, LogoTurtle.new().normalize(360), DELTA) assert_in_delta(45, LogoTurtle.new().normalize(405), DELTA) assert_in_delta(350, LogoTurtle.new().normalize(-10), DELTA) assert_in_delta(220, LogoTurtle.new().normalize(-500), DELTA) assert_in_delta(90, LogoTurtle.new().normalize(36000000000090.0), DELTA) assert_in_delta(0, LogoTurtle.new().normalize("asdf"), DELTA) end
Test state changing methods for LogoTurtle instances
# File LogoTurtle.rb, line 437 def teststate a = LogoTurtle.new assert(a.pen) assert(a.visible) assert_equal([], a.lines) assert_equal([], a.messages) a.penup assert(!a.pen) a.forward(100) assert_equal(0, a.lines.length) a.pendown assert(a.pen) a.forward(100) assert_equal(1, a.lines.length) a.hide assert(!a.visible) a.show assert(a.visible) assert_equal(6, a.messages.length) a.clearMessages assert_equal(0, a.messages.length) assert_equal(1, a.lines.length) a.setColor("invalidcolor") assert_equal("invalidcolor", a.color) a.color = "red" # simulate override from user interface assert_equal("red", a.color) a.setBackground("invalidbackground") assert_equal("invalidbackground", a.background) a.background = "grey" # simulate override from user interface assert_equal("grey", a.background) assert_equal(2, a.messages.length) assert_equal(1, a.lines.length) a.log("test abc test") a.log(12345) assert_equal(4, a.messages.length) a.reset assert_equal("black", a.color) assert_equal(1, a.messages.length) assert_equal(0, a.lines.length) end