Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
Fix DataChunk* precondition on date by requiring :date keyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
eightysteele committed Jul 20, 2012
1 parent 062d74f commit 840760b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/clj/forma/thrift.clj
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,15 @@

(defn DataChunk*
"Create a DataChunk."
[name loc val res & date]
{:pre [(every? #(instance? java.lang.String %) [name res])
[name loc val res & {:keys [date] :or {date nil}}]
{:pre [(every? string? [name res])
(or (nil? date) (string? date))
(LocationPropertyValue? loc)
(DataValue? val)
(or (not date) (string? (first date)))]}
(DataValue? val)]}
(let [loc (mk-location-prop loc)
val (if (coll? val)
(->> val pack mk-array-value mk-data-value)
(mk-data-value val))
[date] date
chunk (DataChunk. name loc val res)]
(if date
(doto chunk
Expand Down
30 changes: 29 additions & 1 deletion test/forma/thrift_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,37 @@
LocationProperty.)
data (->> (vec (map int [1 1 1 1])) IntArray. ArrayValue/ints DataValue/vals)
x (DataChunk. "name" loc data "16")
c (DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" "2001")]
c (DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" :date "2001")]
(doto x
(.setDate "2001"))
c => x
(unpack c) => ["name" loc data "16" "2001"]))

(fact "Test DataChunk* with various date values."
(let [loc (->> (ModisChunkLocation. "500" 8 0 100 24000)
LocationPropertyValue/chunkLocation
LocationProperty.)
data (->> (vec (map int [1 1 1 1])) IntArray. ArrayValue/ints DataValue/vals)
dc (DataChunk. "name" loc data "16")]

(doto dc
(.setDate ""))

(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16") =>
(DataChunk. "name" loc data "16")

(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" :date nil) =>
(DataChunk. "name" loc data "16")

(doto dc
(.setDate nil))
(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" :date nil) => dc
(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16") => dc

(doto dc
(.setDate ""))
(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" :date "") => dc

(doto dc
(.setDate "1977"))
(DataChunk* "name" (ModisChunkLocation. "500" 8 0 100 24000) [1 1 1 1] "16" :date "1977") => dc)))

0 comments on commit 840760b

Please sign in to comment.