(load "lib/poker-hands.egi") ;; match List (test (match-all {1 2 3 4 5} (List Integer) [ [x xs]])) (test (match-all {1 2 3 4 5} (List Integer) [ xs])) (test (match-all {1 2 3 4 5} (List Integer) [ xs])) (test (match-all {[1 2] [1 2]} (List [Integer Integer]) [ [a b]])) ;; match Multiset (test (match-all {1 2 3 4 5} (Multiset Integer) [> [m n]])) ;; match a collection of collections (test (match-all {{1 2 3} {11} {21 22}} (List (Multiset Integer)) [ >>> [x y z]])) ;; 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])) ;; pattern as first class object (test (let {[$pat >]} (match {1} (Multiset Integer) {[pat ] [_ ]}))) ;; Or-pattern test1 (test (match {} (Multiset Integer) {[(| >) ] [_ ]})) ;; Or-pattern test2 (test (match {1} (Multiset Integer) {[(| >) ] [_ ]})) (test (match-all {1 2 3 4 5 6 7 1 3 5 7} (Multiset Integer) [> x])) (test (match-all {{1 2 3} {2 3 4} {1}} (Multiset (Multiset Integer)) [> >>> x])) (test (match-all {{1 2 3} {2 3 4}} (Multiset (Multiset Integer)) [> >> x])) (test (match-all {1 2 3} (List Integer) [ [hs ts]])) (test (match-all {1 2 3} (List Integer) [ [hs ts]])) (test (match-all {1 2 3} (Multiset Integer) [ [hs ts]])) (test (match-all {1 2 3} (Set Integer) [ [hs ts]])) (test (match-all {1 2 3} (List Integer) [> [hs x ts]])) ;; 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])) (define $pair (macro [$s $pat] >)) (test (match-all {1 2 3 1 2} (Multiset Integer) [(pair %k _) k])) (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) ] [_ ]}))