www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test-equal+hash.rkt (1169B)


      1 #lang typed/racket
      2 
      3 (require typed-struct-props
      4          typed/rackunit)
      5 
      6 (struct/props foo ([f : Number]) #:transparent
      7               #:property prop:equal+hash (list (λ (a b rec) #f)
      8                                                (λ (a rec) 42)
      9                                                (λ (a rec) 43)))
     10 
     11 (struct/props bar ([f : Number]) #:transparent)
     12 
     13 (test-not-exn "The structure's constructor and type work properly"
     14               (λ () (ann (foo 12) foo)))
     15 
     16 (test-equal? "The structure's constructor and accessor work properly"
     17              (ann (foo-f (foo 12)) Number)
     18              12)
     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 34))
     29              (equal-hash-code (foo 56)))
     30 
     31 (test-equal?
     32  "The equal-secondary hash-code function supplied to #:equal+hash is used"
     33  (equal-secondary-hash-code (foo 78))
     34  (equal-secondary-hash-code (foo 90)))