-
Notifications
You must be signed in to change notification settings - Fork 35
Add $ln, $log, and $log10 tests #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielfrankcom
wants to merge
6
commits into
documentdb:main
Choose a base branch
from
danielfrankcom:pr/log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bde80e0
Add $ln arithmetic expression tests
danielfrankcom 0baa02b
Add $log arithmetic expression tests
danielfrankcom e6085bc
Add $log10 arithmetic expression tests
danielfrankcom 2aa0603
Add __init__.py files
danielfrankcom 0801148
merge from upstream/main
danielfrankcom ad249a4
merge from upstream/main
danielfrankcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
158 changes: 158 additions & 0 deletions
158
...b_tests/compatibility/tests/core/operator/expressions/arithmetic/ln/test_ln_boundaries.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| """Tests for $ln at representable-range boundaries, including subnormal and extreme inputs.""" | ||
|
|
||
| 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_with_insert, | ||
| ) | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.test_constants import ( | ||
| DECIMAL128_MAX, | ||
| DECIMAL128_MIN_POSITIVE, | ||
| DECIMAL128_SMALL_EXPONENT, | ||
| DECIMAL128_TRAILING_ZERO, | ||
| DECIMAL128_ZERO, | ||
| DOUBLE_MAX_SAFE_INTEGER, | ||
| DOUBLE_MIN_SUBNORMAL, | ||
| DOUBLE_NEAR_MAX, | ||
| DOUBLE_NEAR_MIN, | ||
| DOUBLE_PRECISION_LOSS, | ||
| INT32_MAX, | ||
| INT32_MAX_MINUS_1, | ||
| INT64_MAX, | ||
| INT64_MAX_MINUS_1, | ||
| ) | ||
|
|
||
| # Property [Integer Boundaries]: $ln of the largest representable integers returns a finite double. | ||
| LN_INTEGER_BOUNDARY_TESTS: list[ExpressionTestCase] = [ | ||
| ExpressionTestCase( | ||
| "int32_max", | ||
| doc={"value": INT32_MAX}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(21.487562596892644), | ||
| msg="$ln should return the natural log of INT32_MAX", | ||
| ), | ||
| ExpressionTestCase( | ||
| "int32_max_minus_1", | ||
| doc={"value": INT32_MAX_MINUS_1}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(21.487562596426983), | ||
| msg="$ln should return the natural log of INT32_MAX minus one", | ||
| ), | ||
| ExpressionTestCase( | ||
| "int64_max", | ||
| doc={"value": INT64_MAX}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(43.66827237527655), | ||
| msg="$ln should return the natural log of INT64_MAX", | ||
| ), | ||
| ExpressionTestCase( | ||
| "int64_max_minus_1", | ||
| doc={"value": INT64_MAX_MINUS_1}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(43.66827237527655), | ||
| msg="$ln should return the natural log of INT64_MAX minus one", | ||
| ), | ||
| ] | ||
|
|
||
| # Property [Double Boundaries]: $ln at the double subnormal and near-limit range returns the | ||
| # expected large-magnitude values. | ||
| LN_DOUBLE_BOUNDARY_TESTS: list[ExpressionTestCase] = [ | ||
| ExpressionTestCase( | ||
| "double_min_subnormal", | ||
| doc={"value": DOUBLE_MIN_SUBNORMAL}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(-744.4400719213812), | ||
| msg="$ln should return a large negative value for the minimum subnormal double", | ||
| ), | ||
| ExpressionTestCase( | ||
| "double_near_min", | ||
| doc={"value": DOUBLE_NEAR_MIN}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(-709.1962086421661), | ||
| msg="$ln should return a large negative value for a near-zero positive double", | ||
| ), | ||
| ExpressionTestCase( | ||
| "double_near_max", | ||
| doc={"value": DOUBLE_NEAR_MAX}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(709.1962086421661), | ||
| msg="$ln should return a large positive value for a near-maximum double", | ||
| ), | ||
| ExpressionTestCase( | ||
| "double_max_safe_integer", | ||
| doc={"value": DOUBLE_MAX_SAFE_INTEGER}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(36.7368005696771), | ||
| msg="$ln should return the natural log of the maximum safe integer double", | ||
| ), | ||
| ExpressionTestCase( | ||
| "double_precision_loss", | ||
| doc={"value": DOUBLE_PRECISION_LOSS}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(36.7368005696771), | ||
| msg="$ln should return the same value as the maximum safe integer for the next " | ||
| "integer double, which is not representable", | ||
| ), | ||
| ExpressionTestCase( | ||
| "very_small_positive", | ||
| doc={"value": 1e-300}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=pytest.approx(-690.7755278982137), | ||
| msg="$ln should return a large negative value for a very small positive double", | ||
| ), | ||
| ] | ||
|
|
||
| # Property [Decimal128 Boundaries]: $ln of extreme decimal128 exponents returns a full-precision | ||
| # decimal128 result. | ||
| LN_DECIMAL_BOUNDARY_TESTS: list[ExpressionTestCase] = [ | ||
| ExpressionTestCase( | ||
| "decimal_small_exponent", | ||
| doc={"value": DECIMAL128_SMALL_EXPONENT}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=Decimal128("-14144.78022626242263692252150612605"), | ||
| msg="$ln should return a large negative decimal128 for a decimal128 with a small exponent", | ||
| ), | ||
| ExpressionTestCase( | ||
| "decimal_min_positive", | ||
| doc={"value": DECIMAL128_MIN_POSITIVE}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=Decimal128("-14220.76553433122614449511522413063"), | ||
| msg="$ln should return a large negative decimal128 for the smallest positive decimal128", | ||
| ), | ||
| ExpressionTestCase( | ||
| "decimal_max", | ||
| doc={"value": DECIMAL128_MAX}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=Decimal128("14149.38539644841072829055748903542"), | ||
| msg="$ln should return a large positive decimal128 for the maximum decimal128", | ||
| ), | ||
| ExpressionTestCase( | ||
| "decimal_trailing_zero", | ||
| doc={"value": DECIMAL128_TRAILING_ZERO}, | ||
| expression={"$ln": ["$value"]}, | ||
| expected=DECIMAL128_ZERO, | ||
| msg="$ln should return zero for a decimal128 one with a trailing zero", | ||
| ), | ||
| ] | ||
|
|
||
| LN_BOUNDARY_ALL_TESTS = ( | ||
| LN_INTEGER_BOUNDARY_TESTS + LN_DOUBLE_BOUNDARY_TESTS + LN_DECIMAL_BOUNDARY_TESTS | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test_case", pytest_params(LN_BOUNDARY_ALL_TESTS)) | ||
| def test_ln_boundaries(collection, test_case: ExpressionTestCase): | ||
| """Test $ln representable-range boundary cases.""" | ||
| result = execute_expression_with_insert(collection, test_case.expression, test_case.doc) | ||
| assert_expression_result( | ||
| result, | ||
| expected=test_case.expected, | ||
| error_code=test_case.error_code, | ||
| msg=test_case.msg, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.