Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cloojure committed Jan 24, 2019
1 parent b2bfcc0 commit 3b6c7d0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject tupelo "0.9.123"
(defproject tupelo "0.9.124"
:description "Tupelo: Clojure With A Spoonful of Honey"
:url "http://github.com/cloojure/tupelo"
:license {:name "Eclipse Public License"
Expand Down
26 changes: 26 additions & 0 deletions src/clj/tupelo/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
(BigInteger. ^bytes (glue zeros-4
(read-bytes 8 (validate data-input-stream? dis)))))


; #todo finish
(s/defn read-float :- s/Num ; #todo need test
"Reads a 4 byte single-precision floating-point value from the data-input-stream"
[dis :- DataInputStream]
(.readFloat (validate data-input-stream? dis)))

(s/defn read-double :- s/Num ; #todo need test
"Reads an 8 byte double-precision floating-point value from the data-input-stream"
[dis :- DataInputStream]
(.readDouble (validate data-input-stream? dis)))

;---------------------------------------------------------------------------------------------------
(s/defn write-string-bytes :- s/Str
"Writes the an ASCII string as bytes to a DataInputStream."
Expand Down Expand Up @@ -183,6 +195,20 @@



(s/defn write-float :- s/Num ; #todo need test
"Writes a 4 byte single-precision floating-point value to the data-output-stream"
[dos :- DataOutputStream
val :- s/Num]
(.writeFloat ^DataOutputStream (validate data-output-stream? dos) val)
val)

(s/defn write-double :- s/Num ; #todo need test
"Writes a 4 byte double-precision floating-point value to the data-output-stream"
[dos :- DataOutputStream
val :- s/Num]
(.writeDouble ^DataOutputStream (validate data-output-stream? dos) val)
val)




Expand Down
31 changes: 27 additions & 4 deletions test/clj/tst/tupelo/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
[tupelo.types :as types])
(:import [java.io DataInputStream DataOutputStream FileOutputStream ]))

(def int-val (long (+ 1e9 123456789)))
(def long-val (long 12345e9))
(def int-val (long (+ 1e9 123456789)))
(def long-val (long 12345e9))
(def pi-float (float Math/PI))
(def pi-double (double Math/PI))

(def dummy-file-name "tst.tupelo.io")
(def dummy-file (create-temp-file dummy-file-name))
Expand Down Expand Up @@ -118,7 +120,18 @@

(write-long-unsigned long-val)
(write-long-unsigned types/LONG_UNSIGNED_MIN_VALUE)
(write-long-unsigned types/LONG_UNSIGNED_MAX_VALUE)))
(write-long-unsigned types/LONG_UNSIGNED_MAX_VALUE)

(write-float pi-float)
(write-float Float/MIN_VALUE)
(write-float Float/MAX_VALUE)

(write-double pi-double)
(write-double Double/MIN_VALUE)
(write-double Double/MAX_VALUE)


))

(with-open [dis (DataInputStream. (io/input-stream dummy-file))]
(is= (read-string-bytes 5 dis) "hello")
Expand Down Expand Up @@ -156,7 +169,17 @@

(is= (read-long-unsigned dis) long-val)
(is= (read-long-unsigned dis) types/LONG_UNSIGNED_MIN_VALUE)
(is= (read-long-unsigned dis) types/LONG_UNSIGNED_MAX_VALUE)))
(is= (read-long-unsigned dis) types/LONG_UNSIGNED_MAX_VALUE)

(is= (read-float dis) pi-float)
(is= (read-float dis) Float/MIN_VALUE)
(is= (read-float dis) Float/MAX_VALUE)

(is= (read-double dis) pi-double)
(is= (read-double dis) Double/MIN_VALUE)
(is= (read-double dis) Double/MAX_VALUE))

)



Expand Down

0 comments on commit 3b6c7d0

Please sign in to comment.