コード例 #1
0
ファイル: test_point.py プロジェクト: encukou/upoints
 def test_import_locations(self):
     locations = Points()
     locations.import_locations(['0;0', '52.015 -0.221'])
     expect(repr(locations)) == \
         ("Points([Point(0.0, 0.0, 'metric', 'degrees', 0), "
          "Point(52.015, -0.221, 'metric', 'degrees', 0)], "
          "False, 'metric')")
コード例 #2
0
ファイル: test_point.py プロジェクト: encukou/upoints
 def setUp(self):
     self.locs = Points(['52.015;-0.221', '52.168;0.040', '52.855;0.657'],
                        parse=True)
コード例 #3
0
ファイル: test_point.py プロジェクト: encukou/upoints
class TestPoints(TestCase):
    def setUp(self):
        self.locs = Points(['52.015;-0.221', '52.168;0.040', '52.855;0.657'],
                           parse=True)

    def test___repr__(self):
        locations = [Point(0, 0)] * 4
        expect(repr(Points(locations))) == \
            ("Points([Point(0.0, 0.0, 'metric', 'degrees', 0), "
             "Point(0.0, 0.0, 'metric', 'degrees', 0), "
             "Point(0.0, 0.0, 'metric', 'degrees', 0), "
             "Point(0.0, 0.0, 'metric', 'degrees', 0)], "
             "False, 'metric')")

    def test_import_locations(self):
        locations = Points()
        locations.import_locations(['0;0', '52.015 -0.221'])
        expect(repr(locations)) == \
            ("Points([Point(0.0, 0.0, 'metric', 'degrees', 0), "
             "Point(52.015, -0.221, 'metric', 'degrees', 0)], "
             "False, 'metric')")

    def test_distance(self):
        expect('%.3f' % sum(self.locs.distance())) == '111.632'

    def test_bearing(self):
        expect(['%.3f' % x for x in self.locs.bearing()]) == \
            ['46.242', '28.416']

    def test_final_bearing(self):
        expect(['%.3f' % x for x in self.locs.final_bearing()]) == \
            ['46.448', '28.906']

    def test_inverse(self):
        expect(list(self.locs.inverse())) == \
            [(46.24239319802467, 24.629669163425465),
             (28.41617384845358, 87.00207583308533)]

    def test_midpoint(self):
        expect(list(self.locs.midpoint())) == \
            [Point(52.09157204324692, -0.09072375391429187, 'metric',
                   'degrees', 0),
             Point(52.51190105089283, 0.3460886030865466, 'metric',
                   'degrees', 0)]

    def test_range(self):
        expect(list(self.locs.range(Point(52.015, -0.221), 20))) == \
            [Point(52.015, -0.221, 'metric', 'degrees', 0)]

    def test_destination(self):
        expect(list(self.locs.destination(42, 240))) == \
            [Point(53.59560782169536, 2.2141813683976777, 'metric', 'degrees',
                   0),
             Point(53.74846914951471, 2.4840382137470614, 'metric', 'degrees',
                   0),
             Point(54.43483380445103, 3.1418347849815293, 'metric', 'degrees',
                   0)]

    def test_sunrise(self):
        expect(list(self.locs.sunrise(datetime.date(2008, 5, 2)))) == \
            [datetime.time(4, 28), datetime.time(4, 26), datetime.time(4, 21)]

    def test_sunset(self):
        expect(list(self.locs.sunset(datetime.date(2008, 5, 2)))) == \
            [datetime.time(19, 28), datetime.time(19, 27),
             datetime.time(19, 27)]

    def test_sun_events(self):
        expect(list(self.locs.sun_events(datetime.date(2008, 5, 2)))) == \
            [(datetime.time(4, 28), datetime.time(19, 28)),
             (datetime.time(4, 26), datetime.time(19, 27)),
             (datetime.time(4, 21), datetime.time(19, 27))]

    def test_to_grid_locator(self):
        expect(list(self.locs.to_grid_locator('extsquare'))) == \
            ['IO92va33', 'JO02ae40', 'JO02hu85']
        expect(list(self.locs.to_grid_locator('subsquare'))) == \
            ['IO92va', 'JO02ae', 'JO02hu']