Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/contracts/builtin_contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def self.valid? val
# Check that an argument is a positive number.
class Pos
def self.valid? val
val > 0
val && val > 0
end
end

# Check that an argument is a negative number.
class Neg
def self.valid? val
val < 0
val && val < 0
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/builtin_contracts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
it "should fail for negative numbers" do
expect { @o.pos_test(-1) }.to raise_error(ContractError)
end

it "should fail for nil" do
expect { @o.pos_test(nil) }.to raise_error(ContractError)
end
end

describe "Neg:" do
Expand All @@ -43,6 +47,10 @@
it "should fail for positive numbers" do
expect { @o.neg_test(1) }.to raise_error(ContractError)
end

it "should fail for nil" do
expect { @o.neg_test(nil) }.to raise_error(ContractError)
end
end

describe "Nat:" do
Expand All @@ -61,6 +69,10 @@
it "should fail for negative numbers" do
expect { @o.nat_test(-1) }.to raise_error(ContractError)
end

it "should fail for nil" do
expect { @o.nat_test(nil) }.to raise_error(ContractError)
end
end

describe "Any:" do
Expand Down