Created
April 24, 2014 14:34
-
-
Save godfat/11256842 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 'bacon' | |
require 'rubyqc' | |
Bacon.summary_on_exit | |
Bacon::Context.include RubyQC::API | |
class User < Struct.new(:name, :gold) | |
def self.rubyqc | |
new(String.rubyqc, (0..99).rubyqc) | |
end | |
def give that, amount | |
if gold >= amount | |
self.gold -= amount | |
that.gold += amount | |
true | |
else | |
false | |
end | |
end | |
end | |
describe User do | |
should 'Generate random users' do | |
check(User) do |user| | |
user .should.kind_of User | |
user.name.should.kind_of String | |
user.gold.should.kind_of Fixnum | |
end | |
end | |
should 'Give gold to others' do | |
check(User, User, 0..99) do |a, b, gold| | |
total = a.gold + b.gold | |
agold = a.gold | |
a.give(b, gold).should == gold <= agold | |
a.gold.should >= 0 | |
b.gold.should >= 0 | |
(a.gold + b.gold).should == total | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment