File: srctran.lisp

package info (click to toggle)
cmucl 21a-4
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 50,060 kB
  • sloc: lisp: 375,822; ansic: 30,304; asm: 2,977; sh: 1,372; makefile: 355; csh: 31
file content (104 lines) | stat: -rw-r--r-- 5,476 bytes parent folder | download | duplicates (4)
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
;; Tests for various source transformations.

(defpackage :srctran-tests
  (:use :cl :lisp-unit))

(in-package "SRCTRAN-TESTS")

(define-test floor-quotient-bound
  "Test the first value of FLOOR returns the correct interval"
  (assert-equalp (c::make-interval :low 0 :high 10)
		 (c::floor-quotient-bound
		  (c::make-interval :low 0.3 :high 10.3)))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 10)
		 (c::floor-quotient-bound
		  (c::make-interval :low 0.3 :high '(10.3))))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 10)
		(c::floor-quotient-bound (c::make-interval :low 0.3 :high 10)))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 9)
		 (c::floor-quotient-bound (c::make-interval :low 0.3 :high '(10))))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 9)
		 (c::floor-quotient-bound (c::make-interval :low 0.3 :high '(10))))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 10)
		 (c::floor-quotient-bound (c::make-interval :low '(0.3) :high 10.3)))
  (assert-equalp (c::make-interval :LOW 0 :HIGH 10)
		 (c::floor-quotient-bound (c::make-interval :low '(0.0) :high 10.3)))
  (assert-equalp (c::make-interval :LOW -2 :HIGH 10)
		 (c::floor-quotient-bound (c::make-interval :low '(-1.3) :high 10.3)))
  (assert-equalp (c::make-interval :LOW -1 :HIGH 10)
		 (c::floor-quotient-bound (c::make-interval :low '(-1.0) :high 10.3)))
  (assert-equalp (c::make-interval :LOW -1 :HIGH 10)
		 (c::floor-quotient-bound (c::make-interval :low -1.0 :high 10.3))))

(define-test floor-rem-bound
  "Test the second value of FLOOR returns the correct interval"
  (assert-equalp (c::make-interval :low 0 :high '(10.3))
		 (c::floor-rem-bound (c::make-interval :low 0.3 :high 10.3)))
  (assert-equalp (c::make-interval :low 0 :high '(10.3))
		 (c::floor-rem-bound (c::make-interval :low 0.3 :high '(10.3))))
  (assert-equalp (c::make-interval :low '(-10) :high 0)
		 (c::floor-rem-bound (c::make-interval :low -10 :high -2.3)))
  (assert-equalp (c::make-interval :low 0 :high '(10))
		 (c::floor-rem-bound (c::make-interval :low 0.3 :high 10)))
  (assert-equalp (c::make-interval :low '(-10.3) :high '(10.3))
		 (c::floor-rem-bound (c::make-interval :low '(-1.3) :high 10.3)))
  (assert-equalp (c::make-interval :low '(-20.3) :high '(20.3))
		 (c::floor-rem-bound (c::make-interval :low '(-20.3) :high 10.3))))

(define-test ceiling-quotient-bound
  "Test the first value of CEILING returns the correct interval"
  (assert-equalp (c::make-interval :low 1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low 0.3 :high 10.3)))
  (assert-equalp (c::make-interval :low 1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low 0.3 :high '(10.3))))
  (assert-equalp (c::make-interval :low 1 :high 10)
		 (c::ceiling-quotient-bound (c::make-interval :low 0.3 :high 10)))
  (assert-equalp (c::make-interval :low 1 :high 10)
		 (c::ceiling-quotient-bound (c::make-interval :low 0.3 :high '(10))))
  (assert-equalp (c::make-interval :low 1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low '(0.3) :high 10.3)))
  (assert-equalp (c::make-interval :low 1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low '(0.0) :high 10.3)))
  (assert-equalp (c::make-interval :low -1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low '(-1.3) :high 10.3)))
  (assert-equalp (c::make-interval :low 0 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low '(-1.0) :high 10.3)))
  (assert-equalp (c::make-interval :low -1 :high 11)
		 (c::ceiling-quotient-bound (c::make-interval :low -1.0 :high 10.3))))

(define-test ceiling-rem-bound
  "Test the second value of CEILING returns the correct interval"
  (assert-equalp (c::make-interval :low '(-10.3) :high 0)
		 (c::ceiling-rem-bound (c::make-interval :low 0.3 :high 10.3)))
  (assert-equalp (c::make-interval :low '(-10.3) :high 0)
		 (c::ceiling-rem-bound (c::make-interval :low 0.3 :high '(10.3))))
  (assert-equalp (c::make-interval :low 0 :high '(10))
		 (c::ceiling-rem-bound (c::make-interval :low -10 :high -2.3)))
  (assert-equalp (c::make-interval :low '(-10) :high 0)
		 (c::ceiling-rem-bound (c::make-interval :low 0.3 :high 10)))
  (assert-equalp (c::make-interval :low '(-10.3) :high '(10.3))
		 (c::ceiling-rem-bound (c::make-interval :low '(-1.3) :high 10.3)))
  (assert-equalp (c::make-interval :low '(-20.3) :high '(20.3))
		 (c::ceiling-rem-bound (c::make-interval :low '(-20.3) :high 10.3))))

(define-test round-quotient-bound
  "Test the first value of ROUND returns the correct interval"
  (assert-equalp (c::make-interval :low 0 :high 10)
		 (c::round-quotient-bound (c::make-interval :low 0.3 :high 10.5)))
  (assert-equalp (c::make-interval :low 0 :high 12)
		 (c::round-quotient-bound (c::make-interval :low 0.3 :high 11.5)))
  (assert-equalp (c::make-interval :low 0 :high 10)
		 (c::round-quotient-bound (c::make-interval :low 0.3 :high '(10.5))))
  ;; Known failure: returns high limit of 12 instead of 11
  (assert-equalp (c::make-interval :low 0 :high 11)
		 (c::round-quotient-bound (c::make-interval :low 0.3 :high '(11.5))))
  (assert-equalp (c::make-interval :low 2 :high 10)
		 (c::round-quotient-bound (c::make-interval :low 1.5 :high 10.5)))
  (assert-equalp (c::make-interval :low 2 :high 10)
		 (c::round-quotient-bound (c::make-interval :low '(1.5) :high 10.5)))
  ;; Known failure: returns high limit of 0 instead of 1
  (assert-equalp (c::make-interval :low 1 :high 10)
		 (c::round-quotient-bound (c::make-interval :low '(0.5) :high 10.5)))
  )