Skip to content

Commit

Permalink
some more spec (multiple constraints, exhausted tree)
Browse files Browse the repository at this point in the history
  • Loading branch information
chikamichi committed Aug 28, 2011
1 parent cc9dc8d commit 9109219
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions spec/amb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,42 @@ def test_public_api
end

def test_simple_constraint_as_arg
x = @amb.choose(1,2,3,4)
@amb.assert((x % 2) == 0)
assert x == 2, "#{x} must equal 2 (first-match)"
@x = @amb.choose(1,2,3,4)
@amb.assert((@x % 2) == 0)
assert @x == 2, "#{@x} must equal 2 (first-match)"
end

def test_simple_constraint_as_block
@x = @amb.choose(1,2,3,4)
@amb.assert { @x % 2 == 0 }
assert @x == 2, "#{@x} must equal 2 (first-match)"
end

def test_simple_constraint_as_block_with_parameters
@x = @amb.choose(1,2,3,4)
@amb.assert(4) { |i| (i * @x) % 2 == 0 }
assert @x == 1, "#{@x} must equal 1 (first-match)"
end

def test_multiple_alternatives
x = @amb.choose(1,2,3,4)
@amb.assert { x % 2 == 0 }
assert x == 2, "#{x} must equal 2 (first-match)"
y = @amb.choose(1,2,3,4)

@amb.assert x + y == 5
@amb.assert x - y == 1

assert x == 3, "#{x} must equal 3"
assert y == 2, "#{y} must equal 2"
end

def test_amb_tree_exhausted
assert_raises(Amb::ExhaustedError) do
x = @amb.choose(1,2,3,4)
y = @amb.choose(1,2,3,4)

@amb.assert x + y == 5
@amb.assert x - y == 1
@amb.assert x == 2
end
end
end

0 comments on commit 9109219

Please sign in to comment.