HPS (Hierarchy Property Service): Initial Setup
First steps for HPS (Hierarchy Property Service)
Ok, after the first problems I was able to start coding.
Because I want TDD I was really missing lein-test-refresh, but after some research I found Kaocha
Kaocha
Basically is a full fledged tool for Testing.
There are some steps to do to just have an initial setup:
- Add a dependency on your deps.edn
- :aliases {:test {:extra-paths ["src/test/clojure"] :extra-deps {lambdaisland/kaocha {:mvn/version "1.0.641"}}
- Do your setup of kaocha, basically create a script at ~/bin/kaocha and chmod +x it, inside write:
- clojure -A:test -m kaocha.runner "$@"
- Create a tests.edn in your foolder, (this step is needed if you don't have your tests in a test folder on the root of your project):
- #kaocha/v1 {:tests [{:id :unit
- #kaocha/v1 is a default configuration for kaocha, while the other one set the tests path for my project.
- now run in a terminal in your project root folder:
- ~/bin/kaocha --watch
- There it is, automatic reload and run in parallel of all your tests 😁
:test-paths ["src/test/clojure"]}]}
First development
What I did, after setting up the TDD environment was then setting up maps that represent a hierarchy, and a in memory database (for now) done in an atom with some utility methods to store hierarchy:
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
(ns persistence) | |
(def hierarchy-store (atom [])) | |
(defn save-hierarchy | |
[hierarchy] | |
(swap! hierarchy-store conj hierarchy) | |
hierarchy) | |
(defn remove-hierarchy | |
[hierarchy] | |
(swap! hierarchy-store #(remove (fn [it] (= hierarchy it)) %)) | |
hierarchy) | |
(defn find-hierarchy | |
[name] | |
(first (filter #(= (:name %) name) @hierarchy-store))) | |
(def remove-hierarchy-by-name (comp remove-hierarchy find-hierarchy)) | |
(defn update-hierarchy | |
[hierarchy] | |
(remove-hierarchy-by-name (:name hierarchy)) | |
(save-hierarchy hierarchy) | |
hierarchy) |
And some definition of my domain objects (for now simple maps):
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
(ns domain) | |
(defn node | |
[name level] | |
{:name name :level level}) | |
(defn hierarchy | |
[name & nodes] | |
{:name name | |
:nodes (set nodes)}) |
Again my feeling are there, Clojure is like your first love, whenever you see it again you feel well 😊
Comments
Post a Comment