|
|
|
|
@ -654,7 +654,24 @@ new list." |
|
|
|
|
(defexamples -max-by |
|
|
|
|
(-max-by '> '(4 3 6 1)) => 6 |
|
|
|
|
(--max-by (> (car it) (car other)) '((1 2 3) (2) (3 2))) => '(3 2) |
|
|
|
|
(--max-by (> (length it) (length other)) '((1 2 3) (2) (3 2))) => '(1 2 3))) |
|
|
|
|
(--max-by (> (length it) (length other)) '((1 2 3) (2) (3 2))) => '(1 2 3)) |
|
|
|
|
|
|
|
|
|
(defexamples -frequencies |
|
|
|
|
(-frequencies '()) => '() |
|
|
|
|
(-frequencies '(1 2 3 1 2 1)) => '((1 . 3) (2 . 2) (3 . 1)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-frequencies '(a "a"))) => '((a . 2)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-frequencies '("a" a))) => '(("a" . 2)) |
|
|
|
|
(-frequencies '(1)) => '((1 . 1)) |
|
|
|
|
(-frequencies '(1 1)) => '((1 . 2)) |
|
|
|
|
(-frequencies '(2 1 1)) => '((2 . 1) (1 . 2)) |
|
|
|
|
(let ((-compare-fn #'eq) |
|
|
|
|
(a (string ?a))) |
|
|
|
|
(-frequencies `(,a ,(string ?a) ,a))) |
|
|
|
|
=> '(("a" . 2) ("a" . 1)) |
|
|
|
|
(let ((-compare-fn #'eq) |
|
|
|
|
(a (string ?a))) |
|
|
|
|
(-frequencies `(,(string ?a) ,a ,a))) |
|
|
|
|
=> '(("a" . 1) ("a" . 2)))) |
|
|
|
|
|
|
|
|
|
(def-example-group "Unfolding" |
|
|
|
|
"Operations dual to reductions, building lists from a seed |
|
|
|
|
@ -1189,13 +1206,72 @@ related predicates." |
|
|
|
|
(let ((-compare-fn #'string=)) (-intersection '("a") '(a)) => '("a"))) |
|
|
|
|
|
|
|
|
|
(defexamples -powerset |
|
|
|
|
(-powerset '()) => '(nil) |
|
|
|
|
(-powerset '(x y z)) => '((x y z) (x y) (x z) (x) (y z) (y) (z) nil)) |
|
|
|
|
(-powerset '()) => '(()) |
|
|
|
|
(-powerset '(x y)) => '((x y) (x) (y) ()) |
|
|
|
|
(-powerset '(x y z)) => '((x y z) (x y) (x z) (x) (y z) (y) (z) ()) |
|
|
|
|
(let ((p (-powerset '()))) (setcar p t) (-powerset '())) => '(())) |
|
|
|
|
|
|
|
|
|
(defexamples -permutations |
|
|
|
|
(-permutations '()) => '(nil) |
|
|
|
|
(-permutations '()) => '(()) |
|
|
|
|
(-permutations '(a a b)) => '((a a b) (a b a) (b a a)) |
|
|
|
|
(-permutations '(a b c)) |
|
|
|
|
=> '((a b c) (a c b) (b a c) (b c a) (c a b) (c b a)) |
|
|
|
|
(-permutations '(1)) => '((1)) |
|
|
|
|
(-permutations '(a)) => '((a)) |
|
|
|
|
(-permutations '(())) => '((())) |
|
|
|
|
(-permutations '(1 1)) => '((1 1)) |
|
|
|
|
(-permutations '(1 2)) => '((1 2) (2 1)) |
|
|
|
|
(-permutations '(a b c)) => '((a b c) (a c b) (b a c) (b c a) (c a b) (c b a))) |
|
|
|
|
(-permutations '(2 1)) => '((2 1) (1 2)) |
|
|
|
|
(-permutations '(1 a)) => '((1 a) (a 1)) |
|
|
|
|
(-permutations '(a 1)) => '((a 1) (1 a)) |
|
|
|
|
(-permutations '(a a)) => '((a a)) |
|
|
|
|
(-permutations '(a b)) => '((a b) (b a)) |
|
|
|
|
(-permutations '(b a)) => '((b a) (a b)) |
|
|
|
|
(-permutations '(1 1 1)) => '((1 1 1)) |
|
|
|
|
(-permutations '(1 1 2)) => '((1 1 2) (1 2 1) (2 1 1)) |
|
|
|
|
(-permutations '(1 2 1)) => '((1 1 2) (1 2 1) (2 1 1)) |
|
|
|
|
(-permutations '(2 1 1)) => '((2 1 1) (1 2 1) (1 1 2)) |
|
|
|
|
(-permutations '(1 1 a)) => '((1 1 a) (1 a 1) (a 1 1)) |
|
|
|
|
(-permutations '(1 a 1)) => '((1 1 a) (1 a 1) (a 1 1)) |
|
|
|
|
(-permutations '(a 1 1)) => '((a 1 1) (1 a 1) (1 1 a)) |
|
|
|
|
(-permutations '(a a 1)) => '((a a 1) (a 1 a) (1 a a)) |
|
|
|
|
(-permutations '(a 1 a)) => '((a a 1) (a 1 a) (1 a a)) |
|
|
|
|
(-permutations '(1 a a)) => '((1 a a) (a 1 a) (a a 1)) |
|
|
|
|
(-permutations '(1 2 3)) |
|
|
|
|
=> '((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)) |
|
|
|
|
(-permutations '(3 2 1)) |
|
|
|
|
=> '((3 2 1) (3 1 2) (2 3 1) (2 1 3) (1 3 2) (1 2 3)) |
|
|
|
|
(-permutations '(1 2 a)) |
|
|
|
|
=> '((1 2 a) (1 a 2) (2 1 a) (2 a 1) (a 1 2) (a 2 1)) |
|
|
|
|
(-permutations '(1 a 2)) |
|
|
|
|
=> '((1 a 2) (1 2 a) (a 1 2) (a 2 1) (2 1 a) (2 a 1)) |
|
|
|
|
(-permutations '(a 1 2)) |
|
|
|
|
=> '((a 1 2) (a 2 1) (1 a 2) (1 2 a) (2 a 1) (2 1 a)) |
|
|
|
|
(-permutations '(a b 1)) |
|
|
|
|
=> '((a b 1) (a 1 b) (b a 1) (b 1 a) (1 a b) (1 b a)) |
|
|
|
|
(-permutations '(a 1 b)) |
|
|
|
|
=> '((a 1 b) (a b 1) (1 a b) (1 b a) (b a 1) (b 1 a)) |
|
|
|
|
(-permutations '(1 a b)) |
|
|
|
|
=> '((1 a b) (1 b a) (a 1 b) (a b 1) (b 1 a) (b a 1)) |
|
|
|
|
(-permutations '(a a a)) => '((a a a)) |
|
|
|
|
(-permutations '(a b a)) => '((a a b) (a b a) (b a a)) |
|
|
|
|
(-permutations '(b a a)) => '((b a a) (a b a) (a a b)) |
|
|
|
|
(-permutations '(c b a)) |
|
|
|
|
=> '((c b a) (c a b) (b c a) (b a c) (a c b) (a b c)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '(a "a"))) => '((a a)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '("a" a))) => '(("a" "a")) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '(a "a" b))) |
|
|
|
|
=> '((a a b) (a b a) (b a a)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '(a b "a"))) |
|
|
|
|
=> '((a a b) (a b a) (b a a)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '(b a "a"))) |
|
|
|
|
=> '((b a a) (a b a) (a a b)) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '("a" a b))) |
|
|
|
|
=> '(("a" "a" b) ("a" b "a") (b "a" "a")) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '("a" b a))) |
|
|
|
|
=> '(("a" "a" b) ("a" b "a") (b "a" "a")) |
|
|
|
|
(let ((-compare-fn #'string=)) (-permutations '(b "a" a))) |
|
|
|
|
=> '((b "a" "a") ("a" b "a") ("a" "a" b))) |
|
|
|
|
|
|
|
|
|
(defexamples -distinct |
|
|
|
|
(-distinct '()) => '() |
|
|
|
|
@ -2271,6 +2347,24 @@ or readability." |
|
|
|
|
(should (equal (funcall member "foo" '(foo bar)) '(foo bar))) |
|
|
|
|
(should (equal (funcall member "foo" '(bar foo)) '(foo))))) |
|
|
|
|
|
|
|
|
|
(ert-deftest dash--assoc-fn () |
|
|
|
|
"Test `dash--assoc-fn'." |
|
|
|
|
(dolist (cmp '(nil equal)) |
|
|
|
|
(let ((-compare-fn cmp)) |
|
|
|
|
(should (eq (dash--assoc-fn) #'assoc)))) |
|
|
|
|
(let ((-compare-fn #'eq)) |
|
|
|
|
(should (eq (dash--assoc-fn) #'assq))) |
|
|
|
|
(let* ((-compare-fn #'string=) |
|
|
|
|
(assoc (dash--assoc-fn))) |
|
|
|
|
(should-not (memq assoc '(assoc assq))) |
|
|
|
|
(should-not (funcall assoc 'foo ())) |
|
|
|
|
(should-not (funcall assoc 'foo '(foo))) |
|
|
|
|
(should-not (funcall assoc 'foo '((bar)))) |
|
|
|
|
(should-not (funcall assoc 'bar '((foo) bar))) |
|
|
|
|
(should (equal (funcall assoc 'foo '((foo))) '(foo))) |
|
|
|
|
(should (equal (funcall assoc 'bar '((foo) (bar))) '(bar))) |
|
|
|
|
(should (equal (funcall assoc 'foo '((foo 1) (foo 2))) '(foo 1))))) |
|
|
|
|
|
|
|
|
|
(ert-deftest dash--hash-test-fn () |
|
|
|
|
"Test `dash--hash-test-fn'." |
|
|
|
|
(let ((-compare-fn nil)) |
|
|
|
|
@ -2297,4 +2391,66 @@ or readability." |
|
|
|
|
(should (= (dash--size+ most-positive-fixnum i) |
|
|
|
|
most-positive-fixnum)))) |
|
|
|
|
|
|
|
|
|
(ert-deftest dash--numbers<= () |
|
|
|
|
"Test `dash--numbers<='." |
|
|
|
|
(should (dash--numbers<= ())) |
|
|
|
|
(should (dash--numbers<= '(0))) |
|
|
|
|
(should (dash--numbers<= '(0 0))) |
|
|
|
|
(should (dash--numbers<= '(0 1))) |
|
|
|
|
(should (dash--numbers<= '(0 0 0))) |
|
|
|
|
(should (dash--numbers<= '(0 0 1))) |
|
|
|
|
(should (dash--numbers<= '(0 1 1))) |
|
|
|
|
(should-not (dash--numbers<= '(a))) |
|
|
|
|
(should-not (dash--numbers<= '(0 a))) |
|
|
|
|
(should-not (dash--numbers<= '(a 0))) |
|
|
|
|
(should-not (dash--numbers<= '(0 0 a))) |
|
|
|
|
(should-not (dash--numbers<= '(0 a 0))) |
|
|
|
|
(should-not (dash--numbers<= '(1 0))) |
|
|
|
|
(should-not (dash--numbers<= '(1 0 0))) |
|
|
|
|
(should-not (dash--numbers<= '(1 1 0)))) |
|
|
|
|
|
|
|
|
|
(ert-deftest dash--next-lex-perm () |
|
|
|
|
"Test `dash--next-lex-perm'." |
|
|
|
|
(dolist (vecs '(([0]) |
|
|
|
|
([0 0]) |
|
|
|
|
([0 1] . [1 0]) |
|
|
|
|
([0 0 0]) |
|
|
|
|
([0 0 1] . [0 1 0]) |
|
|
|
|
([0 1 0] . [1 0 0]) |
|
|
|
|
([0 1 1] . [1 0 1]) |
|
|
|
|
([1 0 0]) |
|
|
|
|
([1 0 1] . [1 1 0]) |
|
|
|
|
([1 1 0]) |
|
|
|
|
([1 1 1]) |
|
|
|
|
([0 1 2] . [0 2 1]) |
|
|
|
|
([0 2 1] . [1 0 2]) |
|
|
|
|
([1 0 2] . [1 2 0]) |
|
|
|
|
([1 2 0] . [2 0 1]) |
|
|
|
|
([2 0 1] . [2 1 0]) |
|
|
|
|
([2 1 0]))) |
|
|
|
|
(let* ((prev (copy-sequence (car vecs))) |
|
|
|
|
(copy (copy-sequence prev)) |
|
|
|
|
(next (cdr vecs))) |
|
|
|
|
(should (equal (dash--next-lex-perm prev (length prev)) next)) |
|
|
|
|
;; Vector should either be updated in place, or left alone. |
|
|
|
|
(should (equal prev (or next copy)))))) |
|
|
|
|
|
|
|
|
|
(ert-deftest dash--lex-perms () |
|
|
|
|
"Test `dash--lex-perms'." |
|
|
|
|
(dolist (perms '(([0] (0)) |
|
|
|
|
([0 0] (0 0)) |
|
|
|
|
([0 1] (0 1) (1 0)) |
|
|
|
|
([1 0] (1 0)))) |
|
|
|
|
(should (equal (dash--lex-perms (copy-sequence (car perms))) |
|
|
|
|
(cdr perms)))) |
|
|
|
|
(should (equal (dash--lex-perms (vector 0 1) (vector 2 3)) |
|
|
|
|
'((2 3) (3 2)))) |
|
|
|
|
(should (equal (dash--lex-perms (vector 0 1 2) (vector 5 4 3)) |
|
|
|
|
'((5 4 3) |
|
|
|
|
(5 3 4) |
|
|
|
|
(4 5 3) |
|
|
|
|
(4 3 5) |
|
|
|
|
(3 5 4) |
|
|
|
|
(3 4 5))))) |
|
|
|
|
|
|
|
|
|
;;; examples.el ends here |
|
|
|
|
|