diff options
| author | Junyi Jiao <jiaojunyi90@gmail.com> | 2018-07-05 11:02:12 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-07-05 11:02:12 -0400 |
| commit | a0b19a0f5b1731cf575546175034da53f5af5367 (patch) | |
| tree | 912f6367180636e4c9e1aecc4045830046a70ea6 /tests/db_functions/math/test_atan2.py | |
| parent | 48aeca44d885929106e71fe78379fe50850af001 (diff) | |
Refs #28643 -- Added math database functions.
Thanks Nick Pope for much review.
Diffstat (limited to 'tests/db_functions/math/test_atan2.py')
| -rw-r--r-- | tests/db_functions/math/test_atan2.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/db_functions/math/test_atan2.py b/tests/db_functions/math/test_atan2.py new file mode 100644 index 0000000000..195892dfdd --- /dev/null +++ b/tests/db_functions/math/test_atan2.py @@ -0,0 +1,33 @@ +import math +from decimal import Decimal + +from django.db.models.functions import ATan2 +from django.test import TestCase + +from ..models import DecimalModel, FloatModel, IntegerModel + + +class ATan2Tests(TestCase): + + def test_decimal(self): + DecimalModel.objects.create(n1=Decimal('-9.9'), n2=Decimal('4.6')) + obj = DecimalModel.objects.annotate(n_atan2=ATan2('n1', 'n2')).first() + self.assertIsInstance(obj.n_atan2, Decimal) + self.assertAlmostEqual(obj.n_atan2, Decimal(math.atan2(obj.n1, obj.n2))) + + def test_float(self): + FloatModel.objects.create(f1=-25, f2=0.33) + obj = FloatModel.objects.annotate(f_atan2=ATan2('f1', 'f2')).first() + self.assertIsInstance(obj.f_atan2, float) + self.assertAlmostEqual(obj.f_atan2, math.atan2(obj.f1, obj.f2)) + + def test_integer(self): + IntegerModel.objects.create(small=0, normal=1, big=10) + obj = IntegerModel.objects.annotate( + atan2_sn=ATan2('small', 'normal'), + atan2_nb=ATan2('normal', 'big'), + ).first() + self.assertIsInstance(obj.atan2_sn, float) + self.assertIsInstance(obj.atan2_nb, float) + self.assertAlmostEqual(obj.atan2_sn, math.atan2(obj.small, obj.normal)) + self.assertAlmostEqual(obj.atan2_nb, math.atan2(obj.normal, obj.big)) |
