/contrib/clojure-package/test/org/apache/clojure_mxnet/primitives_test.clj

https://github.com/hpi-xnor/BMXNet-v2 · Clojure · 45 lines · 24 code · 5 blank · 16 comment · 3 complexity · a9ed4739dfe0b1f214a4b1ba0638caab MD5 · raw file

  1. ;;
  2. ;; Licensed to the Apache Software Foundation (ASF) under one or more
  3. ;; contributor license agreements. See the NOTICE file distributed with
  4. ;; this work for additional information regarding copyright ownership.
  5. ;; The ASF licenses this file to You under the Apache License, Version 2.0
  6. ;; (the "License"); you may not use this file except in compliance with
  7. ;; the License. You may obtain a copy of the License at
  8. ;;
  9. ;; http://www.apache.org/licenses/LICENSE-2.0
  10. ;;
  11. ;; Unless required by applicable law or agreed to in writing, software
  12. ;; distributed under the License is distributed on an "AS IS" BASIS,
  13. ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ;; See the License for the specific language governing permissions and
  15. ;; limitations under the License.
  16. ;;
  17. (ns org.apache.clojure-mxnet.primitives-test
  18. (:require [org.apache.clojure-mxnet.primitives :as primitives]
  19. [clojure.test :refer :all])
  20. (:import (org.apache.mxnet MX_PRIMITIVES$MX_PRIMITIVE_TYPE
  21. MX_PRIMITIVES$MX_FLOAT
  22. MX_PRIMITIVES$MX_Double)))
  23. (deftest test-primitive-types
  24. (is (not (primitives/primitive? 3)))
  25. (is (primitives/primitive? (primitives/mx-float 3)))
  26. (is (primitives/primitive? (primitives/mx-double 3))))
  27. (deftest test-float-primitives
  28. (is (instance? MX_PRIMITIVES$MX_PRIMITIVE_TYPE (primitives/mx-float 3)))
  29. (is (instance? MX_PRIMITIVES$MX_FLOAT (primitives/mx-float 3)))
  30. (is (instance? Float (-> (primitives/mx-float 3)
  31. (primitives/->num))))
  32. (is (= 3.0 (-> (primitives/mx-float 3)
  33. (primitives/->num)))))
  34. (deftest test-double-primitives
  35. (is (instance? MX_PRIMITIVES$MX_PRIMITIVE_TYPE (primitives/mx-double 2)))
  36. (is (instance? MX_PRIMITIVES$MX_Double (primitives/mx-double 2)))
  37. (is (instance? Double (-> (primitives/mx-double 2)
  38. (primitives/->num))))
  39. (is (= 2.0 (-> (primitives/mx-double 2)
  40. (primitives/->num)))))