#!/usr/bin/ruby require 'runit/testcase' require 'bowl' class TestFrame < RUNIT::TestCase def testMarks f = Frame.new assert_equals(Frame::NOMARK, f.mark) f.addRoll(1) assert_equals(Frame::NOMARK, f.mark) f.addRoll(9) assert_equals(Frame::SPARE, f.mark) f = Frame.new f.addRoll(10) assert_equals(Frame::STRIKE, f.mark) end def testAddRoll f = Frame.new f.addRoll(2) assert_equals(2, f.first) f.addRoll(4) assert_equals(4, f.second) f.addRoll(5) assert_equals(5, f.roll(2)) f.addRoll(7) assert_equals(0, f.roll(3)) end def testScore f = Frame.new assert_equals(0, f.score) f.addRoll(3) assert_equals(3, f.score) f.addRoll(5) assert_equals(8, f.score) f.addRoll(7) assert_equals(8, f.score) f = Frame.new f.addRoll(8) f.addRoll(2) f.addRoll(4) assert_equals(14, f.score) f = Frame.new f.addRoll(10) f.addRoll(5) f.addRoll(6) assert_equals(21, f.score) end end class TestGame < RUNIT::TestCase def setup end def testTypicalGame rolls = [1, 4, 4, 5, 6, 4, 5, 5, 10, 0, 1, 7, 3, 6, 4, 10, 2, 8, 6] b = Game.new rolls.each do | pins | b.roll(pins) end f = b.getFrame(0) assert_equals(1, f.first) assert_equals(4, f.second) assert_equals(Frame::NOMARK, f.mark) assert_equals(5, f.score) assert_equals(5, b.score(0)) f = b.getFrame(1) assert_equals(4, f.first) assert_equals(5, f.second) assert_equals(Frame::NOMARK, f.mark) assert_equals(9, f.score) assert_equals(14, b.score(1)) f = b.getFrame(2) assert_equals(6, f.first) assert_equals(4, f.second) assert_equals(Frame::SPARE, f.mark) assert_equals(15, f.score) assert_equals(29, b.score(2)) f = b.getFrame(3) assert_equals(5, f.first) assert_equals(5, f.second) assert_equals(Frame::SPARE, f.mark) assert_equals(20, f.score) assert_equals(49, b.score(3)) f = b.getFrame(4) assert_equals(10, f.first) assert_equals(0, f.second) assert_equals(Frame::STRIKE, f.mark) assert_equals(11, f.score) assert_equals(60, b.score(4)) f = b.getFrame(5) assert_equals(0, f.first) assert_equals(1, f.second) assert_equals(Frame::NOMARK, f.mark) assert_equals(1, f.score) assert_equals(61, b.score(5)) f = b.getFrame(6) assert_equals(7, f.first) assert_equals(3, f.second) assert_equals(Frame::SPARE, f.mark) assert_equals(16, f.score) assert_equals(77, b.score(6)) f = b.getFrame(7) assert_equals(6, f.first) assert_equals(4, f.second) assert_equals(Frame::SPARE, f.mark) assert_equals(20, f.score) assert_equals(97, b.score(7)) f = b.getFrame(8) assert_equals(10, f.first) assert_equals(2, f.second) assert_equals(Frame::STRIKE, f.mark) assert_equals(20, f.score) assert_equals(117, b.score(8)) f = b.getFrame(9) assert_equals(2, f.first) assert_equals(8, f.second) assert_equals(Frame::SPARE, f.mark) assert_equals(16, f.score) assert_equals(133, b.score(9)) f = b.getFrame(10) assert_equals(6, f.first) assert_equals(Frame::NOMARK, f.mark) assert_equals(133, b.finalScore) end def testPerfectGame b = Game.new 12.times do b.roll(10) end assert_equals(300, b.finalScore) end def testHeartBreaker b = Game.new 11.times do b.roll(10) end b.roll(9) assert_equals(299, b.finalScore) end end #--- main program ---- if __FILE__ == $0 require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(TestFrame.suite) RUNIT::CUI::TestRunner.run(TestGame.suite) end