From 8f2435b3989d62f72e973110b20514294c14090c Mon Sep 17 00:00:00 2001 From: Samar Farooqi Date: Wed, 2 Dec 2026 00:09:12 +0000 Subject: [PATCH 1/2] Add second-pass tests for the trigonometry expression operators 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 #18. Signed-off-by: Samar Farooqi --- .../trigonometry/acos/test_acos_basic.py | 92 ++++++++++++ .../acos/test_acos_bson_type_validation.py | 69 +++++++++ .../trigonometry/acos/test_acos_errors.py | 94 ++++++++++++ .../trigonometry/acosh/test_acosh_basic.py | 93 ++++++++++++ .../acosh/test_acosh_bson_type_validation.py | 69 +++++++++ .../trigonometry/acosh/test_acosh_errors.py | 86 +++++++++++ .../trigonometry/asin/test_asin_basic.py | 98 ++++++++++++ .../asin/test_asin_bson_type_validation.py | 69 +++++++++ .../trigonometry/asin/test_asin_errors.py | 94 ++++++++++++ .../trigonometry/asinh/test_asinh_basic.py | 133 +++++++++++++++++ .../asinh/test_asinh_bson_type_validation.py | 62 ++++++++ .../trigonometry/asinh/test_asinh_errors.py | 41 ++++++ .../trigonometry/atan/test_atan_basic.py | 133 +++++++++++++++++ .../atan/test_atan_bson_type_validation.py | 62 ++++++++ .../trigonometry/atan/test_atan_errors.py | 41 ++++++ .../trigonometry/atan2/test_atan2_basic.py | 91 ++++++++++++ .../atan2/test_atan2_bson_type_validation.py | 74 ++++++++++ .../trigonometry/atan2/test_atan2_errors.py | 47 ++++++ .../trigonometry/atanh/test_atanh_basic.py | 94 ++++++++++++ .../atanh/test_atanh_bson_type_validation.py | 69 +++++++++ .../trigonometry/atanh/test_atanh_errors.py | 94 ++++++++++++ .../trigonometry/cos/test_cos_basic.py | 105 +++++++++++++ .../cos/test_cos_bson_type_validation.py | 58 ++++++++ .../trigonometry/cos/test_cos_errors.py | 74 ++++++++++ .../trigonometry/cosh/test_cosh_basic.py | 133 +++++++++++++++++ .../cosh/test_cosh_bson_type_validation.py | 62 ++++++++ .../trigonometry/cosh/test_cosh_errors.py | 41 ++++++ .../test_degreesToRadians_basic.py | 139 ++++++++++++++++++ ...t_degreesToRadians_bson_type_validation.py | 62 ++++++++ .../test_degreesToRadians_errors.py | 41 ++++++ .../test_radiansToDegrees_basic.py | 133 +++++++++++++++++ ...t_radiansToDegrees_bson_type_validation.py | 62 ++++++++ .../test_radiansToDegrees_errors.py | 41 ++++++ .../trigonometry/sin/test_sin_basic.py | 111 ++++++++++++++ .../sin/test_sin_bson_type_validation.py | 58 ++++++++ .../trigonometry/sin/test_sin_errors.py | 74 ++++++++++ .../trigonometry/sinh/test_sinh_basic.py | 139 ++++++++++++++++++ .../sinh/test_sinh_bson_type_validation.py | 62 ++++++++ .../trigonometry/sinh/test_sinh_errors.py | 41 ++++++ .../trigonometry/tan/test_tan_basic.py | 105 +++++++++++++ .../tan/test_tan_bson_type_validation.py | 58 ++++++++ .../trigonometry/tan/test_tan_errors.py | 74 ++++++++++ .../trigonometry/tanh/test_tanh_basic.py | 133 +++++++++++++++++ .../tanh/test_tanh_bson_type_validation.py | 62 ++++++++ .../trigonometry/tanh/test_tanh_errors.py | 41 ++++++ documentdb_tests/framework/error_codes.py | 3 + 46 files changed, 3617 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_bson_type_validation.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py new file mode 100644 index 000000000..cb9d60466 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py @@ -0,0 +1,92 @@ +""" +trigonometry $acos tests. + +Tests $acos results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NAN, + MISSING, +) + +ACOS_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$acos": 1}, + expected=0.0, + msg="$acos of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$acos": 0.5}, + expected=1.0471975511965979, + msg="$acos of double half", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$acos": Decimal128("0.5")}, + expected=Decimal128("1.047197551196597746154214461093168"), + msg="$acos of decimal128 half", + ), + ExpressionTestCase( + "null", + expression={"$acos": None}, + expected=None, + msg="$acos of null", + ), + ExpressionTestCase( + "missing", + expression={"$acos": MISSING}, + expected=None, + msg="$acos of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$acos": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$acos of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$acos": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$acos of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$acos": DOUBLE_NEGATIVE_ZERO}, + expected=1.5707963267948966, + msg="$acos of negative zero", + ), + ExpressionTestCase( + "double_negative_one", + expression={"$acos": -1.0}, + expected=3.141592653589793, + msg="$acos of double negative one", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ACOS_BASIC_TESTS)) +def test_acos_basic(collection, test): + """Test $acos values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_bson_type_validation.py new file mode 100644 index 000000000..bb6e6651c --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_bson_type_validation.py @@ -0,0 +1,69 @@ +""" +BSON type validation tests for $acos expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest +from bson import Decimal128, Int64 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ACOS_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$acos should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + valid_inputs={ + BsonType.DOUBLE: 0.5, + BsonType.INT: 1, + BsonType.LONG: Int64(1), + BsonType.DECIMAL: Decimal128("0.5"), + }, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ACOS_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ACOS_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_acos_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $acos rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$acos": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_acos_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $acos accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$acos": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$acos should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py new file mode 100644 index 000000000..1b2c35d7f --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py @@ -0,0 +1,94 @@ +""" +trigonometry $acos tests. + +Tests $acos errors: argument count, and inputs outside the operator's range. +""" + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +ACOS_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_two", + expression={"$acos": 2.0}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of double two should fail", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$acos": Decimal128("-2")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of decimal128 negative two should fail", + ), + ExpressionTestCase( + "double_max", + expression={"$acos": DOUBLE_MAX}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of double max should fail", + ), + ExpressionTestCase( + "double_infinity", + expression={"$acos": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$acos": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$acos": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$acos": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acos of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$acos": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$acos of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$acos": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$acos of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ACOS_ERRORS_TESTS)) +def test_acos_errors(collection, test): + """Test $acos errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py new file mode 100644 index 000000000..c33f96595 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py @@ -0,0 +1,93 @@ +""" +trigonometry $acosh tests. + +Tests $acosh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DOUBLE_MAX, + FLOAT_INFINITY, + FLOAT_NAN, + MISSING, +) + +ACOSH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$acosh": 1}, + expected=0.0, + msg="$acosh of int one", + ), + ExpressionTestCase( + "double_two", + expression={"$acosh": 2.0}, + expected=1.3169578969248166, + msg="$acosh of double two", + ), + ExpressionTestCase( + "double_max", + expression={"$acosh": DOUBLE_MAX}, + expected=710.4758600739439, + msg="$acosh of double max", + ), + ExpressionTestCase( + "null", + expression={"$acosh": None}, + expected=None, + msg="$acosh of null", + ), + ExpressionTestCase( + "missing", + expression={"$acosh": MISSING}, + expected=None, + msg="$acosh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$acosh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$acosh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$acosh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$acosh of decimal128 nan", + ), + ExpressionTestCase( + "double_infinity", + expression={"$acosh": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$acosh of double infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$acosh": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$acosh of decimal128 infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ACOSH_BASIC_TESTS)) +def test_acosh_basic(collection, test): + """Test $acosh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_bson_type_validation.py new file mode 100644 index 000000000..1bf5f2b9b --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_bson_type_validation.py @@ -0,0 +1,69 @@ +""" +BSON type validation tests for $acosh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest +from bson import Decimal128, Int64 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ACOSH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$acosh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + valid_inputs={ + BsonType.DOUBLE: 2.0, + BsonType.INT: 1, + BsonType.LONG: Int64(1), + BsonType.DECIMAL: Decimal128("2"), + }, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ACOSH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ACOSH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_acosh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $acosh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$acosh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_acosh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $acosh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$acosh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$acosh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py new file mode 100644 index 000000000..c97cd6b22 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py @@ -0,0 +1,86 @@ +""" +trigonometry $acosh tests. + +Tests $acosh errors: argument count, and inputs outside the operator's range. +""" + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NEGATIVE_INFINITY, +) + +ACOSH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_half", + expression={"$acosh": 0.5}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of double half should fail", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$acosh": Decimal128("0.5")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of decimal128 half should fail", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$acosh": Decimal128("-2")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of decimal128 negative two should fail", + ), + ExpressionTestCase( + "negative_zero", + expression={"$acosh": DOUBLE_NEGATIVE_ZERO}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of negative zero should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$acosh": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$acosh": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$acosh of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$acosh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$acosh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$acosh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$acosh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ACOSH_ERRORS_TESTS)) +def test_acosh_errors(collection, test): + """Test $acosh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py new file mode 100644 index 000000000..a5c50d38a --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py @@ -0,0 +1,98 @@ +""" +trigonometry $asin tests. + +Tests $asin results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NAN, + MISSING, +) + +ASIN_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$asin": 1}, + expected=1.5707963267948966, + msg="$asin of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$asin": 0.5}, + expected=0.5235987755982989, + msg="$asin of double half", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$asin": Decimal128("0.5")}, + expected=Decimal128("0.5235987755982988730771072305465838"), + msg="$asin of decimal128 half", + ), + ExpressionTestCase( + "null", + expression={"$asin": None}, + expected=None, + msg="$asin of null", + ), + ExpressionTestCase( + "missing", + expression={"$asin": MISSING}, + expected=None, + msg="$asin of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$asin": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$asin of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$asin": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$asin of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$asin": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$asin of negative zero", + ), + ExpressionTestCase( + "double_negative_one", + expression={"$asin": -1.0}, + expected=-1.5707963267948966, + msg="$asin of double negative one", + ), + ExpressionTestCase( + "single_element_array", + expression={"$asin": [0.5]}, + expected=0.5235987755982989, + msg="$asin of single element array", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ASIN_BASIC_TESTS)) +def test_asin_basic(collection, test): + """Test $asin values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_bson_type_validation.py new file mode 100644 index 000000000..d6c8c4e96 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_bson_type_validation.py @@ -0,0 +1,69 @@ +""" +BSON type validation tests for $asin expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest +from bson import Decimal128, Int64 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ASIN_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$asin should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + valid_inputs={ + BsonType.DOUBLE: 0.5, + BsonType.INT: 1, + BsonType.LONG: Int64(1), + BsonType.DECIMAL: Decimal128("0.5"), + }, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ASIN_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ASIN_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_asin_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $asin rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$asin": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_asin_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $asin accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$asin": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$asin should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py new file mode 100644 index 000000000..149b45d43 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py @@ -0,0 +1,94 @@ +""" +trigonometry $asin tests. + +Tests $asin errors: argument count, and inputs outside the operator's range. +""" + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +ASIN_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_two", + expression={"$asin": 2.0}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of double two should fail", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$asin": Decimal128("-2")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of decimal128 negative two should fail", + ), + ExpressionTestCase( + "double_max", + expression={"$asin": DOUBLE_MAX}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of double max should fail", + ), + ExpressionTestCase( + "double_infinity", + expression={"$asin": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$asin": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$asin": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$asin": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$asin of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$asin": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$asin of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$asin": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$asin of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ASIN_ERRORS_TESTS)) +def test_asin_errors(collection, test): + """Test $asin errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py new file mode 100644 index 000000000..dbad2e4d5 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py @@ -0,0 +1,133 @@ +""" +trigonometry $asinh tests. + +Tests $asinh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +ASINH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$asinh": 1}, + expected=0.881373587019543, + msg="$asinh of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$asinh": 0.5}, + expected=0.48121182505960347, + msg="$asinh of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$asinh": 2.0}, + expected=1.4436354751788103, + msg="$asinh of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$asinh": Decimal128("0.5")}, + expected=Decimal128("0.4812118250596034474977589134243684"), + msg="$asinh of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$asinh": Decimal128("-2")}, + expected=Decimal128("-1.443635475178810342493276740273105"), + msg="$asinh of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$asinh": DOUBLE_MAX}, + expected=710.4758600739439, + msg="$asinh of double max", + ), + ExpressionTestCase( + "null", + expression={"$asinh": None}, + expected=None, + msg="$asinh of null", + ), + ExpressionTestCase( + "missing", + expression={"$asinh": MISSING}, + expected=None, + msg="$asinh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$asinh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$asinh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$asinh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$asinh of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$asinh": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$asinh of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$asinh": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$asinh of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$asinh": FLOAT_NEGATIVE_INFINITY}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="$asinh of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$asinh": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$asinh of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$asinh": DECIMAL128_NEGATIVE_INFINITY}, + expected=DECIMAL128_NEGATIVE_INFINITY, + msg="$asinh of decimal128 negative infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ASINH_BASIC_TESTS)) +def test_asinh_basic(collection, test): + """Test $asinh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_bson_type_validation.py new file mode 100644 index 000000000..be1e948e5 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $asinh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ASINH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$asinh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ASINH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ASINH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_asinh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $asinh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$asinh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_asinh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $asinh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$asinh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$asinh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py new file mode 100644 index 000000000..421a0d9fc --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $asinh tests. + +Tests $asinh errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +ASINH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$asinh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$asinh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$asinh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$asinh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ASINH_ERRORS_TESTS)) +def test_asinh_errors(collection, test): + """Test $asinh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py new file mode 100644 index 000000000..0325fc377 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py @@ -0,0 +1,133 @@ +""" +trigonometry $atan tests. + +Tests $atan results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +ATAN_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$atan": 1}, + expected=0.7853981633974483, + msg="$atan of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$atan": 0.5}, + expected=0.4636476090008061, + msg="$atan of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$atan": 2.0}, + expected=1.1071487177940904, + msg="$atan of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$atan": Decimal128("0.5")}, + expected=Decimal128("0.4636476090008061162142562314612144"), + msg="$atan of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$atan": Decimal128("-2")}, + expected=Decimal128("-1.107148717794090503017065460178537"), + msg="$atan of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$atan": DOUBLE_MAX}, + expected=1.5707963267948966, + msg="$atan of double max", + ), + ExpressionTestCase( + "null", + expression={"$atan": None}, + expected=None, + msg="$atan of null", + ), + ExpressionTestCase( + "missing", + expression={"$atan": MISSING}, + expected=None, + msg="$atan of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$atan": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$atan of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$atan": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$atan of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$atan": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$atan of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$atan": FLOAT_INFINITY}, + expected=1.5707963267948966, + msg="$atan of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$atan": FLOAT_NEGATIVE_INFINITY}, + expected=-1.5707963267948966, + msg="$atan of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$atan": DECIMAL128_INFINITY}, + expected=Decimal128("1.570796326794896619231321691639751"), + msg="$atan of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$atan": DECIMAL128_NEGATIVE_INFINITY}, + expected=Decimal128("-1.570796326794896619231321691639751"), + msg="$atan of decimal128 negative infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATAN_BASIC_TESTS)) +def test_atan_basic(collection, test): + """Test $atan values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_bson_type_validation.py new file mode 100644 index 000000000..e04176ff2 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $atan expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ATAN_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$atan should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ATAN_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ATAN_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_atan_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $atan rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$atan": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_atan_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $atan accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$atan": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$atan should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py new file mode 100644 index 000000000..859864e0a --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $atan tests. + +Tests $atan errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +ATAN_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$atan": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atan of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$atan": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atan of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATAN_ERRORS_TESTS)) +def test_atan_errors(collection, test): + """Test $atan errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py new file mode 100644 index 000000000..699efab50 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py @@ -0,0 +1,91 @@ +""" +trigonometry $atan2 tests. + +Tests $atan2 results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + FLOAT_INFINITY, + FLOAT_NAN, + MISSING, +) + +ATAN2_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_double", + expression={"$atan2": [1.0, 1.0]}, + expected=0.7853981633974483, + msg="$atan2 of double double", + ), + ExpressionTestCase( + "decimal128_decimal128", + expression={"$atan2": [Decimal128("1"), Decimal128("1")]}, + expected=Decimal128("0.7853981633974483096156608458198757"), + msg="$atan2 of decimal128 decimal128", + ), + ExpressionTestCase( + "decimal128_double", + expression={"$atan2": [Decimal128("1"), 1.0]}, + expected=Decimal128("0.7853981633974483096156608458198757"), + msg="$atan2 of decimal128 double", + ), + ExpressionTestCase( + "double_decimal128", + expression={"$atan2": [1.0, Decimal128("1")]}, + expected=Decimal128("0.7853981633974483096156608458198757"), + msg="$atan2 of double decimal128", + ), + ExpressionTestCase( + "null_y", + expression={"$atan2": [None, 1.0]}, + expected=None, + msg="$atan2 of null y", + ), + ExpressionTestCase( + "missing_y", + expression={"$atan2": [MISSING, 1.0]}, + expected=None, + msg="$atan2 of missing y", + ), + ExpressionTestCase( + "nan_y", + expression={"$atan2": [FLOAT_NAN, 1.0]}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$atan2 of nan y", + ), + ExpressionTestCase( + "infinity_y", + expression={"$atan2": [FLOAT_INFINITY, 1.0]}, + expected=1.5707963267948966, + msg="$atan2 of infinity y", + ), + ExpressionTestCase( + "zero_zero", + expression={"$atan2": [0.0, 0.0]}, + expected=0.0, + msg="$atan2 of zero zero", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATAN2_BASIC_TESTS)) +def test_atan2_basic(collection, test): + """Test $atan2 values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_bson_type_validation.py new file mode 100644 index 000000000..a2438fe4c --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_bson_type_validation.py @@ -0,0 +1,74 @@ +""" +BSON type validation tests for $atan2 expression. + +Verifies that each of the two numeric inputs (y and x) accepts the four numeric +types plus null, and rejects every other BSON type with its own error code. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import ( + TWO_NUMERIC_ARGS_FIRST_TYPE_ERROR, + TWO_NUMERIC_ARGS_SECOND_TYPE_ERROR, +) + +NUMERIC_OR_NULL = [ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, +] + +ATAN2_BSON_PARAMS = [ + BsonTypeTestCase( + id="y", + msg="$atan2 should reject a non-numeric first argument", + keyword="y", + valid_types=NUMERIC_OR_NULL, + default_error_code=TWO_NUMERIC_ARGS_FIRST_TYPE_ERROR, + ), + BsonTypeTestCase( + id="x", + msg="$atan2 should reject a non-numeric second argument", + keyword="x", + valid_types=NUMERIC_OR_NULL, + default_error_code=TWO_NUMERIC_ARGS_SECOND_TYPE_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ATAN2_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ATAN2_BSON_PARAMS) + + +def _expression(spec): + return {"$atan2": ["$value", 1]} if spec.keyword == "y" else {"$atan2": [1, "$value"]} + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_atan2_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $atan2 rejects invalid BSON types in each argument.""" + result = execute_expression_with_insert(collection, _expression(spec), {"value": sample_value}) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_atan2_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $atan2 accepts valid numeric BSON types (and null) in each argument.""" + result = execute_expression_with_insert(collection, _expression(spec), {"value": sample_value}) + assertNotError(result, msg=f"$atan2 should accept {bson_type.value} for {spec.keyword}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py new file mode 100644 index 000000000..8976a6981 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py @@ -0,0 +1,47 @@ +""" +trigonometry $atan2 tests. + +Tests $atan2 errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +ATAN2_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_one_arg", + expression={"$atan2": [1]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atan2 of arity one arg should fail", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$atan2": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atan2 of arity three args should fail", + ), + ExpressionTestCase( + "non_array_arg", + expression={"$atan2": 1}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atan2 of non array arg should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATAN2_ERRORS_TESTS)) +def test_atan2_errors(collection, test): + """Test $atan2 errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py new file mode 100644 index 000000000..35e11a179 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py @@ -0,0 +1,94 @@ +""" +trigonometry $atanh tests. + +Tests $atanh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +ATANH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$atanh": 1}, + expected=FLOAT_INFINITY, + msg="$atanh of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$atanh": 0.5}, + expected=0.5493061443340548, + msg="$atanh of double half", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$atanh": Decimal128("0.5")}, + expected=Decimal128("0.5493061443340548456976226184612628"), + msg="$atanh of decimal128 half", + ), + ExpressionTestCase( + "null", + expression={"$atanh": None}, + expected=None, + msg="$atanh of null", + ), + ExpressionTestCase( + "missing", + expression={"$atanh": MISSING}, + expected=None, + msg="$atanh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$atanh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$atanh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$atanh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$atanh of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$atanh": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$atanh of negative zero", + ), + ExpressionTestCase( + "double_negative_one", + expression={"$atanh": -1.0}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="$atanh of double negative one", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATANH_BASIC_TESTS)) +def test_atanh_basic(collection, test): + """Test $atanh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_bson_type_validation.py new file mode 100644 index 000000000..1d36ec403 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_bson_type_validation.py @@ -0,0 +1,69 @@ +""" +BSON type validation tests for $atanh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest +from bson import Decimal128, Int64 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +ATANH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$atanh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + valid_inputs={ + BsonType.DOUBLE: 0.5, + BsonType.INT: 1, + BsonType.LONG: Int64(1), + BsonType.DECIMAL: Decimal128("0.5"), + }, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(ATANH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(ATANH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_atanh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $atanh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$atanh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_atanh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $atanh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$atanh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$atanh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py new file mode 100644 index 000000000..115246ecf --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py @@ -0,0 +1,94 @@ +""" +trigonometry $atanh tests. + +Tests $atanh errors: argument count, and inputs outside the operator's range. +""" + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +ATANH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_two", + expression={"$atanh": 2.0}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of double two should fail", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$atanh": Decimal128("-2")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of decimal128 negative two should fail", + ), + ExpressionTestCase( + "double_max", + expression={"$atanh": DOUBLE_MAX}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of double max should fail", + ), + ExpressionTestCase( + "double_infinity", + expression={"$atanh": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$atanh": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$atanh": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$atanh": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$atanh of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$atanh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atanh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$atanh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$atanh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ATANH_ERRORS_TESTS)) +def test_atanh_errors(collection, test): + """Test $atanh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py new file mode 100644 index 000000000..195d4c810 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py @@ -0,0 +1,105 @@ +""" +trigonometry $cos tests. + +Tests $cos results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NAN, + MISSING, +) + +COS_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$cos": 1}, + expected=0.5403023058681398, + msg="$cos of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$cos": 0.5}, + expected=0.8775825618903728, + msg="$cos of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$cos": 2.0}, + expected=-0.4161468365471424, + msg="$cos of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$cos": Decimal128("0.5")}, + expected=Decimal128("0.8775825618903727161162815826038297"), + msg="$cos of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$cos": Decimal128("-2")}, + expected=Decimal128("-0.4161468365471423869975682295007621"), + msg="$cos of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$cos": DOUBLE_MAX}, + expected=-0.9999876894265599, + msg="$cos of double max", + ), + ExpressionTestCase( + "null", + expression={"$cos": None}, + expected=None, + msg="$cos of null", + ), + ExpressionTestCase( + "missing", + expression={"$cos": MISSING}, + expected=None, + msg="$cos of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$cos": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$cos of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$cos": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$cos of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$cos": DOUBLE_NEGATIVE_ZERO}, + expected=1.0, + msg="$cos of negative zero", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(COS_BASIC_TESTS)) +def test_cos_basic(collection, test): + """Test $cos values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_bson_type_validation.py new file mode 100644 index 000000000..7d75b8ca0 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_bson_type_validation.py @@ -0,0 +1,58 @@ +""" +BSON type validation tests for $cos expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +COS_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$cos should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(COS_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(COS_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_cos_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $cos rejects invalid BSON types.""" + result = execute_expression_with_insert(collection, {"$cos": "$value"}, {"value": sample_value}) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_cos_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $cos accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert(collection, {"$cos": "$value"}, {"value": sample_value}) + assertNotError(result, msg=f"$cos should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py new file mode 100644 index 000000000..711920c41 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py @@ -0,0 +1,74 @@ +""" +trigonometry $cos tests. + +Tests $cos errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +COS_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_infinity", + expression={"$cos": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$cos of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$cos": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$cos of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$cos": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$cos of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$cos": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$cos of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$cos": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$cos of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$cos": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$cos of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(COS_ERRORS_TESTS)) +def test_cos_errors(collection, test): + """Test $cos errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py new file mode 100644 index 000000000..3d5b981c3 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py @@ -0,0 +1,133 @@ +""" +trigonometry $cosh tests. + +Tests $cosh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +COSH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$cosh": 1}, + expected=1.5430806348152437, + msg="$cosh of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$cosh": 0.5}, + expected=1.1276259652063807, + msg="$cosh of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$cosh": 2.0}, + expected=3.7621956910836314, + msg="$cosh of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$cosh": Decimal128("0.5")}, + expected=Decimal128("1.127625965206380785226225161402672"), + msg="$cosh of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$cosh": Decimal128("-2")}, + expected=Decimal128("3.762195691083631459562213477773746"), + msg="$cosh of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$cosh": DOUBLE_MAX}, + expected=FLOAT_INFINITY, + msg="$cosh of double max", + ), + ExpressionTestCase( + "null", + expression={"$cosh": None}, + expected=None, + msg="$cosh of null", + ), + ExpressionTestCase( + "missing", + expression={"$cosh": MISSING}, + expected=None, + msg="$cosh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$cosh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$cosh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$cosh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$cosh of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$cosh": DOUBLE_NEGATIVE_ZERO}, + expected=1.0, + msg="$cosh of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$cosh": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$cosh of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$cosh": FLOAT_NEGATIVE_INFINITY}, + expected=FLOAT_INFINITY, + msg="$cosh of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$cosh": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$cosh of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$cosh": DECIMAL128_NEGATIVE_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$cosh of decimal128 negative infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(COSH_BASIC_TESTS)) +def test_cosh_basic(collection, test): + """Test $cosh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_bson_type_validation.py new file mode 100644 index 000000000..4eaeed36c --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $cosh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +COSH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$cosh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(COSH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(COSH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_cosh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $cosh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$cosh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_cosh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $cosh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$cosh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$cosh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py new file mode 100644 index 000000000..4766ea2f7 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $cosh tests. + +Tests $cosh errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +COSH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$cosh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$cosh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$cosh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$cosh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(COSH_ERRORS_TESTS)) +def test_cosh_errors(collection, test): + """Test $cosh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py new file mode 100644 index 000000000..16721320c --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py @@ -0,0 +1,139 @@ +""" +trigonometry $degreesToRadians tests. + +Tests $degreesToRadians results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +DEGREESTORADIANS_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$degreesToRadians": 1}, + expected=0.017453292519943295, + msg="$degreesToRadians of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$degreesToRadians": 0.5}, + expected=0.008726646259971648, + msg="$degreesToRadians of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$degreesToRadians": 2.0}, + expected=0.03490658503988659, + msg="$degreesToRadians of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$degreesToRadians": Decimal128("0.5")}, + expected=Decimal128("0.008726646259971647884618453842443065"), + msg="$degreesToRadians of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$degreesToRadians": Decimal128("-2")}, + expected=Decimal128("-0.03490658503988659153847381536977226"), + msg="$degreesToRadians of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$degreesToRadians": DOUBLE_MAX}, + expected=3.1375664143845866e306, + msg="$degreesToRadians of double max", + ), + ExpressionTestCase( + "null", + expression={"$degreesToRadians": None}, + expected=None, + msg="$degreesToRadians of null", + ), + ExpressionTestCase( + "missing", + expression={"$degreesToRadians": MISSING}, + expected=None, + msg="$degreesToRadians of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$degreesToRadians": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$degreesToRadians of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$degreesToRadians": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$degreesToRadians of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$degreesToRadians": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$degreesToRadians of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$degreesToRadians": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$degreesToRadians of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$degreesToRadians": FLOAT_NEGATIVE_INFINITY}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="$degreesToRadians of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$degreesToRadians": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$degreesToRadians of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$degreesToRadians": DECIMAL128_NEGATIVE_INFINITY}, + expected=DECIMAL128_NEGATIVE_INFINITY, + msg="$degreesToRadians of decimal128 negative infinity", + ), + ExpressionTestCase( + "single_element_array", + expression={"$degreesToRadians": [0.5]}, + expected=0.008726646259971648, + msg="$degreesToRadians of single element array", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(DEGREESTORADIANS_BASIC_TESTS)) +def test_degreesToRadians_basic(collection, test): + """Test $degreesToRadians values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_bson_type_validation.py new file mode 100644 index 000000000..30ffabac0 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $degreesToRadians expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +DEGREESTORADIANS_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$degreesToRadians should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(DEGREESTORADIANS_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(DEGREESTORADIANS_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_degreesToRadians_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $degreesToRadians rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$degreesToRadians": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_degreesToRadians_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $degreesToRadians accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$degreesToRadians": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$degreesToRadians should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py new file mode 100644 index 000000000..451f9cf00 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $degreesToRadians tests. + +Tests $degreesToRadians errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +DEGREESTORADIANS_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$degreesToRadians": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$degreesToRadians of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$degreesToRadians": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$degreesToRadians of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(DEGREESTORADIANS_ERRORS_TESTS)) +def test_degreesToRadians_errors(collection, test): + """Test $degreesToRadians errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py new file mode 100644 index 000000000..febc7e42d --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py @@ -0,0 +1,133 @@ +""" +trigonometry $radiansToDegrees tests. + +Tests $radiansToDegrees results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +RADIANSTODEGREES_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$radiansToDegrees": 1}, + expected=57.29577951308232, + msg="$radiansToDegrees of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$radiansToDegrees": 0.5}, + expected=28.64788975654116, + msg="$radiansToDegrees of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$radiansToDegrees": 2.0}, + expected=114.59155902616465, + msg="$radiansToDegrees of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$radiansToDegrees": Decimal128("0.5")}, + expected=Decimal128("28.64788975654116043839907740705258"), + msg="$radiansToDegrees of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$radiansToDegrees": Decimal128("-2")}, + expected=Decimal128("-114.5915590261646417535963096282103"), + msg="$radiansToDegrees of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$radiansToDegrees": DOUBLE_MAX}, + expected=FLOAT_INFINITY, + msg="$radiansToDegrees of double max", + ), + ExpressionTestCase( + "null", + expression={"$radiansToDegrees": None}, + expected=None, + msg="$radiansToDegrees of null", + ), + ExpressionTestCase( + "missing", + expression={"$radiansToDegrees": MISSING}, + expected=None, + msg="$radiansToDegrees of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$radiansToDegrees": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$radiansToDegrees of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$radiansToDegrees": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$radiansToDegrees of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$radiansToDegrees": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$radiansToDegrees of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$radiansToDegrees": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$radiansToDegrees of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$radiansToDegrees": FLOAT_NEGATIVE_INFINITY}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="$radiansToDegrees of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$radiansToDegrees": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$radiansToDegrees of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$radiansToDegrees": DECIMAL128_NEGATIVE_INFINITY}, + expected=DECIMAL128_NEGATIVE_INFINITY, + msg="$radiansToDegrees of decimal128 negative infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(RADIANSTODEGREES_BASIC_TESTS)) +def test_radiansToDegrees_basic(collection, test): + """Test $radiansToDegrees values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_bson_type_validation.py new file mode 100644 index 000000000..1b8a42706 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $radiansToDegrees expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +RADIANSTODEGREES_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$radiansToDegrees should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(RADIANSTODEGREES_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(RADIANSTODEGREES_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_radiansToDegrees_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $radiansToDegrees rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$radiansToDegrees": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_radiansToDegrees_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $radiansToDegrees accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$radiansToDegrees": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$radiansToDegrees should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py new file mode 100644 index 000000000..d47cf6515 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $radiansToDegrees tests. + +Tests $radiansToDegrees errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +RADIANSTODEGREES_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$radiansToDegrees": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$radiansToDegrees of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$radiansToDegrees": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$radiansToDegrees of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(RADIANSTODEGREES_ERRORS_TESTS)) +def test_radiansToDegrees_errors(collection, test): + """Test $radiansToDegrees errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py new file mode 100644 index 000000000..bcc611f3c --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py @@ -0,0 +1,111 @@ +""" +trigonometry $sin tests. + +Tests $sin results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NAN, + MISSING, +) + +SIN_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$sin": 1}, + expected=0.8414709848078965, + msg="$sin of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$sin": 0.5}, + expected=0.479425538604203, + msg="$sin of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$sin": 2.0}, + expected=0.9092974268256817, + msg="$sin of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$sin": Decimal128("0.5")}, + expected=Decimal128("0.4794255386042030002732879352155714"), + msg="$sin of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$sin": Decimal128("-2")}, + expected=Decimal128("-0.9092974268256816953960198659117449"), + msg="$sin of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$sin": DOUBLE_MAX}, + expected=0.004961954789184062, + msg="$sin of double max", + ), + ExpressionTestCase( + "null", + expression={"$sin": None}, + expected=None, + msg="$sin of null", + ), + ExpressionTestCase( + "missing", + expression={"$sin": MISSING}, + expected=None, + msg="$sin of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$sin": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$sin of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$sin": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$sin of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$sin": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$sin of negative zero", + ), + ExpressionTestCase( + "single_element_array", + expression={"$sin": [0.5]}, + expected=0.479425538604203, + msg="$sin of single element array", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(SIN_BASIC_TESTS)) +def test_sin_basic(collection, test): + """Test $sin values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_bson_type_validation.py new file mode 100644 index 000000000..dbe821364 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_bson_type_validation.py @@ -0,0 +1,58 @@ +""" +BSON type validation tests for $sin expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +SIN_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$sin should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(SIN_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(SIN_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_sin_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $sin rejects invalid BSON types.""" + result = execute_expression_with_insert(collection, {"$sin": "$value"}, {"value": sample_value}) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_sin_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $sin accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert(collection, {"$sin": "$value"}, {"value": sample_value}) + assertNotError(result, msg=f"$sin should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py new file mode 100644 index 000000000..3a3428c30 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py @@ -0,0 +1,74 @@ +""" +trigonometry $sin tests. + +Tests $sin errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +SIN_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_infinity", + expression={"$sin": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$sin of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$sin": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$sin of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$sin": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$sin of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$sin": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$sin of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$sin": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$sin of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$sin": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$sin of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(SIN_ERRORS_TESTS)) +def test_sin_errors(collection, test): + """Test $sin errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py new file mode 100644 index 000000000..e0bbb1528 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py @@ -0,0 +1,139 @@ +""" +trigonometry $sinh tests. + +Tests $sinh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +SINH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$sinh": 1}, + expected=1.1752011936438014, + msg="$sinh of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$sinh": 0.5}, + expected=0.5210953054937474, + msg="$sinh of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$sinh": 2.0}, + expected=3.626860407847019, + msg="$sinh of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$sinh": Decimal128("0.5")}, + expected=Decimal128("0.5210953054937473616224256264114915"), + msg="$sinh of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$sinh": Decimal128("-2")}, + expected=Decimal128("-3.626860407847018767668213982801262"), + msg="$sinh of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$sinh": DOUBLE_MAX}, + expected=FLOAT_INFINITY, + msg="$sinh of double max", + ), + ExpressionTestCase( + "null", + expression={"$sinh": None}, + expected=None, + msg="$sinh of null", + ), + ExpressionTestCase( + "missing", + expression={"$sinh": MISSING}, + expected=None, + msg="$sinh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$sinh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$sinh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$sinh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$sinh of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$sinh": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$sinh of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$sinh": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="$sinh of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$sinh": FLOAT_NEGATIVE_INFINITY}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="$sinh of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$sinh": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="$sinh of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$sinh": DECIMAL128_NEGATIVE_INFINITY}, + expected=DECIMAL128_NEGATIVE_INFINITY, + msg="$sinh of decimal128 negative infinity", + ), + ExpressionTestCase( + "single_element_array", + expression={"$sinh": [0.5]}, + expected=0.5210953054937474, + msg="$sinh of single element array", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(SINH_BASIC_TESTS)) +def test_sinh_basic(collection, test): + """Test $sinh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_bson_type_validation.py new file mode 100644 index 000000000..b6c62cb39 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $sinh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +SINH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$sinh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(SINH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(SINH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_sinh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $sinh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$sinh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_sinh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $sinh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$sinh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$sinh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py new file mode 100644 index 000000000..6dc00d5f6 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $sinh tests. + +Tests $sinh errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +SINH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$sinh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$sinh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$sinh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$sinh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(SINH_ERRORS_TESTS)) +def test_sinh_errors(collection, test): + """Test $sinh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py new file mode 100644 index 000000000..ad790a9fa --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py @@ -0,0 +1,105 @@ +""" +trigonometry $tan tests. + +Tests $tan results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_NAN, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_NAN, + MISSING, +) + +TAN_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$tan": 1}, + expected=1.5574077246549023, + msg="$tan of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$tan": 0.5}, + expected=0.5463024898437905, + msg="$tan of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$tan": 2.0}, + expected=-2.185039863261519, + msg="$tan of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$tan": Decimal128("0.5")}, + expected=Decimal128("0.5463024898437905132551794657802854"), + msg="$tan of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$tan": Decimal128("-2")}, + expected=Decimal128("2.185039863261518991643306102313683"), + msg="$tan of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$tan": DOUBLE_MAX}, + expected=-0.004962015874444895, + msg="$tan of double max", + ), + ExpressionTestCase( + "null", + expression={"$tan": None}, + expected=None, + msg="$tan of null", + ), + ExpressionTestCase( + "missing", + expression={"$tan": MISSING}, + expected=None, + msg="$tan of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$tan": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$tan of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$tan": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$tan of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$tan": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$tan of negative zero", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(TAN_BASIC_TESTS)) +def test_tan_basic(collection, test): + """Test $tan values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_bson_type_validation.py new file mode 100644 index 000000000..787c00dcf --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_bson_type_validation.py @@ -0,0 +1,58 @@ +""" +BSON type validation tests for $tan expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +TAN_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$tan should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(TAN_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(TAN_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_tan_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $tan rejects invalid BSON types.""" + result = execute_expression_with_insert(collection, {"$tan": "$value"}, {"value": sample_value}) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_tan_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $tan accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert(collection, {"$tan": "$value"}, {"value": sample_value}) + assertNotError(result, msg=f"$tan should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py new file mode 100644 index 000000000..914d78124 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py @@ -0,0 +1,74 @@ +""" +trigonometry $tan tests. + +Tests $tan errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TRIG_INPUT_OUT_OF_RANGE_ERROR, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NEGATIVE_INFINITY, + FLOAT_INFINITY, + FLOAT_NEGATIVE_INFINITY, +) + +TAN_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "double_infinity", + expression={"$tan": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$tan of double infinity should fail", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$tan": FLOAT_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$tan of double negative infinity should fail", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$tan": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$tan of decimal128 infinity should fail", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$tan": DECIMAL128_NEGATIVE_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="$tan of decimal128 negative infinity should fail", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$tan": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$tan of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$tan": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$tan of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(TAN_ERRORS_TESTS)) +def test_tan_errors(collection, test): + """Test $tan errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py new file mode 100644 index 000000000..58a92ada9 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py @@ -0,0 +1,133 @@ +""" +trigonometry $tanh tests. + +Tests $tanh results for numeric input types, special values (null, missing, NaN, +-0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +""" + +import math + +import pytest +from bson import Decimal128 + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DECIMAL128_INFINITY, + DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, + FLOAT_INFINITY, + FLOAT_NAN, + FLOAT_NEGATIVE_INFINITY, + MISSING, +) + +TANH_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_one", + expression={"$tanh": 1}, + expected=0.7615941559557649, + msg="$tanh of int one", + ), + ExpressionTestCase( + "double_half", + expression={"$tanh": 0.5}, + expected=0.46211715726000974, + msg="$tanh of double half", + ), + ExpressionTestCase( + "double_two", + expression={"$tanh": 2.0}, + expected=0.9640275800758169, + msg="$tanh of double two", + ), + ExpressionTestCase( + "decimal128_half", + expression={"$tanh": Decimal128("0.5")}, + expected=Decimal128("0.4621171572600097585023184836436726"), + msg="$tanh of decimal128 half", + ), + ExpressionTestCase( + "decimal128_negative_two", + expression={"$tanh": Decimal128("-2")}, + expected=Decimal128("-0.9640275800758168839464137241009232"), + msg="$tanh of decimal128 negative two", + ), + ExpressionTestCase( + "double_max", + expression={"$tanh": DOUBLE_MAX}, + expected=1.0, + msg="$tanh of double max", + ), + ExpressionTestCase( + "null", + expression={"$tanh": None}, + expected=None, + msg="$tanh of null", + ), + ExpressionTestCase( + "missing", + expression={"$tanh": MISSING}, + expected=None, + msg="$tanh of missing", + ), + ExpressionTestCase( + "double_nan", + expression={"$tanh": FLOAT_NAN}, + expected=pytest.approx(math.nan, nan_ok=True), + msg="$tanh of double nan", + ), + ExpressionTestCase( + "decimal128_nan", + expression={"$tanh": DECIMAL128_NAN}, + expected=DECIMAL128_NAN, + msg="$tanh of decimal128 nan", + ), + ExpressionTestCase( + "negative_zero", + expression={"$tanh": DOUBLE_NEGATIVE_ZERO}, + expected=-0.0, + msg="$tanh of negative zero", + ), + ExpressionTestCase( + "double_infinity", + expression={"$tanh": FLOAT_INFINITY}, + expected=1.0, + msg="$tanh of double infinity", + ), + ExpressionTestCase( + "double_negative_infinity", + expression={"$tanh": FLOAT_NEGATIVE_INFINITY}, + expected=-1.0, + msg="$tanh of double negative infinity", + ), + ExpressionTestCase( + "decimal128_infinity", + expression={"$tanh": DECIMAL128_INFINITY}, + expected=Decimal128("1"), + msg="$tanh of decimal128 infinity", + ), + ExpressionTestCase( + "decimal128_negative_infinity", + expression={"$tanh": DECIMAL128_NEGATIVE_INFINITY}, + expected=Decimal128("-1"), + msg="$tanh of decimal128 negative infinity", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(TANH_BASIC_TESTS)) +def test_tanh_basic(collection, test): + """Test $tanh values with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_bson_type_validation.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_bson_type_validation.py new file mode 100644 index 000000000..8996396b3 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_bson_type_validation.py @@ -0,0 +1,62 @@ +""" +BSON type validation tests for $tanh expression. + +Verifies that the single numeric input accepts the four numeric types plus null, +and rejects every other BSON type. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.assertions import assertNotError +from documentdb_tests.framework.bson_type_validator import ( + BsonType, + BsonTypeTestCase, + generate_bson_acceptance_test_cases, + generate_bson_rejection_test_cases, +) +from documentdb_tests.framework.error_codes import NON_NUMERIC_TYPE_MISMATCH_ERROR + +TANH_BSON_PARAMS = [ + BsonTypeTestCase( + id="input", + msg="$tanh should reject non-numeric input", + keyword="input", + valid_types=[ + BsonType.DOUBLE, + BsonType.INT, + BsonType.LONG, + BsonType.DECIMAL, + BsonType.NULL, + ], + default_error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + ), +] + +REJECTION_CASES = generate_bson_rejection_test_cases(TANH_BSON_PARAMS) +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases(TANH_BSON_PARAMS) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) +def test_tanh_bson_type_rejected(collection, bson_type, sample_value, spec): + """Verifies $tanh rejects invalid BSON types.""" + result = execute_expression_with_insert( + collection, {"$tanh": "$value"}, {"value": sample_value} + ) + assert_expression_result( + result, + error_code=spec.expected_code(bson_type), + msg=f"{spec.msg}: {bson_type.value}", + ) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_tanh_bson_type_accepted(collection, bson_type, sample_value, spec): + """Verifies $tanh accepts valid numeric BSON types (and null).""" + result = execute_expression_with_insert( + collection, {"$tanh": "$value"}, {"value": sample_value} + ) + assertNotError(result, msg=f"$tanh should accept {bson_type.value}") diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py new file mode 100644 index 000000000..8b66d0c75 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py @@ -0,0 +1,41 @@ +""" +trigonometry $tanh tests. + +Tests $tanh errors: argument count, and inputs outside the operator's range. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression, +) +from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR +from documentdb_tests.framework.parametrize import pytest_params + +TANH_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "arity_zero_args", + expression={"$tanh": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$tanh of arity zero args should fail", + ), + ExpressionTestCase( + "arity_two_args", + expression={"$tanh": [1, 2]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="$tanh of arity two args should fail", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(TANH_ERRORS_TESTS)) +def test_tanh_errors(collection, test): + """Test $tanh errors with literal arguments.""" + result = execute_expression(collection, test.expression) + assert_expression_result( + result, expected=test.expected, error_code=test.error_code, msg=test.msg + ) diff --git a/documentdb_tests/framework/error_codes.py b/documentdb_tests/framework/error_codes.py index 0a6544559..1df86850b 100644 --- a/documentdb_tests/framework/error_codes.py +++ b/documentdb_tests/framework/error_codes.py @@ -399,6 +399,9 @@ CLUSTERED_INFINITY_DUPLICATE_ERROR = 50826 RESUME_AFTER_START_AFTER_CONFLICT_ERROR = 50865 PLAN_CACHE_STATS_COLLECTION_NOT_FOUND_ERROR = 50933 +TRIG_INPUT_OUT_OF_RANGE_ERROR = 50989 +TWO_NUMERIC_ARGS_FIRST_TYPE_ERROR = 51044 +TWO_NUMERIC_ARGS_SECOND_TYPE_ERROR = 51045 LOOKUP_SUB_PIPELINE_NOT_ALLOWED_ERROR = 51047 REGEX_OPTIONS_BEFORE_REGEX_FLAGS_ERROR = 51074 REGEX_FLAGS_AND_OPTIONS_CONFLICT_ERROR = 51075 From 7a78b209a5e874c1e0f976d67f1bdae3790aa115 Mon Sep 17 00:00:00 2001 From: Samar Farooqi Date: Wed, 2 Dec 2026 18:09:25 +0000 Subject: [PATCH 2/2] Cover more trigonometry edge cases and follow the test format guide 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 #18. Signed-off-by: Samar Farooqi --- .../trigonometry/acos/test_acos_basic.py | 98 +++++++++++--- .../trigonometry/acos/test_acos_errors.py | 104 +++++++++++++-- .../trigonometry/acosh/test_acosh_basic.py | 74 ++++++++--- .../trigonometry/acosh/test_acosh_errors.py | 98 +++++++++++--- .../trigonometry/asin/test_asin_basic.py | 100 ++++++++++---- .../trigonometry/asin/test_asin_errors.py | 104 +++++++++++++-- .../trigonometry/asinh/test_asinh_basic.py | 87 ++++++++---- .../trigonometry/asinh/test_asinh_errors.py | 47 +++++-- .../trigonometry/atan/test_atan_basic.py | 87 ++++++++---- .../trigonometry/atan/test_atan_errors.py | 47 +++++-- .../trigonometry/atan2/test_atan2_basic.py | 125 +++++++++++++++--- .../trigonometry/atan2/test_atan2_errors.py | 34 +++-- .../trigonometry/atanh/test_atanh_basic.py | 100 +++++++++++--- .../trigonometry/atanh/test_atanh_errors.py | 104 +++++++++++++-- .../trigonometry/cos/test_cos_basic.py | 93 ++++++++++--- .../trigonometry/cos/test_cos_errors.py | 64 +++++++-- .../trigonometry/cosh/test_cosh_basic.py | 87 ++++++++---- .../trigonometry/cosh/test_cosh_errors.py | 47 +++++-- .../test_degreesToRadians_basic.py | 114 ++++++++++++---- .../test_degreesToRadians_errors.py | 48 +++++-- .../test_radiansToDegrees_basic.py | 116 ++++++++++++---- .../test_radiansToDegrees_errors.py | 48 +++++-- .../trigonometry/sin/test_sin_basic.py | 91 +++++++++---- .../trigonometry/sin/test_sin_errors.py | 64 +++++++-- .../trigonometry/sinh/test_sinh_basic.py | 85 ++++++++---- .../trigonometry/sinh/test_sinh_errors.py | 47 +++++-- .../trigonometry/tan/test_tan_basic.py | 93 ++++++++++--- .../trigonometry/tan/test_tan_errors.py | 64 +++++++-- .../trigonometry/tanh/test_tanh_basic.py | 87 ++++++++---- .../trigonometry/tanh/test_tanh_errors.py | 47 +++++-- 30 files changed, 1887 insertions(+), 517 deletions(-) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py index cb9d60466..3592cc7d5 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_basic.py @@ -1,25 +1,27 @@ """ -trigonometry $acos tests. +$acos results. -Tests $acos results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $acos results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and the domain bounds and the values just inside them. Expected values are +MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NAN, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_NEGATIVE_ZERO, FLOAT_NAN, MISSING, @@ -30,63 +32,117 @@ "int_one", expression={"$acos": 1}, expected=0.0, - msg="$acos of int one", + msg="Should return 0.0 for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$acos": Int64(1)}, + expected=0.0, + msg="Should return 0.0 for a long input", ), ExpressionTestCase( "double_half", - expression={"$acos": 0.5}, + expression={"$acos": DOUBLE_HALF}, expected=1.0471975511965979, - msg="$acos of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "decimal128_half", - expression={"$acos": Decimal128("0.5")}, + expression={"$acos": DECIMAL128_HALF}, expected=Decimal128("1.047197551196597746154214461093168"), - msg="$acos of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$acos": DECIMAL128_ZERO}, + expected=Decimal128("1.570796326794896619231321691639751"), + msg="Should return the Decimal128 result for Decimal128 zero", ), ExpressionTestCase( "null", expression={"$acos": None}, expected=None, - msg="$acos of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$acos": MISSING}, expected=None, - msg="$acos of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$acos": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$acos of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$acos": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$acos of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$acos": DOUBLE_NEGATIVE_ZERO}, expected=1.5707963267948966, - msg="$acos of negative zero", + msg="Should return the double result for -0.0", + ), + ExpressionTestCase( + "single_element_array", + expression={"$acos": [DOUBLE_HALF]}, + expected=1.0471975511965979, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "double_one", + expression={"$acos": 1.0}, + expected=0.0, + msg="Should return 0.0 for the upper domain bound", ), ExpressionTestCase( "double_negative_one", expression={"$acos": -1.0}, expected=3.141592653589793, - msg="$acos of double negative one", + msg="Should return the double result for the lower domain bound", + ), + ExpressionTestCase( + "long_negative_one", + expression={"$acos": Int64(-1)}, + expected=3.141592653589793, + msg="Should return the double result for the lower domain bound as a long", + ), + ExpressionTestCase( + "decimal128_one", + expression={"$acos": Decimal128("1")}, + expected=Decimal128("0E-6176"), + msg="Should return a Decimal128 zero for the upper domain bound as Decimal128", + ), + ExpressionTestCase( + "decimal128_negative_one", + expression={"$acos": Decimal128("-1")}, + expected=Decimal128("3.141592653589793238462643383279503"), + msg="Should return the Decimal128 result for the lower domain bound as Decimal128", + ), + ExpressionTestCase( + "double_just_below_one", + expression={"$acos": 0.9999999999999999}, + expected=1.4901161193847656e-08, + msg="Should return the double result for the largest double below 1", + ), + ExpressionTestCase( + "decimal128_just_below_one", + expression={"$acos": Decimal128("0.9999999999999999999999999999999999")}, + expected=Decimal128("1.414213562373095048801688724209698E-17"), + msg="Should return the Decimal128 result for the largest 34-digit Decimal128 below 1", ), ] @pytest.mark.parametrize("test", pytest_params(ACOS_BASIC_TESTS)) def test_acos_basic(collection, test): - """Test $acos values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $acos results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py index 1b2c35d7f..af3765e70 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acos/test_acos_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $acos tests. +$acos errors. -Tests $acos errors: argument count, and inputs outside the operator's range. +Tests that $acos rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -12,17 +13,21 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ONE_AND_HALF, + DOUBLE_HALF, DOUBLE_MAX, + DOUBLE_ONE_AND_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -32,63 +37,134 @@ "double_two", expression={"$acos": 2.0}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of double two should fail", + msg="Should reject a double input of 2 with error 50989", ), ExpressionTestCase( "decimal128_negative_two", expression={"$acos": Decimal128("-2")}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of decimal128 negative two should fail", + msg="Should reject a Decimal128 input of -2 with error 50989", ), ExpressionTestCase( "double_max", expression={"$acos": DOUBLE_MAX}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of double max should fail", + msg="Should reject the largest double with error 50989", ), ExpressionTestCase( "double_infinity", expression={"$acos": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$acos": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$acos": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$acos": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acos of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$acos": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$acos": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$acos": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$acos of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$acos": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$acos of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$acos": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$acos": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$acos": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$acos": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", + ), + ExpressionTestCase( + "double_just_above_one", + expression={"$acos": 1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest double above 1 with error 50989", + ), + ExpressionTestCase( + "double_just_below_negative_one", + expression={"$acos": -1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the largest double below -1 with error 50989", + ), + ExpressionTestCase( + "decimal128_just_above_one", + expression={"$acos": Decimal128("1.000000000000000000000000000000001")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest 34-digit Decimal128 above 1 with error 50989", + ), + ExpressionTestCase( + "out_of_range_field", + expression={"$acos": "$v"}, + doc={"v": DOUBLE_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain double read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_out_of_range_field", + expression={"$acos": "$v"}, + doc={"v": DECIMAL128_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain Decimal128 read from a field with error 50989", ), ] @pytest.mark.parametrize("test", pytest_params(ACOS_ERRORS_TESTS)) def test_acos_errors(collection, test): - """Test $acos errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $acos errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py index c33f96595..37aded6e3 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_basic.py @@ -1,20 +1,20 @@ """ -trigonometry $acosh tests. +$acosh results. -Tests $acosh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $acosh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0, the domain bounds and the values just inside them and infinite input. +Expected values are MongoDB's. """ -import math - import pytest +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( @@ -31,63 +31,101 @@ "int_one", expression={"$acosh": 1}, expected=0.0, - msg="$acosh of int one", + msg="Should return 0.0 for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$acosh": Int64(1)}, + expected=0.0, + msg="Should return 0.0 for a long input", ), ExpressionTestCase( "double_two", expression={"$acosh": 2.0}, expected=1.3169578969248166, - msg="$acosh of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "double_max", expression={"$acosh": DOUBLE_MAX}, expected=710.4758600739439, - msg="$acosh of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$acosh": None}, expected=None, - msg="$acosh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$acosh": MISSING}, expected=None, - msg="$acosh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$acosh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$acosh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$acosh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$acosh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "double_infinity", expression={"$acosh": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$acosh of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$acosh": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$acosh of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$acosh": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$acosh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "double_one", + expression={"$acosh": 1.0}, + expected=0.0, + msg="Should return 0.0 for the lower domain bound", + ), + ExpressionTestCase( + "decimal128_one", + expression={"$acosh": Decimal128("1")}, + expected=Decimal128("0"), + msg="Should return a Decimal128 zero for the lower domain bound as Decimal128", + ), + ExpressionTestCase( + "decimal128_two", + expression={"$acosh": Decimal128("2")}, + expected=Decimal128("1.316957896924816708625046347307968"), + msg="Should return the Decimal128 result for a Decimal128 input of 2", ), ] @pytest.mark.parametrize("test", pytest_params(ACOSH_BASIC_TESTS)) def test_acosh_basic(collection, test): - """Test $acosh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $acosh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py index c97cd6b22..8adfa3768 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/acosh/test_acosh_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $acosh tests. +$acosh errors. -Tests $acosh errors: argument count, and inputs outside the operator's range. +Tests that $acosh rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -12,15 +13,19 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_NEGATIVE_ZERO, FLOAT_NEGATIVE_INFINITY, ) @@ -28,59 +33,122 @@ ACOSH_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "double_half", - expression={"$acosh": 0.5}, + expression={"$acosh": DOUBLE_HALF}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of double half should fail", + msg="Should reject a double input with error 50989", ), ExpressionTestCase( "decimal128_half", - expression={"$acosh": Decimal128("0.5")}, + expression={"$acosh": DECIMAL128_HALF}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of decimal128 half should fail", + msg="Should reject a Decimal128 input with error 50989", ), ExpressionTestCase( "decimal128_negative_two", expression={"$acosh": Decimal128("-2")}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of decimal128 negative two should fail", + msg="Should reject a Decimal128 input of -2 with error 50989", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$acosh": DECIMAL128_ZERO}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 zero with error 50989", ), ExpressionTestCase( "negative_zero", expression={"$acosh": DOUBLE_NEGATIVE_ZERO}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of negative zero should fail", + msg="Should reject -0.0 with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$acosh": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$acosh": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$acosh of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "single_element_array", + expression={"$acosh": [DOUBLE_HALF]}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject a single-element argument array with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$acosh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$acosh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$acosh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$acosh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$acosh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$acosh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$acosh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$acosh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", + ), + ExpressionTestCase( + "double_just_below_one", + expression={"$acosh": 0.9999999999999999}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the largest double below 1 with error 50989", + ), + ExpressionTestCase( + "decimal128_just_below_one", + expression={"$acosh": Decimal128("0.9999999999999999999999999999999999")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the largest 34-digit Decimal128 below 1 with error 50989", + ), + ExpressionTestCase( + "out_of_range_field", + expression={"$acosh": "$v"}, + doc={"v": DOUBLE_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain double read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_out_of_range_field", + expression={"$acosh": "$v"}, + doc={"v": DECIMAL128_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain Decimal128 read from a field with error 50989", ), ] @pytest.mark.parametrize("test", pytest_params(ACOSH_ERRORS_TESTS)) def test_acosh_errors(collection, test): - """Test $acosh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $acosh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py index a5c50d38a..5f7eb096e 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_basic.py @@ -1,25 +1,27 @@ """ -trigonometry $asin tests. +$asin results. -Tests $asin results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $asin results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and the domain bounds and the values just inside them. Expected values are +MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NAN, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_NEGATIVE_ZERO, FLOAT_NAN, MISSING, @@ -30,69 +32,117 @@ "int_one", expression={"$asin": 1}, expected=1.5707963267948966, - msg="$asin of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$asin": Int64(1)}, + expected=1.5707963267948966, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$asin": 0.5}, + expression={"$asin": DOUBLE_HALF}, expected=0.5235987755982989, - msg="$asin of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "decimal128_half", - expression={"$asin": Decimal128("0.5")}, + expression={"$asin": DECIMAL128_HALF}, expected=Decimal128("0.5235987755982988730771072305465838"), - msg="$asin of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$asin": DECIMAL128_ZERO}, + expected=Decimal128("0E-40"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "null", expression={"$asin": None}, expected=None, - msg="$asin of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$asin": MISSING}, expected=None, - msg="$asin of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$asin": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$asin of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$asin": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$asin of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$asin": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$asin of negative zero", + msg="Should return -0.0 for -0.0", + ), + ExpressionTestCase( + "single_element_array", + expression={"$asin": [DOUBLE_HALF]}, + expected=0.5235987755982989, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "double_one", + expression={"$asin": 1.0}, + expected=1.5707963267948966, + msg="Should return the double result for the upper domain bound", ), ExpressionTestCase( "double_negative_one", expression={"$asin": -1.0}, expected=-1.5707963267948966, - msg="$asin of double negative one", + msg="Should return the double result for the lower domain bound", ), ExpressionTestCase( - "single_element_array", - expression={"$asin": [0.5]}, - expected=0.5235987755982989, - msg="$asin of single element array", + "long_negative_one", + expression={"$asin": Int64(-1)}, + expected=-1.5707963267948966, + msg="Should return the double result for the lower domain bound as a long", + ), + ExpressionTestCase( + "decimal128_one", + expression={"$asin": Decimal128("1")}, + expected=Decimal128("1.570796326794896619231321691639751"), + msg="Should return the Decimal128 result for the upper domain bound as Decimal128", + ), + ExpressionTestCase( + "decimal128_negative_one", + expression={"$asin": Decimal128("-1")}, + expected=Decimal128("-1.570796326794896619231321691639751"), + msg="Should return the Decimal128 result for the lower domain bound as Decimal128", + ), + ExpressionTestCase( + "double_just_below_one", + expression={"$asin": 0.9999999999999999}, + expected=1.5707963118937354, + msg="Should return the double result for the largest double below 1", + ), + ExpressionTestCase( + "decimal128_just_below_one", + expression={"$asin": Decimal128("0.9999999999999999999999999999999999")}, + expected=Decimal128("1.570796326794896605089186067908801"), + msg="Should return the Decimal128 result for the largest 34-digit Decimal128 below 1", ), ] @pytest.mark.parametrize("test", pytest_params(ASIN_BASIC_TESTS)) def test_asin_basic(collection, test): - """Test $asin values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $asin results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py index 149b45d43..93ea9c2ea 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asin/test_asin_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $asin tests. +$asin errors. -Tests $asin errors: argument count, and inputs outside the operator's range. +Tests that $asin rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -12,17 +13,21 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ONE_AND_HALF, + DOUBLE_HALF, DOUBLE_MAX, + DOUBLE_ONE_AND_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -32,63 +37,134 @@ "double_two", expression={"$asin": 2.0}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of double two should fail", + msg="Should reject a double input of 2 with error 50989", ), ExpressionTestCase( "decimal128_negative_two", expression={"$asin": Decimal128("-2")}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of decimal128 negative two should fail", + msg="Should reject a Decimal128 input of -2 with error 50989", ), ExpressionTestCase( "double_max", expression={"$asin": DOUBLE_MAX}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of double max should fail", + msg="Should reject the largest double with error 50989", ), ExpressionTestCase( "double_infinity", expression={"$asin": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$asin": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$asin": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$asin": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$asin of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$asin": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$asin": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$asin": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$asin of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$asin": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$asin of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$asin": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$asin": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$asin": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$asin": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", + ), + ExpressionTestCase( + "double_just_above_one", + expression={"$asin": 1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest double above 1 with error 50989", + ), + ExpressionTestCase( + "double_just_below_negative_one", + expression={"$asin": -1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the largest double below -1 with error 50989", + ), + ExpressionTestCase( + "decimal128_just_above_one", + expression={"$asin": Decimal128("1.000000000000000000000000000000001")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest 34-digit Decimal128 above 1 with error 50989", + ), + ExpressionTestCase( + "out_of_range_field", + expression={"$asin": "$v"}, + doc={"v": DOUBLE_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain double read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_out_of_range_field", + expression={"$asin": "$v"}, + doc={"v": DECIMAL128_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain Decimal128 read from a field with error 50989", ), ] @pytest.mark.parametrize("test", pytest_params(ASIN_ERRORS_TESTS)) def test_asin_errors(collection, test): - """Test $asin errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $asin errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py index dbad2e4d5..eed191e94 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_basic.py @@ -1,27 +1,28 @@ """ -trigonometry $asinh tests. +$asinh results. -Tests $asinh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $asinh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, @@ -35,99 +36,131 @@ "int_one", expression={"$asinh": 1}, expected=0.881373587019543, - msg="$asinh of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$asinh": Int64(1)}, + expected=0.881373587019543, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$asinh": 0.5}, + expression={"$asinh": DOUBLE_HALF}, expected=0.48121182505960347, - msg="$asinh of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$asinh": 2.0}, expected=1.4436354751788103, - msg="$asinh of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$asinh": Decimal128("0.5")}, + expression={"$asinh": DECIMAL128_HALF}, expected=Decimal128("0.4812118250596034474977589134243684"), - msg="$asinh of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$asinh": Decimal128("-2")}, expected=Decimal128("-1.443635475178810342493276740273105"), - msg="$asinh of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$asinh": DECIMAL128_ZERO}, + expected=Decimal128("0E-6176"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$asinh": DOUBLE_MAX}, expected=710.4758600739439, - msg="$asinh of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$asinh": None}, expected=None, - msg="$asinh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$asinh": MISSING}, expected=None, - msg="$asinh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$asinh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$asinh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$asinh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$asinh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$asinh": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$asinh of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$asinh": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$asinh of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$asinh": FLOAT_NEGATIVE_INFINITY}, expected=FLOAT_NEGATIVE_INFINITY, - msg="$asinh of double negative infinity", + msg="Should return -Infinity for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$asinh": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$asinh of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$asinh": DECIMAL128_NEGATIVE_INFINITY}, expected=DECIMAL128_NEGATIVE_INFINITY, - msg="$asinh of decimal128 negative infinity", + msg="Should return Decimal128 -Infinity for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$asinh": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$asinh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "single_element_array", + expression={"$asinh": [DOUBLE_HALF]}, + expected=0.48121182505960347, + msg="Should return the double result for a single-element argument array", ), ] @pytest.mark.parametrize("test", pytest_params(ASINH_BASIC_TESTS)) def test_asinh_basic(collection, test): - """Test $asinh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $asinh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py index 421a0d9fc..562634329 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/asinh/test_asinh_errors.py @@ -1,7 +1,7 @@ """ -trigonometry $asinh tests. +$asinh errors. -Tests $asinh errors: argument count, and inputs outside the operator's range. +Tests that $asinh rejects a wrong argument count (16020) and non-numeric input (28765). """ import pytest @@ -11,31 +11,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) ASINH_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$asinh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$asinh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$asinh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$asinh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$asinh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$asinh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$asinh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$asinh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(ASINH_ERRORS_TESTS)) def test_asinh_errors(collection, test): - """Test $asinh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $asinh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py index 0325fc377..9772ddfe3 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_basic.py @@ -1,27 +1,28 @@ """ -trigonometry $atan tests. +$atan results. -Tests $atan results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $atan results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, @@ -35,99 +36,131 @@ "int_one", expression={"$atan": 1}, expected=0.7853981633974483, - msg="$atan of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$atan": Int64(1)}, + expected=0.7853981633974483, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$atan": 0.5}, + expression={"$atan": DOUBLE_HALF}, expected=0.4636476090008061, - msg="$atan of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$atan": 2.0}, expected=1.1071487177940904, - msg="$atan of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$atan": Decimal128("0.5")}, + expression={"$atan": DECIMAL128_HALF}, expected=Decimal128("0.4636476090008061162142562314612144"), - msg="$atan of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$atan": Decimal128("-2")}, expected=Decimal128("-1.107148717794090503017065460178537"), - msg="$atan of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$atan": DECIMAL128_ZERO}, + expected=Decimal128("0"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$atan": DOUBLE_MAX}, expected=1.5707963267948966, - msg="$atan of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$atan": None}, expected=None, - msg="$atan of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$atan": MISSING}, expected=None, - msg="$atan of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$atan": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$atan of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$atan": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$atan of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$atan": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$atan of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$atan": FLOAT_INFINITY}, expected=1.5707963267948966, - msg="$atan of double infinity", + msg="Should return the double result for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$atan": FLOAT_NEGATIVE_INFINITY}, expected=-1.5707963267948966, - msg="$atan of double negative infinity", + msg="Should return the double result for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$atan": DECIMAL128_INFINITY}, expected=Decimal128("1.570796326794896619231321691639751"), - msg="$atan of decimal128 infinity", + msg="Should return the Decimal128 result for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$atan": DECIMAL128_NEGATIVE_INFINITY}, expected=Decimal128("-1.570796326794896619231321691639751"), - msg="$atan of decimal128 negative infinity", + msg="Should return the Decimal128 result for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$atan": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=1.5707963267948966, + msg="Should return the double result for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$atan": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=Decimal128("1.570796326794896619231321691639751"), + msg="Should return the Decimal128 result for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "single_element_array", + expression={"$atan": [DOUBLE_HALF]}, + expected=0.4636476090008061, + msg="Should return the double result for a single-element argument array", ), ] @pytest.mark.parametrize("test", pytest_params(ATAN_BASIC_TESTS)) def test_atan_basic(collection, test): - """Test $atan values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atan results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py index 859864e0a..ad3e6bb89 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan/test_atan_errors.py @@ -1,7 +1,7 @@ """ -trigonometry $atan tests. +$atan errors. -Tests $atan errors: argument count, and inputs outside the operator's range. +Tests that $atan rejects a wrong argument count (16020) and non-numeric input (28765). """ import pytest @@ -11,31 +11,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) ATAN_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$atan": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atan of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$atan": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atan of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$atan": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$atan": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$atan": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$atan": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(ATAN_ERRORS_TESTS)) def test_atan_errors(collection, test): - """Test $atan errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atan errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py index 699efab50..43e51ea59 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_basic.py @@ -1,91 +1,178 @@ """ -trigonometry $atan2 tests. +$atan2 results. -Tests $atan2 results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $atan2 results for int, long, double and Decimal128 argument pairs, null and +missing in each argument, NaN and infinity in each argument, the sign of zero and field- +path arguments. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_NEGATIVE_ZERO, + DOUBLE_MAX, + DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, FLOAT_NAN, MISSING, ) ATAN2_BASIC_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "int_int", + expression={"$atan2": [1, 1]}, + expected=0.7853981633974483, + msg="Should return the double result for two int arguments", + ), + ExpressionTestCase( + "long_long", + expression={"$atan2": [Int64(1), Int64(1)]}, + expected=0.7853981633974483, + msg="Should return the double result for two long arguments", + ), ExpressionTestCase( "double_double", expression={"$atan2": [1.0, 1.0]}, expected=0.7853981633974483, - msg="$atan2 of double double", + msg="Should return the double result for two double arguments", ), ExpressionTestCase( "decimal128_decimal128", expression={"$atan2": [Decimal128("1"), Decimal128("1")]}, expected=Decimal128("0.7853981633974483096156608458198757"), - msg="$atan2 of decimal128 decimal128", + msg="Should return the Decimal128 result for two Decimal128 arguments", ), ExpressionTestCase( "decimal128_double", expression={"$atan2": [Decimal128("1"), 1.0]}, expected=Decimal128("0.7853981633974483096156608458198757"), - msg="$atan2 of decimal128 double", + msg="Should return the Decimal128 result for a Decimal128 y and a double x", ), ExpressionTestCase( "double_decimal128", expression={"$atan2": [1.0, Decimal128("1")]}, expected=Decimal128("0.7853981633974483096156608458198757"), - msg="$atan2 of double decimal128", + msg="Should return the Decimal128 result for a double y and a Decimal128 x", + ), + ExpressionTestCase( + "double_max_both", + expression={"$atan2": [DOUBLE_MAX, DOUBLE_MAX]}, + expected=0.7853981633974483, + msg="Should return the double result for the largest double in both arguments", + ), + ExpressionTestCase( + "fields", + expression={"$atan2": ["$y", "$x"]}, + doc={"y": 1.0, "x": -1.0}, + expected=2.356194490192345, + msg="Should return the double result for both arguments read from fields", ), ExpressionTestCase( "null_y", expression={"$atan2": [None, 1.0]}, expected=None, - msg="$atan2 of null y", + msg="Should return null for a null y", + ), + ExpressionTestCase( + "null_x", + expression={"$atan2": [1.0, None]}, + expected=None, + msg="Should return null for a null x", ), ExpressionTestCase( "missing_y", expression={"$atan2": [MISSING, 1.0]}, expected=None, - msg="$atan2 of missing y", + msg="Should return null for a missing y", + ), + ExpressionTestCase( + "missing_x", + expression={"$atan2": [1.0, MISSING]}, + expected=None, + msg="Should return null for a missing x", + ), + ExpressionTestCase( + "null_y_string_x", + expression={"$atan2": [None, "a"]}, + expected=None, + msg="Should return null for a null y with a string x", ), ExpressionTestCase( "nan_y", expression={"$atan2": [FLOAT_NAN, 1.0]}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$atan2 of nan y", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for a NaN y", + ), + ExpressionTestCase( + "nan_x", + expression={"$atan2": [1.0, FLOAT_NAN]}, + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for a NaN x", ), ExpressionTestCase( "infinity_y", expression={"$atan2": [FLOAT_INFINITY, 1.0]}, expected=1.5707963267948966, - msg="$atan2 of infinity y", + msg="Should return the double result for an infinite y", + ), + ExpressionTestCase( + "infinity_x", + expression={"$atan2": [1.0, FLOAT_INFINITY]}, + expected=0.0, + msg="Should return 0.0 for an infinite x", + ), + ExpressionTestCase( + "infinity_both", + expression={"$atan2": [FLOAT_INFINITY, FLOAT_INFINITY]}, + expected=0.7853981633974483, + msg="Should return the double result for infinite y and x", ), ExpressionTestCase( "zero_zero", expression={"$atan2": [0.0, 0.0]}, expected=0.0, - msg="$atan2 of zero zero", + msg="Should return 0.0 for zero y and zero x", + ), + ExpressionTestCase( + "zero_negative_zero", + expression={"$atan2": [0.0, DOUBLE_NEGATIVE_ZERO]}, + expected=3.141592653589793, + msg="Should return the double result for zero y and -0.0 x", + ), + ExpressionTestCase( + "negative_zero_zero", + expression={"$atan2": [DOUBLE_NEGATIVE_ZERO, 0.0]}, + expected=-0.0, + msg="Should return -0.0 for -0.0 y and zero x", + ), + ExpressionTestCase( + "negative_zero_negative_x", + expression={"$atan2": [DOUBLE_NEGATIVE_ZERO, -1.0]}, + expected=-3.141592653589793, + msg="Should return the double result for -0.0 y and a negative x", + ), + ExpressionTestCase( + "decimal128_negative_zero_negative_x", + expression={"$atan2": [DECIMAL128_NEGATIVE_ZERO, Decimal128("-1")]}, + expected=Decimal128("-3.141592653589793238462643383279503"), + msg="Should return the Decimal128 result for Decimal128 -0 y and a negative Decimal128 x", ), ] @pytest.mark.parametrize("test", pytest_params(ATAN2_BASIC_TESTS)) def test_atan2_basic(collection, test): - """Test $atan2 values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atan2 results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py index 8976a6981..709f5aaec 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atan2/test_atan2_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $atan2 tests. +$atan2 errors. -Tests $atan2 errors: argument count, and inputs outside the operator's range. +Tests that $atan2 rejects a wrong argument count (16020) and a non-numeric first +argument (51044). """ import pytest @@ -11,37 +12,52 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + TWO_NUMERIC_ARGS_FIRST_TYPE_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params ATAN2_ERRORS_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "string_y_null_x", + expression={"$atan2": ["a", None]}, + error_code=TWO_NUMERIC_ARGS_FIRST_TYPE_ERROR, + msg="Should reject a string y with a null x with error 51044", + ), + ExpressionTestCase( + "arity_zero_args", + expression={"$atan2": []}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject an empty argument array with error 16020", + ), ExpressionTestCase( "arity_one_arg", expression={"$atan2": [1]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atan2 of arity one arg should fail", + msg="Should reject one argument with error 16020", ), ExpressionTestCase( "arity_three_args", expression={"$atan2": [1, 2, 3]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atan2 of arity three args should fail", + msg="Should reject three arguments with error 16020", ), ExpressionTestCase( "non_array_arg", expression={"$atan2": 1}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atan2 of non array arg should fail", + msg="Should reject a non-array argument with error 16020", ), ] @pytest.mark.parametrize("test", pytest_params(ATAN2_ERRORS_TESTS)) def test_atan2_errors(collection, test): - """Test $atan2 errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atan2 errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py index 35e11a179..cb1f3f06e 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_basic.py @@ -1,25 +1,29 @@ """ -trigonometry $atanh tests. +$atanh results. -Tests $atanh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $atanh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and the domain bounds and the values just inside them. Expected values are +MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, + DECIMAL128_INFINITY, DECIMAL128_NAN, + DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, FLOAT_NAN, @@ -32,63 +36,117 @@ "int_one", expression={"$atanh": 1}, expected=FLOAT_INFINITY, - msg="$atanh of int one", + msg="Should return Infinity for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$atanh": Int64(1)}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for a long input", ), ExpressionTestCase( "double_half", - expression={"$atanh": 0.5}, + expression={"$atanh": DOUBLE_HALF}, expected=0.5493061443340548, - msg="$atanh of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "decimal128_half", - expression={"$atanh": Decimal128("0.5")}, + expression={"$atanh": DECIMAL128_HALF}, expected=Decimal128("0.5493061443340548456976226184612628"), - msg="$atanh of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$atanh": DECIMAL128_ZERO}, + expected=Decimal128("0E-6176"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "null", expression={"$atanh": None}, expected=None, - msg="$atanh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$atanh": MISSING}, expected=None, - msg="$atanh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$atanh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$atanh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$atanh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$atanh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$atanh": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$atanh of negative zero", + msg="Should return -0.0 for -0.0", + ), + ExpressionTestCase( + "single_element_array", + expression={"$atanh": [DOUBLE_HALF]}, + expected=0.5493061443340548, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "double_one", + expression={"$atanh": 1.0}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for the upper domain bound", ), ExpressionTestCase( "double_negative_one", expression={"$atanh": -1.0}, expected=FLOAT_NEGATIVE_INFINITY, - msg="$atanh of double negative one", + msg="Should return -Infinity for the lower domain bound", + ), + ExpressionTestCase( + "long_negative_one", + expression={"$atanh": Int64(-1)}, + expected=FLOAT_NEGATIVE_INFINITY, + msg="Should return -Infinity for the lower domain bound as a long", + ), + ExpressionTestCase( + "decimal128_one", + expression={"$atanh": Decimal128("1")}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for the upper domain bound as Decimal128", + ), + ExpressionTestCase( + "decimal128_negative_one", + expression={"$atanh": Decimal128("-1")}, + expected=DECIMAL128_NEGATIVE_INFINITY, + msg="Should return Decimal128 -Infinity for the lower domain bound as Decimal128", + ), + ExpressionTestCase( + "double_just_below_one", + expression={"$atanh": 0.9999999999999999}, + expected=18.714973875118524, + msg="Should return the double result for the largest double below 1", + ), + ExpressionTestCase( + "decimal128_just_below_one", + expression={"$atanh": Decimal128("0.9999999999999999999999999999999999")}, + expected=Decimal128("39.49052017117874928301447079036328"), + msg="Should return the Decimal128 result for the largest 34-digit Decimal128 below 1", ), ] @pytest.mark.parametrize("test", pytest_params(ATANH_BASIC_TESTS)) def test_atanh_basic(collection, test): - """Test $atanh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atanh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py index 115246ecf..e56fbda7e 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/atanh/test_atanh_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $atanh tests. +$atanh errors. -Tests $atanh errors: argument count, and inputs outside the operator's range. +Tests that $atanh rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -12,17 +13,21 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ONE_AND_HALF, + DOUBLE_HALF, DOUBLE_MAX, + DOUBLE_ONE_AND_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -32,63 +37,134 @@ "double_two", expression={"$atanh": 2.0}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of double two should fail", + msg="Should reject a double input of 2 with error 50989", ), ExpressionTestCase( "decimal128_negative_two", expression={"$atanh": Decimal128("-2")}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of decimal128 negative two should fail", + msg="Should reject a Decimal128 input of -2 with error 50989", ), ExpressionTestCase( "double_max", expression={"$atanh": DOUBLE_MAX}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of double max should fail", + msg="Should reject the largest double with error 50989", ), ExpressionTestCase( "double_infinity", expression={"$atanh": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$atanh": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$atanh": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$atanh": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$atanh of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$atanh": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$atanh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$atanh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atanh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$atanh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$atanh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$atanh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$atanh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$atanh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$atanh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", + ), + ExpressionTestCase( + "double_just_above_one", + expression={"$atanh": 1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest double above 1 with error 50989", + ), + ExpressionTestCase( + "double_just_below_negative_one", + expression={"$atanh": -1.0000000000000002}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the largest double below -1 with error 50989", + ), + ExpressionTestCase( + "decimal128_just_above_one", + expression={"$atanh": Decimal128("1.000000000000000000000000000000001")}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject the smallest 34-digit Decimal128 above 1 with error 50989", + ), + ExpressionTestCase( + "out_of_range_field", + expression={"$atanh": "$v"}, + doc={"v": DOUBLE_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain double read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_out_of_range_field", + expression={"$atanh": "$v"}, + doc={"v": DECIMAL128_ONE_AND_HALF}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject an out-of-domain Decimal128 read from a field with error 50989", ), ] @pytest.mark.parametrize("test", pytest_params(ATANH_ERRORS_TESTS)) def test_atanh_errors(collection, test): - """Test $atanh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $atanh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py index 195d4c810..39371e841 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_basic.py @@ -1,25 +1,28 @@ """ -trigonometry $cos tests. +$cos results. -Tests $cos results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $cos results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and multiples of a quarter turn. Expected values are MongoDB's. """ import math import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NAN, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_NAN, @@ -31,75 +34,123 @@ "int_one", expression={"$cos": 1}, expected=0.5403023058681398, - msg="$cos of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$cos": Int64(1)}, + expected=0.5403023058681398, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$cos": 0.5}, + expression={"$cos": DOUBLE_HALF}, expected=0.8775825618903728, - msg="$cos of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$cos": 2.0}, expected=-0.4161468365471424, - msg="$cos of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$cos": Decimal128("0.5")}, + expression={"$cos": DECIMAL128_HALF}, expected=Decimal128("0.8775825618903727161162815826038297"), - msg="$cos of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$cos": Decimal128("-2")}, expected=Decimal128("-0.4161468365471423869975682295007621"), - msg="$cos of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$cos": DECIMAL128_ZERO}, + expected=Decimal128("1.000000000000000000000000000000000"), + msg="Should return the Decimal128 result for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$cos": DOUBLE_MAX}, expected=-0.9999876894265599, - msg="$cos of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$cos": None}, expected=None, - msg="$cos of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$cos": MISSING}, expected=None, - msg="$cos of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$cos": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$cos of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$cos": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$cos of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$cos": DOUBLE_NEGATIVE_ZERO}, expected=1.0, - msg="$cos of negative zero", + msg="Should return the double result for -0.0", + ), + ExpressionTestCase( + "single_element_array", + expression={"$cos": [DOUBLE_HALF]}, + expected=0.8775825618903728, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "half_pi", + expression={"$cos": math.pi / 2}, + expected=6.123233995736766e-17, + msg="Should return the double result for a quarter-turn angle", + ), + ExpressionTestCase( + "pi", + expression={"$cos": math.pi}, + expected=-1.0, + msg="Should return the double result for a half-turn angle", + ), + ExpressionTestCase( + "three_halves_pi", + expression={"$cos": 3 * math.pi / 2}, + expected=-1.8369701987210297e-16, + msg="Should return the double result for a three-quarter-turn angle", + ), + ExpressionTestCase( + "two_pi", + expression={"$cos": 2 * math.pi}, + expected=1.0, + msg="Should return the double result for a full-turn angle", + ), + ExpressionTestCase( + "decimal128_pi", + expression={"$cos": Decimal128("3.141592653589793238462643383279503")}, + expected=Decimal128("-1"), + msg="Should return the Decimal128 result for a Decimal128 half-turn angle", ), ] @pytest.mark.parametrize("test", pytest_params(COS_BASIC_TESTS)) def test_cos_basic(collection, test): - """Test $cos values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $cos results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py index 711920c41..a47eb70a6 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cos/test_cos_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $cos tests. +$cos errors. -Tests $cos errors: argument count, and inputs outside the operator's range. +Tests that $cos rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -11,16 +12,18 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -30,45 +33,84 @@ "double_infinity", expression={"$cos": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$cos of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$cos": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$cos of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$cos": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$cos of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$cos": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$cos of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$cos": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$cos": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$cos": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$cos of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$cos": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$cos of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$cos": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$cos": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$cos": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$cos": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(COS_ERRORS_TESTS)) def test_cos_errors(collection, test): - """Test $cos errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $cos errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py index 3d5b981c3..d0f5ae14b 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_basic.py @@ -1,27 +1,28 @@ """ -trigonometry $cosh tests. +$cosh results. -Tests $cosh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $cosh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, @@ -35,99 +36,131 @@ "int_one", expression={"$cosh": 1}, expected=1.5430806348152437, - msg="$cosh of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$cosh": Int64(1)}, + expected=1.5430806348152437, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$cosh": 0.5}, + expression={"$cosh": DOUBLE_HALF}, expected=1.1276259652063807, - msg="$cosh of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$cosh": 2.0}, expected=3.7621956910836314, - msg="$cosh of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$cosh": Decimal128("0.5")}, + expression={"$cosh": DECIMAL128_HALF}, expected=Decimal128("1.127625965206380785226225161402672"), - msg="$cosh of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$cosh": Decimal128("-2")}, expected=Decimal128("3.762195691083631459562213477773746"), - msg="$cosh of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$cosh": DECIMAL128_ZERO}, + expected=Decimal128("1.000000000000000000000000000000000"), + msg="Should return the Decimal128 result for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$cosh": DOUBLE_MAX}, expected=FLOAT_INFINITY, - msg="$cosh of double max", + msg="Should return Infinity for the largest double", ), ExpressionTestCase( "null", expression={"$cosh": None}, expected=None, - msg="$cosh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$cosh": MISSING}, expected=None, - msg="$cosh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$cosh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$cosh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$cosh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$cosh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$cosh": DOUBLE_NEGATIVE_ZERO}, expected=1.0, - msg="$cosh of negative zero", + msg="Should return the double result for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$cosh": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$cosh of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$cosh": FLOAT_NEGATIVE_INFINITY}, expected=FLOAT_INFINITY, - msg="$cosh of double negative infinity", + msg="Should return Infinity for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$cosh": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$cosh of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$cosh": DECIMAL128_NEGATIVE_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$cosh of decimal128 negative infinity", + msg="Should return Decimal128 Infinity for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$cosh": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$cosh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "single_element_array", + expression={"$cosh": [DOUBLE_HALF]}, + expected=1.1276259652063807, + msg="Should return the double result for a single-element argument array", ), ] @pytest.mark.parametrize("test", pytest_params(COSH_BASIC_TESTS)) def test_cosh_basic(collection, test): - """Test $cosh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $cosh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py index 4766ea2f7..7f681e27f 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/cosh/test_cosh_errors.py @@ -1,7 +1,7 @@ """ -trigonometry $cosh tests. +$cosh errors. -Tests $cosh errors: argument count, and inputs outside the operator's range. +Tests that $cosh rejects a wrong argument count (16020) and non-numeric input (28765). """ import pytest @@ -11,31 +11,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) COSH_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$cosh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$cosh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$cosh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$cosh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$cosh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$cosh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$cosh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$cosh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(COSH_ERRORS_TESTS)) def test_cosh_errors(collection, test): - """Test $cosh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $cosh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py index 16721320c..693109f98 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_basic.py @@ -1,28 +1,34 @@ """ -trigonometry $degreesToRadians tests. +$degreesToRadians results. -Tests $degreesToRadians results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $degreesToRadians results for int, long, double and Decimal128 input, null and +missing input, NaN, -0.0, overflow and underflow at the double and Decimal128 limits and +infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, + DECIMAL128_MAX, + DECIMAL128_MIN_POSITIVE, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, + DOUBLE_MIN_SUBNORMAL, + DOUBLE_NEAR_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, FLOAT_NAN, @@ -35,105 +41,155 @@ "int_one", expression={"$degreesToRadians": 1}, expected=0.017453292519943295, - msg="$degreesToRadians of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$degreesToRadians": Int64(1)}, + expected=0.017453292519943295, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$degreesToRadians": 0.5}, + expression={"$degreesToRadians": DOUBLE_HALF}, expected=0.008726646259971648, - msg="$degreesToRadians of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$degreesToRadians": 2.0}, expected=0.03490658503988659, - msg="$degreesToRadians of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$degreesToRadians": Decimal128("0.5")}, + expression={"$degreesToRadians": DECIMAL128_HALF}, expected=Decimal128("0.008726646259971647884618453842443065"), - msg="$degreesToRadians of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$degreesToRadians": Decimal128("-2")}, expected=Decimal128("-0.03490658503988659153847381536977226"), - msg="$degreesToRadians of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$degreesToRadians": DECIMAL128_ZERO}, + expected=Decimal128("0E-35"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$degreesToRadians": DOUBLE_MAX}, expected=3.1375664143845866e306, - msg="$degreesToRadians of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$degreesToRadians": None}, expected=None, - msg="$degreesToRadians of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$degreesToRadians": MISSING}, expected=None, - msg="$degreesToRadians of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$degreesToRadians": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$degreesToRadians of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$degreesToRadians": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$degreesToRadians of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$degreesToRadians": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$degreesToRadians of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$degreesToRadians": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$degreesToRadians of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$degreesToRadians": FLOAT_NEGATIVE_INFINITY}, expected=FLOAT_NEGATIVE_INFINITY, - msg="$degreesToRadians of double negative infinity", + msg="Should return -Infinity for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$degreesToRadians": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$degreesToRadians of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$degreesToRadians": DECIMAL128_NEGATIVE_INFINITY}, expected=DECIMAL128_NEGATIVE_INFINITY, - msg="$degreesToRadians of decimal128 negative infinity", + msg="Should return Decimal128 -Infinity for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$degreesToRadians": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$degreesToRadians": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", ), ExpressionTestCase( "single_element_array", - expression={"$degreesToRadians": [0.5]}, + expression={"$degreesToRadians": [DOUBLE_HALF]}, expected=0.008726646259971648, - msg="$degreesToRadians of single element array", + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "double_near_max", + expression={"$degreesToRadians": DOUBLE_NEAR_MAX}, + expected=1.7453292519943295e306, + msg="Should return the double result for a double near the largest double", + ), + ExpressionTestCase( + "double_min_subnormal", + expression={"$degreesToRadians": DOUBLE_MIN_SUBNORMAL}, + expected=0.0, + msg="Should return 0.0 for the smallest subnormal double", + ), + ExpressionTestCase( + "decimal128_max", + expression={"$degreesToRadians": DECIMAL128_MAX}, + expected=Decimal128("1.745329251994329576923690768488613E+6143"), + msg="Should return the Decimal128 result for the largest Decimal128", + ), + ExpressionTestCase( + "decimal128_min_positive", + expression={"$degreesToRadians": DECIMAL128_MIN_POSITIVE}, + expected=Decimal128("0E-6176"), + msg="Should return a Decimal128 zero for the smallest positive Decimal128", ), ] @pytest.mark.parametrize("test", pytest_params(DEGREESTORADIANS_BASIC_TESTS)) def test_degreesToRadians_basic(collection, test): - """Test $degreesToRadians values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $degreesToRadians results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py index 451f9cf00..de9b5a1d7 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/degreesToRadians/test_degreesToRadians_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $degreesToRadians tests. +$degreesToRadians errors. -Tests $degreesToRadians errors: argument count, and inputs outside the operator's range. +Tests that $degreesToRadians rejects a wrong argument count (16020) and non-numeric +input (28765). """ import pytest @@ -11,31 +12,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) DEGREESTORADIANS_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$degreesToRadians": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$degreesToRadians of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$degreesToRadians": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$degreesToRadians of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$degreesToRadians": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$degreesToRadians": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$degreesToRadians": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$degreesToRadians": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(DEGREESTORADIANS_ERRORS_TESTS)) def test_degreesToRadians_errors(collection, test): - """Test $degreesToRadians errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $degreesToRadians errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py index febc7e42d..3b3c08a77 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_basic.py @@ -1,28 +1,34 @@ """ -trigonometry $radiansToDegrees tests. +$radiansToDegrees results. -Tests $radiansToDegrees results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $radiansToDegrees results for int, long, double and Decimal128 input, null and +missing input, NaN, -0.0, overflow and underflow at the double and Decimal128 limits and +infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, + DECIMAL128_MAX, + DECIMAL128_MIN_POSITIVE, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, + DOUBLE_MIN_SUBNORMAL, + DOUBLE_NEAR_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, FLOAT_NAN, @@ -35,99 +41,155 @@ "int_one", expression={"$radiansToDegrees": 1}, expected=57.29577951308232, - msg="$radiansToDegrees of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$radiansToDegrees": Int64(1)}, + expected=57.29577951308232, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$radiansToDegrees": 0.5}, + expression={"$radiansToDegrees": DOUBLE_HALF}, expected=28.64788975654116, - msg="$radiansToDegrees of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$radiansToDegrees": 2.0}, expected=114.59155902616465, - msg="$radiansToDegrees of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$radiansToDegrees": Decimal128("0.5")}, + expression={"$radiansToDegrees": DECIMAL128_HALF}, expected=Decimal128("28.64788975654116043839907740705258"), - msg="$radiansToDegrees of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$radiansToDegrees": Decimal128("-2")}, expected=Decimal128("-114.5915590261646417535963096282103"), - msg="$radiansToDegrees of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$radiansToDegrees": DECIMAL128_ZERO}, + expected=Decimal128("0E-32"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$radiansToDegrees": DOUBLE_MAX}, expected=FLOAT_INFINITY, - msg="$radiansToDegrees of double max", + msg="Should return Infinity for the largest double", ), ExpressionTestCase( "null", expression={"$radiansToDegrees": None}, expected=None, - msg="$radiansToDegrees of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$radiansToDegrees": MISSING}, expected=None, - msg="$radiansToDegrees of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$radiansToDegrees": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$radiansToDegrees of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$radiansToDegrees": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$radiansToDegrees of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$radiansToDegrees": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$radiansToDegrees of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$radiansToDegrees": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$radiansToDegrees of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$radiansToDegrees": FLOAT_NEGATIVE_INFINITY}, expected=FLOAT_NEGATIVE_INFINITY, - msg="$radiansToDegrees of double negative infinity", + msg="Should return -Infinity for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$radiansToDegrees": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$radiansToDegrees of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$radiansToDegrees": DECIMAL128_NEGATIVE_INFINITY}, expected=DECIMAL128_NEGATIVE_INFINITY, - msg="$radiansToDegrees of decimal128 negative infinity", + msg="Should return Decimal128 -Infinity for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$radiansToDegrees": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$radiansToDegrees": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "single_element_array", + expression={"$radiansToDegrees": [DOUBLE_HALF]}, + expected=28.64788975654116, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "double_near_max", + expression={"$radiansToDegrees": DOUBLE_NEAR_MAX}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for a double near the largest double", + ), + ExpressionTestCase( + "double_min_subnormal", + expression={"$radiansToDegrees": DOUBLE_MIN_SUBNORMAL}, + expected=2.8e-322, + msg="Should return the double result for the smallest subnormal double", + ), + ExpressionTestCase( + "decimal128_max", + expression={"$radiansToDegrees": DECIMAL128_MAX}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for the largest Decimal128", + ), + ExpressionTestCase( + "decimal128_min_positive", + expression={"$radiansToDegrees": DECIMAL128_MIN_POSITIVE}, + expected=Decimal128("5.7E-6175"), + msg="Should return the Decimal128 result for the smallest positive Decimal128", ), ] @pytest.mark.parametrize("test", pytest_params(RADIANSTODEGREES_BASIC_TESTS)) def test_radiansToDegrees_basic(collection, test): - """Test $radiansToDegrees values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $radiansToDegrees results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py index d47cf6515..49b635bbb 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/radiansToDegrees/test_radiansToDegrees_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $radiansToDegrees tests. +$radiansToDegrees errors. -Tests $radiansToDegrees errors: argument count, and inputs outside the operator's range. +Tests that $radiansToDegrees rejects a wrong argument count (16020) and non-numeric +input (28765). """ import pytest @@ -11,31 +12,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) RADIANSTODEGREES_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$radiansToDegrees": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$radiansToDegrees of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$radiansToDegrees": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$radiansToDegrees of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$radiansToDegrees": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$radiansToDegrees": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$radiansToDegrees": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$radiansToDegrees": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(RADIANSTODEGREES_ERRORS_TESTS)) def test_radiansToDegrees_errors(collection, test): - """Test $radiansToDegrees errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $radiansToDegrees errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py index bcc611f3c..b44aa2549 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_basic.py @@ -1,25 +1,28 @@ """ -trigonometry $sin tests. +$sin results. -Tests $sin results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $sin results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and multiples of a quarter turn. Expected values are MongoDB's. """ import math import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NAN, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_NAN, @@ -31,81 +34,123 @@ "int_one", expression={"$sin": 1}, expected=0.8414709848078965, - msg="$sin of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$sin": Int64(1)}, + expected=0.8414709848078965, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$sin": 0.5}, + expression={"$sin": DOUBLE_HALF}, expected=0.479425538604203, - msg="$sin of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$sin": 2.0}, expected=0.9092974268256817, - msg="$sin of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$sin": Decimal128("0.5")}, + expression={"$sin": DECIMAL128_HALF}, expected=Decimal128("0.4794255386042030002732879352155714"), - msg="$sin of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$sin": Decimal128("-2")}, expected=Decimal128("-0.9092974268256816953960198659117449"), - msg="$sin of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$sin": DECIMAL128_ZERO}, + expected=Decimal128("0"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$sin": DOUBLE_MAX}, expected=0.004961954789184062, - msg="$sin of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$sin": None}, expected=None, - msg="$sin of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$sin": MISSING}, expected=None, - msg="$sin of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$sin": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$sin of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$sin": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$sin of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$sin": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$sin of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "single_element_array", - expression={"$sin": [0.5]}, + expression={"$sin": [DOUBLE_HALF]}, expected=0.479425538604203, - msg="$sin of single element array", + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "half_pi", + expression={"$sin": math.pi / 2}, + expected=1.0, + msg="Should return the double result for a quarter-turn angle", + ), + ExpressionTestCase( + "pi", + expression={"$sin": math.pi}, + expected=1.2246467991473532e-16, + msg="Should return the double result for a half-turn angle", + ), + ExpressionTestCase( + "three_halves_pi", + expression={"$sin": 3 * math.pi / 2}, + expected=-1.0, + msg="Should return the double result for a three-quarter-turn angle", + ), + ExpressionTestCase( + "two_pi", + expression={"$sin": 2 * math.pi}, + expected=-2.4492935982947064e-16, + msg="Should return the double result for a full-turn angle", + ), + ExpressionTestCase( + "decimal128_pi", + expression={"$sin": Decimal128("3.141592653589793238462643383279503")}, + expected=Decimal128("-1.158028306006248941790250554076922E-34"), + msg="Should return the Decimal128 result for a Decimal128 half-turn angle", ), ] @pytest.mark.parametrize("test", pytest_params(SIN_BASIC_TESTS)) def test_sin_basic(collection, test): - """Test $sin values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $sin results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py index 3a3428c30..736fc8605 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sin/test_sin_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $sin tests. +$sin errors. -Tests $sin errors: argument count, and inputs outside the operator's range. +Tests that $sin rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -11,16 +12,18 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -30,45 +33,84 @@ "double_infinity", expression={"$sin": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$sin of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$sin": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$sin of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$sin": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$sin of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$sin": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$sin of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$sin": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$sin": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$sin": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$sin of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$sin": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$sin of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$sin": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$sin": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$sin": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$sin": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(SIN_ERRORS_TESTS)) def test_sin_errors(collection, test): - """Test $sin errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $sin errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py index e0bbb1528..93432faa9 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_basic.py @@ -1,27 +1,28 @@ """ -trigonometry $sinh tests. +$sinh results. -Tests $sinh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $sinh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, @@ -35,105 +36,131 @@ "int_one", expression={"$sinh": 1}, expected=1.1752011936438014, - msg="$sinh of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$sinh": Int64(1)}, + expected=1.1752011936438014, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$sinh": 0.5}, + expression={"$sinh": DOUBLE_HALF}, expected=0.5210953054937474, - msg="$sinh of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$sinh": 2.0}, expected=3.626860407847019, - msg="$sinh of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$sinh": Decimal128("0.5")}, + expression={"$sinh": DECIMAL128_HALF}, expected=Decimal128("0.5210953054937473616224256264114915"), - msg="$sinh of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$sinh": Decimal128("-2")}, expected=Decimal128("-3.626860407847018767668213982801262"), - msg="$sinh of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$sinh": DECIMAL128_ZERO}, + expected=Decimal128("0E-40"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$sinh": DOUBLE_MAX}, expected=FLOAT_INFINITY, - msg="$sinh of double max", + msg="Should return Infinity for the largest double", ), ExpressionTestCase( "null", expression={"$sinh": None}, expected=None, - msg="$sinh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$sinh": MISSING}, expected=None, - msg="$sinh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$sinh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$sinh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$sinh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$sinh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$sinh": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$sinh of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$sinh": FLOAT_INFINITY}, expected=FLOAT_INFINITY, - msg="$sinh of double infinity", + msg="Should return Infinity for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$sinh": FLOAT_NEGATIVE_INFINITY}, expected=FLOAT_NEGATIVE_INFINITY, - msg="$sinh of double negative infinity", + msg="Should return -Infinity for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$sinh": DECIMAL128_INFINITY}, expected=DECIMAL128_INFINITY, - msg="$sinh of decimal128 infinity", + msg="Should return Decimal128 Infinity for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$sinh": DECIMAL128_NEGATIVE_INFINITY}, expected=DECIMAL128_NEGATIVE_INFINITY, - msg="$sinh of decimal128 negative infinity", + msg="Should return Decimal128 -Infinity for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$sinh": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=FLOAT_INFINITY, + msg="Should return Infinity for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$sinh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=DECIMAL128_INFINITY, + msg="Should return Decimal128 Infinity for Decimal128 Infinity read from a field", ), ExpressionTestCase( "single_element_array", - expression={"$sinh": [0.5]}, + expression={"$sinh": [DOUBLE_HALF]}, expected=0.5210953054937474, - msg="$sinh of single element array", + msg="Should return the double result for a single-element argument array", ), ] @pytest.mark.parametrize("test", pytest_params(SINH_BASIC_TESTS)) def test_sinh_basic(collection, test): - """Test $sinh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $sinh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py index 6dc00d5f6..0af0b9b99 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/sinh/test_sinh_errors.py @@ -1,7 +1,7 @@ """ -trigonometry $sinh tests. +$sinh errors. -Tests $sinh errors: argument count, and inputs outside the operator's range. +Tests that $sinh rejects a wrong argument count (16020) and non-numeric input (28765). """ import pytest @@ -11,31 +11,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) SINH_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$sinh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$sinh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$sinh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$sinh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$sinh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$sinh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$sinh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$sinh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(SINH_ERRORS_TESTS)) def test_sinh_errors(collection, test): - """Test $sinh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $sinh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py index ad790a9fa..4d1e625d4 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_basic.py @@ -1,25 +1,28 @@ """ -trigonometry $tan tests. +$tan results. -Tests $tan results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $tan results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and multiples of a quarter turn. Expected values are MongoDB's. """ import math import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_NAN, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_NAN, @@ -31,75 +34,123 @@ "int_one", expression={"$tan": 1}, expected=1.5574077246549023, - msg="$tan of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$tan": Int64(1)}, + expected=1.5574077246549023, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$tan": 0.5}, + expression={"$tan": DOUBLE_HALF}, expected=0.5463024898437905, - msg="$tan of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$tan": 2.0}, expected=-2.185039863261519, - msg="$tan of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$tan": Decimal128("0.5")}, + expression={"$tan": DECIMAL128_HALF}, expected=Decimal128("0.5463024898437905132551794657802854"), - msg="$tan of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$tan": Decimal128("-2")}, expected=Decimal128("2.185039863261518991643306102313683"), - msg="$tan of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$tan": DECIMAL128_ZERO}, + expected=Decimal128("0E-40"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$tan": DOUBLE_MAX}, expected=-0.004962015874444895, - msg="$tan of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$tan": None}, expected=None, - msg="$tan of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$tan": MISSING}, expected=None, - msg="$tan of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$tan": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$tan of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$tan": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$tan of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$tan": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$tan of negative zero", + msg="Should return -0.0 for -0.0", + ), + ExpressionTestCase( + "single_element_array", + expression={"$tan": [DOUBLE_HALF]}, + expected=0.5463024898437905, + msg="Should return the double result for a single-element argument array", + ), + ExpressionTestCase( + "half_pi", + expression={"$tan": math.pi / 2}, + expected=1.633123935319537e16, + msg="Should return the double result for a quarter-turn angle", + ), + ExpressionTestCase( + "pi", + expression={"$tan": math.pi}, + expected=-1.2246467991473532e-16, + msg="Should return the double result for a half-turn angle", + ), + ExpressionTestCase( + "three_halves_pi", + expression={"$tan": 3 * math.pi / 2}, + expected=5443746451065123.0, + msg="Should return the double result for a three-quarter-turn angle", + ), + ExpressionTestCase( + "two_pi", + expression={"$tan": 2 * math.pi}, + expected=-2.4492935982947064e-16, + msg="Should return the double result for a full-turn angle", + ), + ExpressionTestCase( + "decimal128_pi", + expression={"$tan": Decimal128("3.141592653589793238462643383279503")}, + expected=Decimal128("1.158028306006248941790250554076922E-34"), + msg="Should return the Decimal128 result for a Decimal128 half-turn angle", ), ] @pytest.mark.parametrize("test", pytest_params(TAN_BASIC_TESTS)) def test_tan_basic(collection, test): - """Test $tan values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $tan results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py index 914d78124..a80cbe607 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tan/test_tan_errors.py @@ -1,7 +1,8 @@ """ -trigonometry $tan tests. +$tan errors. -Tests $tan errors: argument count, and inputs outside the operator's range. +Tests that $tan rejects a wrong argument count (16020), non-numeric input (28765) and +out-of-range input (50989). """ import pytest @@ -11,16 +12,18 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.error_codes import ( EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, TRIG_INPUT_OUT_OF_RANGE_ERROR, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( DECIMAL128_INFINITY, DECIMAL128_NEGATIVE_INFINITY, + DOUBLE_HALF, FLOAT_INFINITY, FLOAT_NEGATIVE_INFINITY, ) @@ -30,45 +33,84 @@ "double_infinity", expression={"$tan": FLOAT_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$tan of double infinity should fail", + msg="Should reject double Infinity with error 50989", ), ExpressionTestCase( "double_negative_infinity", expression={"$tan": FLOAT_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$tan of double negative infinity should fail", + msg="Should reject double -Infinity with error 50989", ), ExpressionTestCase( "decimal128_infinity", expression={"$tan": DECIMAL128_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$tan of decimal128 infinity should fail", + msg="Should reject Decimal128 Infinity with error 50989", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$tan": DECIMAL128_NEGATIVE_INFINITY}, error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, - msg="$tan of decimal128 negative infinity should fail", + msg="Should reject Decimal128 -Infinity with error 50989", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$tan": "$v"}, + doc={"v": FLOAT_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject double Infinity read from a field with error 50989", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$tan": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + error_code=TRIG_INPUT_OUT_OF_RANGE_ERROR, + msg="Should reject Decimal128 Infinity read from a field with error 50989", ), ExpressionTestCase( "arity_zero_args", expression={"$tan": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$tan of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$tan": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$tan of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$tan": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$tan": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$tan": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$tan": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(TAN_ERRORS_TESTS)) def test_tan_errors(collection, test): - """Test $tan errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $tan errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py index 58a92ada9..3434091b6 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_basic.py @@ -1,27 +1,28 @@ """ -trigonometry $tanh tests. +$tanh results. -Tests $tanh results for numeric input types, special values (null, missing, NaN, --0.0, infinities where valid) and boundaries. Expected values are MongoDB's. +Tests $tanh results for int, long, double and Decimal128 input, null and missing input, +NaN, -0.0 and infinite input. Expected values are MongoDB's. """ -import math - import pytest -from bson import Decimal128 +from bson import Decimal128, Int64 from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( # noqa: E501 ExpressionTestCase, ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, ) from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_constants import ( + DECIMAL128_HALF, DECIMAL128_INFINITY, DECIMAL128_NAN, DECIMAL128_NEGATIVE_INFINITY, + DECIMAL128_ZERO, + DOUBLE_HALF, DOUBLE_MAX, DOUBLE_NEGATIVE_ZERO, FLOAT_INFINITY, @@ -35,99 +36,131 @@ "int_one", expression={"$tanh": 1}, expected=0.7615941559557649, - msg="$tanh of int one", + msg="Should return the double result for an int input", + ), + ExpressionTestCase( + "long_one", + expression={"$tanh": Int64(1)}, + expected=0.7615941559557649, + msg="Should return the double result for a long input", ), ExpressionTestCase( "double_half", - expression={"$tanh": 0.5}, + expression={"$tanh": DOUBLE_HALF}, expected=0.46211715726000974, - msg="$tanh of double half", + msg="Should return the double result for a double input", ), ExpressionTestCase( "double_two", expression={"$tanh": 2.0}, expected=0.9640275800758169, - msg="$tanh of double two", + msg="Should return the double result for a double input of 2", ), ExpressionTestCase( "decimal128_half", - expression={"$tanh": Decimal128("0.5")}, + expression={"$tanh": DECIMAL128_HALF}, expected=Decimal128("0.4621171572600097585023184836436726"), - msg="$tanh of decimal128 half", + msg="Should return the Decimal128 result for a Decimal128 input", ), ExpressionTestCase( "decimal128_negative_two", expression={"$tanh": Decimal128("-2")}, expected=Decimal128("-0.9640275800758168839464137241009232"), - msg="$tanh of decimal128 negative two", + msg="Should return the Decimal128 result for a Decimal128 input of -2", + ), + ExpressionTestCase( + "decimal128_zero", + expression={"$tanh": DECIMAL128_ZERO}, + expected=Decimal128("0"), + msg="Should return a Decimal128 zero for Decimal128 zero", ), ExpressionTestCase( "double_max", expression={"$tanh": DOUBLE_MAX}, expected=1.0, - msg="$tanh of double max", + msg="Should return the double result for the largest double", ), ExpressionTestCase( "null", expression={"$tanh": None}, expected=None, - msg="$tanh of null", + msg="Should return null for null input", ), ExpressionTestCase( "missing", expression={"$tanh": MISSING}, expected=None, - msg="$tanh of missing", + msg="Should return null for a missing field", ), ExpressionTestCase( "double_nan", expression={"$tanh": FLOAT_NAN}, - expected=pytest.approx(math.nan, nan_ok=True), - msg="$tanh of double nan", + expected=pytest.approx(FLOAT_NAN, nan_ok=True), + msg="Should return NaN for double NaN", ), ExpressionTestCase( "decimal128_nan", expression={"$tanh": DECIMAL128_NAN}, expected=DECIMAL128_NAN, - msg="$tanh of decimal128 nan", + msg="Should return Decimal128 NaN for Decimal128 NaN", ), ExpressionTestCase( "negative_zero", expression={"$tanh": DOUBLE_NEGATIVE_ZERO}, expected=-0.0, - msg="$tanh of negative zero", + msg="Should return -0.0 for -0.0", ), ExpressionTestCase( "double_infinity", expression={"$tanh": FLOAT_INFINITY}, expected=1.0, - msg="$tanh of double infinity", + msg="Should return the double result for double Infinity", ), ExpressionTestCase( "double_negative_infinity", expression={"$tanh": FLOAT_NEGATIVE_INFINITY}, expected=-1.0, - msg="$tanh of double negative infinity", + msg="Should return the double result for double -Infinity", ), ExpressionTestCase( "decimal128_infinity", expression={"$tanh": DECIMAL128_INFINITY}, expected=Decimal128("1"), - msg="$tanh of decimal128 infinity", + msg="Should return the Decimal128 result for Decimal128 Infinity", ), ExpressionTestCase( "decimal128_negative_infinity", expression={"$tanh": DECIMAL128_NEGATIVE_INFINITY}, expected=Decimal128("-1"), - msg="$tanh of decimal128 negative infinity", + msg="Should return the Decimal128 result for Decimal128 -Infinity", + ), + ExpressionTestCase( + "double_infinity_field", + expression={"$tanh": "$v"}, + doc={"v": FLOAT_INFINITY}, + expected=1.0, + msg="Should return the double result for double Infinity read from a field", + ), + ExpressionTestCase( + "decimal128_infinity_field", + expression={"$tanh": "$v"}, + doc={"v": DECIMAL128_INFINITY}, + expected=Decimal128("1"), + msg="Should return the Decimal128 result for Decimal128 Infinity read from a field", + ), + ExpressionTestCase( + "single_element_array", + expression={"$tanh": [DOUBLE_HALF]}, + expected=0.46211715726000974, + msg="Should return the double result for a single-element argument array", ), ] @pytest.mark.parametrize("test", pytest_params(TANH_BASIC_TESTS)) def test_tanh_basic(collection, test): - """Test $tanh values with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $tanh results for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg ) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py index 8b66d0c75..4776d6500 100644 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/trigonometry/tanh/test_tanh_errors.py @@ -1,7 +1,7 @@ """ -trigonometry $tanh tests. +$tanh errors. -Tests $tanh errors: argument count, and inputs outside the operator's range. +Tests that $tanh rejects a wrong argument count (16020) and non-numeric input (28765). """ import pytest @@ -11,31 +11,62 @@ ) from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( assert_expression_result, - execute_expression, + execute_expression_with_insert, +) +from documentdb_tests.framework.error_codes import ( + EXPRESSION_TYPE_MISMATCH_ERROR, + NON_NUMERIC_TYPE_MISMATCH_ERROR, ) -from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_constants import ( + DOUBLE_HALF, +) TANH_ERRORS_TESTS: list[ExpressionTestCase] = [ ExpressionTestCase( "arity_zero_args", expression={"$tanh": []}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$tanh of arity zero args should fail", + msg="Should reject an empty argument array with error 16020", ), ExpressionTestCase( "arity_two_args", expression={"$tanh": [1, 2]}, error_code=EXPRESSION_TYPE_MISMATCH_ERROR, - msg="$tanh of arity two args should fail", + msg="Should reject two arguments with error 16020", + ), + ExpressionTestCase( + "arity_three_args", + expression={"$tanh": [1, 2, 3]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject three arguments with error 16020", + ), + ExpressionTestCase( + "arity_two_nulls", + expression={"$tanh": [None, None]}, + error_code=EXPRESSION_TYPE_MISMATCH_ERROR, + msg="Should reject two null arguments with error 16020", + ), + ExpressionTestCase( + "nested_array_arg", + expression={"$tanh": [[DOUBLE_HALF]]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject an array argument inside the argument array with error 28765", + ), + ExpressionTestCase( + "array_field", + expression={"$tanh": "$v"}, + doc={"v": [DOUBLE_HALF]}, + error_code=NON_NUMERIC_TYPE_MISMATCH_ERROR, + msg="Should reject a field holding an array with error 28765", ), ] @pytest.mark.parametrize("test", pytest_params(TANH_ERRORS_TESTS)) def test_tanh_errors(collection, test): - """Test $tanh errors with literal arguments.""" - result = execute_expression(collection, test.expression) + """Test $tanh errors for literal and field-path arguments.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) assert_expression_result( result, expected=test.expected, error_code=test.error_code, msg=test.msg )