File: comparison.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (128 lines) | stat: -rw-r--r-- 3,082 bytes parent folder | download | duplicates (5)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(in-package #:local-time.test)

(defsuite* (comparison :in simple))

(defmacro defcmptest (comparator-name &body args)
  `(deftest ,(symbolicate 'test/simple/comparison/ comparator-name) ()
    (flet ((make (day &optional (sec 0) (nsec 0))
             (make-timestamp :day day :sec sec :nsec nsec)))
      ,@(loop
          :for entry :in args
          :when (= (length entry) 1)
            :do (push 'is entry)
          :else
            :do (if (member (car entry) '(t true is) :test #'eq)
                    'is
                    'is)
          collect (let ((body `(,comparator-name (make ,@(second entry))
                                                 (make ,@(third entry)))))
                    (cond
                      ((eq (car entry) 'true)
                       `(is ,body))
                      ((eq (car entry) 'false)
                       `(is (not ,body)))
                      (t (error "Don't know how to interpret ~S" entry))))))))

(defcmptest timestamp<
  (true (1 0 0)
        (2 0 0))
  (true (0 1 0)
        (0 2 0))
  (true (0 0 1)
        (0 0 2))

  (false (2 0 0)
         (1 0 0))
  (false (0 2 0)
         (0 1 0))
  (false (0 0 2)
         (0 0 1)))

(defcmptest timestamp<=
  (true (1 0 0)
        (2 0 0))
  (true (0 1 0)
        (0 2 0))
  (true (0 0 1)
        (0 0 2))
  (true (1 0 0)
        (1 0 0))
  (true (1 1 0)
        (1 1 0))
  (true (1 1 1)
        (1 1 1))

  (false (2 0 0)
         (1 0 0))
  (false (0 2 0)
         (0 1 0))
  (false (0 0 2)
         (0 0 1)))

(defcmptest timestamp>
  (true (2 0 0)
        (1 0 0))
  (true (0 2 0)
        (0 1 0))
  (true (0 0 2)
        (0 0 1))

  (false (1 0 0)
         (2 0 0))
  (false (0 1 0)
         (0 2 0))
  (false (0 0 1)
         (0 0 2)))

(defcmptest timestamp>=
  (true (2 0 0)
        (1 0 0))
  (true (0 2 0)
        (0 1 0))
  (true (0 0 2)
        (0 0 1))
  (true (1 0 0)
        (1 0 0))
  (true (1 1 0)
        (1 1 0))
  (true (1 1 1)
        (1 1 1))

  (false (1 0 0)
         (2 0 0))
  (false (0 1 0)
         (0 2 0))
  (false (0 0 1)
         (0 0 2)))

(defcmptest timestamp=
  (true (1 0 0)
        (1 0 0))
  (true (1 1 0)
        (1 1 0))
  (true (1 1 1)
        (1 1 1))

  (false (1 0 0)
         (2 0 0))
  (false (0 1 0)
         (0 2 0))
  (false (0 0 1)
         (0 0 2)))

(deftest test/simple/comparison/timestamp=/2 ()
  (is (timestamp= (make-timestamp) (make-timestamp)))
  (is (not (timestamp= (make-timestamp) (make-timestamp :nsec 1)))))

(deftest test/simple/comparison/timestamp=/3 ()
  (is (eql (handler-case
               (timestamp= (make-timestamp) nil)
             (type-error ()
               :correct-error))
           :correct-error)))

(deftest test/simple/comparison/timestamp/= ()
  (is (timestamp/= (make-timestamp :nsec 1) (make-timestamp :nsec 2)))
  (is (timestamp/= (make-timestamp :nsec 1) (make-timestamp :nsec 2) (make-timestamp :nsec 3)))
  (is (not (timestamp/= (make-timestamp :nsec 1) (make-timestamp :nsec 2) (make-timestamp :nsec 1))))
  (is (not (timestamp/= (make-timestamp) (make-timestamp)))))