(load "lib/poker-hands.egi") ;; match List (test (match-all {1 2 3 4 5} (List Integer) [ [x xs]])) (test {[5 {1 2 3 4}]}) (test (match-all {1 2 3 4 5} (List Integer) [ xs])) (test {{3 4 5}}) (test (match-all {1 2 3 4 5} (List Integer) [> xs])) (test {{} {1} {1 2} {1 2 3} {1 2 3 4} {1 2 3 4 5} {} {2} {2 3} {2 3 4} {2 3 4 5} {} {3} {3 4} {3 4 5} {} {4} {4 5} {} {5} {}}) (test (match-all {[1 2] [1 2]} (List [Integer Integer]) [ [a b]])) (test {[1 2]}) ;; match Multiset (test (match-all {1 2 3 4 5} (Multiset Integer) [> [m n]])) (test {[1 2] [1 3] [1 4] [1 5] [2 1] [2 3] [2 4] [2 5] [3 1] [3 2] [3 4] [3 5] [4 1] [4 2] [4 3] [4 5] [5 1] [5 2] [5 3] [5 4]}) ;; match a collection of collections (test (match-all {{1 2 3} {11} {21 22}} (List (Multiset Integer)) [ >>> [x y z]])) (test {[1 11 21] [1 11 22] [2 11 21] [2 11 22] [3 11 21] [3 11 22]}) ;; match a collection of collections with value patterns (test (match-all {{1 2 3 4 5} {4 5 1} {6 1 7 4}} (List (Multiset Integer)) [ >>> n])) (test {1 4}) ;; pattern as first class object (test (let {[$pat >]} (match {1} (Multiset Integer) {[pat ] [_ ]}))) (test ) ;; Or-pattern test1 (test (match {} (Multiset Integer) {[(| >) ] [_ ]})) (test ) ;; Or-pattern test2 (test (match {1} (Multiset Integer) {[(| >) ] [_ ]})) (test ) (test (match-all {1 2 3 4 5 6 7 1 3 5 7} (Multiset Integer) [> x])) (test {2 4 6}) (test (match-all {{1 2 3} {2 3 4} {1}} (Multiset (Multiset Integer)) [> >>> x])) (test {4 4}) ; is really ok? (test (match-all {{1 2 3} {2 3 4}} (Multiset (Multiset Integer)) [> >> x])) (test {1 4}) (test (match-all {1 2 3} (List Integer) [ [hs ts]])) (test "here") (test {[{} {1 2 3}] [{1} {2 3}] [{1 2} {3}] [{1 2 3} {}]}) (test (match-all {1 2 3} (List Integer) [ [hs ts]])) (test {[{1 2 3} {}] [{2 3} {1}] [{3} {1 2}] [{} {1 2 3}]}) (test (match-all {1 2 3} (Multiset Integer) [ [hs ts]])) (test {[{} {3 2 1}] [{1} {3 2}] [{2} {3 1}] [{1 2} {3}] [{3} {2 1}] [{1 3} {2}] [{2 3} {1}] [{1 2 3} {}]}) (test (match-all {1 2 3} (Set Integer) [ [hs ts]])) (test {[{} {3 2 1}] [{1} {3 2}] [{1} {3 2 1}] [{2} {3 1}] [{2} {3 1 2}] [{1 2} {3}] [{1 2} {3 1}] [{1 2} {3 2}] [{1 2} {3 1 2}] [{3} {2 1}] [{3} {2 1 3}] [{1 3} {2}] [{1 3} {2 1}] [{1 3} {2 3}] [{1 3} {2 1 3}] [{2 3} {1}] [{2 3} {1 2}] [{2 3} {1 3}] [{2 3} {1 2 3}] [{1 2 3} {}] [{1 2 3} {1}] [{1 2 3} {2}] [{1 2 3} {1 2}] [{1 2 3} {3}] [{1 2 3} {1 3}] [{1 2 3} {2 3}] [{1 2 3} {1 2 3}]}) (test (match-all {1 2 3} (List Integer) [> [hs x ts]])) (test {[{} 1 {2 3}] [{1} 2 {3}] [{1 2} 3 {}]}) ;; noij (test (match-all { } (List Something) [ [xs ys]])) (test ((remove-collection Suit) { } { })) (test (subcollections { })) ;; Cut-pattern (test (match {2 7 7 2 7} (Multiset Integer) {[>>>>> ] [_ ]})) ;; Value-pattern (test (match {5 2 1 3 4} (Multiset Integer) {[>>>>> ] [_ ]})) (test (match-all {1 2 3 4} (List Integer) [> ns])) ;; pattern macro (define $single (macro [$s $pat] )) (test (match-all {1 2 3 1 2} (Multiset Integer) [(single %k _) k])) (test {1 2 3}) (define $pair (macro [$s $pat] >)) (test (match-all {1 2 3 1 2} (Multiset Integer) [(pair %k _) k])) (test {1 2}) (define $loop-pat (lambda [$k $i] (match i Integer {[,k >] [_ >]}))) (define $loop-pat (lambda [$k] (| ))) (define $isStraight? (lambda [$Ns] (match Ns (Multiset Integer) {[ ] [_ ]}))) (define $isStraight? (lambda [$Ns] (match Ns (Multiset Integer) {[ ] [_ ]}))) (test (isStraight? {1 2})) ;; comparison of large list (test (match (between 1 10000) (List Integer) {[,(between 1 10000) ] [_ ]}))