From b1c377335064b92a55881b8762e31a27e5fe31d8 Mon Sep 17 00:00:00 2001 From: krishnasai453 Date: Tue, 23 Jun 2026 23:11:09 -0400 Subject: [PATCH 1/4] Phase 3: Added implementation plan and details of implementation --- .../bitwise/bitAnd/test_expression_bitAnd.py | 81 +++++++++++++++ ...est_expression_bitAnd_testing_strategy.txt | 99 +++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py new file mode 100644 index 000000000..909c46580 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py @@ -0,0 +1,81 @@ +""" +Tests for $bitAnd expression type smoke tests. + +Covers literal, field reference, and nested expression operator inputs. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( + 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 + + +LITERAL_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "literal_bit_and", + expression={"$bitAnd": [5, 3]}, + expected=1, + msg="$bitAnd of two literals should compute the bitwise AND result", + ), + ExpressionTestCase( + "literal_bit_and_with_zero", + expression={"$bitAnd": [0, 7]}, + expected=0, + msg="$bitAnd with zero should produce zero", + ), +] + +FIELD_REFERENCE_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "field_reference_bit_and", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 5, "b": 3}, + expected=1, + msg="$bitAnd should compute the bitwise AND of two field values", + ), + ExpressionTestCase( + "field_reference_bit_and_secondary", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 12, "b": 10}, + expected=8, + msg="$bitAnd should compute the bitwise AND for other field values", + ), +] + +EXPRESSION_OPERATOR_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "nested_expression_bit_and", + expression={ + "$bitAnd": [ + {"$add": ["$a", 1]}, + {"$subtract": ["$b", 1]}, + ] + }, + doc={"a": 4, "b": 6}, + expected=5, + msg="$bitAnd should accept nested expression operator inputs", + ), +] + +ALL_INSERT_TESTS = FIELD_REFERENCE_TESTS + EXPRESSION_OPERATOR_TESTS + + +@pytest.mark.parametrize("test", pytest_params(LITERAL_TESTS)) +def test_bitAnd_expression_types_literal(collection, test): + """Test $bitAnd with literal expression inputs.""" + result = execute_expression(collection, test.expression) + assert_expression_result(result, expected=test.expected, msg=test.msg) + + +@pytest.mark.parametrize("test", pytest_params(ALL_INSERT_TESTS)) +def test_bitAnd_expression_types_insert(collection, test): + """Test $bitAnd with field reference and nested expression inputs.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) + assert_expression_result(result, expected=test.expected, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt new file mode 100644 index 000000000..2e9e5d735 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt @@ -0,0 +1,99 @@ +""" +Tests for $bitAnd expression type smoke tests. + +Covers literal, field reference, expression operator, array expression, +and object expression. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( + 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 + + +LITERAL_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "literal_zero_and", + expression={"$bitAnd": [5, 3]}, + expected=1, + msg="$bitAnd of two literals should compute bitwise AND", + ), + ExpressionTestCase( + "literal_all_zero", + expression={"$bitAnd": [0, 7]}, + expected=0, + msg="$bitAnd with zero should produce zero", + ), +] + +FIELD_REFERENCE_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "field_refs", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 5, "b": 3}, + expected=1, + msg="$bitAnd should compute bitwise AND of two field values", + ), + ExpressionTestCase( + "field_refs_negative", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 12, "b": 10}, + expected=8, + msg="$bitAnd should compute bitwise AND for other field values", + ), +] + +EXPRESSION_OPERATOR_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "nested_expression", + expression={"$bitAnd": [{"$add": [4, 1]}, {"$subtract": [6, 1]}]}, + expected=5, + msg="$bitAnd should accept nested expression operator inputs", + ), +] + +ARRAY_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "array_expression", + expression={"$bitAnd": [["$a", "$b"], 3]}, + doc={"a": 1, "b": 3}, + expected=1, + msg="$bitAnd should accept an array expression as first operand", + ), +] + +OBJECT_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "object_expression", + expression={"$bitAnd": [{"x": "$a", "y": "$b"}, 0]}, + doc={"a": 1, "b": 3}, + expected=0, + msg="$bitAnd should accept an object expression as an input", + ), +] + +ALL_INSERT_TESTS = ( + FIELD_REFERENCE_TESTS + + EXPRESSION_OPERATOR_TESTS + + ARRAY_EXPRESSION_TESTS + + OBJECT_EXPRESSION_TESTS +) + + +@pytest.mark.parametrize("test", pytest_params(LITERAL_TESTS)) +def test_bitAnd_expression_types_literal(collection, test): + result = execute_expression(collection, test.expression) + assert_expression_result(result, expected=test.expected, msg=test.msg) + + +@pytest.mark.parametrize("test", pytest_params(ALL_INSERT_TESTS)) +def test_bitAnd_expression_types_insert(collection, test): + result = execute_expression_with_insert(collection, test.expression, test.doc) + assert_expression_result(result, expected=test.expected, msg=test.msg) \ No newline at end of file From f21c5f77a78d24e59e41862f58f2a957c467aa53 Mon Sep 17 00:00:00 2001 From: krishnasai453 Date: Tue, 23 Jun 2026 23:11:09 -0400 Subject: [PATCH 2/4] Phase 3: Added implementation plan and details of implementation --- .../bitwise/bitAnd/test_expression_bitAnd.py | 81 +++++++++++++++ ...est_expression_bitAnd_testing_strategy.txt | 99 +++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py new file mode 100644 index 000000000..909c46580 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd.py @@ -0,0 +1,81 @@ +""" +Tests for $bitAnd expression type smoke tests. + +Covers literal, field reference, and nested expression operator inputs. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( + 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 + + +LITERAL_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "literal_bit_and", + expression={"$bitAnd": [5, 3]}, + expected=1, + msg="$bitAnd of two literals should compute the bitwise AND result", + ), + ExpressionTestCase( + "literal_bit_and_with_zero", + expression={"$bitAnd": [0, 7]}, + expected=0, + msg="$bitAnd with zero should produce zero", + ), +] + +FIELD_REFERENCE_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "field_reference_bit_and", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 5, "b": 3}, + expected=1, + msg="$bitAnd should compute the bitwise AND of two field values", + ), + ExpressionTestCase( + "field_reference_bit_and_secondary", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 12, "b": 10}, + expected=8, + msg="$bitAnd should compute the bitwise AND for other field values", + ), +] + +EXPRESSION_OPERATOR_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "nested_expression_bit_and", + expression={ + "$bitAnd": [ + {"$add": ["$a", 1]}, + {"$subtract": ["$b", 1]}, + ] + }, + doc={"a": 4, "b": 6}, + expected=5, + msg="$bitAnd should accept nested expression operator inputs", + ), +] + +ALL_INSERT_TESTS = FIELD_REFERENCE_TESTS + EXPRESSION_OPERATOR_TESTS + + +@pytest.mark.parametrize("test", pytest_params(LITERAL_TESTS)) +def test_bitAnd_expression_types_literal(collection, test): + """Test $bitAnd with literal expression inputs.""" + result = execute_expression(collection, test.expression) + assert_expression_result(result, expected=test.expected, msg=test.msg) + + +@pytest.mark.parametrize("test", pytest_params(ALL_INSERT_TESTS)) +def test_bitAnd_expression_types_insert(collection, test): + """Test $bitAnd with field reference and nested expression inputs.""" + result = execute_expression_with_insert(collection, test.expression, test.doc) + assert_expression_result(result, expected=test.expected, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt new file mode 100644 index 000000000..2e9e5d735 --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt @@ -0,0 +1,99 @@ +""" +Tests for $bitAnd expression type smoke tests. + +Covers literal, field reference, expression operator, array expression, +and object expression. +""" + +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( + 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 + + +LITERAL_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "literal_zero_and", + expression={"$bitAnd": [5, 3]}, + expected=1, + msg="$bitAnd of two literals should compute bitwise AND", + ), + ExpressionTestCase( + "literal_all_zero", + expression={"$bitAnd": [0, 7]}, + expected=0, + msg="$bitAnd with zero should produce zero", + ), +] + +FIELD_REFERENCE_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "field_refs", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 5, "b": 3}, + expected=1, + msg="$bitAnd should compute bitwise AND of two field values", + ), + ExpressionTestCase( + "field_refs_negative", + expression={"$bitAnd": ["$a", "$b"]}, + doc={"a": 12, "b": 10}, + expected=8, + msg="$bitAnd should compute bitwise AND for other field values", + ), +] + +EXPRESSION_OPERATOR_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "nested_expression", + expression={"$bitAnd": [{"$add": [4, 1]}, {"$subtract": [6, 1]}]}, + expected=5, + msg="$bitAnd should accept nested expression operator inputs", + ), +] + +ARRAY_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "array_expression", + expression={"$bitAnd": [["$a", "$b"], 3]}, + doc={"a": 1, "b": 3}, + expected=1, + msg="$bitAnd should accept an array expression as first operand", + ), +] + +OBJECT_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "object_expression", + expression={"$bitAnd": [{"x": "$a", "y": "$b"}, 0]}, + doc={"a": 1, "b": 3}, + expected=0, + msg="$bitAnd should accept an object expression as an input", + ), +] + +ALL_INSERT_TESTS = ( + FIELD_REFERENCE_TESTS + + EXPRESSION_OPERATOR_TESTS + + ARRAY_EXPRESSION_TESTS + + OBJECT_EXPRESSION_TESTS +) + + +@pytest.mark.parametrize("test", pytest_params(LITERAL_TESTS)) +def test_bitAnd_expression_types_literal(collection, test): + result = execute_expression(collection, test.expression) + assert_expression_result(result, expected=test.expected, msg=test.msg) + + +@pytest.mark.parametrize("test", pytest_params(ALL_INSERT_TESTS)) +def test_bitAnd_expression_types_insert(collection, test): + result = execute_expression_with_insert(collection, test.expression, test.doc) + assert_expression_result(result, expected=test.expected, msg=test.msg) \ No newline at end of file From abce1dbcf1e44e886f169aa9b4eb3598eba3f426 Mon Sep 17 00:00:00 2001 From: krishnasai453 Date: Tue, 30 Jun 2026 23:30:12 -0400 Subject: [PATCH 3/4] added complete fix for bitAnd operator --- .../test_expression_bitAnd_additional.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_additional.py diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_additional.py b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_additional.py new file mode 100644 index 000000000..d5538705b --- /dev/null +++ b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_additional.py @@ -0,0 +1,45 @@ +import pytest + +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( + ExpressionTestCase, +) +from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( + assert_expression_result, + execute_expression_with_insert, +) +from documentdb_tests.framework.parametrize import pytest_params + +from documentdb_tests.framework.error_codes import TYPE_MISMATCH_ERROR + +# Array expression tests: $bitAnd where the first operand is an array expression +ARRAY_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "array_expression", + expression={"$bitAnd": [["$a", "$b"], 3]}, + doc={"a": 1, "b": 3}, + error_code=TYPE_MISMATCH_ERROR, + msg="$bitAnd should reject an array expression as first operand", + ), +] + +# Object expression tests: $bitAnd where the first operand is an object expression +OBJECT_EXPRESSION_TESTS: list[ExpressionTestCase] = [ + ExpressionTestCase( + "object_expression", + expression={"$bitAnd": [{"x": "$a", "y": "$b"}, 0]}, + doc={"a": 1, "b": 3}, + error_code=TYPE_MISMATCH_ERROR, + msg="$bitAnd should reject an object expression as an input", + ), +] + +ALL_ADDITIONAL_TESTS = ARRAY_EXPRESSION_TESTS + OBJECT_EXPRESSION_TESTS + + +@pytest.mark.parametrize("test", pytest_params(ALL_ADDITIONAL_TESTS)) +def test_bitAnd_expression_additional(collection, test): + """Test $bitAnd with array and object expression inputs.""" + 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 + ) From 7b6b7b17b19f5a6cfa0520a27619549d410589aa Mon Sep 17 00:00:00 2001 From: krishnasai453 Date: Tue, 30 Jun 2026 23:36:38 -0400 Subject: [PATCH 4/4] removed the strategy text --- ...est_expression_bitAnd_testing_strategy.txt | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt diff --git a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt b/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt deleted file mode 100644 index 2e9e5d735..000000000 --- a/documentdb_tests/compatibility/tests/core/operator/expressions/bitwise/bitAnd/test_expression_bitAnd_testing_strategy.txt +++ /dev/null @@ -1,99 +0,0 @@ -""" -Tests for $bitAnd expression type smoke tests. - -Covers literal, field reference, expression operator, array expression, -and object expression. -""" - -import pytest - -from documentdb_tests.compatibility.tests.core.operator.expressions.utils.expression_test_case import ( - 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 - - -LITERAL_TESTS: list[ExpressionTestCase] = [ - ExpressionTestCase( - "literal_zero_and", - expression={"$bitAnd": [5, 3]}, - expected=1, - msg="$bitAnd of two literals should compute bitwise AND", - ), - ExpressionTestCase( - "literal_all_zero", - expression={"$bitAnd": [0, 7]}, - expected=0, - msg="$bitAnd with zero should produce zero", - ), -] - -FIELD_REFERENCE_TESTS: list[ExpressionTestCase] = [ - ExpressionTestCase( - "field_refs", - expression={"$bitAnd": ["$a", "$b"]}, - doc={"a": 5, "b": 3}, - expected=1, - msg="$bitAnd should compute bitwise AND of two field values", - ), - ExpressionTestCase( - "field_refs_negative", - expression={"$bitAnd": ["$a", "$b"]}, - doc={"a": 12, "b": 10}, - expected=8, - msg="$bitAnd should compute bitwise AND for other field values", - ), -] - -EXPRESSION_OPERATOR_TESTS: list[ExpressionTestCase] = [ - ExpressionTestCase( - "nested_expression", - expression={"$bitAnd": [{"$add": [4, 1]}, {"$subtract": [6, 1]}]}, - expected=5, - msg="$bitAnd should accept nested expression operator inputs", - ), -] - -ARRAY_EXPRESSION_TESTS: list[ExpressionTestCase] = [ - ExpressionTestCase( - "array_expression", - expression={"$bitAnd": [["$a", "$b"], 3]}, - doc={"a": 1, "b": 3}, - expected=1, - msg="$bitAnd should accept an array expression as first operand", - ), -] - -OBJECT_EXPRESSION_TESTS: list[ExpressionTestCase] = [ - ExpressionTestCase( - "object_expression", - expression={"$bitAnd": [{"x": "$a", "y": "$b"}, 0]}, - doc={"a": 1, "b": 3}, - expected=0, - msg="$bitAnd should accept an object expression as an input", - ), -] - -ALL_INSERT_TESTS = ( - FIELD_REFERENCE_TESTS - + EXPRESSION_OPERATOR_TESTS - + ARRAY_EXPRESSION_TESTS - + OBJECT_EXPRESSION_TESTS -) - - -@pytest.mark.parametrize("test", pytest_params(LITERAL_TESTS)) -def test_bitAnd_expression_types_literal(collection, test): - result = execute_expression(collection, test.expression) - assert_expression_result(result, expected=test.expected, msg=test.msg) - - -@pytest.mark.parametrize("test", pytest_params(ALL_INSERT_TESTS)) -def test_bitAnd_expression_types_insert(collection, test): - result = execute_expression_with_insert(collection, test.expression, test.doc) - assert_expression_result(result, expected=test.expected, msg=test.msg) \ No newline at end of file