Repository navigation
Conversation
Adds basic, error and BSON type validation tests for all 15 trigonometry operators ($sin, $cos, $tan, $asin, $acos, $atan, $atan2, $sinh, $cosh, $tanh, $asinh, $acosh, $atanh, $degreesToRadians, $radiansToDegrees), and the error codes 50989, 51044 and 51045 they check. Part of documentdb#18. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, test-framework); effort from diff stats (3617+0 LOC, 46 files) If a label is wrong, ping |
Adds long and Decimal128-zero results, values read from fields, argument shapes (three arguments, nested arrays, array fields), the domain bounds and the values just inside and outside them for $asin, $acos, $atanh and $acosh, multiples of a quarter turn for $sin, $cos and $tan, overflow and underflow for the angle converters, and the null, NaN, infinity and signed-zero cases of $atan2's second argument. Messages now state the expected behaviour, inputs use the framework constants, and the module docstrings list what each file covers. Part of documentdb#18. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
eerxuan
left a comment
There was a problem hiding this comment.
Thanks for the update. Most of the earlier gaps are now covered: long input, the expected-result msg wording, the docstrings, and the near-bound errors look good.
A few asks remain, inline below. Tags follow docs/REVIEW.md: [Required] should be fixed before merge, [Suggestion] and [Nitpick] are up to you.
|
|
||
| @pytest.mark.parametrize("test", pytest_params(ACOS_BASIC_TESTS)) | ||
| def test_acos_basic(collection, test): | ||
| """Test $acos results for literal and field-path arguments.""" |
There was a problem hiding this comment.
[Required] Thanks for adding field paths and the one-element array form. TEST_COVERAGE.md §3 also asks each operator for a nested expression input (e.g. {$sin: {$add: [...]}}), an object expression input, and a composite array path ("$a.b" over an array of documents). None of the 15 operators has these yet.
[Nitpick] This docstring says "literal and field-path arguments", but this list has no field-path case. The same is true for the asin, atanh, cos, sin and tan basic files, and for the atan2 errors file. Adding one field-path success case to each basic file would fix both points; otherwise please trim the docstrings. The acosh basic module docstring also lists -0.0, which is only in the errors file.
| expected=0.0, | ||
| msg="Should return 0.0 for an infinite x", | ||
| ), | ||
| ExpressionTestCase( |
There was a problem hiding this comment.
[Required] The x-side and signed-zero cases look good. Still missing for $atan2:
- quadrants III and IV:
[-1, -1],[-1, 1] - -Infinity in each argument, and
[-Infinity, Infinity],[-Infinity, -Infinity] [-0.0, -0.0]- the mixed pairs with int or long (int/long, int/double, int/Decimal128, long/double, long/Decimal128). The description says "every numeric type pair", but the file has 6 of the 16.
[Suggestion] The infinity and NaN cases are double-only. Could you also add Decimal128 ones: [Decimal128("Infinity"), 0] → π/2, [Decimal128("-Infinity"), 0] → -π/2, [Decimal128("-Infinity"), Decimal128("Infinity")] → -π/4, [Decimal128("-Infinity"), Decimal128("-Infinity")] → -3π/4, and Decimal128("NaN") in y, in x and in both → Decimal128("NaN")?
| from documentdb_tests.framework.test_constants import ( | ||
| DECIMAL128_HALF, | ||
| DECIMAL128_NAN, | ||
| DECIMAL128_ZERO, |
There was a problem hiding this comment.
[Required] TEST_COVERAGE.md §2/§7 also want DECIMAL128_NEGATIVE_ZERO, a +0.0 double input, DOUBLE_MIN_SUBNORMAL and the Decimal128 boundary constants for each operator. Right now Decimal128 -0 is only in $atan2, the subnormal and Decimal128 limits are only in the two angle converters, and no single-input operator has a +0.0 double case (a Decimal128 zero was added instead).
| MISSING, | ||
| ) | ||
|
|
||
| ACOS_BASIC_TESTS: list[ExpressionTestCase] = [ |
There was a problem hiding this comment.
[Suggestion] Could you group the cases with # Property [...]: comments (e.g. Numeric Types, Null/Missing, Non-Finite, Domain Bounds, Domain Errors, Arity), as docs/REVIEW.md §4 asks? This applies to all the new files.
| ) | ||
|
|
||
| ACOS_ERRORS_TESTS: list[ExpressionTestCase] = [ | ||
| ExpressionTestCase( |
There was a problem hiding this comment.
[Suggestion] The domain-error cases still use only double and Decimal128 input. Could you add an int and a long out-of-domain case for each of $acos, $asin, $atanh and $acosh, e.g. {$acos: 2}, {$acos: Int64(-2)}, {$atanh: 2}, {$acosh: 0}, {$acosh: Int64(0)}, each expecting 50989?
| expected=Decimal128("3.141592653589793238462643383279503"), | ||
| msg="Should return the Decimal128 result for the lower domain bound as Decimal128", | ||
| ), | ||
| ExpressionTestCase( |
There was a problem hiding this comment.
[Nitpick] The "just inside the bound" cases are only on the +1 side. Could you add -0.9999999999999999 and Decimal128("-0.9999999999999999999999999999999999") for $acos, $asin and $atanh?
| ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ATAN2_BSON_PARAMS) | ||
|
|
||
|
|
||
| def _expression(spec): |
There was a problem hiding this comment.
[Nitpick] Optional: type hints on _expression here, and DOUBLE_ZERO / DOUBLE_NEGATIVE_ZERO instead of the remaining 0.0 / -0.0 literals (e.g. the expected=0.0 lines and the [0.0, ...] inputs in atan2/test_atan2_basic.py).
Summary
Second-pass compatibility tests for the 15 trigonometry expression operators. Each operator gets three files next to its existing smoke test:
test_<op>_basic.py: results for int, long, double and Decimal128 input, null and missing input, NaN, -0.0, Decimal128 zero, single-element argument arrays and values read from fields. Per group:$asin,$acos,$atanh,$acosh: the domain bounds as double, long and Decimal128, and the values just inside them.$sin,$cos,$tan: multiples of a quarter turn, as double and Decimal128.$degreesToRadians,$radiansToDegrees: overflow and underflow at the double and Decimal128 limits.$atan2: every numeric type pair, null, missing, NaN and infinity in each argument, the sign of zero, and field arguments.test_<op>_errors.py: argument count and shape (16020, 28765), and out-of-domain or infinite input where MongoDB rejects it (50989), as literals and as values read from fields.test_<op>_bson_type_validation.py: accepted and rejected BSON types, generated withbson_type_validator.$atan2checks both arguments (51044, 51045).That adds 730 cases (297 basic, 161 errors, 272 BSON type). Expected values come from MongoDB 8.2.4.
error_codes.pygets the three codes the new tests check.Testing
pre-commit run(black, isort, flake8, mypy) andpytest -m unitpass.Issues
Part of #18.
Closes #332, closes #333, closes #334, closes #335, closes #336, closes #337, closes #338, closes #339, closes #340, closes #341, closes #342, closes #343, closes #344, closes #345, closes #346.