spec/dice_spec.rb in rdice-0.0.2 vs spec/dice_spec.rb in rdice-0.0.3
- old
+ new
@@ -1,30 +1,127 @@
require 'spec_helper'
+
describe Dice do
- let(:dice) { Dice.new }
+ NTIMES = 300
- describe "new" do
- it "roll one dice" do
- 1.upto(6).include?(dice.roll).should be_true
+ describe "new with default values" do
+
+ describe ".roll" do
+ let(:dice) { Dice.new }
+
+ it "return value between 1 to 6" do
+ NTIMES.times { 1.upto(6).include?(dice.roll).should be_true }
+ end
end
+
+ describe ".roll_two" do
+ let(:dice) { Dice.new }
+
+ it "return value between 2 to 12" do
+ NTIMES.times { 2.upto(12).include?(dice.roll_two).should be_true }
+ end
+
+ it "cant return 1" do
+ NTIMES.times { 2.upto(12).include?(dice.roll_two).should_not == 1 }
+ end
+
+ it "cant be lesser then 2" do
+ NTIMES.times { dice.roll_two.should_not < 2 }
+ end
+
+ it "cant return 13" do
+ NTIMES.times { dice.roll_two.should_not > 13 }
+ end
+ end
+
+ describe ".roll_d20" do
+ let(:dice) { Dice.new }
+
+ it "return value between 1 to 20" do
+ NTIMES.times { 1.upto(20).include?(dice.roll_d20).should be_true }
+ end
+
+ it "cant return 21" do
+ NTIMES.times { dice.roll_two.should_not > 20 }
+ end
+ end
+
+ describe ".roll_two_d10" do
+ let(:dice) { Dice.new }
+
+ it "return value between 1 to 10" do
+ NTIMES.times { 2.upto(20).include?(dice.roll_two_d10).should be_true }
+ end
+
+ it "can be less than 2" do
+ NTIMES.times { dice.roll_two_d10.should_not < 2 }
+ end
+
+ it "cant return 21" do
+ NTIMES.times { dice.roll_two_d10.should_not > 20 }
+ end
+ end
+
end
-
- describe "new with 2 dices" do
- it "return value between 2 to 12" do
- 2.upto(12).include?(dice.roll_two).should be_true
+
+ describe "new with 12 faces and 3 dices" do
+
+ describe ".roll" do
+ let(:dice) { Dice.new(12,3) }
+
+ it "return value between 3 to 36" do
+ 3.upto(36).include?(dice.roll).should be_true
+ end
end
- it "cant return 1" do
- 30.times { 2.upto(12).include?(dice.roll_two).should_not == 1 }
+ describe ".roll_two" do
+ let(:dice) { Dice.new(12,3) }
+
+ it "return value between 2 to 24" do
+ NTIMES.times { 2.upto(24).include?(dice.roll_two).should be_true }
+ end
+
+ it "cant return 1" do
+ NTIMES.times { 2.upto(24).include?(dice.roll_two).should_not == 1 }
+ end
+
+ it "cant be lesser then 2" do
+ NTIMES.times { dice.roll_two.should_not < 2 }
+ end
+
+ it "cant return 25" do
+ NTIMES.times { dice.roll_two.should_not > 25 }
+ end
end
- it "cant be lesser then 2" do
- 30.times { dice.roll_two.should_not < 2 }
+ describe ".roll_d20" do
+ let(:dice) { Dice.new(12,3) }
+
+ it "return value between 1 to 60" do
+ NTIMES.times { 3.upto(60).include?(dice.roll_d20).should be_true }
+ end
+
+ it "cant return 61" do
+ NTIMES.times { dice.roll_two.should_not > 61 }
+ end
end
- it "cant return 13" do
- 30.times { dice.roll_two.should_not > 13 }
+ describe ".roll_two_d10" do
+ let(:dice) { Dice.new(12,3) }
+
+ it "return value between 1 to 10" do
+ NTIMES.times { 2.upto(20).include?(dice.roll_two_d10).should be_true }
+ end
+
+ it "can be less than 2" do
+ NTIMES.times { dice.roll_two_d10.should_not < 2 }
+ end
+
+ it "cant return 21" do
+ NTIMES.times { dice.roll_two_d10.should_not > 20 }
+ end
end
+
end
-
+
end
\ No newline at end of file