Skip to content

Commit

Permalink
Merge pull request souffle-lang#245 from mmcgr/master
Browse files Browse the repository at this point in the history
Add 5 new tests of aggregate functions.
  • Loading branch information
Bernhard Scholz authored Dec 6, 2016
2 parents 563af86 + 55ddfe1 commit 7da1038
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/evaluation.at
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ POSITIVE_TEST([circuit_records],[evaluation])
POSITIVE_TEST([circuit_sat],[evaluation])
POSITIVE_TEST([factoring],[evaluation])
POSITIVE_TEST([perfect_numbers],[evaluation])
POSITIVE_TEST([shortest_path],[evaluation])
POSITIVE_TEST([shortest_edges],[evaluation])
POSITIVE_TEST([degree],[evaluation])
POSITIVE_TEST([highest_degree],[evaluation])
POSITIVE_TEST([disconnected],[evaluation])
4 changes: 4 additions & 0 deletions tests/evaluation/degree/InDegree.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
b 1
e 3
c 1
d 1
3 changes: 3 additions & 0 deletions tests/evaluation/degree/OutDegree.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a 2
b 2
c 2
12 changes: 12 additions & 0 deletions tests/evaluation/degree/degree.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Find the shorted outward edge for every Node
.type Node

.decl Edge(n:Node, m:Node, w:number) input

.decl OutDegree(n:Node, l:number) output

OutDegree(x, l) :- Edge(x, _, _), l = sum 1 : Edge(x, _, _).

.decl InDegree(n:Node, l:number) output

InDegree(x, l) :- Edge(_, x, _), l = sum 1 : Edge(_, x, _).
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions tests/evaluation/degree/facts/Edge.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
27 changes: 27 additions & 0 deletions tests/evaluation/disconnected/DisConnected.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
a g
a h
a f
b g
b h
b f
c b
c g
c h
c f
f b
f e
f c
f d
g b
g e
g c
g d
h b
h e
h c
h d
b a
c a
f a
g a
h a
16 changes: 16 additions & 0 deletions tests/evaluation/disconnected/disconnected.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Find all disconnected node pairs
.type Node

.decl Edge(n:Node, m:Node, w:number) input

// Find the connected nodes
.decl Connected(n:Node, m:Node)
Connected(n, n) :- Edge(n, _, _).
Connected(n, n) :- Edge(_, n, _).
Connected(n, m) :- Edge(n, m, _).
Connected(n, m) :- Edge(n, z, _), Connected(z, m).

// Find nodes without a connection
.decl DisConnected(n:Node, m:Node) output
DisConnected(n, m) :- Edge(n, _, _), Edge(_, m, _), !Connected(n, m).
DisConnected(n, m) :- Edge(n, _, _), Edge(m, _, _), !Connected(n, m).
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions tests/evaluation/disconnected/facts/Edge.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
f g 1
g h 1
h f 1
1 change: 1 addition & 0 deletions tests/evaluation/highest_degree/HighestInDegree.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions tests/evaluation/highest_degree/HighestOutDegree.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
6 changes: 6 additions & 0 deletions tests/evaluation/highest_degree/facts/Edge.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
17 changes: 17 additions & 0 deletions tests/evaluation/highest_degree/highest_degree.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Find the highest in and out degree nodes in the graph
.type Node

.decl Edge(n:Node, m:Node, w:number) input

.decl OutDegree(n:Node, l:number)
OutDegree(x, l) :- Edge(x, _, _), l = sum 1 : Edge(x, _, _).

.decl InDegree(n:Node, l:number)
InDegree(x, l) :- Edge(_, x, _), l = sum 1 : Edge(_, x, _).

.decl HighestOutDegree(d:number) output
HighestOutDegree(d) :- OutDegree(_, _), d = max D : OutDegree(_, D).

.decl HighestInDegree(d:number) output
HighestInDegree(d) :- InDegree(_, _), d = max D : InDegree(_, D).

Empty file.
Empty file.
3 changes: 3 additions & 0 deletions tests/evaluation/shortest_edges/ShortestEdgeFromN.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a 1
b 2
c 3
6 changes: 6 additions & 0 deletions tests/evaluation/shortest_edges/facts/Edge.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
8 changes: 8 additions & 0 deletions tests/evaluation/shortest_edges/shortest_edges.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Find the shortest outward edge for every Node
.type Node

.decl Edge(n:Node, m:Node, w:number) input

.decl ShortestEdgeFromN(n:Node, l:number) output

ShortestEdgeFromN(x, l) :- Edge(x, _, _), l = min Z : Edge(x, _, Z).
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions tests/evaluation/shortest_path/ShortestPath.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
a c 3
b d 5
a d 6
6 changes: 6 additions & 0 deletions tests/evaluation/shortest_path/facts/Edge.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a b 1
a e 5
b c 2
b e 4
c d 3
c e 40
13 changes: 13 additions & 0 deletions tests/evaluation/shortest_path/shortest_path.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Find the shortest paths between all nodes, the slow way
.type Node

.decl Edge(n:Node, m:Node, w:number) input

// Find all paths
.decl Length (n:Node, m:Node, l:number)
Length(x,y,t) :- t=l, Edge(x,y,l).
Length(x,y,t+l) :- Edge(x,z,l), Length(z,y,t).

// Filter out the longest path
.decl ShortestPath(n:Node, m:Node, l:number) output
ShortestPath(x, y, a) :- Length(x, y, _), a = min Z : Length(x, y, Z).
Empty file.
Empty file.

0 comments on commit 7da1038

Please sign in to comment.