Skip to content

Commit

Permalink
Add within assertion helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jbn committed Oct 14, 2015
1 parent a020ad4 commit 31f38e9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ B = (1 + 1e-6)*A
#### `less_than`/
#### `less_than_or_equal`/
#### `less_than_or_equal`/
#### `greater_than_or_equal`
#### `greater_than_or_equal`/
#### `within`
Test inequality relationships between numbers.
```julia
@fact 1 --> less_than(2)
@fact 1 --> less_than_or_equal(1)
@fact 2 --> greater_than(1)
@fact 2 --> greater_than_or_equal(2)
@fact 2 --> within(1:3)
```

#### `anyof`
Expand Down
6 changes: 4 additions & 2 deletions src/FactCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export @fact, @fact_throws, @pending,
roughly,
anyof,
less_than, less_than_or_equal,
greater_than, greater_than_or_equal
greater_than, greater_than_or_equal,
within

const INDENT = " "

Expand Down Expand Up @@ -182,7 +183,8 @@ print_compact(s::Pending) = print_with_color(:yellow, "P")

const SPECIAL_FACTCHECK_FUNCTIONS =
Set([:not, :exactly, :roughly, :anyof,
:less_than, :less_than_or_equal, :greater_than, :greater_than_or_equal])
:less_than, :less_than_or_equal, :greater_than, :greater_than_or_equal,
:within])

@compat const FACTCHECK_FUN_NAMES =
Dict{Symbol,AbstractString}(
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ greater_than(compared) = (compare) -> compare > compared

# greater_than_or_equal: Comparing two numbers
greater_than_or_equal(compared) = (compare) -> compare >= compared

within(range::Range) = (compare) -> compare in range
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ facts("FactCheck assertion helper functions") do
@fact 2 --> greater_than_or_equal(1)
@fact 2 --> greater_than_or_equal(2)
end

context("within") do
@fact 2 --> within(1:3)
end
end

exitstatus()
Expand Down

0 comments on commit 31f38e9

Please sign in to comment.