summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-05-23 15:31:27 +1000
committerJed Barber <jjbarber@y7mail.com>2020-05-23 15:31:27 +1000
commit7f56d08907ffdd192f4b4898bfb22c1dce8f1cd0 (patch)
tree791bc8ca10d1f23226aafca9fd24c8c7612a1a02 /test
parent5bb4bfd85fb558380a8b06ac77d0e5b27aee1feb (diff)
Added Iterate_By function for custom iteration
Diffstat (limited to 'test')
-rw-r--r--test/graph_tests-search.adb69
-rw-r--r--test/graph_tests-search.ads4
2 files changed, 72 insertions, 1 deletions
diff --git a/test/graph_tests-search.adb b/test/graph_tests-search.adb
index 17c2cbb..d72ce67 100644
--- a/test/graph_tests-search.adb
+++ b/test/graph_tests-search.adb
@@ -230,6 +230,75 @@ package body Graph_Tests.Search is
end Iterate_Subgraph_Check;
+ function Iterate_By_Check
+ return Test_Result
+ is
+ function Max
+ (Nodes : in Graphs.Node_Array)
+ return Node_ID
+ is
+ Current : Node_ID := 1;
+ begin
+ for N of Nodes loop
+ if N > Current then
+ Current := N;
+ end if;
+ end loop;
+ return Current;
+ end Max;
+
+ function My_Choices
+ (Position : in Graphs.Cursor)
+ return Graphs.Cursor
+ is
+ Pick_From : Graphs.Node_Array := Graphs.Children (Position);
+ begin
+ if Pick_From'Length = 0 then
+ return Graphs.No_Element;
+ end if;
+ return Graphs.Cursor_To (Position, Max (Pick_From));
+ end My_Choices;
+
+ function My_Filter
+ (Position : in Graphs.Cursor)
+ return Boolean is
+ begin
+ return not Graphs.Has_Element (Position) or else
+ Graphs.Element (Position) mod 2 = 0;
+ end My_Filter;
+
+ Index : Positive := 1;
+ Check_1 : Graphs.Node_Array := (1, 5, 7, 10);
+ Check_2 : Graphs.Node_Array := (1 => 10);
+
+ Start : Graphs.Cursor := My_Complex_Graph.To_Cursor (1);
+ begin
+ for C in My_Complex_Graph.Iterate_By (Start, My_Choices'Unrestricted_Access) loop
+ if Index not in Check_1'Range or else
+ Graphs.Element (C) /= Check_1 (Index)
+ then
+ return Fail;
+ else
+ Index := Index + 1;
+ end if;
+ end loop;
+
+ Index := 1;
+ for C in My_Complex_Graph.Iterate_By
+ (Start, My_Choices'Unrestricted_Access, My_Filter'Unrestricted_Access)
+ loop
+ if Index not in Check_2'Range or else
+ Graphs.Element (C) /= Check_2 (Index)
+ then
+ return Fail;
+ else
+ Index := Index + 1;
+ end if;
+ end loop;
+ return Pass;
+ end Iterate_By_Check;
+
+
end Graph_Tests.Search;
diff --git a/test/graph_tests-search.ads b/test/graph_tests-search.ads
index d0ea2bb..63602e7 100644
--- a/test/graph_tests-search.ads
+++ b/test/graph_tests-search.ads
@@ -15,6 +15,7 @@ package Graph_Tests.Search is
function Contains_Label_Subgraph_Check return Test_Result;
function Iterate_Check return Test_Result;
function Iterate_Subgraph_Check return Test_Result;
+ function Iterate_By_Check return Test_Result;
Tests : Test_Array :=
@@ -25,7 +26,8 @@ package Graph_Tests.Search is
(+"Contains_In_Subgraph", Contains_Subgraph_Check'Access),
(+"Contains_Label_In_Subgraph", Contains_Label_Subgraph_Check'Access),
(+"Iterate", Iterate_Check'Access),
- (+"Iterate_Subgraph", Iterate_Subgraph_Check'Access));
+ (+"Iterate_Subgraph", Iterate_Subgraph_Check'Access),
+ (+"Iterate_By", Iterate_By_Check'Access));
end Graph_Tests.Search;