Restrict assert checks to .rb files.
[ruby_koans.git] / koans / about_dice_project.rb
1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
2
3 # Implement a DiceSet Class here:
4 #
5 # class DiceSet
6 #   code ...
7 # end
8
9 class AboutDiceProject < EdgeCase::Koan
10   def test_can_create_a_dice_set
11     dice = DiceSet.new
12     assert_not_nil dice
13   end
14
15   def test_rolling_the_dice_returns_a_set_of_integers_between_1_and_6
16     dice = DiceSet.new
17
18     dice.roll(5)
19     assert dice.values.is_a?(Array), "should be an array"
20     assert_equal 5, dice.values.size
21     dice.values.each do |value|
22       assert value >= 1 && value <= 6, "value #{value} must be between 1 and 6"
23     end
24   end
25
26   def test_dice_values_do_not_change_unless_explicitly_rolled
27     dice = DiceSet.new
28     dice.roll(5)
29     first_time = dice.values
30     second_time = dice.values
31     assert_equal first_time, second_time
32   end
33
34   def test_dice_values_should_change_between_rolls
35     dice = DiceSet.new
36
37     dice.roll(5)
38     first_time = dice.values
39
40     dice.roll(5)
41     second_time = dice.values
42
43     assert_not_equal first_time, second_time,
44       "Two rolls should not be equal"
45
46     # THINK ABOUT IT:
47     #
48     # If the rolls are random, then it is possible (although not
49     # likely) that two consecutive rolls are equal.  What would be a
50     # better way to test this.
51   end
52
53   def test_you_can_roll_different_numbers_of_dice
54     dice = DiceSet.new
55
56     dice.roll(3)
57     assert_equal 3, dice.values.size
58
59     dice.roll(1)
60     assert_equal 1, dice.values.size
61   end
62
63 end