test/unit/test_slot.rb in slot_machine-0.1.0 vs test/unit/test_slot.rb in slot_machine-0.1.1
- old
+ new
@@ -12,10 +12,15 @@
assert_equal 10, Slot.default_interval
Slot.class_eval do
interval 20
end
assert_equal 20, Slot.default_interval
+
+ Slot.class_eval do
+ interval 10
+ end
+ assert_equal 10, Slot.default_interval
end
end
describe "instance methods" do
it "should have the expected instance methods" do
@@ -26,12 +31,14 @@
assert slot.respond_to?(:start=)
assert slot.respond_to?(:end)
assert slot.respond_to?(:end=)
assert slot.respond_to?(:length)
assert slot.respond_to?(:length=)
- assert slot.respond_to?(:to_compared)
+ assert slot.respond_to?(:to_compared, true)
assert slot.respond_to?(:match)
+ assert slot.respond_to?(:+)
+ assert slot.respond_to?(:-)
end
end
describe "initialization" do
it "should accept a range" do
@@ -73,11 +80,11 @@
assert slot.length?
end
end
describe "equality" do
- it "should return whether it equals another objects" do
+ it "should return whether it equals another object" do
slot = Slot.new 1
assert !(slot == 1)
assert !(slot == Slot.new(1..2))
assert_equal slot, Slot.new(1)
@@ -188,10 +195,24 @@
end
assert_raises ArgumentError do
Slot.new(5).match(5)
end
end
+
+ it "should be able to add other slots" do
+ assert_equal Slots, (Slot.new(1..10) + (5..8)).class
+ assert_equal Slots, (Slot.new(1..10) + Slot.new(5..8)).class
+ assert_equal Slots, (Slot.new(1..10) + [5..8]).class
+ assert_equal Slots, (Slot.new(1..10) + Slots.new([5..8])).class
+ end
+
+ it "should be able to subtract other slots" do
+ assert_equal Slots, (Slot.new(1..10) - (5..8)).class
+ assert_equal Slots, (Slot.new(1..10) - Slot.new(5..8)).class
+ assert_equal Slots, (Slot.new(1..10) - [5..8]).class
+ assert_equal Slots, (Slot.new(1..10) - Slots.new([5..8])).class
+ end
end
describe "length slots" do
it "should only set length (not start or end) and typecast the passed argument" do
slot = Slot.new 10
@@ -231,7 +252,8 @@
it "should represent itself as an integer when invoking to_compared" do
assert_equal 10, Slot.new(10).send(:to_compared)
end
end
end
+
end
end
\ No newline at end of file