]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/semantic-db/semantic-db-tests.factor
6747141e7f892e9edaae8f1c1e9f787b72b2db4f
[factor.git] / unmaintained / semantic-db / semantic-db-tests.factor
1 USING: accessors arrays continuations db db.sqlite db.tuples io.files
2 kernel math namespaces semantic-db sequences sorting tools.test
3 tools.walker ;
4 IN: semantic-db.tests
5
6 SYMBOL: context
7
8 : db-path "semantic-db-test.db" temp-file ;
9 : test-db db-path sqlite-db ;
10 : delete-db db-path ?delete-file ;
11
12 delete-db
13
14 test-db [
15     node create-table arc create-table
16     [ 1 ] [ "first node" create-node id>> ] unit-test
17     [ 2 ] [ "second node" create-node id>> ] unit-test
18     [ 3 ] [ "third node" create-node id>> ] unit-test
19     [ 4 ] [ f create-node id>> ] unit-test
20     [ ] [ 1 f <node> 2 f <node> 3 f <node> create-arc ] unit-test
21     [ { 1 2 3 4 } ] [ all-node-ids ] unit-test
22 ] with-db delete-db
23
24  test-db [
25      init-semantic-db
26      "test content" create-context context set
27      [ T{ node f 3 "test content" } ] [ context get ] unit-test
28      [ T{ node f 4 "is test content" } ] [ "is test content" context get create-relation ] unit-test
29      [ T{ node f 4 "is test content" } ] [ "is test content" context get get-relation ] unit-test
30      [ T{ node f 4 "is test content" } ] [ "is test content" context get ensure-relation ] unit-test
31      [ T{ node f 5 "has parent" } ] [ "has parent" context get ensure-relation ] unit-test
32      [ T{ node f 5 "has parent" } ] [ "has parent" context get ensure-relation ] unit-test
33      [ "has parent" ] [ "has parent" context get ensure-relation node-content ] unit-test
34      [ "test content" ] [ context get node-content ] unit-test
35  ] with-db delete-db
36  
37  ! "test1" "test1-relation-id-word" f f f f <relation-definition> define-relation
38  ! "test2" t t t t t <relation-definition> define-relation
39  RELATION: test3
40  test-db [
41      init-semantic-db
42      ! [ T{ node f 3 "test1" } ] [ test1-relation-id-word ] unit-test
43      ! [ T{ node f 4 "test2" } ] [ test2-relation ] unit-test
44      [ T{ node f 4 "test3" } ] [ test3-relation ] unit-test
45  ] with-db delete-db
46  
47  ! test hierarchy
48  RELATION: has-parent
49  test-db [
50      init-semantic-db
51      "adam" create-node "adam" set
52      "eve" create-node "eve" set
53      "bob" create-node "bob" set
54      "fran" create-node "fran" set
55      "charlie" create-node "charlie" set
56      "gertrude" create-node "gertrude" set
57       [ ] [ "bob" get "adam" get has-parent ] unit-test
58      { { "bob" "eve" } { "fran" "eve" } { "gertrude" "bob" } { "fran" "bob" } { "charlie" "fran" } } [ first2 [ get ] bi@ has-parent ] each
59      [ { "bob" "fran" } ] [ "eve" get has-parent-relation children [ node-content ] map ] unit-test
60      [ { "adam" "eve" } ] [ "bob" get has-parent-relation parents [ node-content ] map ] unit-test
61      [ "fran" { "charlie" } ] [ "fran" get has-parent-relation get-node-tree-s dup node>> node-content swap children>> [ node>> node-content ] map ] unit-test
62      [ { "adam" "eve" } ] [ "charlie" get has-parent-relation get-root-nodes [ node-content ] map natural-sort >array ] unit-test
63      [ { } ] [ "charlie" get dup "fran" get !has-parent has-parent-relation parents [ node-content ] map ] unit-test
64      [ { "adam" "eve" } ] [ has-parent-relation ultimate-objects node-results [ node-content ] map ] unit-test
65      [ { "fran" "gertrude" } ] [ has-parent-relation ultimate-subjects node-results [ node-content ] map ] unit-test
66  ] with-db delete-db
67