source: trunk/source/tests/ansi-tests/decode-universal-time.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 4.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat May  7 07:00:58 2005
4;;;; Contains: Tests of DECODE-UNIVERSAL-TIME
5
6(in-package :cl-test)
7
8(deftest decode-universal-time.1
9  (decode-universal-time 0 0)
10  0 0 0 1 1 1900 0 nil 0)
11
12(deftest decode-universal-time.2
13  (decode-universal-time 0 -1)
14  0 0 1 1 1 1900 0 nil -1)
15
16(deftest decode-universal-time.3
17  (let ((count 0))
18    (loop for time = (random 10000000000)
19          for tz = (- (random 49) 24)
20          for (second minute hour date month year day daylight-p zone)
21          = (multiple-value-list (decode-universal-time time tz))
22          for time2 = (encode-universal-time second minute hour date month year zone)
23          repeat 1000
24          unless (and (eql tz zone) (eql time time2) (null daylight-p))
25          collect (progn (incf count)
26                         (list time tz (list second minute hour date month year day daylight-p zone) time2))
27          until (>= count 100)))
28  nil)
29
30(deftest decode-universal-time.4
31  (let ((count 0))
32    (loop for time = (random 10000000000)
33          for tz = (/ (- (random (1+ (* 48 3600))) (* 24 3600)) 3600)
34          for (second minute hour date month year day daylight-p zone)
35          = (multiple-value-list (decode-universal-time time tz))
36          for time2 = (encode-universal-time second minute hour date month year zone)
37          repeat 1000
38          unless (and (eql tz zone) (eql time time2) (null daylight-p))
39          collect (progn (incf count)
40                         (list time tz (list second minute hour date month year day daylight-p zone) time2))
41          until (>= count 100)))
42  nil)
43
44(deftest decode-universal-time.5
45  (let ((count 0))
46    (loop for time = (random 10000000000)
47          for (second minute hour date month year day daylight-p zone)
48          = (handler-case
49             (multiple-value-list (decode-universal-time time))
50             (error (c) (print time) (error c)))
51          for time2 = (encode-universal-time second minute hour date month year)
52          repeat 1000
53          unless (let ((daylight-p-2 (nth-value 7 (decode-universal-time time2))))
54                   (or (eql time time2)
55                       (and daylight-p (not daylight-p-2) ; (eql time (- time2 3600))
56                            )
57                       (and (not daylight-p) daylight-p-2 ; (eql time (+ time2 3600))
58                            )))
59          collect (progn (incf count)
60                         (list time (list second minute hour date month year day daylight-p zone) time2))
61          until (>= count 100)))
62  nil)
63
64(deftest decode-universal-time.6
65  (let ((vals0 (multiple-value-list (get-decoded-time)))
66        (vals1 (multiple-value-list (decode-universal-time (get-universal-time))))
67        (vals2 (multiple-value-list (get-decoded-time))))
68    (when (equal vals0 vals2)
69      (assert (= (length vals1) 9))
70      (assert (= (length vals2) 9))
71      (assert (equal (subseq vals1 0 7) (subseq vals2 0 7)))
72      (assert (if (elt vals1 7) (elt vals2 7) (not (elt vals2 7))))
73      (assert (= (elt vals1 8) (elt vals2 8))))
74    (values)))
75
76(deftest decode-universal-time.7
77  (decode-universal-time  (* 365 3600 24) 0)
78  0 0 0 1 1 1901 1 nil 0)
79
80(deftest decode-universal-time.8
81  (decode-universal-time  (* 2 365 3600 24) 0)
82  0 0 0 1 1 1902 2 nil 0)
83
84(deftest decode-universal-time.9
85  (decode-universal-time  (* 3 365 3600 24) 0)
86  0 0 0 1 1 1903 3 nil 0)
87
88(deftest decode-universal-time.10
89  (decode-universal-time  (* 4 365 3600 24) 0)
90  0 0 0 1 1 1904 4 nil 0)
91
92(deftest decode-universal-time.11
93  (decode-universal-time (+ (* 24 3600) (* 5 365 3600 24)) 0)
94  0 0 0 1 1 1905 6 nil 0)
95
96(deftest decode-universal-time.12
97  (loop for time = (random 100000000000)
98        for tz = (- (random 49) 24)
99        for interval = (1+ (random 10000))
100        for time2 = (+ time (* interval  24 3600))
101        ;; 'time2' is exactly interval days after 'time'
102        for day = (nth-value 6 (decode-universal-time time tz))
103        for day2 = (nth-value 6 (decode-universal-time time2 tz))
104        repeat 1000
105        ;; Check that the days of the week are consistent
106        unless (= (mod day2 7) (mod (+ day interval) 7))
107        collect (list time time2 tz interval day day2))
108  nil)
109
110;;; Error tests
111
112(deftest decode-universal-time.error.1
113  (signals-error (decode-universal-time) program-error)
114  t)
115
116(deftest decode-universal-time.error.2
117  (signals-error (decode-universal-time 0 0 nil) program-error)
118  t)
119
120
121
122
Note: See TracBrowser for help on using the repository browser.