3 Comparison and Equality Expectations
procedure
(expect-compare compare other) → expectation?
compare : (-> any/c any/c any/c) other : any/c
> (define expect-foo (expect-compare string=? "foo")) > (expect! "foo" expect-foo) > (expect! "bar" expect-foo) expected a different value
subject: "bar"
expected: string=? to "foo"
actual: "bar"
procedure
(expect-not-compare compare other) → expectation?
compare : (-> any/c any/c any/c) other : any/c
> (define expect-not-foo (expect-not-compare string=? "foo")) > (expect! "bar" expect-not-foo) > (expect! "foo" expect-not-foo) expected a different value
subject: "foo"
expected: not string=? to "foo"
actual: "foo"
procedure
(expect-contains? contains? v) → expectation?
contains? : (-> any/c any/c any/c) v : any/c
> (define exp-foo (expect-contains? hash-has-key? 'foo)) > (expect! (hash 'foo 1 'bar 2) exp-foo) > (expect! (hash 'bar 2) exp-foo) expected a value to be contained
subject: '#hash((bar . 2))
expected: 'foo contained with hash-has-key?
actual: '#hash((bar . 2))
procedure
(expect-not-contains? contains? v) → expectation?
contains? : (-> any/c any/c any/c) v : any/c
> (define exp-not-foo (expect-not-contains? hash-has-key? 'foo)) > (expect! (hash 'bar 2) exp-not-foo) > (expect! (hash 'foo 1 'bar 2) exp-not-foo) expected a value to not be contained
subject: '#hash((bar . 2) (foo . 1))
expected: not 'foo contained with hash-has-key?
actual: '#hash((bar . 2) (foo . 1))
procedure
(expect-contains-all? contains? vs) → expectation?
contains? : (-> any/c any/c any/c) vs : list?
> (define exp-keys (expect-contains-all? hash-has-key? '(foo bar baz))) > (expect! (hash 'foo 1 'bar 2 'baz 3) exp-keys) > (expect! (hash 'foo 1 'blah 4) exp-keys) expected values to be contained
subject: '#hash((blah . 4) (foo . 1))
expected: 'bar and 'baz contained with hash-has-key?
actual: '#hash((blah . 4) (foo . 1))
procedure
(expect-contains-none? contains? vs) → expectation?
contains? : (-> any/c any/c any/c) vs : list?
> (define exp-no-keys (expect-contains-none? hash-has-key? '(foo bar baz))) > (expect! (hash 'blah 4) exp-no-keys) > (expect! (hash 'foo 1 'baz 3 'blah 4) exp-no-keys) expected values to not be contained
subject: '#hash((baz . 3) (blah . 4) (foo . 1))
expected: not 'foo or 'baz contained with hash-has-key?
actual: '#hash((baz . 3) (blah . 4) (foo . 1))
procedure
(expect-eq? v) → expectation?
v : any/c
procedure
(expect-eqv? v) → expectation?
v : any/c
procedure
(expect-equal? v) → expectation?
v : any/c
> (expect! '(1 2 (foo 4 5) not-a-list 8) (expect-equal? '(1 2 (3 4 5) (6 7) 8))) multiple failures
subject: '(1 2 (foo 4 5) not-a-list 8)
fault: expected a different value
in: item at position 2
in: item at position 0
expected: equal? to 3
actual: 'foo
fault: expected a different kind of value
in: item at position 3
expected: list?
actual: 'not-a-list
procedure
(expect-not-eq? v) → expectation?
v : any/c
procedure
(expect-not-eqv? v) → expectation?
v : any/c
procedure
v : any/c
> (expect! '(1 foo) (expect-not-equal? '(1 2))) > (expect! 'a (expect-not-eq? 'a)) expected a different value
subject: 'a
expected: not eq? to 'a
actual: 'a
procedure
(expect-= x epsilon) → expectation?
x : real? epsilon : real?
> (define exp10 (expect-= 10 0.01)) > (expect! 10 exp10) > (expect! 25 exp10) expected a different number
subject: 25
expected: = to 10 (with tolerance of 0.01)
actual: 25
> (expect! 10.0001 exp10)
3.1 Comparison Attributes
struct
(struct compare-attribute attribute (proc other) #:transparent) proc : (-> any/c any/c any/c) other : any/c
procedure
(make-compare-attribute proc other) → compare-attribute?
proc : (-> any/c any/c any/c) other : any/c
struct
(struct contains-attribute attribute (proc value) #:transparent) proc : (-> any/c any/c any/c) value : any/c
procedure
(make-contains-attribute proc value) → contains-attribute?
proc : (-> any/c any/c any/c) value : any/c
procedure
(make-contains-all-attribute contains? vs) → and-attribute?
contains? : (-> any/c any/c any/c) vs : list?
> (make-contains-all-attribute hash-has-key? '(foo bar baz))
(and-attribute
"'foo, 'bar and 'baz contained with hash-has-key?"
(list
(contains-attribute
"'foo contained with hash-has-key?"
#<procedure:hash-has-key?>
'foo)
(contains-attribute
"'bar contained with hash-has-key?"
#<procedure:hash-has-key?>
'bar)
(contains-attribute
"'baz contained with hash-has-key?"
#<procedure:hash-has-key?>
'baz)))
procedure
(make-contains-none-attribute contains? vs) → not-attribute?
contains? : (-> any/c any/c any/c) vs : list?
> (make-contains-none-attribute hash-has-key? '(foo bar baz))
(not-attribute
"not 'foo, 'bar or 'baz contained with hash-has-key?"
(or-attribute
"'foo, 'bar or 'baz contained with hash-has-key?"
(list
(contains-attribute
"'foo contained with hash-has-key?"
#<procedure:hash-has-key?>
'foo)
(contains-attribute
"'bar contained with hash-has-key?"
#<procedure:hash-has-key?>
'bar)
(contains-attribute
"'baz contained with hash-has-key?"
#<procedure:hash-has-key?>
'baz))))
struct
(struct =-attribute attribute (value epsilon) #:transparent) value : real? epsilon : real?
procedure
(make-=-attribute value epsilon) → =-attribute?
value : real? epsilon : real?
procedure
(eq-attribute? v) → boolean?
v : any/c
procedure
(eqv-attribute? v) → boolean?
v : any/c
procedure
(equal-attribute? v) → boolean?
v : any/c
procedure
(make-eq-attribute value) → eq-attribute?
value : any/c
procedure
(make-eqv-attribute value) → eqv-attribute?
value : any/c
procedure
(make-equal-attribute value) → equal-attribute?
value : any/c