summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2024-12-18 06:50:48 -0500
committerGitHub <noreply@github.com>2024-12-18 08:50:48 -0300
commitbb6114ce5094eca25c52a7a1a56156d512cba065 (patch)
tree1cf61bcbcbc375970c4e9a30d43364dcc506cb18 /tests
parent20f9f6180531279785ceabed6ab2f29ab634d8dc (diff)
Added DatabaseFeatures.rounds_to_even.
This feature flag useful with MongoDB: "Rounding to the nearest even value supports more even distribution of rounded data than always rounding up or down."
Diffstat (limited to 'tests')
-rw-r--r--tests/db_functions/comparison/test_cast.py3
-rw-r--r--tests/db_functions/math/test_round.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/tests/db_functions/comparison/test_cast.py b/tests/db_functions/comparison/test_cast.py
index 80375cc389..49cabdbd21 100644
--- a/tests/db_functions/comparison/test_cast.py
+++ b/tests/db_functions/comparison/test_cast.py
@@ -52,7 +52,8 @@ class CastTests(TestCase):
),
).get()
self.assertEqual(float_obj.cast_f1_decimal, decimal.Decimal("-1.93"))
- self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal("3.5"))
+ expected = "3.4" if connection.features.rounds_to_even else "3.5"
+ self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal(expected))
author_obj = Author.objects.annotate(
cast_alias_decimal=Cast(
"alias", models.DecimalField(max_digits=8, decimal_places=2)
diff --git a/tests/db_functions/math/test_round.py b/tests/db_functions/math/test_round.py
index 04ece4246d..c110dc71ca 100644
--- a/tests/db_functions/math/test_round.py
+++ b/tests/db_functions/math/test_round.py
@@ -112,7 +112,8 @@ class RoundTests(TestCase):
IntegerModel.objects.create(normal=365)
obj = IntegerModel.objects.annotate(normal_round=Round("normal", -1)).first()
self.assertIsInstance(obj.normal_round, int)
- self.assertEqual(obj.normal_round, 370)
+ expected = 360 if connection.features.rounds_to_even else 370
+ self.assertEqual(obj.normal_round, expected)
def test_transform(self):
with register_lookup(DecimalField, Round):