-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-jvm.lisp
80 lines (71 loc) · 2.75 KB
/
test-jvm.lisp
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
(defpackage jvm.jvm-test
(:use common-lisp
jvm.unit-test
jvm)
(:nicknames jvm.jvm-test)
(:export ))
(in-package jvm.jvm-test)
(deftest test-d ()
(macrolet ((def (name v)
`(let ((vm (make-instance 'jvm::virtual-machine)))
(,name vm nil)
(equal ,v (jvm::current-stack vm)))))
(check
(def jvm::dconst-0 '(0 0))
(def jvm::dconst-1 '(1072693248 0)))))
(deftest test-i ()
(macrolet ((def (name v)
`(let ((vm (make-instance 'jvm::virtual-machine)))
(,name vm nil)
(equal ,v (jvm::current-stack vm)))))
(check
(def jvm::iconst-m1 '(-1))
(def jvm::iconst-0 '(0))
(def jvm::iconst-1 '(1))
(def jvm::iconst-2 '(2))
(def jvm::iconst-3 '(3))
(def jvm::iconst-4 '(4))
(def jvm::iconst-5 '(5)))))
(deftest test-l ()
(macrolet ((def (name v)
`(let ((vm (make-instance 'jvm::virtual-machine)))
(,name vm nil)
(equal ,v (jvm::current-stack vm)))))
(check
(def jvm::lconst-0 '(0 0))
(def jvm::lconst-1 '(0 1)))))
(deftest test-f ()
(macrolet ((def (name v)
`(let ((vm (make-instance 'jvm::virtual-machine)))
(,name vm nil)
(equal ,v (jvm::current-stack vm)))))
(check
(def jvm::fconst-0 '(0))
(def jvm::fconst-1 '(1065353216))
(def jvm::fconst-2 '(2)))))
(deftest test-->words ()
(check (equal (jvm::->words -1.0f0) '(3212836864))
(equal (jvm::->words 0.0f0) '(0))
(equal (jvm::->words -0.0f0) '(2147483648))
(equal (jvm::->words 1.0f0) '(1065353216))
(equal (jvm::->words 2.0f0) '(1073741824))
(equal (jvm::->words -1.0) '(3220176896 0))
(equal (jvm::->words 0.0) '(0 0))
(equal (jvm::->words -0.0) '(2147483648 0))
(equal (jvm::->words 1.0) '(1072693248 0))
(equal (jvm::->words 2.0) '(1073741824 0))))
(deftest test-words->single-float ()
(check (eq (jvm::words->single-float '(3212836864)) -1.0f0)
(eq (jvm::words->single-float '(0)) 0.0f0)
(eq (jvm::words->single-float '(2147483648)) -0.0f0)
(eq (jvm::words->single-float '(1065353216)) 1.0f0)
(eq (jvm::words->single-float '(1073741824)) 2.0f0)))
(deftest test-->single-float ()
(check (eq (jvm::->single-float '(0 0 0 0)) 0.0f0)
(eq (jvm::->single-float '(128 0 0 0)) -0.0f0)))
(deftest test-words->double-float ()
(check (eql (jvm::words->double-float '(3220176896 0)) -1.0)
(eql (jvm::words->double-float '(0 0)) 0.0)
(eql (jvm::words->double-float '(2147483648 0)) -0.0)
(eql (jvm::words->double-float '(1072693248 0)) 1.0)
(eql (jvm::words->double-float '(1073741824 0)) 2.0)))