File: test_angle.py

package info (click to toggle)
pymeeus 0.4.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,856 kB
  • sloc: python: 42,407; makefile: 15; sh: 11
file content (757 lines) | stat: -rw-r--r-- 21,435 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# -*- coding: utf-8 -*-


# PyMeeus: Python module implementing astronomical algorithms.
# Copyright (C) 2018  Dagoberto Salazar
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.


from math import pi

from pymeeus.base import TOL
from pymeeus.Angle import Angle


# Angle class

def test_angle_constructor():
    """Tests the constructor of Angle class"""

    a = Angle(23.44694444)
    assert abs(a._deg - 23.44694444) < TOL, \
        "ERROR: 1st constructor test, degrees value doesn't match"

    b = Angle(-23.44694444)
    assert abs(b._deg - (-23.44694444)) < TOL, \
        "ERROR: 2nd constructor test, degrees value doesn't match"

    c = Angle(383.44694444)
    assert abs(c._deg - 23.44694444) < TOL, \
        "ERROR: 3rd constructor test, degrees value doesn't match"

    d = Angle(-383.44694444)
    assert abs(d._deg - (-23.44694444)) < TOL, \
        "ERROR: 4th constructor test, degrees value doesn't match"

    e = Angle(-23.0, 26.0, 48.999983999)
    assert abs(e._deg - (-23.44694444)) < TOL, \
        "ERROR: 5th constructor test, degrees value doesn't match"

    f = Angle(23.0, -30.0)
    assert abs(f._deg - (-23.5)) < TOL, \
        "ERROR: 6th constructor test, degrees value doesn't match"

    g = Angle((-23.0, 26.0, 48.999983999))
    assert abs(g._deg - (-23.44694444)) < TOL, \
        "ERROR: 7th constructor test, degrees value doesn't match"

    h = Angle([-23.0, 26.0, 48.999983999])
    assert abs(h._deg - (-23.44694444)) < TOL, \
        "ERROR: 8th constructor test, degrees value doesn't match"

    i = Angle(1.0, radians=True)
    assert abs(i._deg - 57.29577951308232) < TOL, \
        "ERROR: 9th constructor test, degrees value doesn't match"

    j = Angle((23.0, 26.0, 48.999983999, -1.0))
    assert abs(j._deg - (-23.44694444)) < TOL, \
        "ERROR: 10th constructor test, degrees value doesn't match"

    k = Angle(23.0, 26.0, 48.999983999, -7.4)
    assert abs(k._deg - (-23.44694444)) < TOL, \
        "ERROR: 11th constructor test, degrees value doesn't match"

    m = Angle([23.0, -26.0, 48.999983999, -4.5])
    assert abs(m._deg - (-23.44694444)) < TOL, \
        "ERROR: 12th constructor test, degrees value doesn't match"


def test_angle_set_radians():
    """Tests the set_radians() method of Angle class"""

    a = Angle()

    a.set_radians(pi)                               # Input is in radians
    assert abs(a() - 180.0) < TOL, \
        "ERROR: 1st set_radians() test, degrees value doesn't match"


def test_angle_set_ra():
    """Tests the set_ra() method of Angle class"""

    a = Angle()

    a.set_ra(9.248833333333)                        # Input is in RA
    assert abs(a._deg - 138.7325) < TOL, \
        "ERROR: 1st set_ra() test, degrees value doesn't match"

    a.set_ra(-9.248833333333)
    assert abs(a._deg - (-138.7325)) < TOL, \
        "ERROR: 2nd set_ra() test, degrees value doesn't match"

    a.set_ra(9, 14, 55.8)
    assert abs(a._deg - 138.7325) < TOL, \
        "ERROR: 3rd set_ra() test, degrees value doesn't match"

    a.set_ra((9, 14, 55.8, -1.0))
    assert abs(a._deg - (-138.7325)) < TOL, \
        "ERROR: 4th set_ra() test, degrees value doesn't match"


def test_angle_deg2dms():
    """Tests deg2dms() static method of Angle class"""

    (d, m, s, sign) = Angle.deg2dms(23.44694444)
    assert abs(d - 23.0) < TOL, \
        "ERROR: In 1st deg2dms() test, degrees value doesn't match"
    assert abs(m - 26.0) < TOL, \
        "ERROR: In 1st deg2dms() test, minutes value doesn't match"
    assert abs(s - 48.9999839999999) < TOL, \
        "ERROR: In 1st deg2dms() test, seconds value doesn't match"
    assert abs(sign - 1.0) < TOL, \
        "ERROR: In 1st deg2dms() test, sign value doesn't match"

    (d, m, s, sign) = Angle.deg2dms(-23.44694444)
    assert abs(d - 23.0) < TOL, \
        "ERROR: In 2nd deg2dms() test, degrees value doesn't match"
    assert abs(m - 26.0) < TOL, \
        "ERROR: In 2nd deg2dms() test, minutes value doesn't match"
    assert abs(s - 48.9999839999999) < TOL, \
        "ERROR: In 2nd deg2dms() test, seconds value doesn't match"
    assert abs(sign - (-1.0)) < TOL, \
        "ERROR: In 2nd deg2dms() test, sign value doesn't match"


def test_angle_dms2deg():
    """Tests dms2deg() static method of Angle class"""

    d = Angle.dms2deg(23.0, 26.0, 48.999984)
    assert abs(d - 23.44694444) < TOL, \
        "ERROR: In 1st dms2deg() test, degrees value doesn't match"

    d = Angle.dms2deg(-23.0, 26.0, 48.999984)
    assert abs(d - (-23.44694444)) < TOL, \
        "ERROR: In 2nd dms2deg() test, degrees value doesn't match"

    d = Angle.dms2deg(0.0, -26.0, 48.999984)
    assert abs(d - (-0.44694444)) < TOL, \
        "ERROR: In 3rd dms2deg() test, degrees value doesn't match"


def test_angle_reduce_deg():
    """Tests reduce_deg() static method of Angle class"""

    d = Angle.reduce_deg(745.67)
    assert abs(d - 25.67) < TOL, \
        "ERROR: In 1st reduce_deg() test, degrees value doesn't match"

    d = Angle.reduce_deg(-360.86)
    assert abs(d - (-0.86)) < TOL, \
        "ERROR: In 2nd reduce_deg() test, degrees value doesn't match"


def test_angle_reduce_dms():
    """Tests reduce_dms() static method of Angle class"""

    (d, m, s, sign) = Angle.reduce_dms(383.0, 26.0, 48.999984)
    assert abs(d - 23.0) < TOL, \
        "ERROR: In 1st reduce_dms() test, degrees value doesn't match"

    assert abs(m - 26.0) < TOL, \
        "ERROR: In 1st reduce_dms() test, minutes value doesn't match"

    assert abs(s - 48.999984) < TOL, \
        "ERROR: In 1st reduce_dms() test, seconds value doesn't match"

    assert abs(sign - 1.0) < TOL, \
        "ERROR: In 1st reduce_dms() test, sign value doesn't match"

    (d, m, s, sign) = Angle.reduce_dms(-1103.6, 86.5, 168.84)
    assert abs(d - 25.0) < TOL, \
        "ERROR: In 2nd reduce_dms() test, degrees value doesn't match"

    assert abs(m - 5.0) < TOL, \
        "ERROR: In 2nd reduce_dms() test, minutes value doesn't match"

    assert abs(s - 18.8399999997) < TOL, \
        "ERROR: In 2nd reduce_dms() test, seconds value doesn't match"

    assert abs(sign - (-1.0)) < TOL, \
        "ERROR: In 2nd reduce_dms() test, sign value doesn't match"

    (d, m, s, sign) = Angle.reduce_dms(0.0, -206.71)
    assert abs(d - 3.0) < TOL, \
        "ERROR: In 3rd reduce_dms() test, degrees value doesn't match"

    assert abs(m - 26.0) < TOL, \
        "ERROR: In 3rd reduce_dms() test, minutes value doesn't match"

    assert abs(s - 42.6) < TOL, \
        "ERROR: In 3rd reduce_dms() test, seconds value doesn't match"

    assert abs(sign - (-1.0)) < TOL, \
        "ERROR: In 3rd reduce_dms() test, sign value doesn't match"


def test_angle_dms_str():
    """Tests dms_str() method of Angle class"""
    a = Angle(0, -46.25, 0.0)

    result = a.dms_str()
    assert result == "-46' 15.0''", \
        "ERROR: In 1st dms_str() test, the output value doesn't match"

    result = a.dms_str(False)
    assert result == "0:-46:15.0", \
        "ERROR: In 2nd dms_str() test, the output value doesn't match"


def test_angle_ra_str():
    """Tests ra_str() method of Angle class"""
    a = Angle(138.75)

    result = a.ra_str()
    assert result == "9h 15' 0.0''", \
        "ERROR: In 1st ra_str() test, the output value doesn't match"

    result = a.ra_str(False)
    assert result == "9:15:0.0", \
        "ERROR: In 2nd ra_str() test, the output value doesn't match"


def test_angle_get_ra():
    """Tests get_ra() method of Angle class"""
    a = Angle(138.75)

    assert abs(a.get_ra() - 9.25) < TOL, \
        "ERROR: In 1st get_ra() test, the output value doesn't match"


def test_angle_call():
    """Tests the __call__() method of Angle class"""

    type_ok = False
    a = Angle(40, -46.25, 0.0)
    if isinstance(a(), (int, float)):       # Test the returned type
        type_ok = True

    assert type_ok, "ERROR: In 1st __call__() test, type doesn't match"

    assert abs(a() - (-40.770833333333)) < TOL, \
        "ERROR: In 2nd __call__() test, degrees value doesn't match"


def test_angle_str():
    """Tests the __str__() method of Angle class"""

    type_ok = False
    a = Angle(40, -46.5, 0.0)
    if isinstance(a.__str__(), str):                  # Test the returned type
        type_ok = True

    assert type_ok, "ERROR: In 1st __str__() test, type doesn't match"

    assert a.__str__() == "-40.775", \
        "ERROR: In 2nd __str__() test, degrees value doesn't match"


def test_angle_rad():
    """Tests the rad() method of Angle class"""
    a = Angle(180.0)

    assert abs(a.rad() - pi) < TOL, \
        "ERROR: In 1st rad() test, radians value doesn't match"


def test_angle_to_positive():
    """Tests the to_positive() method"""
    a = Angle(-87.32)
    b = Angle(87.32)

    assert abs(a.to_positive()() - 272.68) < TOL, \
        "ERROR: In 1st to_positive() test, value doesn't match"

    assert abs(b.to_positive()() - 87.32) < TOL, \
        "ERROR: In 2nd to_positive() test, value doesn't match"


def test_angle_ne():
    """Tests the 'is not equal' operator of Angles"""
    # NOTE: Test 'is not equal' also tests 'is equal' operator
    # Default tolerance for Angles is 1E-10
    a = Angle(152.7)
    b = Angle(152.7000000001)

    assert (a != b), \
        "ERROR: In 1st __ne__() test, Angles are different but taken as equal"

    a = Angle(-13, 30)
    b = Angle(-13.50000000001)

    assert not (a != b), \
        "ERROR: In 2nd __ne__() test, Angles are equal but taken as different"


def test_angle_ge():
    """Tests the 'is greater or equal' operator of Angles"""
    # NOTE: Test of 'is greater or equal' also test 'is less than' operator
    a = Angle(152.7)
    b = Angle(152.70000001)

    assert not (a >= b), \
        "ERROR: In 1st __ge__() test, Angles values don't match operator"

    a = Angle(-13, 30)
    b = Angle(-13.5)

    assert (a >= b), \
        "ERROR: In 2nd __ne__() test, Angles values don't match operator"


def test_angle_le():
    """Tests the 'is less or equal' operator of Angles"""
    # NOTE: Test of 'is less or equal' also test 'is greater than' operator
    a = Angle(152.7)
    b = Angle(152.70000001)

    assert (a <= b), \
        "ERROR: In 1st __le__() test, Angles values don't match operator"

    a = Angle(-13, 30)
    b = Angle(-13.5)

    assert (a <= b), \
        "ERROR: In 2nd __le__() test, Angles values don't match operator"


def test_angle_neg():
    """Tests the negation of Angles"""
    a = Angle(152.7)

    b = -a

    assert abs(b() - (-152.7)) < TOL, \
        "ERROR: In 1st __neg__() test, degrees value doesn't match"

    a = Angle(-13, 30)
    b = -a

    assert abs(b() - 13.5) < TOL, \
        "ERROR: In 2nd __neg__() test, degrees value doesn't match"


def test_angle_abs():
    """Tests the absolute value of Angles"""
    a = Angle(152.7)

    b = abs(a)

    assert abs(b() - 152.7) < TOL, \
        "ERROR: In 1st __abs__() test, degrees value doesn't match"

    a = Angle(-13, 30)
    b = abs(a)

    assert abs(b() - 13.5) < TOL, \
        "ERROR: In 2nd __abs__() test, degrees value doesn't match"


def test_angle_mod():
    """Tests the module of Angles"""
    a = Angle(152.7)

    b = a % 50

    assert abs(b() - 2.7) < TOL, \
        "ERROR: In 1st __mod__() test, degrees value doesn't match"

    a = Angle(-13, 30)
    b = a % 7

    assert abs(b() - (-6.5)) < TOL, \
        "ERROR: In 2nd __mod__() test, degrees value doesn't match"


def test_angle_add():
    """Tests the addition between Angles"""
    a = Angle(180.0)
    b = Angle(13, 30)
    c = a + b

    assert abs(c() - 193.5) < TOL, \
        "ERROR: In 1st __add__() test, degrees value doesn't match"

    b.set(-13, 30)
    c = a + b

    assert abs(c() - 166.5) < TOL, \
        "ERROR: In 2nd __add__() test, degrees value doesn't match"

    c = a + 11.5

    assert abs(c() - 191.5) < TOL, \
        "ERROR: In 3rd __add__() test, degrees value doesn't match"


def test_angle_sub():
    """Tests the subtraction between Angles"""
    a = Angle(180.0)
    b = Angle(13, 30)
    c = a - b

    assert abs(c() - 166.5) < TOL, \
        "ERROR: In 1st __sub__() test, degrees value doesn't match"

    b.set(-13, 30)
    c = a - b

    assert abs(c() - 193.5) < TOL, \
        "ERROR: In 2nd __sub__() test, degrees value doesn't match"

    c = a - 11.5

    assert abs(c() - 168.5) < TOL, \
        "ERROR: In 3rd __sub__() test, degrees value doesn't match"


def test_angle_mul():
    """Tests the multiplication between Angles"""
    a = Angle(150.0)
    b = Angle(5.0)
    c = a * b

    assert abs(c() - 30.0) < TOL, \
        "ERROR: In 1st __mul__() test, degrees value doesn't match"

    b.set(-5.0)
    c = a * b

    assert abs(c() - (-30.0)) < TOL, \
        "ERROR: In 2nd __mul__() test, degrees value doesn't match"

    c = a * 2.5

    assert abs(c() - 15.0) < TOL, \
        "ERROR: In 3rd __mul__() test, degrees value doesn't match"


def test_angle_div():
    """Tests the division between Angles"""
    # NOTE: This also tests method self.__truediv__()
    a = Angle(150.0)
    b = Angle(6.0)
    c = a / b

    assert abs(c() - 25.0) < TOL, \
        "ERROR: In 1st __div__() test, degrees value doesn't match"

    b.set(-6.0)
    c = a / b

    assert abs(c() - (-25.0)) < TOL, \
        "ERROR: In 2nd __div__() test, degrees value doesn't match"

    c = a / 1.5

    assert abs(c() - 100.0) < TOL, \
        "ERROR: In 3rd __div__() test, degrees value doesn't match"


def test_angle_pow():
    """Tests the power operation in Angles"""
    a = Angle(13, 30)
    b = a ** 3

    assert abs(b() - 300.375) < TOL, \
        "ERROR: In 1st __pow__() test, degrees value doesn't match"

    b.set(-2.0)
    c = a ** b

    assert abs(c() - 0.005486968449931413) < TOL, \
        "ERROR: In 2nd __pow__() test, degrees value doesn't match"


def test_angle_imod():
    """Tests the accumulative module between Angles"""
    a = Angle(152.7)

    a %= 50

    assert abs(a() - 2.7) < TOL, \
        "ERROR: In 1st __imod__() test, degrees value doesn't match"

    a = Angle(-13, 30)
    a %= 7

    assert abs(a() - (-6.5)) < TOL, \
        "ERROR: In 2nd __imod__() test, degrees value doesn't match"


def test_angle_iadd():
    """Tests the accumulative addition between Angles"""
    a = Angle(180.0)
    b = Angle(13, 30)
    a += b

    assert abs(a() - 193.5) < TOL, \
        "ERROR: In 1st __iadd__() test, degrees value doesn't match"

    b.set(-10, 30)
    a += b

    assert abs(a() - 183.0) < TOL, \
        "ERROR: In 2nd __iadd__() test, degrees value doesn't match"

    a += 37.5

    assert abs(a() - 220.5) < TOL, \
        "ERROR: In 3rd __iadd__() test, degrees value doesn't match"


def test_angle_isub():
    """Tests the accumulative subtraction between Angles"""
    a = Angle(180.0)
    b = Angle(13, 30)
    a -= b

    assert abs(a() - 166.5) < TOL, \
        "ERROR: In 1st __isub__() test, degrees value doesn't match"

    b.set(-10, 30)
    a -= b

    assert abs(a() - 177.0) < TOL, \
        "ERROR: In 2nd __isub__() test, degrees value doesn't match"

    a -= 37.5

    assert abs(a() - 139.5) < TOL, \
        "ERROR: In 3rd __isub__() test, degrees value doesn't match"


def test_angle_imul():
    """Tests the accumulative multiplication between Angles"""
    a = Angle(150.0)
    b = Angle(5.0)
    a *= b

    assert abs(a() - 30.0) < TOL, \
        "ERROR: In 1st __imul__() test, degrees value doesn't match"

    b.set(-5.0)
    a *= b

    assert abs(a() - (-150.0)) < TOL, \
        "ERROR: In 2nd __imul__() test, degrees value doesn't match"

    a *= 2.5

    assert abs(a() - (-15.0)) < TOL, \
        "ERROR: In 3rd __imul__() test, degrees value doesn't match"


def test_angle_idiv():
    """Tests the accumulative division between Angles"""
    # NOTE: This also tests method self.__itruediv__()
    a = Angle(150.0)
    b = Angle(6.0)
    a /= b

    assert abs(a() - 25.0) < TOL, \
        "ERROR: In 1st __idiv__() test, degrees value doesn't match"

    b.set(-20.0)
    a /= b

    assert abs(a() - (-1.25)) < TOL, \
        "ERROR: In 2nd __idiv__() test, degrees value doesn't match"

    a /= 1.5

    assert abs(a() - (-0.833333333333333)) < TOL, \
        "ERROR: In 3rd __idiv__() test, degrees value doesn't match"


def test_angle_ipow():
    """Tests the accumulative power operation in Angles"""
    a = Angle(13, 30)
    a **= 3

    assert abs(a() - 300.375) < TOL, \
        "ERROR: In 1st __ipow__() test, degrees value doesn't match"

    b = Angle(-2.0)
    a **= b

    assert abs(a() - 1.108338532999e-05) < TOL, \
        "ERROR: In 2nd __ipow__() test, degrees value doesn't match"


def test_angle_rmod():
    """Tests the module operation between Angles by the right"""
    a = Angle(25.0)
    b = Angle(163.0)
    c = a.__rmod__(b)

    assert abs(c() - 13.0) < TOL, \
        "ERROR: In 1st __rmod__() test, degrees value doesn't match"

    b.set(-78.0)
    c = a.__rmod__(b)

    assert abs(c() - (-3.0)) < TOL, \
        "ERROR: In 2nd __rmod__() test, degrees value doesn't match"

    c = 31.5 % a

    assert abs(c() - 6.5) < TOL, \
        "ERROR: In 3rd __rmod__() test, degrees value doesn't match"


def test_angle_radd():
    """Tests the addition between Angles by the right"""
    a = Angle(180.0)
    b = Angle(13, 30)
    c = a.__radd__(b)

    assert abs(c() - 193.5) < TOL, \
        "ERROR: In 1st __radd__() test, degrees value doesn't match"

    b.set(-13, 30)
    c = a.__radd__(b)

    assert abs(c() - 166.5) < TOL, \
        "ERROR: In 2nd __radd__() test, degrees value doesn't match"

    c = 11.5 + a

    assert abs(c() - 191.5) < TOL, \
        "ERROR: In 3rd __radd__() test, degrees value doesn't match"


def test_angle_rsub():
    """Tests the subtraction between Angles by the right"""
    a = Angle(180.0)
    b = Angle(-13, 30)
    c = a.__rsub__(b)

    assert abs(c() - (-193.5)) < TOL, \
        "ERROR: In 1st __rsub__() test, degrees value doesn't match"

    b.set(13, 30)
    c = a.__rsub__(b)

    assert abs(c() - (-166.5)) < TOL, \
        "ERROR: In 2nd __rsub__() test, degrees value doesn't match"

    c = 11.5 - a

    assert abs(c() - (-168.5)) < TOL, \
        "ERROR: In 3rd __rsub__() test, degrees value doesn't match"


def test_angle_rmul():
    """Tests the multiplication between Angles by the right"""
    a = Angle(150.0)
    b = Angle(5.0)
    c = a.__rmul__(b)

    assert abs(c() - 30.0) < TOL, \
        "ERROR: In 1st __rmul__() test, degrees value doesn't match"

    b.set(-5.0)
    c = a.__rmul__(b)

    assert abs(c() - (-30.0)) < TOL, \
        "ERROR: In 2nd __rmul__() test, degrees value doesn't match"

    c = 2.5 * a

    assert abs(c() - 15.0) < TOL, \
        "ERROR: In 3rd __rmul__() test, degrees value doesn't match"


def test_angle_rdiv():
    """Tests the division between Angles by the right"""
    a = Angle(150.0)
    b = Angle(5.0)
    c = b.__rdiv__(a)

    assert abs(c() - 30.0) < TOL, \
        "ERROR: In 1st __rdiv__() test, degrees value doesn't match"

    b.set(-5.0)
    a = b.__rdiv__(c)

    assert abs(a() - (-6.0)) < TOL, \
        "ERROR: In 2nd __rdiv__() test, degrees value doesn't match"

    c = -24.0 / a

    assert abs(c() - 4.0) < TOL, \
        "ERROR: In 3rd __rdiv__() test, degrees value doesn't match"


def test_angle_rpow():
    """Tests the power operation between Angles by the right"""
    a = Angle(15.0)
    b = Angle(3.0)
    c = b.__rpow__(a)

    assert abs(c() - 135.0) < TOL, \
        "ERROR: In 1st __rpow__() test, degrees value doesn't match"

    b.set(-2.0)
    a = b.__rpow__(c)

    assert abs(a() - 5.48697e-05) < TOL, \
        "ERROR: In 2nd __rpow__() test, degrees value doesn't match"

    c = -10.0 ** b

    assert abs(c() - (-0.01)) < TOL, \
        "ERROR: In 3rd __rpow__() test, degrees value doesn't match"


def test_angle_float():
    """Tests the 'float()' operation on Angles"""
    a = Angle(15, 30)

    assert abs(float(a) - 15.5) < TOL, \
        "ERROR: In 1st __float__() test, degrees value doesn't match"


def test_angle_int():
    """Tests the 'int()' operation on Angles"""
    a = Angle(15, 30)

    assert abs(int(a) - 15) < TOL, \
        "ERROR: In 1st __int__() test, degrees value doesn't match"


def test_angle_round():
    """Tests the 'round()' operation on Angles"""
    a = Angle(1.0, radians=True)

    # NOTE: The 'float(round(x))' hack makes this test work in Python 2 and 3
    assert abs(float(round(a)) - 57.0) < TOL, \
        "ERROR: In 1st __round__() test, degrees value doesn't match"

    assert abs(float(round(a, 3)) - 57.296) < TOL, \
        "ERROR: In 2nd __round__() test, degrees value doesn't match"

    assert abs(float(round(a, 7)) - 57.2957795) < TOL, \
        "ERROR: In 3rd __round__() test, degrees value doesn't match"