www

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

test-traversal-1.rkt (4332B)


      1 #lang type-expander
      2 
      3 (require "traversal-util.rkt"
      4          "ck.rkt")
      5 
      6 (define-type Foo (Listof String))
      7 
      8 (define-fold f₁ t₁ Null String)
      9 (define-fold f₂ t₂ (Pairof Null Null) String)
     10 (define-fold f₃ t₃ String String)
     11 (define-fold f₄ t₄ (Pairof Null String) String)
     12 (define-fold f₅ t₅ (Listof Null) String)
     13 (define-fold f₆ t₆ (List Null (Pairof Null Null) Null) String)
     14 (define-fold f₇ t₇ (Listof String) String)
     15 (define-fold f₈ t₈ (List String Foo (Listof String)) String)
     16 (define-fold f₉ t₉ (List (Listof String) Foo (Listof String)) (Listof String))
     17 (define-fold f₁₀ t₁₀ (List String Foo (Listof String)) (Listof String))
     18 (define-fold f₁₁ t₁₁ (List (Listof String) (Listof Number)) (Listof String))
     19 (define-fold f₁₂ t₁₂ (List (Listof String) (Listof String)) (Listof String))
     20 (define-fold f₁₃ t₁₃
     21   (List Null
     22         (Pairof (List (List Null))
     23                 (List (List Null)))
     24         Null)
     25   String)
     26 
     27 (define (string->symbol+acc [x : String] [acc : Integer])
     28   (values (string->symbol x) (add1 acc)))
     29 
     30 (check-equal?-values: ((f₁ string? string->symbol+acc) '() 0)
     31                       '() 0)
     32 
     33 (check-equal?-values: ((f₁ string? string->symbol+acc) '() 0)
     34                       : (Values Null Integer)
     35                       '() 0)
     36 
     37 (check-equal?-values: ((f₂ string? string->symbol+acc) '(() . ()) 0)
     38                       : (Values (Pairof Null Null) Integer)
     39                       '(() . ()) 0)
     40 
     41 (check-equal?-values: ((f₃ string? string->symbol+acc) "abc" 0)
     42                       : (Values Symbol Integer)
     43                       'abc 1)
     44 
     45 (check-equal?-values: ((f₄ string? string->symbol+acc) '(() . "def") 0)
     46                       : (Values (Pairof Null Symbol) Integer)
     47                       '(() . def) 1)
     48 
     49 (check-equal?-values: ((f₅ string? string->symbol+acc) '(() () () ()) 0)
     50                       : (Values (Listof Null) Integer)
     51                       '(() () () ()) 0)
     52 
     53 (check-equal?-values: ((f₅ string? string->symbol+acc) '(()) 0)
     54                       : (Values (Listof Null) Integer)
     55                       '(()) 0)
     56 
     57 (check-equal?-values: ((f₅ string? string->symbol+acc) '() 0)
     58                       : (Values (Listof Null) Integer)
     59                       '() 0)
     60 
     61 (check-equal?-values: ((f₆ string? string->symbol+acc) '(() (() . ()) ()) 0)
     62                       : (Values (List Null (Pairof Null Null) Null) Integer)
     63                       '(() (() . ()) ()) 0)
     64 
     65 (check-equal?-values: ((f₇ string? string->symbol+acc) '("abc" "def" "ghi") 0)
     66                       : (Values (Listof Symbol) Integer)
     67                       '(abc def ghi) 3)
     68 
     69 (check-equal?-values: ((f₈ string? string->symbol+acc) '("abc" ("def" "ghi")
     70                                                                ("jkl" "mno"))
     71                                                        0)
     72                       : (Values (List Symbol (Listof String) (Listof Symbol))
     73                                 Integer)
     74                       '(abc ("def" "ghi") (jkl mno)) 3)
     75 
     76 (check-equal?-values: ((f₉ (make-predicate (Listof String))
     77                            (λ ([l : (Listof String)] [acc : Integer])
     78                              (values (map string->symbol l)
     79                                      (add1 acc))))
     80                        '(("a" "b" "c")
     81                          ("def" "ghi")
     82                          ("jkl" "mno"))
     83                        0)
     84                       : (Values (List (Listof Symbol)
     85                                       (Listof String)
     86                                       (Listof Symbol))
     87                                 Integer)
     88                       '((a b c) ("def" "ghi") (jkl mno)) 2)
     89 
     90 (check-equal?-values: ((f₁₀ (make-predicate (Listof String))
     91                            (λ ([l : (Listof String)] [acc : Integer])
     92                              (values (map string->symbol l)
     93                                      (add1 acc))))
     94                        '("abc"
     95                          ("def" "ghi")
     96                          ("jkl" "mno"))
     97                        0)
     98                       : (Values (List String
     99                                       (Listof String)
    100                                       (Listof Symbol))
    101                                 Integer)
    102                       '("abc" ("def" "ghi") (jkl mno)) 1)