Sha256: 63a95923636d1046b1a01449120fb7c108aa1d6c9c2f763a52897db6b99fb0d5
Contents?: true
Size: 801 Bytes
Versions: 2
Compression:
Stored size: 801 Bytes
Contents
require 'contract' class StackContract < Contract post :push do |stack_pre, stack, exception, result, element| assert_nil(result) assert_equal(element, stack.top) assert_equal(stack.size, stack_pre.size + 1) end pre :pop do |stack| assert_operator(stack.size, :>=, 0) end post :pop do |stack_pre, stack, exception, result| if stack_pre.empty? assert_kind_of(Stack::NoPopForEmptyStack, exception) else assert_equal(stack_pre.top, result) assert_equal(stack_pre.size - 1, stack.size) end end pre :top do |stack| assert_operator(stack.size, :>=, 1) end post :top do |stack_pre, stack, exception, result| assert_equal(stack_pre.size, stack.size) end invariant do |stack| assert_operator(stack.size, :>=, 0) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
armin-joellenbeck-rdbc-0.0.6 | examples/stack_contract.rb |
armin-joellenbeck-rdbc-0.0.7 | examples/stack_contract.rb |