test-equal+hash-poly.rkt (1181B)
1 #lang typed/racket 2 3 (require typed-struct-props 4 typed/rackunit) 5 6 (struct/props (A) foo ([f : A]) #:transparent 7 #:property prop:equal+hash (list (λ (a b rec) #f) 8 (λ (a rec) 42) 9 (λ (a rec) 43))) 10 11 (struct/props (A) bar ([f : A]) #:transparent) 12 13 (test-not-exn "The structure's constructor and type work properly" 14 (λ () (ann (foo "b") (foo String)))) 15 16 (test-equal? "The structure's constructor and accessor work properly" 17 (ann (foo-f (foo "b")) String) 18 "b") 19 20 (test-begin 21 (test-false "The equal? function supplied to #:equal+hash is used" 22 (equal? (foo 0) (foo 0))) 23 24 (test-true "When unspecified, the default implementation of equal? is used" 25 (equal? (bar 0) (bar 0)))) 26 27 (test-equal? "The equal-hash-code function supplied to #:equal+hash is used" 28 (equal-hash-code (foo "d")) 29 (equal-hash-code (foo "e"))) 30 31 (test-equal? 32 "The equal-secondary hash-code function supplied to #:equal+hash is used" 33 (equal-secondary-hash-code (foo 'f)) 34 (equal-secondary-hash-code (foo 'g)))