aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtwiwtg-test.lisp
blob: 3fd3781be5cd64fbbfe25af055985938535b1d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(defpackage :gtwiwtg-test
  (:use :cl :gtwiwtg))

(in-package :gtwiwtg-test)


(defun gtwiwtg::test-collect ()
  (assert (equal '(1 2 3 4) (collect (range :from 1 :to 4 :inclusive t))))
  (assert (equal '(1 2 3 4) (collect (range :from 1 :to 5))))
  (assert (equal '((1 #\a) (2 #\b) (3 #\c))
                 (collect
                     (zip! (range :from 1)
                           (seq "abc")))))
  (assert (null (collect (seq ())))))

(defun gtwiwtg::test-take ()
  (assert (null (take 100 (seq ""))))
  (assert (equal '(#\a #\b #\c) (take 100 (seq "abc"))))
  (assert (equal '(#\a #\b) (take 2 (seq "abcdefg")))))


(defun gtwiwtg::test-pick-out ()
  (assert
   (equal '(40 30 20)
          (pick-out '(3 2 1)
                    (range :from 10 :by 10))))
  (assert
   (equal '(101)
          (pick-out '(101)
                    (range)))))

(defun gtwiwtg::test-argmax ()
  (assert (equal '(-10 . 100)
                 (argmax (lambda (x) (* x x))
                         (seq '(1 -10 3 4 -4))))))

(defun gtwiwtg::test-argmin ()
  (assert (equal '(1 . 1)
                 (argmin (lambda (x) (* x x))
                         (seq '(1 -10 3 4 -4))))))