Skip to content

Commit

Permalink
forgot to add the new files locations in the previous commit, fixing #8
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Feb 1, 2021
1 parent 6e428dc commit 70862f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/tablecloth/time/validatable.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns tablecloth.time.validatable)

(defn add-validatable
"Add metadata derived from a few columns,
validatable by checking if these columns
are identical to their values when it was created."
[ds column-names name metadata]
(-> ds
(vary-meta assoc-in
[:validatable name]
{:column-names column-names
:columns (select-keys ds column-names)
:metadata metadata})))

(defn valid?
"Check if metadata derived from a few columns is still valid
(that is, if the columns have not changed)."
[ds name]
(let [{:keys [columns column-names]} (-> ds
meta
:validatable
(get name))]
(->> column-names
(every? (fn [column-name]
(identical? (ds column-name)
(columns column-name)))))))

25 changes: 25 additions & 0 deletions test/tablecloth/time/validatable_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns tablecloth.time.validatable-test
(:require [clojure.test :refer [deftest is]]
[tablecloth.api :as tablecloth]
[tablecloth.time.validatable :as validatable]))

(deftest validatable-test
(let [ds (tablecloth/dataset {:x [1 2 3]
:y [4 5 6]})
ds-with-validatable (validatable/add-validatable ds
[:x]
:id1
9999)]
(is (-> ds-with-validatable
(tablecloth/select-rows [0 2])
(validatable/valid? :id1)
not))
(is (-> ds-with-validatable
(tablecloth/add-or-replace-column :x 9)
(validatable/valid? :id1)
not))
(is (-> ds-with-validatable
(tablecloth/add-or-replace-column :z 9)
(validatable/valid? :id1)))))


0 comments on commit 70862f2

Please sign in to comment.