-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoffset_angle_test.py
executable file
·68 lines (59 loc) · 2.59 KB
/
offset_angle_test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# A sanity check for our heading conversion/offset. This makes no assertions;
# its output is meant to be read on the console.
#
import pytest
import sys, time, math
from numpy import arange
from colorama import init, Fore, Style
init()
from lib.logger import Level, Logger
from lib.convert import Convert
# ..............................................................................
@pytest.mark.unit
def test_offset():
_log = Logger('test-offset', Level.INFO)
_test_offset(_log, 330.0, 70.0, 40.0)
_test_offset(_log, 350.0, 15.0, 5.0)
_test_offset(_log, 360.0, -10.0, 350.0)
_test_offset(_log, 270.0, -70.0, 200.0)
_log.info('complete.')
# ..............................................................................
@pytest.mark.unit
def _test_offset(log, angle, offset, expected):
log.heading('Rotate Test','{:5.2f}°, offset {:5.2f}°, expected {:5.2f}°'.format(angle, offset, expected),'1/4')
result = Convert.offset_in_degrees(angle, offset)
if not math.isclose(result, expected):
log.error('expected {:5.2f}°, not {:5.2f}°\n'.format(expected, result))
# now radians...
result2 = Convert.to_degrees(Convert.offset_in_radians(Convert.to_radians(angle), Convert.to_radians(offset)))
if not math.isclose(result2, expected):
log.error('expected {:5.2f}°, not {:5.2f}°\n'.format(expected, result2))
log.info(Fore.GREEN + 'result:\t{:>5.2f}°'.format(result))
# ..............................................................................
@pytest.mark.unit
def test_offset_rotate():
_log = Logger("offset-rotate-test", Level.INFO)
_count = 0
for offset in arange(0.0, 360.0, 90.0):
_count += 1
_log.heading('Offset Rotate Test', 'offset={:<5.2f};'.format(offset), '{:d}/4'.format(_count))
for angle in arange(0.0, 360.0, 30.0):
_alt = Convert.offset_in_degrees(angle, offset)
_log.info(Fore.GREEN + 'from {:>5.2f}°\tto {:>5.2f}°;'.format(angle, _alt) + Fore.BLACK + '\toffset={:<5.2f};'.format(offset))
time.sleep(0.01)
_log.info('complete.')
# main .........................................................................
def main(argv):
test_offset()
test_offset_rotate()
# call main ....................................................................
if __name__== "__main__":
main(sys.argv[1:])
#EOF