mirror of
https://github.com/janet-lang/janet
synced 2024-12-24 15:30:27 +00:00
56 lines
2.0 KiB
Clojure
56 lines
2.0 KiB
Clojure
# Copyright (c) 2019 Calvin Rose & contributors
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to
|
|
# deal in the Software without restriction, including without limitation the
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
# IN THE SOFTWARE.
|
|
|
|
(import test/helper :prefix "" :exit true)
|
|
(start-suite 5)
|
|
# some tests typed array
|
|
|
|
(assert-no-error
|
|
"create some typed array"
|
|
(do
|
|
(def a (tarray/new :float64 10))
|
|
(def b (tarray/new :float64 5 2 0 a))
|
|
(def c (tarray/new :uint32 20))
|
|
))
|
|
|
|
(assert-no-error
|
|
"create some typed array from buffer"
|
|
(do
|
|
(def buf (tarray/buffer (+ 64 (* (+ 1 (* (- 10 1) 2)) 8))))
|
|
(def b (tarray/new :float64 10 2 64 buf))))
|
|
|
|
(def a (tarray/new :float64 10))
|
|
(def b (tarray/new :float64 5 2 0 a))
|
|
|
|
(assert-no-error
|
|
"fill tarray"
|
|
(for i 0 (tarray/length a)
|
|
(set (a i) i)))
|
|
|
|
(assert (= (tarray/buffer a) (tarray/buffer b)) "tarray views pointing same buffer")
|
|
(assert (= (a 2) (b 1) ) "tarray views pointing same buffer")
|
|
(assert (= ((tarray/slice b) 3) (b 3) (a 6) 6) "tarray slice")
|
|
(assert (= ((tarray/slice b 1) 2) (b 3) (a 6) 6) "tarray slice")
|
|
|
|
(assert (= ((unmarshal (marshal b)) 3) (b 3)) "marshal")
|
|
|
|
(end-suite)
|
|
|