Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Forked from jredville/temp2.rb
Created September 13, 2012 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimweirich/3717491 to your computer and use it in GitHub Desktop.
Save jimweirich/3717491 to your computer and use it in GitHub Desktop.
describe Stack do
# Suggested Syntax...
Invariants do
If { stack.empty? }
Then { stack.depth.should == 0 }
Then { stack.should be_pushable }
ElseIf { stack.full? }
Then { stack.depth.should == stack.max_depth }
Then { stack.should_not be_pushable }
Else
Then { stack.depth.should be > 0 } # not wild about this part
end
# all of the above can be done with existing invariants
# (and an imply matcher)
Invariant { stack.empty?.should imply(stack.depth == 0) }
Invariant { stack.empty?.should imply(stack.pushable?) }
Invariant { stack.full?.should imply(stack.depth == stack.max_depth) }
Invariant { stack.full?.should imply(! stack.pushable?) }
Invariant { (!stack.full? && ! stack.empty?).should imply(stack.depth > 0) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment