summaryrefslogtreecommitdiff
path: root/test/graph_tests-basic.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-05-20 01:21:51 +1000
committerJed Barber <jjbarber@y7mail.com>2020-05-20 01:21:51 +1000
commitd07979218ea80c58e64148d9638ed3e6195ff6ed (patch)
treedef34d24f16923e8a05fc652e847240d8eb16865 /test/graph_tests-basic.adb
parent65c9afbdc7daf588aaff505b2c148c4218f231d5 (diff)
Initial unit tests
Diffstat (limited to 'test/graph_tests-basic.adb')
-rw-r--r--test/graph_tests-basic.adb96
1 files changed, 96 insertions, 0 deletions
diff --git a/test/graph_tests-basic.adb b/test/graph_tests-basic.adb
new file mode 100644
index 0000000..b0292a8
--- /dev/null
+++ b/test/graph_tests-basic.adb
@@ -0,0 +1,96 @@
+
+
+-- Remove these when all tests are written
+with Ada.Text_IO, Ada.Exceptions;
+use Ada.Text_IO, Ada.Exceptions;
+
+
+package body Graph_Tests.Basic is
+
+
+ No_Nodes : Graphs.Node_Array (1 .. 0);
+ No_Edges : Graphs.Edge_Array (1 .. 0);
+
+ Dup_Nodes : Graphs.Node_Array := (1, 2, 2, 3, 5, 9, 9, 9);
+
+ Some_Nodes : Graphs.Node_Array := (1, 2, 5, 9);
+ Some_Edges : Graphs.Edge_Array := ((1, 1, 2), (2, 5, 9), (5, 9, 1));
+
+ My_Empty_Graph : Graphs.Graph := Graphs.To_Graph (No_Nodes, No_Edges);
+ My_Nonempty_Graph : Graphs.Graph := Graphs.To_Graph (Some_Nodes, Some_Edges);
+
+
+ function To_Graph_Check
+ return Test_Result
+ is
+ Illegal_Graph : Graphs.Graph;
+ begin
+ begin
+ Illegal_Graph := Graphs.To_Graph (No_Nodes, Some_Edges);
+ return Fail;
+ exception
+ when Constraint_Error => null;
+ end;
+ begin
+ Illegal_Graph := Graphs.To_Graph (Dup_Nodes, No_Edges);
+ return Fail;
+ exception
+ when Constraint_Error => null;
+ end;
+ return Pass;
+ end To_Graph_Check;
+
+
+ function Is_Empty_Check
+ return Test_Result is
+ begin
+ if My_Empty_Graph.Is_Empty and not My_Nonempty_Graph.Is_Empty then
+ return Pass;
+ else
+ return Fail;
+ end if;
+ end Is_Empty_Check;
+
+
+ function Clear_Check
+ return Test_Result
+ is
+ My_Cleared_Graph : Graphs.Graph := My_Nonempty_Graph;
+ begin
+ My_Cleared_Graph.Clear;
+ if My_Cleared_Graph.Is_Empty then
+ return Pass;
+ else
+ return Fail;
+ end if;
+ end Clear_Check;
+
+
+ function Cursor_Element_Check
+ return Test_Result
+ is
+ use type Graphs.Cursor;
+ My_Cursor : Graphs.Cursor;
+ begin
+ if Graphs.Has_Element (Graphs.No_Element) or
+ Graphs.Element (Graphs.No_Element) /= Graphs.Extended_Node_ID_Type'First
+ then
+ return Fail;
+ end if;
+ My_Cursor := My_Nonempty_Graph.To_Cursor (2);
+ if not Graphs.Has_Element (My_Cursor) or
+ Graphs.Element (My_Cursor) /= 2
+ then
+ return Fail;
+ end if;
+ My_Cursor := My_Empty_Graph.To_Cursor (1);
+ if My_Cursor /= Graphs.No_Element then
+ return Fail;
+ end if;
+ return Pass;
+ end Cursor_Element_Check;
+
+
+end Graph_Tests.Basic;
+
+