-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_gnsscal.py
148 lines (118 loc) · 4.25 KB
/
test_gnsscal.py
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
#!/usr/bin/env python
# coding=utf-8
# creater: Jiang Yingming
# date: 2017-05-17
"""Test gnsscal module."""
import datetime
import unittest
import gnsscal
class Tests(unittest.TestCase):
"""Unit test for gnsscal."""
def test_date2doy(self):
"""Test date2doy function,
use date: 2017-5-17, doy: 137.
"""
date = datetime.date(2017, 5, 17)
doy = gnsscal.date2doy(date)
self.assertEqual(doy, 137)
def test_date2yrdoy(self):
"""Test date2yrdoy function,
use date: 2017-5-17, doy: 137.
"""
date = datetime.date(2017, 5, 17)
year, doy = gnsscal.date2yrdoy(date)
self.assertEqual(year, 2017)
self.assertEqual(doy, 137)
def test_yrdoy2date(self):
"""Test yrdoy2date function,
use date: 2017-5-17, doy: 137.
"""
date = gnsscal.yrdoy2date(2017, 137)
self.assertEqual(date, datetime.date(2017, 5, 17))
with self.assertRaises(ValueError):
gnsscal.yrdoy2date(1991, 0)
gnsscal.yrdoy2date(-1, 1)
gnsscal.yrdoy2date(-1, 0)
def test_date2gpswd(self):
"""Test date2gpswd function,
use date: 2017-5-17, GPS week: 1949, day of week: 3.
"""
date = datetime.date(2017, 5, 17)
gpsweek, dayofweek = gnsscal.date2gpswd(date)
self.assertEqual(gpsweek, 1949)
self.assertEqual(dayofweek, 3)
date = datetime.date(1980, 1, 1)
with self.assertRaises(ValueError):
gnsscal.date2gpswd(date)
def test_date2bdswd(self):
"""Test date2bdswd function,
use date: 2017-5-17, BDS week: 593, day of week: 3."""
date = datetime.date(2017, 5, 17)
bdsweek, dayofweek = gnsscal.date2bdswd(date)
self.assertEqual(bdsweek, 593)
self.assertEqual(dayofweek, 3)
date = datetime.date(1980, 1, 1)
with self.assertRaises(ValueError):
gnsscal.date2bdswd(date)
def test_gpswd2date(self):
"""Test gpswd2date function,
use date: 2017-5-17, GPS week: 1949, day of week: 3.
"""
date = gnsscal.gpswd2date(1949, 3)
self.assertEqual(date, datetime.date(2017, 5, 17))
with self.assertRaises(ValueError):
gnsscal.gpswd2date(-1, 0)
gnsscal.gpswd2date(0, -1)
gnsscal.gpswd2date(-1, -1)
def test_bdswd2date(self):
"""Test bdswd2date function,
use date: 2017-5-17, BDS week: 593, day of week: 3.
"""
date = gnsscal.bdswd2date(593, 3)
self.assertEqual(date, datetime.date(2017, 5, 17))
with self.assertRaises(ValueError):
gnsscal.gpswd2date(-1, 0)
gnsscal.gpswd2date(0, -1)
gnsscal.gpswd2date(-1, -1)
def test_yrdoy2gpswd(self):
"""Test yrdoy2gpswd function,
use date: 2017-5-17, doy: 137, GPS week: 1949, day of week: 3.
"""
gpsweek, dayofweek = gnsscal.yrdoy2gpswd(2017, 137)
self.assertEqual(gpsweek, 1949)
self.assertEqual(dayofweek, 3)
def test_yrdoy2bdswd(self):
"""Test yrdoy2bdswd function,
use date: 2017-5-17, doy: 137, BDS week: 593, day of week: 3.
"""
bdsweek, dayofweek = gnsscal.yrdoy2bdswd(2017, 137)
self.assertEqual(bdsweek, 593)
self.assertEqual(dayofweek, 3)
def test_gpswd2yrdoy(self):
"""Test gpswd2yrdoy function,
use date: 2017-5-17, doy: 137, GPS week: 1949, day of week: 3.
"""
year, doy = gnsscal.gpswd2yrdoy(1949, 3)
self.assertEqual(year, 2017)
self.assertEqual(doy, 137)
def test_bdswd2yrdoy(self):
"""Test bdswd2yrdoy function,
use date: 2017-5-17, doy: 137, GPS week: 593, day of week: 3.
"""
year, doy = gnsscal.bdswd2yrdoy(593, 3)
self.assertEqual(year, 2017)
self.assertEqual(doy, 137)
def test_gpsw2bdsw(self):
"""Test gpsw2bdsw function,
use GPS week 1949.
"""
bdsweek = gnsscal.gpsw2bdsw(1949)
self.assertEqual(bdsweek, 593)
def test_bdsw2gpsw(self):
"""Test bdsw2gpsw function,
use BDS week 593.
"""
gpsweek = gnsscal.bdsw2gpsw(593)
self.assertEqual(gpsweek, 1949)
if __name__ == '__main__':
unittest.main()