graph_editor.plt 4.94 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
:- use_module(library(plunit)).


:- begin_tests(graph_editor).


test('new_graph', [true(Graphs == [new_graph])]) :-
  clear_model,
  new_graph,
  all_items([kind: graph], Graphs).

test('delete_graph', [true(Graphs == [])]) :-
  clear_model,
  new_graph,
  delete_graph(new_graph),
  all_items([kind: graph], Graphs).

test('set_graph_name', [true(Graphs == [my_graph])]) :-
  clear_model,
  new_graph,
  set_graph_name(my_graph),
  all_items([kind: graph], Graphs).

Thierry Martinez's avatar
FOLTL  
Thierry Martinez committed
24
test('list_graphs', [true(Atom == '[0]*new_graph\n')]) :-
Thierry Martinez's avatar
Thierry Martinez committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  clear_model,
  new_graph,
  with_output_to(atom(Atom), list_graphs).

test('select_graph', [true(Item == graphA)]) :-
  clear_model,
  new_graph,
  set_graph_name(graphA),
  new_graph,
  set_graph_name(graphB),
  select_graph(graphA),
  get_current_graph(Id),
  find_item([id: Id, item: Item]).

%    draw_graph/0,
%    export_graph/1,

test('add_vertex', [true(Vertices == ['A'])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
45
  command(add_vertex('A', 'A')),
Thierry Martinez's avatar
Thierry Martinez committed
46 47
  get_current_graph(GraphId),
  all_items([parent: GraphId, kind: vertex], Vertices).
Thierry Martinez's avatar
Thierry Martinez committed
48 49 50 51

test('delete_vertex', [true(Vertices == [])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
52 53
  command(add_vertex('A')),
  command(delete_vertex('A')),
Thierry Martinez's avatar
Thierry Martinez committed
54 55 56 57 58 59
  get_current_graph(GraphId),
  all_items([parent: GraphId, kind: vertex], Vertices).

test('add_edge', [true(Edges == ['A' -> 'B'])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
60 61
  command(add_edge('A' -> 'B', 'A' -> 'B', 'A' -> 'C')),
  command(delete_vertex('C')),
Thierry Martinez's avatar
Thierry Martinez committed
62 63 64 65 66 67
  get_current_graph(GraphId),
  all_items([parent: GraphId, kind: edge], Edges).

test('delete_edge', [true(Edges == [])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
68 69
  command(add_edge('A' -> 'B')),
  command(delete_edge('A' -> 'B')),
Thierry Martinez's avatar
Thierry Martinez committed
70 71
  get_current_graph(GraphId),
  all_items([parent: GraphId, kind: edge], Edges).
Thierry Martinez's avatar
Thierry Martinez committed
72

Thierry Martinez's avatar
Thierry Martinez committed
73
test('list_edges', [true(Atom == '[0] A->B\n')]) :-
Thierry Martinez's avatar
Thierry Martinez committed
74 75
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
76
  command(add_edge('A' -> 'B')),
Thierry Martinez's avatar
Thierry Martinez committed
77 78
  with_output_to(atom(Atom), list_edges).

Thierry Martinez's avatar
Thierry Martinez committed
79 80 81 82 83 84 85 86 87 88 89
test('list_isolated_vertices', [true(Atom == '[0] C\n')]) :-
  clear_model,
  new_graph,
  command(add_vertex('A', 'B', 'C')),
  command(add_edge('A' -> 'B')),
  with_output_to(atom(Atom), list_isolated_vertices).

test(
  'list_graph_objects',
  [true(Atom == '\c
[0] A->B
90
  [1] stochiometry=2
Thierry Martinez's avatar
Thierry Martinez committed
91
[2] B
92
  [3] kind=transition
Thierry Martinez's avatar
Thierry Martinez committed
93
[4] C
94
  [5] kind=place
Thierry Martinez's avatar
Thierry Martinez committed
95 96 97 98 99 100 101 102 103
[6] D
')]) :-
  clear_model,
  new_graph,
  command(add_vertex('A')),
  command(transition('B')),
  command(place('C')),
  command(add_vertex('D')),
  command(add_edge('A' -> 'B')),
104
  command(set_attribute(('A' -> 'B'), stochiometry = 2)),
Thierry Martinez's avatar
Thierry Martinez committed
105 106
  with_output_to(atom(Atom), list_graph_objects).

Thierry Martinez's avatar
Thierry Martinez committed
107 108 109
test('set_attribute vertex', [true(Attributes == ['object', 'item'])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
110 111 112 113
  command(add_vertex('A')),
  command(set_attribute('A', object)),
  command(set_attribute('A', item)),
  command(set_attribute('A', object)),
Thierry Martinez's avatar
Thierry Martinez committed
114 115 116 117
  get_current_graph(GraphId),
  find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
  all_items([parent: VertexId, kind: attribute], Attributes).

118
test('set_attribute edge', [true(Attributes == [stochiometry = 2])]) :-
Thierry Martinez's avatar
Thierry Martinez committed
119 120
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
121 122
  command(add_vertex('A', 'B')),
  command(add_edge('A' -> 'B')),
123
  command(set_attribute(('A' -> 'B'), stochiometry = 2)),
Thierry Martinez's avatar
Thierry Martinez committed
124 125 126 127
  get_current_graph(GraphId),
  find_item([parent: GraphId, kind: edge, key: ('A' -> 'B'), id: EdgeId]),
  all_items([parent: EdgeId, kind: attribute], Attributes).

128
test('place', [true(Attributes == [kind = place])]) :-
Thierry Martinez's avatar
Thierry Martinez committed
129 130
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
131 132 133
  command(transition('A')),
  command(place('A')),
  command(transition('B')),
Thierry Martinez's avatar
Thierry Martinez committed
134 135 136 137
  get_current_graph(GraphId),
  find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
  all_items([parent: VertexId, kind: attribute], Attributes).

138
test('transition', [true(Attributes == [kind = transition])]) :-
Thierry Martinez's avatar
Thierry Martinez committed
139 140
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
141 142 143
  command(place('A')),
  command(transition('A')),
  command(place('B')),
Thierry Martinez's avatar
Thierry Martinez committed
144 145 146 147 148 149 150
  get_current_graph(GraphId),
  find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
  all_items([parent: VertexId, kind: attribute], Attributes).

test('delete_attribute', [true(Attributes == [])]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
151 152 153
  command(add_vertex('A')),
  command(set_attribute('A', object)),
  command(delete_attribute('A', object)),
Thierry Martinez's avatar
Thierry Martinez committed
154 155 156 157
  get_current_graph(GraphId),
  find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
  all_items([parent: VertexId, kind: attribute], Attributes).

158
test('list_attributes vertex', [true(Atom == '[0] kind=place\n')]) :-
Thierry Martinez's avatar
Thierry Martinez committed
159 160
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
161
  command(place('A')),
Thierry Martinez's avatar
Thierry Martinez committed
162 163
  with_output_to(atom(Atom), list_attributes('A')).

164
test('list_attributes edge', [true(Atom == '[0] stochiometry=2\n')]) :-
Thierry Martinez's avatar
Thierry Martinez committed
165 166
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
167 168 169
  command(add_vertex('A')),
  command(add_vertex('B')),
  command(add_edge('A' -> 'B')),
170
  command(set_attribute(('A' -> 'B'), stochiometry = 2)),
Thierry Martinez's avatar
Thierry Martinez committed
171 172 173 174 175
  with_output_to(atom(Atom), list_attributes('A' -> 'B')).

test('get_attribute', [true(Kind == transition)]) :-
  clear_model,
  new_graph,
Thierry Martinez's avatar
Thierry Martinez committed
176
  command(transition('A')),
Thierry Martinez's avatar
Thierry Martinez committed
177
  get_current_graph(GraphId),
178
  once(get_attribute(GraphId, 'A', kind = Kind)).
Thierry Martinez's avatar
Thierry Martinez committed
179 180

:- end_tests(graph_editor).