File: test_angles.py

package info (click to toggle)
pyephem 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,380 kB
  • sloc: ansic: 77,574; python: 2,529; makefile: 74
file content (62 lines) | stat: -rwxr-xr-x 2,482 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

import unittest
from ephem import Angle, degrees, hours

# Determine whether angles work reasonably.

arcsecond_places = 5

class AngleTests(unittest.TestCase):
    def setUp(self):
        self.d = degrees(1.5)
        self.h = hours(1.6)

    def test_Angle_constructor(self):
        self.assertRaises(TypeError, Angle, 1.1)

    def test_degrees_constructor(self):
        self.assertAlmostEqual(self.d, degrees('85:56:37'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees('85::3397'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees('::309397'),
                               places=arcsecond_places)

        self.assertAlmostEqual(self.d, degrees('85 56 37'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees('85 56:37'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees('85:56 37'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees('85 : 56 : 37'),
                               places=arcsecond_places)
        self.assertAlmostEqual(self.d, degrees(' 85 : 56 : 37 '),
                               places=arcsecond_places)

        self.assertAlmostEqual(self.d, degrees(' :  :   309397    '),
                               places=arcsecond_places)

    def test_degrees_constructor_refuses_alphabetics(self):
        self.assertRaises(ValueError, degrees, 'foo:bar')
        self.assertRaises(ValueError, degrees, '1:bar')
        self.assertRaises(ValueError, degrees, '1:2:bar')
        self.assertRaises(ValueError, degrees, '1:2:3bar')

    def test_degrees_float_value(self):
        self.assertAlmostEqual(self.d, 1.5)
    def test_degrees_string_value(self):
        self.assertEqual(str(self.d), '85:56:37.2')

    def test_hours_constructor(self):
        self.assertAlmostEqual(self.h, hours('6:06:41.6'),
                               places=arcsecond_places)
    def test_hours_float_value(self):
        self.assertAlmostEqual(self.h, 1.6)
    def test_hours_string_value(self):
        self.assertEqual(str(self.h), '6:06:41.58')

    def test_angle_addition(self):
        self.assertAlmostEqual(degrees('30') + degrees('90'), degrees('120'))
    def test_angle_subtraction(self):
        self.assertAlmostEqual(degrees('180') - hours('9'), degrees('45'))