Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ===========================================================
- # TESTING LIBRARY
- class Proc
- def t; call rescue nil; end
- def +@; puts t ? 'OK' : f; end
- def -@; puts t ? f : 'OK'; end
- def f; "FAIL @ #{source_location.join(':')}"; end
- end
- # ===========================================================
- # "DIE" - Simple die / dice simulator
- class Die
- def initialize(sides = 6); raise ArgumentError if sides < 2; @sides = sides; end
- def roll; rand(@sides) + 1; end
- end
- # ===========================================================
- # EXAMPLE TEST "SUITE" FOR "DIE"
- #
- # USAGE
- # +-> { block that should fail }
- # --> { block that should succeed }
- +-> { Die.new(2) }
- --> { Die.new(1) }
- +-> { (1..6) === Die.new(6).roll }
- +-> { die = Die.new(6)
- 1000.times { raise unless (1..6) === die.roll } }
- +-> { die = Die.new(6)
- 1000.times { raise if die.roll.zero? } }
- # This test will deliberately fail
- +-> { raise }
Add Comment
Please, Sign In to add comment