Skip to content

Commit c186295

Browse files
author
mdbmes
authored
CDRIVER-5880: Remove workaround for DRIVERS-3095, defer other test improvements (#1901)
* DRIVERS-3095: Update float32 test (specifications change ccd72de68cc29b68fe55a79ad44d20b20ad1b4e7) * CDRIVER-5880: Remove workaround for DRIVERS-3095, defer other test improvements
1 parent 0d5145e commit c186295

File tree

2 files changed

+15
-51
lines changed

2 files changed

+15
-51
lines changed

src/libbson/tests/json/bson_binary_vector/float32.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"description": "Infinity Vector FLOAT32",
3434
"valid": true,
35-
"vector": ["-inf", 0.0, "inf"],
35+
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
3636
"dtype_hex": "0x27",
3737
"dtype_alias": "FLOAT32",
3838
"padding": 0,

src/libbson/tests/test-bson-vector.c

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,11 @@ typedef struct vector_json_test_case_t {
5858
bool *test_valid;
5959
} vector_json_test_case_t;
6060

61-
static void
62-
translate_json_test_vector (bson_t *array_in, bson_t *array_out)
63-
{
64-
// Patches JSON tests until DRIVERS-3095 is resolved:
65-
// - convert "inf" to a double +Infinity
66-
// - convert "-inf" to a double -Infinity
67-
68-
bson_iter_t iter_in;
69-
ASSERT (bson_iter_init (&iter_in, array_in));
70-
bson_array_builder_t *builder = bson_array_builder_new ();
71-
while (bson_iter_next (&iter_in)) {
72-
if (BSON_ITER_HOLDS_UTF8 (&iter_in) && 0 == strcmp ("inf", bson_iter_utf8 (&iter_in, NULL))) {
73-
ASSERT (bson_array_builder_append_double (builder, (double) INFINITY));
74-
} else if (BSON_ITER_HOLDS_UTF8 (&iter_in) && 0 == strcmp ("-inf", bson_iter_utf8 (&iter_in, NULL))) {
75-
ASSERT (bson_array_builder_append_double (builder, (double) -INFINITY));
76-
} else {
77-
ASSERT (bson_array_builder_append_iter (builder, &iter_in));
78-
}
79-
}
80-
ASSERT (bson_array_builder_build (builder, array_out));
81-
bson_array_builder_destroy (builder);
82-
}
83-
8461
static bool
8562
append_vector_packed_bit_from_packed_array (
8663
bson_t *bson, const char *key, int key_length, const bson_iter_t *iter, int64_t padding, bson_error_t *error)
8764
{
88-
// (TODO for DRIVERS-3095, DRIVERS-3097) This implements something the test covers that our API doesn't. If the test
65+
// (Spec test improvement TODO) This implements something the test covers that our API doesn't. If the test
8966
// were modified to cover element-by-element conversion, this can be replaced with
9067
// bson_append_vector_packed_bit_from_array.
9168

@@ -182,7 +159,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
182159
bson_error_t vector_from_array_error;
183160
bool vector_from_array_ok;
184161

185-
// (TODO for DRIVERS-3095, DRIVERS-3097) Patch test cases that have unused bits set to '1' when '0' is required.
162+
// (Spec test improvement TODO) Patch test cases that have unused bits set to '1' when '0' is required.
186163
if (0 == strcmp ("PACKED_BIT with padding", test_case->test_description)) {
187164
bson_iter_t iter;
188165
ASSERT (bson_iter_init_find (&iter, &expected_bson, test_case->scenario_test_key));
@@ -205,26 +182,20 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
205182
&vector_from_array, test_case->scenario_test_key, &iter, &vector_from_array_error);
206183
} else if (0 == strcmp ("0x27", test_case->test_dtype_hex_str)) {
207184
// float32 vector from float64 array
208-
// (TODO for DRIVERS-3095) Convert the unusual numeric array format to a standard array
209-
bson_t converted = BSON_INITIALIZER;
185+
bson_iter_t iter;
210186
bool padding_ok = !test_case->test_padding || *test_case->test_padding == 0;
211-
if (test_case->test_vector_array && padding_ok) {
212-
bson_iter_t iter;
213-
translate_json_test_vector (test_case->test_vector_array, &converted);
214-
vector_from_array_ok = bson_iter_init (&iter, &converted) &&
215-
BSON_APPEND_VECTOR_FLOAT32_FROM_ARRAY (
216-
&vector_from_array, test_case->scenario_test_key, &iter, &vector_from_array_error);
217-
} else {
218-
vector_from_array_ok = false;
219-
}
220-
bson_destroy (&converted);
187+
vector_from_array_ok = test_case->test_vector_array && padding_ok &&
188+
bson_iter_init (&iter, test_case->test_vector_array) &&
189+
BSON_APPEND_VECTOR_FLOAT32_FROM_ARRAY (
190+
&vector_from_array, test_case->scenario_test_key, &iter, &vector_from_array_error);
221191
} else if (0 == strcmp ("0x10", test_case->test_dtype_hex_str)) {
222192
// packed_bit from packed bytes in an int array, with "padding" parameter supplied separately.
223-
// TODO for DRIVERS-3095, DRIVERS-3097:
193+
// Suggested changes to reduce the special cases here:
224194
// - Array-to-Vector should be defined as an element-by-element conversion. This test shouldn't operate on packed
225195
// representations.
226196
// - Include additional JSON tests for packed access, distinct from Array conversion.
227197
// - Tests should keep the unused bits zeroed as required.
198+
// (Spec test improvement TODO)
228199
bson_iter_t iter;
229200
if (!test_case->test_padding) {
230201
test_error ("test '%s' is missing required 'padding' field", test_case->test_description);
@@ -286,12 +257,9 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
286257
bson_array_builder_destroy (array_builder);
287258
}
288259

289-
// (TODO for DRIVERS-3095, DRIVERS-3097) Due to loosely defined element types and rounding behavior in the test
290-
// vectors, this comparison can't be exact. Temporary special cases are needed for float32 and packed_bit.
291-
292260
if (BSON_ITER_HOLDS_VECTOR_FLOAT32 (&iter)) {
293-
// float32 special case: We need to handle the nonstandard "inf" and "-inf" forms, and
294-
// due to underspecified rounding and conversion rules we compare value inexactly.
261+
// float32 special case: Due to underspecified rounding and conversion rules we compare value inexactly.
262+
// (Spec test improvement TODO)
295263

296264
bson_iter_t actual_iter, expected_iter;
297265
ASSERT (bson_iter_init (&actual_iter, &array_from_vector));
@@ -314,12 +282,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
314282
double actual_double = bson_iter_double (&actual_iter);
315283

316284
double expected_double;
317-
if (BSON_ITER_HOLDS_UTF8 (&expected_iter) && 0 == strcmp ("inf", bson_iter_utf8 (&expected_iter, NULL))) {
318-
expected_double = (double) INFINITY;
319-
} else if (BSON_ITER_HOLDS_UTF8 (&expected_iter) &&
320-
0 == strcmp ("-inf", bson_iter_utf8 (&expected_iter, NULL))) {
321-
expected_double = (double) -INFINITY;
322-
} else if (BSON_ITER_HOLDS_DOUBLE (&expected_iter)) {
285+
if (BSON_ITER_HOLDS_DOUBLE (&expected_iter)) {
323286
expected_double = bson_iter_double (&expected_iter);
324287
} else {
325288
test_error ("test-vector array element %d has unexpected type, should be double, 'inf', or '-inf'.",
@@ -357,6 +320,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
357320
// understand it, they're operating on bytes rather than elements. This is the inverse of
358321
// append_vector_packed_bit_from_packed_array() above, and it bypasses the vector-to-array conversion.
359322
// 'array_from_vector' is ignored on this path.
323+
// (Spec test improvement TODO)
360324

361325
bson_iter_t expected_iter;
362326
ASSERT (bson_iter_init (&expected_iter, test_case->test_vector_array));
@@ -372,7 +336,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
372336
test_error ("test-vector array element %d has unexpected type, should be int.", (int) byte_count);
373337
}
374338

375-
// (TODO for DRIVERS-3095, DRIVERS-3097) Packed writes can't set unused bits to '1' in libbson, but the spec
339+
// (Spec test improvement TODO) Packed writes can't set unused bits to '1' in libbson, but the spec
376340
// tests allow padding bits to take on undefined values. Modify the expected values to keep padding bits
377341
// zeroed.
378342
if (0 == strcmp ("PACKED_BIT with padding", test_case->test_description) &&

0 commit comments

Comments
 (0)