-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtc_delta.rb
91 lines (76 loc) · 1.84 KB
/
tc_delta.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require './test_common'
class DeltaTest
include Bud
state do
table :orig, [:k1, :k2] => []
scratch :scr, [:k1, :k2] => []
table :result, [:k1, :k2] => []
end
bootstrap do
orig <= [['a', 'b']]
orig <= [['a', 'c']]
end
bloom do
scr <= orig
result <= scr
end
end
class DeltaJoinTest
include Bud
state do
table :orig, [:from, :to]
scratch :link, [:from, :to]
scratch :path, [:from, :to]
scratch :hashpath, [:from, :to]
end
bootstrap do
orig <= [['a', 'b'], ['b', 'c'], ['c', 'd']]
end
bloom :paths do
link <= orig
path <= link
path <= (link * path).pairs {|l,p| [l.from, p.to] if l.to == p.from}
hashpath <= link
hashpath <= (link * path).pairs(:to => :from) {|l,p| [l.from, p.to]}
end
end
class Delta3JoinTest
include Bud
state do
table :orig, [:from, :to]
table :wanted, [:node]
scratch :link, [:from, :to]
scratch :path, [:from, :to]
scratch :hashpath, [:from, :to]
end
bootstrap do
orig <= [['a', 'b'], ['b', 'c'], ['c', 'd']]
wanted <= [['a'], ['b'], ['c']]
end
bloom :paths do
link <= orig
path <= link
path <= (link * path * wanted).combos {|l,p,w| [l.from, p.to] if l.to == p.from and l.from == w.node}
hashpath <= link
hashpath <= (link * path * wanted).combos(link.to => path.from, link.from => wanted.node) {|l,p| [l.from, p.to]}
end
end
class TestDelta < Minitest::Test
def test_transitivity
program = DeltaTest.new
program.tick
assert_equal(2, program.result.length)
end
def test_one
program = DeltaJoinTest.new
program.tick
assert_equal(6, program.path.length)
assert_equal(6, program.hashpath.length)
end
def test_three
program = Delta3JoinTest.new
program.tick
assert_equal(6, program.path.length)
assert_equal(6, program.hashpath.length)
end
end