Add tests for animation_lib

This commit is contained in:
Arthur Golubtsov
2020-05-27 15:38:14 +03:00
parent 673cd20a43
commit d34e53110b
4 changed files with 1205 additions and 0 deletions

51
tests/animation_1.csv Normal file
View File

@@ -0,0 +1,51 @@
basic
1,0.0,0.0,0.0,0.0,204,2,0
2,0.0,0.0,0.0,0.0,204,9,1
3,0.0,0.0,0.0,0.0,204,21,2
4,0.0,0.0,0.0,0.0,204,37,3
5,0.0,0.0,0.0,0.0,204,56,4
6,0.0,0.0,0.0,0.0,204,77,5
7,0.0,0.0,0.0,0.0,204,97,6
8,0.0,0.0,0.0,0.0,204,116,6
9,0.0,0.0,0.0,0.0,204,131,7
10,0.0,0.0,0.0,0.0,204,143,7
11,0.0,0.0,0.1,0.0,199,153,7
12,0.0,0.0,0.2,0.0,185,163,6
13,0.0,0.0,0.3,0.0,163,172,6
14,0.0,0.0,0.4,0.0,134,181,5
15,0.0,0.0,0.5,0.0,102,188,5
16,0.0,0.0,0.6,0.0,69,194,4
17,0.0,0.0,0.7,0.0,40,199,3
18,0.0,0.0,0.8,0.0,18,201,3
19,0.0,0.0,0.9,0.0,4,203,2
20,0.0,0.0,1.0,0.0,0,204,2
21,0.02217,0.0,1.0,0.0,0,204,2
22,0.08889,0.0,1.0,0.0,0,204,2
23,0.19737,0.0,1.0,0.0,0,204,2
24,0.33926,0.0,1.0,0.0,0,204,2
25,0.5,0.0,1.0,0.0,0,204,2
26,0.66074,0.0,1.0,0.0,0,204,2
27,0.80263,0.0,1.0,0.0,0,204,2
28,0.91111,0.0,1.0,0.0,0,204,2
29,0.97783,0.0,1.0,0.0,0,204,2
30,1.0,0.0,1.0,0.0,0,204,2
31,1.0,0.0,0.9,0.0,3,204,2
32,1.0,0.0,0.8,0.0,14,204,2
33,1.0,0.0,0.7,0.0,32,204,2
34,1.0,0.0,0.6,0.0,56,204,1
35,1.0,0.0,0.5,0.0,84,204,1
36,1.0,0.0,0.4,0.0,112,204,0
37,1.0,0.0,0.3,0.0,138,204,0
38,1.0,0.0,0.2,0.0,159,204,0
39,1.0,0.0,0.1,0.0,175,204,0
40,1.0,0.0,0.0,0.0,183,204,0
41,1.0,0.0,0.0,0.0,188,199,0
42,1.0,0.0,0.0,0.0,192,185,0
43,1.0,0.0,0.0,0.0,196,163,0
44,1.0,0.0,0.0,0.0,199,135,0
45,1.0,0.0,0.0,0.0,201,102,0
46,1.0,0.0,0.0,0.0,202,69,0
47,1.0,0.0,0.0,0.0,203,40,0
48,1.0,0.0,0.0,0.0,203,18,0
49,1.0,0.0,0.0,0.0,203,5,0
50,1.0,0.0,0.0,0.0,204,0,0
1 basic
2 1,0.0,0.0,0.0,0.0,204,2,0
3 2,0.0,0.0,0.0,0.0,204,9,1
4 3,0.0,0.0,0.0,0.0,204,21,2
5 4,0.0,0.0,0.0,0.0,204,37,3
6 5,0.0,0.0,0.0,0.0,204,56,4
7 6,0.0,0.0,0.0,0.0,204,77,5
8 7,0.0,0.0,0.0,0.0,204,97,6
9 8,0.0,0.0,0.0,0.0,204,116,6
10 9,0.0,0.0,0.0,0.0,204,131,7
11 10,0.0,0.0,0.0,0.0,204,143,7
12 11,0.0,0.0,0.1,0.0,199,153,7
13 12,0.0,0.0,0.2,0.0,185,163,6
14 13,0.0,0.0,0.3,0.0,163,172,6
15 14,0.0,0.0,0.4,0.0,134,181,5
16 15,0.0,0.0,0.5,0.0,102,188,5
17 16,0.0,0.0,0.6,0.0,69,194,4
18 17,0.0,0.0,0.7,0.0,40,199,3
19 18,0.0,0.0,0.8,0.0,18,201,3
20 19,0.0,0.0,0.9,0.0,4,203,2
21 20,0.0,0.0,1.0,0.0,0,204,2
22 21,0.02217,0.0,1.0,0.0,0,204,2
23 22,0.08889,0.0,1.0,0.0,0,204,2
24 23,0.19737,0.0,1.0,0.0,0,204,2
25 24,0.33926,0.0,1.0,0.0,0,204,2
26 25,0.5,0.0,1.0,0.0,0,204,2
27 26,0.66074,0.0,1.0,0.0,0,204,2
28 27,0.80263,0.0,1.0,0.0,0,204,2
29 28,0.91111,0.0,1.0,0.0,0,204,2
30 29,0.97783,0.0,1.0,0.0,0,204,2
31 30,1.0,0.0,1.0,0.0,0,204,2
32 31,1.0,0.0,0.9,0.0,3,204,2
33 32,1.0,0.0,0.8,0.0,14,204,2
34 33,1.0,0.0,0.7,0.0,32,204,2
35 34,1.0,0.0,0.6,0.0,56,204,1
36 35,1.0,0.0,0.5,0.0,84,204,1
37 36,1.0,0.0,0.4,0.0,112,204,0
38 37,1.0,0.0,0.3,0.0,138,204,0
39 38,1.0,0.0,0.2,0.0,159,204,0
40 39,1.0,0.0,0.1,0.0,175,204,0
41 40,1.0,0.0,0.0,0.0,183,204,0
42 41,1.0,0.0,0.0,0.0,188,199,0
43 42,1.0,0.0,0.0,0.0,192,185,0
44 43,1.0,0.0,0.0,0.0,196,163,0
45 44,1.0,0.0,0.0,0.0,199,135,0
46 45,1.0,0.0,0.0,0.0,201,102,0
47 46,1.0,0.0,0.0,0.0,202,69,0
48 47,1.0,0.0,0.0,0.0,203,40,0
49 48,1.0,0.0,0.0,0.0,203,18,0
50 49,1.0,0.0,0.0,0.0,203,5,0
51 50,1.0,0.0,0.0,0.0,204,0,0

1066
tests/animation_2.csv Executable file

File diff suppressed because it is too large Load Diff

12
tests/animation_3.csv Normal file
View File

@@ -0,0 +1,12 @@
route
20,0.0,0.0,1.0,0.0,0,204,2
21,0.02217,0.0,1.0,0.0,0,204,2
22,0.08889,0.0,1.0,0.0,0,204,2
23,0.19737,0.0,1.0,0.0,0,204,2
24,0.33926,0.0,1.0,0.0,0,204,2
25,0.5,0.0,1.0,0.0,0,204,2
26,0.66074,0.0,1.0,0.0,0,204,2
27,0.80263,0.0,1.0,0.0,0,204,2
28,0.91111,0.0,1.0,0.0,0,204,2
29,0.97783,0.0,1.0,0.0,0,204,2
30,1.0,0.0,1.0,0.0,0,204,2
1 route
2 20,0.0,0.0,1.0,0.0,0,204,2
3 21,0.02217,0.0,1.0,0.0,0,204,2
4 22,0.08889,0.0,1.0,0.0,0,204,2
5 23,0.19737,0.0,1.0,0.0,0,204,2
6 24,0.33926,0.0,1.0,0.0,0,204,2
7 25,0.5,0.0,1.0,0.0,0,204,2
8 26,0.66074,0.0,1.0,0.0,0,204,2
9 27,0.80263,0.0,1.0,0.0,0,204,2
10 28,0.91111,0.0,1.0,0.0,0,204,2
11 29,0.97783,0.0,1.0,0.0,0,204,2
12 30,1.0,0.0,1.0,0.0,0,204,2

76
tests/animation_test.py Normal file
View File

@@ -0,0 +1,76 @@
import os
import sys
import shutil
# Add parent dir to PATH to import config
import inspect
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir)
sys.path.insert(0, os.path.join(parent_dir,"Drone"))
from config import ConfigManager
config_path = 'animation_config/config'
spec_path = os.path.join(config_path,'spec')
if not os.path.exists(spec_path):
try:
os.makedirs(spec_path)
except OSError:
print("Creation of the directory {} failed".format(spec_path))
else:
print("Successfully created the directory {}".format(spec_path))
shutil.copy("../Drone/config/spec/configspec_client.ini", spec_path)
config = ConfigManager()
config.load_config_and_spec(os.path.join(config_path,'client.ini'))
assert config.config_name == "client"
import animation_lib
a = animation_lib.Animation(config, "animation_1.csv")
assert a.id == 'basic'
assert a.original_frames[0].get_pos() == [0.,0.,0.]
assert a.original_frames[0].get_color() == [204,2,0]
assert a.original_frames[0].pose_is_valid()
# print animation_lib.get_numbers(a.static_begin_frames)
# print animation_lib.get_numbers(a.takeoff_frames)
# print animation_lib.get_numbers(a.route_frames)
# print animation_lib.get_numbers(a.land_frames)
# print animation_lib.get_numbers(a.static_end_frames)
assert animation_lib.get_numbers(a.static_begin_frames) == range(1,11)
assert animation_lib.get_numbers(a.takeoff_frames) == range(11,21)
assert animation_lib.get_numbers(a.route_frames) == range(21,31)
assert animation_lib.get_numbers(a.land_frames) == range(31, 41)
assert animation_lib.get_numbers(a.static_end_frames) == range(41, 51)
a.update_frames(config, "animation_2.csv")
assert a.id == 'parad'
assert a.original_frames[269].get_pos() == [-1.00519,2.65699,0.21]
assert a.original_frames[269].get_color() == [7,255,0]
assert a.original_frames[269].pose_is_valid()
assert animation_lib.get_numbers(a.static_begin_frames) == range(271)
assert animation_lib.get_numbers(a.takeoff_frames) == range(271,285)
assert animation_lib.get_numbers(a.route_frames) == range(285,1065)
assert animation_lib.get_numbers(a.land_frames) == []
assert animation_lib.get_numbers(a.static_end_frames) == []
a.update_frames(config, "animation_3.csv")
assert a.id == 'route'
assert a.original_frames[9].get_pos() == [0.97783,0.0,1.0]
assert a.original_frames[9].get_color() == [0,204,2]
assert a.original_frames[9].pose_is_valid()
assert animation_lib.get_numbers(a.static_begin_frames) == []
assert animation_lib.get_numbers(a.takeoff_frames) == []
assert animation_lib.get_numbers(a.route_frames) == range(20,31)
assert animation_lib.get_numbers(a.land_frames) == []
assert animation_lib.get_numbers(a.static_end_frames) == []
shutil.rmtree('animation_config')