Moved integration tests for assoc and member to the right place.

This commit is contained in:
Georges Dupéron 2015-10-29 15:24:55 +01:00
parent 7cb171e522
commit a6fda347b9
3 changed files with 58 additions and 41 deletions

View File

@ -0,0 +1,28 @@
#lang typed/racket
(require typed/rackunit)
;; Test that (assoc v lst is-equal?) always passes v as the first argument to
;; is-equal? . If this is not the case, the type for the is-equal? argument
;; should be (→ (U a c) (U a c) Any) instead of (→ c a Any).
(let ([needle : Integer
;; Use a random needle to prevent some optimizations (but not all)
(floor (inexact->exact (* (random) 200)))])
(assoc3 needle
(ann (map (λ ([x : Integer]) (cons x (format "~a" x))) (range 1000))
(Listof (Pairof Integer String)))
(λ ([x : Integer] [y : Integer])
;; Check the needle is always the first argument
(check-equal? x needle)
;; Check y = needle implies x = needle
(check-true (or (not (= y needle)) (= x needle)))
(= x y))))
;; Test that the third is-equal? argument is taken into account. If it is taken
;; into account, it will return '("c" . 2). If it isn't, it will return
;; '("x" . 4) instead.
(check-equal? (assoc "x"
'(("bb" . 1) ("c" . 2) ("ddd" . 3) ("x" . 4))
(lambda ([s1 : String] [s2 : String])
(= (string-length s1) (string-length s2))))
'("c" . 2))

View File

@ -0,0 +1,30 @@
#lang typed/racket
(require typed/rackunit)
;; Test that (member v lst is-equal?) always passes v as the first argument to
;; is-equal? . If this is not the case, the type for the is-equal? argument
;; should be (→ (U a b) (U a b) Any) instead of (→ b a Any).
(let ([needle : Integer
;; Use a random needle to prevent some optimizations (but not all)
(floor (inexact->exact (* (random) 200)))])
(member needle
(range 1000)
(λ ([x : Integer] [y : Integer])
;; Check the needle is always the first argument
(check-equal? x needle)
;; Check y = needle implies x = needle
(check-true (or (not (= y needle)) (= x needle)))
(= x y))))
;; Test that the third is-equal? argument is taken into account. If it is taken
;; into account, it will return '("c" "ddd" "x"). If it isn't, it will return
;; '("x") instead.
(check-equal? (member "x"
'("bb" "c" "ddd" "x")
(lambda ([s1 : String] [s2 : String])
(= (string-length s1) (string-length s2))))
'("c" "ddd" "x"))
(check-equal? (member "x" '("bb" "c" "ddd" "x")) '("x"))

View File

@ -2370,47 +2370,6 @@
[tc-e (vector-memq 3 #(a b c)) (t:Un (-val #f) -Index)]
[tc-e (vector-memv 3 #(a b c)) (t:Un (-val #f) -Index)]
[tc-e (vector-member 3 #(a b c)) (t:Un (-val #f) -Index)]
;; Test that (member v lst is-equal?) always passes v as the first
;; argument to is-equal? . If this is not the case, the type for the
;; is-equal? argument should be (→ (U a b) (U a b) Any) instead of
;; (→ b a Any).
;; We use a random needle to prevent some of optimization (but not all):
(let ([needle : Integer (floor (inexact->exact (* (random) 200)))])
(member needle
(range 1000)
(λ ([x : Integer] [y : Integer])
;; Check the needle is always the first argument
(check-equal? x needle)
;; Check y = needle implies x = needle
(check-true (or (not (= y needle)) (= x needle)))
(= x y))))
;; Test that (assoc v lst is-equal?) always passes v as the first
;; argument to is-equal? . If this is not the case, the type for the
;; is-equal? argument should be (→ (U a c) (U a c) Any) instead of
;; (→ c a Any).
;; We use a random needle to prevent some of optimization (but not all):
(let ([needle : Integer (floor (inexact->exact (* (random) 200)))])
(assoc3 needle
(ann (map (λ ([x : Integer]) (cons x (format "~a" x))) (range 1000))
(Listof (Pairof Integer String)))
(λ ([x : Integer] [y : Integer])
;; Check the needle is always the first argument
(check-equal? x needle)
;; Check y = needle implies x = needle
(check-true (or (not (= y needle)) (= x needle)))
(= x y))))
;; Test output of member with third is-equal? argument:
(check-equal? (member "x"
'("bb" "c" "ddd" "x")
(lambda ([s1 : String] [s2 : String])
(= (string-length s1) (string-length s2))))
'("c" "ddd" "x"))
;; Test output of assoc with third is-equal? argument:
(check-equal? (assoc "x"
'(("bb" . 1) ("c" . 2) ("ddd" . 3) ("x" . 4))
(lambda ([s1 : String] [s2 : String])
(= (string-length s1) (string-length s2))))
'("c" . 2))
;; Test `member` with needle not included in is-equal?'s argument type:
[tc-err (member (ann 123 Number)
'("bb" "c" "ddd")