Natools

Check-in [d3c251409e]
Login
Overview
Comment:time_keys-tests: add a test showing a subsecond rounding bug
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d3c251409eec7c4811042d508017ee0d5ca2d116
User & Date: nat on 2015-04-11 21:09:32
Other Links: manifest | tags
Context
2015-04-13
18:15
time_keys: fix subsecond rounding bug check-in: a3f3d5c90c user: nat tags: trunk
2015-04-11
21:09
time_keys-tests: add a test showing a subsecond rounding bug check-in: d3c251409e user: nat tags: trunk
2015-04-10
21:14
s_expressions: add equality operator on atoms, so clients don't have to depend on Ada.Streams check-in: e76def5969 user: nat tags: trunk
Changes

Modified tests/natools-time_keys-tests.adb from [2238f42765] to [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
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 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 Roundtrip_Test
     (Test : in out NT.Test;
      Time : in Ada.Calendar.Time;
      Expected_Key : in String)
   is
      use type Ada.Calendar.Time;







>
>
>
>
>
>

















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
   -------------------------
   -- Complete Test Suite --
   -------------------------

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

   end All_Tests;



   ----------------------
   -- Individual Tests --
   ----------------------







>







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
        (Test,
         Ada.Calendar.Formatting.Time_Of (2304, 12, 31,  0,  0,  0),
         "_0CV");
   exception
      when Error : others => Test.Report_Exception (Error);
   end Roundtrips;















































































end Natools.Time_Keys.Tests;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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;

Modified tests/natools-time_keys-tests.ads from [582c5dff9f] to [71458af104].

19
20
21
22
23
24
25

26
27
package Natools.Time_Keys.Tests is

   package NT renames Natools.Tests;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Roundtrips (Report : in out NT.Reporter'Class);


end Natools.Time_Keys.Tests;







>


19
20
21
22
23
24
25
26
27
28
package Natools.Time_Keys.Tests is

   package NT renames Natools.Tests;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Roundtrips (Report : in out NT.Reporter'Class);
   procedure Subsecond_Rounding (Report : in out NT.Reporter'Class);

end Natools.Time_Keys.Tests;