Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
Tests for $lt argument handling.

Covers argument count variations and error cases.
"""

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 ( # noqa: E501
assert_expression_result,
execute_expression,
)
from documentdb_tests.framework.error_codes import EXPRESSION_TYPE_MISMATCH_ERROR
from documentdb_tests.framework.parametrize import pytest_params

LT_ARG_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"no_args",
expression={"$lt": []},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for empty arguments",
),
ExpressionTestCase(
"single_arg",
expression={"$lt": [1]},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for single argument",
),
ExpressionTestCase(
"non_array_arg",
expression={"$lt": 1},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for non-array argument",
),
ExpressionTestCase(
"non_array_string",
expression={"$lt": "string"},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for string argument",
),
ExpressionTestCase(
"non_array_field_ref",
expression={"$lt": "$field"},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for non-array field reference argument",
),
ExpressionTestCase(
"three_args",
expression={"$lt": [1, 2, 3]},
error_code=EXPRESSION_TYPE_MISMATCH_ERROR,
msg="Should error for three arguments",
),
ExpressionTestCase(
"two_args_lt",
expression={"$lt": [1, 2]},
expected=True,
msg="Should return true when first < second",
),
ExpressionTestCase(
"two_args_eq",
expression={"$lt": [1, 1]},
expected=False,
msg="Should return false when equal",
),
ExpressionTestCase(
"two_args_gt",
expression={"$lt": [2, 1]},
expected=False,
msg="Should return false when first > second",
),
]
Comment thread
vic-tsang marked this conversation as resolved.


@pytest.mark.parametrize("test", pytest_params(LT_ARG_TESTS))
def test_lt_argument_handling(collection, test):
"""Test $lt argument count variations."""
result = execute_expression(collection, test.expression)
assert_expression_result(
result, expected=test.expected, error_code=test.error_code, msg=test.msg
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
"""
Tests for $lt numeric boundaries and double precision.

Covers INT32/INT64 boundaries, double subnormals, and large number precision edge cases.
"""

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 ( # noqa: E501
assert_expression_result,
execute_expression,
)
from documentdb_tests.framework.parametrize import pytest_params
from documentdb_tests.framework.test_constants import (
DOUBLE_MIN_NEGATIVE_SUBNORMAL,
DOUBLE_MIN_SUBNORMAL,
DOUBLE_NEAR_MAX,
Comment thread
vic-tsang marked this conversation as resolved.
DOUBLE_NEAR_MIN,
INT32_MAX,
INT32_MIN,
INT64_MAX,
INT64_MIN,
)

INT32_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"int32_max_minus1_lt_max",
expression={"$lt": [INT32_MAX - 1, INT32_MAX]},
expected=True,
msg="INT32_MAX-1 < INT32_MAX",
),
ExpressionTestCase(
"int32_max_self",
expression={"$lt": [INT32_MAX, INT32_MAX]},
expected=False,
msg="INT32_MAX not < INT32_MAX",
),
ExpressionTestCase(
"int32_min_lt_min_plus1",
expression={"$lt": [INT32_MIN, INT32_MIN + 1]},
expected=True,
msg="INT32_MIN < INT32_MIN+1",
),
ExpressionTestCase(
"int32_min_self",
expression={"$lt": [INT32_MIN, INT32_MIN]},
expected=False,
msg="INT32_MIN not < INT32_MIN",
),
ExpressionTestCase(
"int32_max_lt_long_above",
expression={"$lt": [INT32_MAX, Int64(INT32_MAX + 1)]},
expected=True,
msg="int(INT32_MAX) < long(INT32_MAX+1)",
),
]


INT64_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"int64_max_minus1_lt_max",
expression={"$lt": [Int64(INT64_MAX - 1), INT64_MAX]},
expected=True,
msg="INT64_MAX-1 < INT64_MAX",
),
ExpressionTestCase(
"int64_max_self",
expression={"$lt": [INT64_MAX, INT64_MAX]},
expected=False,
msg="INT64_MAX not < INT64_MAX",
),
ExpressionTestCase(
"int64_min_lt_min_plus1",
expression={"$lt": [INT64_MIN, Int64(INT64_MIN + 1)]},
expected=True,
msg="INT64_MIN < INT64_MIN+1",
),
ExpressionTestCase(
"int64_min_self",
expression={"$lt": [INT64_MIN, INT64_MIN]},
expected=False,
msg="INT64_MIN not < INT64_MIN",
),
]

DOUBLE_PRECISION_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"near_max_self",
expression={"$lt": [DOUBLE_NEAR_MAX, DOUBLE_NEAR_MAX]},
expected=False,
msg="DOUBLE_NEAR_MAX not < itself",
),
ExpressionTestCase(
"zero_lt_subnormal",
expression={"$lt": [0.0, DOUBLE_MIN_SUBNORMAL]},
expected=True,
msg="0.0 < min subnormal",
),
ExpressionTestCase(
"subnormal_lt_zero",
expression={"$lt": [DOUBLE_MIN_SUBNORMAL, 0.0]},
expected=False,
msg="min subnormal not < 0.0",
),
ExpressionTestCase(
"neg_subnormal_lt_zero",
expression={"$lt": [DOUBLE_MIN_NEGATIVE_SUBNORMAL, 0.0]},
expected=True,
msg="neg subnormal < 0.0",
),
ExpressionTestCase(
"zero_lt_neg_subnormal",
expression={"$lt": [0.0, DOUBLE_MIN_NEGATIVE_SUBNORMAL]},
expected=False,
msg="0.0 not < neg subnormal",
),
ExpressionTestCase(
"near_min_lt_near_max",
expression={"$lt": [DOUBLE_NEAR_MIN, DOUBLE_NEAR_MAX]},
expected=True,
msg="DOUBLE_NEAR_MIN < DOUBLE_NEAR_MAX",
),
]


LARGE_NUMBER_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"int64_beyond_double_precision",
expression={"$lt": [Int64(9007199254740992), Int64(9007199254740993)]},
expected=True,
msg="int64 beyond double precision",
),
ExpressionTestCase(
"dec_34_digit",
expression={
"$lt": [
Decimal128("9999999999999999999999999999999998"),
Decimal128("9999999999999999999999999999999999"),
]
},
expected=True,
msg="34-digit decimal comparison",
),
ExpressionTestCase(
"int64_max_vs_double_int64_max",
expression={"$lt": [INT64_MAX, float(INT64_MAX)]},
expected=True,
msg="INT64_MAX < double(INT64_MAX) due to precision loss rounding up",
),
]


ALL_TESTS = INT32_TESTS + INT64_TESTS + DOUBLE_PRECISION_TESTS + LARGE_NUMBER_TESTS


@pytest.mark.parametrize("test", pytest_params(ALL_TESTS))
def test_lt_boundary_precision(collection, test):
"""Test $lt numeric boundaries and double precision."""
result = execute_expression(collection, test.expression)
assert_expression_result(result, expected=test.expected, msg=test.msg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Representative BSON comparison engine wiring tests for $lt.

A small sample of cross-type and special value comparisons to confirm $lt
delegates to the BSON comparison engine correctly. Not an exhaustive matrix —
full BSON ordering coverage lives in /core/data_types/bson_types/.
"""

import pytest
from bson import Decimal128, Int64, MaxKey, MinKey

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 ( # noqa: E501
assert_expression_result,
execute_expression,
)
from documentdb_tests.framework.parametrize import pytest_params
from documentdb_tests.framework.test_constants import DOUBLE_NEGATIVE_ZERO, FLOAT_NAN

BSON_WIRING_TESTS: list[ExpressionTestCase] = [
ExpressionTestCase(
"number_lt_string", expression={"$lt": [1, "a"]}, expected=True, msg="number < string"
),
ExpressionTestCase(
"string_not_lt_number",
expression={"$lt": ["a", 1]},
expected=False,
msg="string not < number",
),
ExpressionTestCase(
"minkey_lt_number", expression={"$lt": [MinKey(), 1]}, expected=True, msg="MinKey < number"
),
ExpressionTestCase(
"maxkey_not_lt_number",
expression={"$lt": [MaxKey(), 1]},
expected=False,
msg="MaxKey not < number",
),
ExpressionTestCase(
"int_not_lt_equivalent_long",
expression={"$lt": [1, Int64(1)]},
expected=False,
msg="int(1) not < long(1)",
),
ExpressionTestCase(
"int_not_lt_equivalent_decimal",
expression={"$lt": [1, Decimal128("1")]},
expected=False,
msg="int(1) not < decimal(1)",
),
ExpressionTestCase(
"neg_zero_not_lt_zero",
expression={"$lt": [DOUBLE_NEGATIVE_ZERO, 0.0]},
expected=False,
msg="-0.0 not < 0.0",
),
ExpressionTestCase(
"nan_not_lt_nan",
expression={"$lt": [FLOAT_NAN, FLOAT_NAN]},
expected=False,
msg="NaN not < NaN (equal)",
),
ExpressionTestCase(
"nan_lt_zero", expression={"$lt": [FLOAT_NAN, 0]}, expected=True, msg="NaN < 0"
),
]


@pytest.mark.parametrize("test", pytest_params(BSON_WIRING_TESTS))
def test_lt_bson_wiring(collection, test):
"""Smoke test: confirm $lt is wired to the BSON comparison engine."""
result = execute_expression(collection, test.expression)
assert_expression_result(result, expected=test.expected, msg=test.msg)
Loading
Loading