-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forgot to add the new files locations in the previous commit, fixing #8
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))) | ||
|
||
|