5 Data Structure Expectations
procedure
(expect-list item-exp ...) → expectation?
item-exp : any/c
> (define num+string-expectation (expect-list (expect-pred number?) (expect-pred string?))) > (expect! '(10 "text") num+string-expectation) > (expect! '(foo bar) num+string-expectation) multiple failures
subject: '(foo bar)
fault: expected a different kind of value
in: item at position 0
expected: number?
actual: 'foo
fault: expected a different kind of value
in: item at position 1
expected: string?
actual: 'bar
> (expect! '(foo) num+string-expectation) multiple failures
subject: '(foo)
fault: expected a different value
in: the number of items
expected: eqv? to 2
actual: 1
fault: expected a different kind of value
in: item at position 0
expected: number?
actual: 'foo
procedure
(expect-list-ref item-exp index) → expectation?
item-exp : any/c index : exact-nonnegative-integer?
> (define expect-second-string? (expect-list-ref (expect-pred string?) 1)) > (expect! '(10 "text") expect-second-string?) > (expect! '(10 20) expect-second-string?) expected a different kind of value
subject: '(10 20)
in: item at position 1
expected: string?
actual: 20
procedure
(expect-list-length len-exp) → expectation?
len-exp : (or/c exact-nonnegative-integer? expectation?)
> (define expect-even-list (expect-list-length (expect-pred even?))) > (expect! '(a b) expect-even-list) > (expect! '(a b c) expect-even-list) expected a different kind of value
subject: '(a b c)
in: the number of items
expected: even?
actual: 3
procedure
(expect-vector item-exp ...) → expectation?
item-exp : any/c
> (define num+foo-vec-expectation (expect-vector (expect-pred number?) 'foo)) > (expect! #(10 foo) num+foo-vec-expectation) > (expect! #(10 bar) num+foo-vec-expectation) expected a different value
subject: '#(10 bar)
in: item at position 1
expected: equal? to 'foo
actual: 'bar
> (expect! #(10) num+foo-vec-expectation) expected a different value
subject: '#(10)
in: the number of items
expected: eqv? to 2
actual: 1
procedure
(expect-vector-ref item-exp index) → expectation?
item-exp : any/c index : exact-nonnegative-integer?
> (define expect-second-string? (expect-vector-ref (expect-pred string?) 1)) > (expect! #(10 "text") expect-second-string?) > (expect! #(10 20) expect-second-string?) expected a different kind of value
subject: '#(10 20)
in: item at position 1
expected: string?
actual: 20
procedure
(expect-vector-length len-exp) → expectation?
len-exp : (or/c exact-nonnegative-integer? expectation?)
> (define expect-even-vector (expect-vector-length (expect-pred even?))) > (expect! #(a b) expect-even-vector) > (expect! #(a b c) expect-even-vector) expected a different kind of value
subject: '#(a b c)
in: the number of items
expected: even?
actual: 3
procedure
(expect-set v ...) → expectation?
v : any/c
> (expect! (set 1 2 3) (expect-set 1 2 3)) > (expect! (set 1 'foo 'bar) (expect-set 1 2 3)) multiple failures
subject: (set 1 'bar 'foo)
fault: expected values to be contained
expected: 2 and 3 contained with set-member?
actual: (set 1 'bar 'foo)
fault: expected values to not be contained
expected: not 'foo or 'bar contained with set-member?
actual: (set 1 'bar 'foo)
procedure
v : any/c
> (expect! (set 1 2) (expect-set-member? 1)) > (expect! (set 1 2) (expect-set-member? 'foo)) expected a value to be contained
subject: (set 1 2)
expected: 'foo contained with set-member?
actual: (set 1 2)
procedure
v : any/c
> (expect! (set 1 2) (expect-set-not-member? 'foo)) > (expect! (set 1 2) (expect-set-not-member? 1)) expected a value to not be contained
subject: (set 1 2)
expected: not 1 contained with set-member?
actual: (set 1 2)
procedure
(expect-superset st) → expectation?
st : set?
> (expect! (set 1 2 3 4 5) (expect-superset (set 1 2 3))) > (expect! (set 1 5) (expect-superset (set 1 2 3))) expected values to be contained
subject: (set 1 5)
expected: 2 and 3 contained with set-member?
actual: (set 1 5)
procedure
(expect-subset st) → expectation?
st : set?
> (expect! (set 1 2) (expect-subset (set 1 2 3))) > (expect! (set 1 2 'foo 'bar) (expect-subset (set 1 2 3))) expected values to not be contained
subject: (set 1 'bar 2 'foo)
expected: not 'foo or 'bar contained with set-member?
actual: (set 1 'bar 2 'foo)
procedure
(expect-set-count count-exp) → expectation?
count-exp : (or/c exact-nonnegative-integer? expectation?)
> (expect! (set 'foo 'bar) (expect-set-count 2)) > (expect! (set 1 2 3) (expect-set-count (expect-pred even?))) expected a different kind of value
subject: (set 1 3 2)
in: the number of items
expected: even?
actual: 3
procedure
(expect-hash k value-exp ... ...) → expectation?
k : any/c value-exp : any/c
> (expect! (hash 'a 1 'b 2) (expect-hash 'a 1 'b 2)) > (expect! (hash 'a 1 'c 3) (expect-hash 'a 1 'b 2)) multiple failures
subject: '#hash((a . 1) (c . 3))
fault: expected values to be contained
in: the set of keys
expected: 'b contained with set-member?
actual: (set 'a 'c)
fault: expected values to not be contained
in: the set of keys
expected: not 'c contained with set-member?
actual: (set 'a 'c)
> (expect! (hash 'a 1 'b 1000) (expect-hash 'a 1 'b 2)) expected a different value
subject: '#hash((a . 1) (b . 1000))
in: value for key 'b
expected: equal? to 2
actual: 1000
procedure
(expect-hash-ref k value-exp) → expectation?
k : any/c value-exp : any/c
> (expect! (hash 'a 1 'b 2) (expect-hash-ref 'a 1)) > (expect! (hash 'a 100) (expect-hash-ref 'a 1)) expected a different value
subject: '#hash((a . 100))
in: value for key 'a
expected: equal? to 1
actual: 100
> (expect! (hash 'b 2) (expect-hash-ref 'a 1)) hash-ref: no value found for key
key: 'a
procedure
(expect-hash-count count-exp) → expectation?
count-exp : (or/c exact-nonnegative-integer? expectation?)
> (expect! (hash 'a 1 'b 2) (expect-hash-count 2)) > (expect! (hash 'a 1) (expect-hash-count (expect-pred even?))) expected a different kind of value
subject: '#hash((a . 1))
in: the number of items
expected: even?
actual: 1
procedure
(expect-hash-keys set-exp) → expectation?
set-exp : (or/c set? expectation?)
> (expect! (hash 'a 1 'b 2) (expect-hash-keys (set 'a 'b))) > (expect! (hash 'a 1) (expect-hash-keys (set 'a 'b))) expected values to be contained
subject: '#hash((a . 1))
in: the set of keys
expected: 'b contained with set-member?
actual: (set 'a)
procedure
(expect-box exp) → expectation?
exp : any/c
> (expect! (box 1) (expect-box 1)) > (expect! (box 100) (expect-box 1)) expected a different value
subject: '#&100
in: the box's value
expected: equal? to 1
actual: 100
procedure
(expect-syntax value-exp) → expectation?
value-exp : any/c
> (expect! #'foo (expect-syntax 'foo)) > (expect! #'#(1 2 3) (expect-syntax (vector #'1 #'2 #'3))) > (expect! #'foo (expect-syntax 'bar)) expected a different value
subject: #<syntax:eval:3:0 foo>
in: the return value of syntax-e
expected: equal? to 'bar
actual: 'foo
5.1 Data Structure Contexts and Attributes
struct
(struct sequence-context context (position) #:transparent) position : exact-nonnegative-integer?
procedure
(make-sequence-context position) → sequence-context?
position : exact-nonnegative-integer?
An apply-context containing the procedure used to extract the length of the sequence, e.g. vector-length.
A sequence-context with position 0, representing the first (and only) return value.
This context is used by expect-list-length, expect-set-count, and similar procedures.
struct
(struct dict-context context (key) #:transparent) key : any/c
procedure
(make-dict-context key) → dict-context?
key : any/c
value
value
procedure
(syntax-context? v) → boolean?
v : any/c