Skip to content

Commit

Permalink
got a basic parse for intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaws committed Oct 1, 2016
1 parent 34114fe commit f767a21
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 42 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[devcards "0.2.1-7"]
[reagent "0.6.0-SNAPSHOT"]
[posh "0.3.5"]
[datascript "0.15.2"]
[datascript "0.15.4"]
[re-frame "0.8.0"]
[re-com "0.8.3"]
[cljsjs/d3 "4.2.2-0"]]
Expand Down
15 changes: 14 additions & 1 deletion resources/public/css/undead.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,25 @@
margin-right: 13px;
}

#bso .btn-intersection {
background-color: #2b2b2b;
color: white;
font-size: 80%;
border-radius: 2px;

}
.tree-children {
margin-left: 20px;
border-left: 1px solid black;

/* opacity: 50%; */
}
.tree-children-parents {
margin-left: 40px;
font-size: 50%;
background-color: LightSlateGray;
/* opacity: 50%; */
}


.node {
border: 0.5px solid LightSlateGray;
Expand Down
1 change: 1 addition & 0 deletions src/undead/cards.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[undead.cards.logic]
[undead.cards.labels]
[undead.cards.grid]
[undead.cards.dstests]
[undead.cards.auto]
[undead.cards.d3]
[undead.cards.keys]
Expand Down
126 changes: 126 additions & 0 deletions src/undead/cards/dstests.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
(ns undead.cards.dstests
(:require
[datascript.core :as d]
[clojure.test :as t])
(:require-macros
[cljs.test :refer [testing is]]
[devcards.core :refer [defcard-rg deftest]]))


;; (deftest test-resolve-eid-refs
;; (let [conn (d/create-conn {:friend {:db/valueType :db.type/ref
;; :db/cardinality :db.cardinality/many}})
;; tx (d/transact! conn [{:name "Sergey"
;; :friend [-1 -2]}
;; [:db/add -1 :name "Ivan"]
;; [:db/add -2 :name "Petr"]
;; [:db/add -4 :name "Boris"]
;; [:db/add -4 :friend -3]
;; [:db/add -3 :name "Oleg"]
;; [:db/add -3 :friend -4]])
;; q '[:find ?fn
;; :in $ ?n
;; :where [?e :name ?n]
;; [?e :friend ?fe]
;; [?fe :name ?fn]]]
;; (is (= (:tempids tx) { -1 2, -2 3, -4 4, -3 5, :db/current-tx (+ d/tx0 1) }))
;; (is (= (d/q q @conn "Sergey") #{["Ivan"] ["Petr"]}))
;; (is (= (d/q q @conn "Boris") #{["Oleg"]}))
;; (is (= (d/q q @conn "Oleg") #{["Boris"]}))))


(deftest test-resolve-eid-refs-deep-map
(let [conn (d/create-conn {:name {:db/unique :db.unique/identity}
:friend {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}})
tx (d/transact! conn [{:name "Sergey"
:friend [{:name "Ivan"}
{:name "Petr"}]}
{:name "Oleg"
:friend [{:name "Dmitri"
:friend [{:name "Sven"
:friend [{:name "John"
:friend [
{:name "Sergey"}
]
:_friend [
{:name "Dmitri"}]}
{:name "Petr"}]
}]}]
:_friend [{:name "Boris"}]}]
)
q '[:find ?fn
:in $ ?n
:where [?e :name ?n]
[?e :friend ?fe]
[?fe :name ?fn]]]
#_(is (= (:tempids tx) { -1 2, -2 3, -4 4, -3 5, :db/current-tx (+ d/tx0 1) }))
(is (= (d/q q @conn "Sergey") #{["Ivan"] ["Petr"]}))
;; true
(is (= (d/q q @conn "Boris") #{["Oleg"]}))
;; true
;; this shows that :_ does build relationship on reverse lookups
;; and can create the new entity at the same time
(is (= (d/q q @conn "Oleg") #{["Dmitri"]}))
;; true
(is (= (d/q q @conn "Sven") #{["John"][ "Petr"]} ))
;; true
(is (= (d/pull @conn '[:name {:_friend 1}] [:name "Petr"])
{:name "Petr"
:_friend [{:name "Sergey"}
{:name "Sven"}]}))
;; true - shows that you can create relationships on a deep add, to existing ents
(is (= (d/q q @conn "Dmitri") #{["Sven"] ["John"]}))
;; fails, only Sven is a friend of Dmitri
;; shows that if you are going to be doing a deep map transaction, each path
;; needs to only go in one direction
(is (= (d/q q @conn "John") #{["Sergey"]}))
;; true, shows that the deep add works when moving in one direction
))



;; (deftest test-resolve-eid-refs-deep-map-with-lookup
;; (let [conn (d/create-conn {:name {:db/unique :db.unique/identity}
;; :friend {:db/valueType :db.type/ref
;; :db/cardinality :db.cardinality/many}})
;; tx (d/transact! conn [{:name "Sergey"
;; :friend [{:name "Ivan"}
;; {:name "Petr"}]}
;; {:name "Oleg" :_friend [{:name "Boris"}]}]
;; )
;; q '[:find ?fn
;; :in $ ?n
;; :where [?e :name ?n]
;; [?e :friend ?fe]
;; [?fe :name ?fn]]]
;; (is (= (d/q q @conn "Sergey") #{["Ivan"] ["Petr"]}))
;; ;; succeeds
;; (is (= (d/q q @conn "Boris") #{["Oleg"]}))
;; ;; succeeds
;; (is (= (d/q q @conn "Oleg") #{["Boris"]}))
;; ;; fails, returns #{}
;; ))

;; (deftest test-resolve-eid-refs-deep-map-with-lookup2
;; (let [conn (d/create-conn {:name {:db/unique :db.unique/identity}
;; :friend {:db/valueType :db.type/ref
;; :db/cardinality :db.cardinality/many}})
;; tx (d/transact! conn [{:name "Sergey"
;; :friend [{:name "Ivan"}
;; {:name "Petr"}]}
;; {:name "Boris"}
;; {:name "Oleg" :_friend [{:name "Boris"}]}]
;; )
;; q '[:find ?fn
;; :in $ ?n
;; :where [?e :name ?n]
;; [?e :friend ?fe]
;; [?fe :name ?fn]]]
;; (is (= (d/q q @conn "Sergey") #{["Ivan"] ["Petr"]}))
;; ;; succeeds
;; (is (= (d/q q @conn "Boris") #{["Oleg"]}))
;; ;; succeeds
;; (is (= (d/q q @conn "Oleg") #{["Boris"]}))
;; ;; fails, returns #{}
;; ))
Loading

0 comments on commit f767a21

Please sign in to comment.