-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibjulia-test.el
76 lines (59 loc) · 2.69 KB
/
libjulia-test.el
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
(require 'ert)
(require 'libjulia)
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Comparison-of-Numbers.html
(defun float-equal (x y)
(let ((float-tol 1.0e-6))
(or (= x y)
(< (/ (abs (- x y))
(max (abs x) (abs y)))
float-tol))))
(ert-deftest test-libjulia-primitive-julia-type-p ()
(should (libjulia-primitive-julia-type-p "Bool"))
(should (libjulia-primitive-julia-type-p "Int64"))
(should (libjulia-primitive-julia-type-p "Float64"))
(should-not (libjulia-primitive-julia-type-p "String"))
(should-not (libjulia-primitive-julia-type-p "SomethingElse")))
;; (ert-deftest test-libjulia-get-type ()
;; ;; Ints
;; (should (equal (libjulia-get-julia-type "3") "Int64"))
;; (should (equal (libjulia-get-julia-type "typemax(Int32)") "Int32"))
;; (should (equal (libjulia-get-julia-type "typemin(Int64)") "Int64"))
;; (should (equal (libjulia-get-julia-type "0x1") "UInt8"))
;; ;; negating an unsigned literal creates an unsigned 2s complement
;; (should (equal (libjulia-get-julia-type "-0x1000") "UInt16"))
;; ;; floats
;; (should (equal (libjulia-get-julia-type "3.14f0") "Float32"))
;; (should (equal (libjulia-get-julia-type "3.14") "Float64")))
;; Implicitly tests unboxing
(ert-deftest test-libjulia-eval-str ()
;; primitives
(should (equal (libjulia-eval-str "3") 3))
(should (float-equal (libjulia-eval-str "3.14f0") 3.14))
(should (float-equal (libjulia-eval-str "3.14") 3.14))
;; strings
(should (equal (libjulia-eval-str "\"Hallo\"") "Hallo")))
(ert-deftest test-libjulia-box-unbox ()
(defun box-unbox (elisp-val julia-type)
(let ((box (libjulia--get-jl-box-sym julia-type))
(unbox (libjulia--get-jl-unbox-sym julia-type)))
(funcall unbox (funcall box elisp-val))))
(defun test-roundrip-is-identity (elisp-val julia-type)
(should (equal (box-unbox elisp-val julia-type) elisp-val)))
(test-roundrip-is-identity 3 "Int64")
(test-roundrip-is-identity 3.4 "Float64")
(test-roundrip-is-identity 't "Bool"))
(ert-deftest test-ffi-array ()
(define-ffi-array test-array :int64 8)
(ffi-set-aref test-array :int64 0 42)
(should (equal (ffi-aref test-array :int64 0) 42))
(ffi-set-aref test-array :int64 7 23)
(should (equal (ffi-aref test-array :int64 7) 23)))
(ert-deftest test-libjulia-jl-call ()
(should (equal 8.0 (libjulia-jl-call "sqrt" '(64.0))))
(should (equal 2 (libjulia-jl-call "+" '(1 1))))
(should (equal t (libjulia-jl-call "!" '(nil)))))
;; (ert-deftest test-libjulia-null-ptr ()
;; (unwind-protect
;; (setq res (libjulia-eval "Julia sees this string unquoted, which returns a null pointer from jl_eval_string."))
;; (should nil)
;; (message (format "%s" res))))