Natools

Diff
Login

Differences From Artifact [2238f42765]:

To Artifact [243ddc1759]:


17
18
19
20
21
22
23






24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

















41
42
43
44
45
46
47
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70







+
+
+
+
+
+

















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







with Ada.Calendar.Formatting;
with Natools.Time_IO.RFC_3339;

package body Natools.Time_Keys.Tests is

   function Image (Date : Ada.Calendar.Time) return String;

   procedure Key_Test
     (Test : in out NT.Test;
      Time : in Ada.Calendar.Time;
      Expected_Key : in String;
      Max_Sub_Second_Digits : in Natural);

   procedure Roundtrip_Test
     (Test : in out NT.Test;
      Time : in Ada.Calendar.Time;
      Expected_Key : in String);


   ------------------------------
   -- Local Helper Subprograms --
   ------------------------------

   function Image (Date : Ada.Calendar.Time) return String is
   begin
      return Time_IO.RFC_3339.Image
        (Date => Date,
         Subsecond_Digits => Duration'Aft);
   end Image;


   procedure Key_Test
     (Test : in out NT.Test;
      Time : in Ada.Calendar.Time;
      Expected_Key : in String;
      Max_Sub_Second_Digits : in Natural)
   is
      Generated_Key : constant String := To_Key (Time, Max_Sub_Second_Digits);
   begin
      if Generated_Key /= Expected_Key then
         Test.Fail ("Generated key """ & Generated_Key
           & """, expected """ & Expected_Key & '"');
         Test.Info ("Time of generated key: "
           & Image (To_Time (Generated_Key)));
      end if;
   end Key_Test;


   procedure Roundtrip_Test
     (Test : in out NT.Test;
      Time : in Ada.Calendar.Time;
      Expected_Key : in String)
   is
      use type Ada.Calendar.Time;
65
66
67
68
69
70
71

72
73
74
75
76
77
78
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102







+







   -------------------------
   -- Complete Test Suite --
   -------------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Roundtrips (Report);
      Subsecond_Rounding (Report);
   end All_Tests;



   ----------------------
   -- Individual Tests --
   ----------------------
108
109
110
111
112
113
114














































































115
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

        (Test,
         Ada.Calendar.Formatting.Time_Of (2304, 12, 31,  0,  0,  0),
         "_0CV");
   exception
      when Error : others => Test.Report_Exception (Error);
   end Roundtrips;


   procedure Subsecond_Rounding (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Overflow in subsecond rounding");
   begin
      if Duration'Small > 1.0 / 256.0 then
         Test.Skip ("Not enough precision in Duration");
         return;
      end if;

      Key_Test
        (Test,
         To_Time ("VV121231~V"),
         "VV121231~",
         2);

      Key_Test
        (Test,
         To_Time ("VV121231~X"),
         "VV121232",
         2);

      Key_Test
        (Test,
         To_Time ("VV124561~~V"),
         "VV124561~~",
         3);

      Key_Test
        (Test,
         To_Time ("VV124561~~X"),
         "VV124562",
         3);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2015, 2, 2,  1,  1,  1, 255.0 / 256.0),
         "VV22112",
         1);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2015, 2, 2,  1,  58, 59, 255.0 / 256.0),
         "VV221w",
         1);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2015, 2, 2,  22,  59, 59, 255.0 / 256.0),
         "VV22N",
         1);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2015, 2, 28, 23, 59, 59, 255.0 / 256.0),
         "VV31",
         1);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2016, 2, 28, 23, 59, 59, 255.0 / 256.0),
         "VW2T",
         1);

      Key_Test
        (Test,
         Ada.Calendar.Formatting.Time_Of
           (2015, 12, 31, 23, 59, 59, 255.0 / 256.0),
         "VW11",
         1);
   exception
      when Error : others => Test.Report_Exception (Error);
   end Subsecond_Rounding;

end Natools.Time_Keys.Tests;