Index: tests/natools-constant_indefinite_ordered_map_tests.adb ================================================================== --- tests/natools-constant_indefinite_ordered_map_tests.adb +++ tests/natools-constant_indefinite_ordered_map_tests.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2014, Natacha Porté -- +-- Copyright (c) 2014-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -110,10 +110,11 @@ Ada_2012_Iteration (Report); Ada_2012_Errors (Report); Range_Iterators (Report); Update_Constructors (Report); Update_Constructor_Exceptions (Report); + Rank (Report); end All_Tests; ---------------------- @@ -878,10 +879,50 @@ end; exception when Error : others => Test.Report_Exception (Error); end Range_Iterators; + + procedure Rank (Report : in out NT.Reporter'Class) is + Test : NT.Test := Report.Item ("Rank function"); + begin + declare + Map : constant Test_Maps.Updatable_Map := Sample_Map; + + procedure Test_Rank + (Cursor : in Test_Maps.Cursor; + Expected : in Ada.Containers.Count_Type; + Name : in String); + + procedure Test_Rank + (Cursor : in Test_Maps.Cursor; + Expected : in Ada.Containers.Count_Type; + Name : in String) + is + use type Ada.Containers.Count_Type; + + Actual : constant Ada.Containers.Count_Type + := Test_Maps.Rank (Cursor); + begin + if Actual /= Expected then + Test.Fail ("Expected rank" + & Ada.Containers.Count_Type'Image (Expected) + & " for " & Name & ", found" + & Ada.Containers.Count_Type'Image (Actual)); + end if; + end Test_Rank; + begin + Test_Rank (Test_Maps.No_Element, 0, "No_Element"); + Test_Rank (Map.First, 1, "Map.First"); + Test_Rank (Map.Last, 20, "Map.Last"); + Test_Rank (Test_Maps.Next (Map.First), 2, "Next (Map.First)"); + Test_Rank (Test_Maps.Next (Map.Last), 0, "Next (Map.Last)"); + end; + exception + when Error : others => Test.Report_Exception (Error); + end Rank; + procedure Unsafe_Map_Roundtrip (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("Constant_Map <-> Unsafe_Map roundtrip"); begin declare Index: tests/natools-constant_indefinite_ordered_map_tests.ads ================================================================== --- tests/natools-constant_indefinite_ordered_map_tests.ads +++ tests/natools-constant_indefinite_ordered_map_tests.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2014, Natacha Porté -- +-- Copyright (c) 2014-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -31,10 +31,11 @@ procedure Direct_Access (Report : in out NT.Reporter'Class); procedure Empty_Map (Report : in out NT.Reporter'Class); procedure Iterations (Report : in out NT.Reporter'Class); procedure Map_Updates (Report : in out NT.Reporter'Class); procedure Range_Iterators (Report : in out NT.Reporter'Class); + procedure Rank (Report : in out NT.Reporter'Class); procedure Unsafe_Map_Roundtrip (Report : in out NT.Reporter'Class); procedure Update_Constructors (Report : in out NT.Reporter'Class); procedure Update_Constructor_Exceptions (Report : in out NT.Reporter'Class); end Natools.Constant_Indefinite_Ordered_Map_Tests;