Last active
December 12, 2015 02:59
-
-
Save woodie/4703843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
import 'cis.SeatChart' | |
import 'cis.ArrayOutOfBoundsException' | |
describe SeatChart, "once created" do | |
before(:each) do | |
@chart = SeatChart.new | |
end | |
it "should have a capacity of 10" do | |
@chart.get_max.should be 10 | |
end | |
# SeatChart.reserve() | |
it "should reserve seat 4" do | |
@chart.reserve(4) | |
@chart.to_string.should eq '4' | |
end | |
it "should raise exception when reserving seat 22" do | |
lambda{ @chart.reserve(22) }.should raise_error(java.lang.ArrayIndexOutOfBoundsException) | |
end | |
# SeatChart.release() | |
it "should reserve and release seat 4" do | |
@chart.reserve(4) | |
@chart.release(4) | |
@chart.to_string.should be_empty | |
end | |
it "should have printed 'invalid seat' message" do | |
print " >> " | |
@chart.release(0) | |
end | |
it "should have printed 'not reserved' message" do | |
print " >> " | |
@chart.release(4) | |
end | |
# SeatChart.available() | |
it "should not be available" do | |
@chart.reserve(4) | |
@chart.should_not be_available(4) | |
end | |
it "should be available" do | |
@chart.should be_available(4) | |
end | |
it "should raise exception" do | |
lambda{ @chart.available(22) }.should raise_error(ArrayOutOfBoundsException) | |
end | |
# SeatChart.isFull() | |
it "should be empty" do | |
@chart.should_not be_is_full | |
end | |
it "should not be full" do | |
1.upto(4) {|n| @chart.reserve(n)} | |
@chart.should_not be_is_full | |
end | |
it "should be full" do | |
1.upto(@chart.get_max) {|n| @chart.reserve(n)} | |
@chart.should be_is_full | |
end | |
# SeatChart.getMax() | |
it "should report capacity" do | |
@chart.get_max.should be 10 | |
end | |
# seatChart.numTaken() | |
it "should report 0 seats taken" do | |
@chart.num_taken.should be 0 | |
end | |
it "should report 4 seats taken" do | |
1.upto(4) {|n| @chart.reserve(n)} | |
@chart.num_taken.should be 4 | |
end | |
# SeatChart.validSeat() | |
it "should be valid seat 4" do | |
@chart.should be_valid_seat(4) | |
end | |
it "should not be valid seat 0" do | |
@chart.should_not be_valid_seat(0) | |
end | |
it "should not be valid seat 22" do | |
@chart.should_not be_valid_seat(22) | |
end | |
# SeatChart.equals() | |
it "should equal SeatChart with default" do | |
@chart.should be_equals(SeatChart.new) | |
end | |
it "should not equal SeatChart with other capacity" do | |
@chart.should_not be_equals(SeatChart.new(6)) | |
end | |
it "should not equal SeatChart with other reservations" do | |
@chart.reserve(4) | |
@chart.should_not be_equals(SeatChart.new) | |
end | |
it "should not equal some other object" do | |
@chart.should_not be_equals(String.new) | |
end | |
# SeatChart.toString() | |
it "should report reservations to string" do | |
1.upto(4) {|n| @chart.reserve(n)} | |
@chart.to_string.should eq "1, 2, 3, 4" | |
end | |
# SeatChart.clearAll() | |
it "should clear all reservations" do | |
1.upto(4) {|n| @chart.reserve(n)} | |
SeatChart.clear_all(@chart) | |
@chart.num_taken.should be 0 | |
end | |
end | |
__END__ | |
jruby -S rspec -fs spec/seat_chart_spec.rb | |
Java::Cis::SeatChart once created | |
should have a capacity of 10 | |
should reserve seat 4 | |
should raise exception when reserving seat 22 | |
should reserve and release seat 4 | |
>> Sorry, invalid seat number | |
should have printed 'invalid seat' message | |
>> Seat not previously reserved | |
should have printed 'not reserved' message | |
should not be available | |
should be available | |
should raise exception | |
should be empty | |
should not be full | |
should be full | |
should report capacity | |
should report 0 seats taken | |
should report 4 seats taken | |
should be valid seat 4 | |
should not be valid seat 0 | |
should not be valid seat 22 | |
should equal SeatChart with default | |
should not equal SeatChart with other capacity | |
should not equal SeatChart with other reservations | |
should not equal some other object | |
should report reservations to string | |
should clear all reservations | |
Finished in 0.162 seconds | |
24 examples, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment