Add $toInt, $toDouble, $toLong, $toDecimal tests#684
Conversation
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…-tests Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…-tests Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…-tests Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…ed magic number with constants Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Migrates tests from old_tests/ to documentdb_tests/compatibility/ tests/core/operator/expressions/type/toLong/ following the migration harness. Files added: - __init__.py - test_smoke_toLong.py (was already present) - test_toLong_arity.py (arity + invalid field path) - test_toLong_numeric.py (null/missing, bool, int32, int64, double) - test_toLong_decimal128.py (Decimal128 truncation and overflow) - test_toLong_datetime_binary.py (datetime, binary, unsupported types) - test_toLong_string.py (string conversion + size limit) - test_toLong_return_type.py (return type invariant + idempotency) - test_toLong_field_ref.py (field references + expression input) Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…idator - Add generate_bson_rejection_test_cases() to test_toLong_return_type.py for ObjectId, Regex, Timestamp, JavaScript/Code, MinKey, MaxKey types - Skip NULL (returns null, not error), OBJECT and ARRAY (need $literal wrapping) from generated rejection — keep hand-written cases for those - Remove the six now-redundant hand-written ExpressionTestCase rejection entries from test_toLong_datetime_binary.py - Drop unused bson imports (Code, MaxKey, MinKey, ObjectId, Regex, Timestamp) Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Add two cases missing from the new test suite vs the old: 1. type_code_with_scope: CodeWithScope (BSON 0x0f) is a distinct type from JavaScript/Code (0x0d) and is not covered by bson_type_validator samples. Verified it produces CONVERSION_FAILURE_ERROR like plain Code. 2. type_nested_array: $toLong([[\x22 42\x22]]) — the outer single-element literal array is unwrapped at parse time, leaving the inner [\x2242\x22] (a runtime array) as the actual argument, which is a conversion failure. Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Replace three bare numeric literals flagged by find_numerical_constant_replacements.py: - 0 (int32) -> INT32_ZERO - 0.5 -> DOUBLE_HALF - -0.5 -> DOUBLE_NEGATIVE_HALF Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
…nstants
framework/test_constants.py:
- Add INT64_FROM_DOUBLE_MAX_FITTING = Int64(9223372036854774784)
(int64 truncation of DOUBLE_MAX_FITTING_INT64)
- Add DOUBLE_BELOW_INT64_MIN = math.nextafter(-float(2**63), float('-inf'))
(first IEEE 754 double strictly below int64 min)
- Add 'import math' for the above
test_toLong_numeric.py:
- Replace inline Int64(9223372036854774784) with INT64_FROM_DOUBLE_MAX_FITTING
- Replace math.nextafter(...) expression with DOUBLE_BELOW_INT64_MIN
- Drop now-redundant 'import math'
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Restore math.nextafter(-float(2**63), FLOAT_NEGATIVE_INFINITY) inline in test_toLong_numeric.py and remove the constant (and import math) that were added to test_constants.py in the previous commit. Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
| ) | ||
|
|
||
| # Property [Datetime]: $toDecimal converts datetime to milliseconds since Unix epoch as Decimal128. | ||
| _TODECIMAL_DATETIME_TESTS: list[ExpressionTestCase] = [ |
There was a problem hiding this comment.
Nit: different files have inconsistent use of underscore prefixed internal constants vs normal constants. Would be good to be consistent both internally, and with established pattern from other operators.
There was a problem hiding this comment.
Removed underscores on test list constants, should now be consistent usage
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, test-framework); effort from diff stats (5654+0 LOC, 36 files); LLM: Adds compatibility test coverage for four type conversion aggregation operators ($toInt, $toDouble, $toLong, $toDecimal), expanding test suite for tracked issues. If a label is wrong, remove it manually and ping |
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
This PR adds the tests for $toInt, $toDouble, $toLong, and $toDecimal. It was originally authored by @danielfrankcom.
Ref: Issue #15, #328, #327, #329, #326