File: encode-universal-time.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (102 lines) | stat: -rw-r--r-- 3,318 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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun May  8 12:54:34 2005
;;;; Contains: Tests of ENCODE-UNIVERSAL-TIME

;;; See also the tests in decode-universal-time.lsp

(in-package :cl-test)

(deftest encode-universal-time.1
  (loop with count = 0
	for year = (+ 1900 (random 1000))
	;; Gregorian leap year algorithm
	for leap? = (and (= (mod year 4) 0)
			 (or (/= (mod year 100) 0)
			     (= (mod year 400) 0)))
	for month = (1+ (random 12))
	for date = (1+ (random (elt (if leap?
					#(0 31 29 31 30 31 30 31 31 30 31 30 31)
				      #(0 31 28 31 30 31 30 31 31 30 31 30 31))
				    month)))
	for hour = (random 24)
	for minute = (random 60)
	for second = (random 60)
	for tz = (if (and (= year 1900) (= date 0) (= month 0))
		     (random 25)
		   (- (random 49) 24))
	for time = (encode-universal-time second minute hour date month year tz)
	for decoded-vals = (multiple-value-list (decode-universal-time time tz))
	for vals = (list second minute hour date month year (elt decoded-vals 6)
			 nil tz)
	repeat 20000
	unless (equal vals decoded-vals)
	collect (progn (incf count) (list vals time decoded-vals))
	until (>= count 100))
  nil)

#|
(deftest encode-universal-time.2
  (loop with count = 0
	for year = (+ 1901 (random 1000))
	;; Gregorian leap year algorithm
	for leap? = (and (= (mod year 4) 0)
			 (or (/= (mod year 100) 0)
			     (= (mod year 400) 0)))
	for month = (1+ (random 12))
	for date = (1+ (random (elt (if leap?
					#(0 31 29 31 30 31 30 31 31 30 31 30 31)
				      #(0 31 28 31 30 31 30 31 31 30 31 30 31))
				    month)))
	for hour = (random 24)
	for minute = (random 60)
	for second = (random 60)
	for time = (encode-universal-time second minute hour date month year)
	for decoded-vals = (multiple-value-list (decode-universal-time time))
	for vals = (list second minute hour date month year (elt decoded-vals 6)
			 (elt decoded-vals 7) (elt decoded-vals 8))
	repeat 20000
	unless (equal vals decoded-vals)
	collect (progn (incf count) (list vals time decoded-vals))
	until (>= count 100))
  nil)
|#

(deftest encode-universal-time.3
  (loop with count = 0
	for year = (+ 1900 (random 1000))
	;; Gregorian leap year algorithm
	for leap? = (and (= (mod year 4) 0)
			 (or (/= (mod year 100) 0)
			     (= (mod year 400) 0)))
	for month = (1+ (random 12))
	for date = (1+ (random (elt (if leap?
					#(0 31 29 31 30 31 30 31 31 30 31 30 31)
				      #(0 31 28 31 30 31 30 31 31 30 31 30 31))
				    month)))
	for hour = (random 24)
	for minute = (random 60)
	for second = (random 60)
	for tz = (/ (if (and (= year 1900) (= date 0) (= month 0))
			(random (1+ (* 24 3600)))
		      (- (random (1+ (* 48 3600))) (* 24 3600)))
		    3600)
	for time = (encode-universal-time second minute hour date month year tz)
	for decoded-vals = (multiple-value-list (decode-universal-time time tz))
	for vals = (list second minute hour date month year (elt decoded-vals 6)
			 nil tz)
	repeat 20000
	unless (equal vals decoded-vals)
	collect (progn (incf count) (list vals time decoded-vals))
	until (>= count 100))
  nil)

;;; Error cases

(deftest encode-universal-time.error.1
  (signals-error (encode-universal-time 0 0 0 1 1) program-error)
  t)

(deftest encode-universal-time.error.2
  (signals-error (encode-universal-time 0 0 0 1 1 1901 0 nil) program-error)
  t)