mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-29 16:29:34 +00:00
tests: Update tests for animation_lib
This commit is contained in:
@@ -81,8 +81,8 @@ class Frame(object):
|
||||
class Animation(object):
|
||||
def __init__(self, config=None, filepath="animation.csv"):
|
||||
self.id = None
|
||||
self.static_begin_time = None
|
||||
self.takeoff_time = None
|
||||
self.static_begin_time = 0
|
||||
self.takeoff_time = 0
|
||||
self.original_frames = None
|
||||
self.static_begin_frames = None
|
||||
self.takeoff_frames = None
|
||||
@@ -138,7 +138,7 @@ class Animation(object):
|
||||
return
|
||||
else:
|
||||
self.original_frames.append(frame)
|
||||
self.split_animation()
|
||||
self.split_animation()
|
||||
|
||||
'''
|
||||
Split animation into 5 parts: static_begin, takeoff, route, land, static_end
|
||||
@@ -150,9 +150,6 @@ class Animation(object):
|
||||
Count static_begin_time and takeoff_time
|
||||
'''
|
||||
def split_animation(self, move_delta=0.01):
|
||||
if len(self.original_frames) == 0:
|
||||
return
|
||||
frames = copy.deepcopy(self.original_frames)
|
||||
self.static_begin_frames = []
|
||||
self.takeoff_frames = []
|
||||
self.route_frames = []
|
||||
@@ -160,26 +157,33 @@ class Animation(object):
|
||||
self.static_end_frames = []
|
||||
self.static_begin_time = 0
|
||||
self.takeoff_time = 0
|
||||
if len(self.original_frames) == 0:
|
||||
return
|
||||
frames = copy.deepcopy(self.original_frames)
|
||||
i = 0 # Moving index from the beginning
|
||||
# Select static begin frames
|
||||
while i < len(frames) - 1:
|
||||
self.static_begin_time += frames[i].delay
|
||||
if moving(frames[i], frames[i+1], move_delta):
|
||||
break
|
||||
self.static_begin_time += frames[i].delay
|
||||
i += 1
|
||||
if i > 0:
|
||||
self.static_begin_frames = frames[:i+1]
|
||||
frames = frames[i+1:]
|
||||
i = 0
|
||||
else:
|
||||
self.static_begin_time = 0
|
||||
# Select takeoff frames
|
||||
while i < len(frames) - 1:
|
||||
self.takeoff_time += frames[i].delay
|
||||
if moving(frames[i], frames[i+1], move_delta, z = False) or (frames[i+1].z - frames[i].z <= 0):
|
||||
break
|
||||
self.takeoff_time += frames[i].delay
|
||||
i += 1
|
||||
if i > 0:
|
||||
self.takeoff_frames = frames[:i+1]
|
||||
frames = frames[i+1:]
|
||||
else:
|
||||
self.takeoff_time = 0
|
||||
i = len(frames) - 1 # Moving index from the end
|
||||
# Select static end frames
|
||||
while i >= 0:
|
||||
@@ -203,6 +207,7 @@ class Animation(object):
|
||||
|
||||
def make_output_frames(self, static_begin, takeoff, route, land, static_end):
|
||||
self.output_frames = []
|
||||
self.output_frames_min_z = None
|
||||
if static_begin:
|
||||
self.output_frames += self.static_begin_frames
|
||||
if takeoff:
|
||||
@@ -213,12 +218,13 @@ class Animation(object):
|
||||
self.output_frames += self.land_frames
|
||||
if static_end:
|
||||
self.output_frames += self.static_end_frames
|
||||
self.output_frames_min_z = min(self.output_frames, key = lambda p: p.z).z
|
||||
if self.output_frames:
|
||||
self.output_frames_min_z = min(self.output_frames, key = lambda p: p.z).z
|
||||
|
||||
def update_frames(self, config, filepath):
|
||||
self.__init__()
|
||||
self.load(filepath, config.animation_frame_delay)
|
||||
if self.original_frames:
|
||||
self.make_output_frames(config.animation_output_static_begin,
|
||||
self.make_output_frames(config.animation_output_static_begin,
|
||||
config.animation_output_takeoff,
|
||||
config.animation_output_route,
|
||||
config.animation_output_land,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from pytest import approx
|
||||
|
||||
# Add parent dir to PATH to import config
|
||||
import inspect
|
||||
@@ -30,47 +31,78 @@ assert config.config_name == "client"
|
||||
|
||||
import animation_lib
|
||||
|
||||
a = animation_lib.Animation(config, "animation_1.csv")
|
||||
a = animation_lib.Animation()
|
||||
|
||||
def test_animation_1():
|
||||
a.update_frames(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()
|
||||
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)
|
||||
assert animation_lib.get_numbers(a.output_frames) == range(11,31)
|
||||
assert approx(a.static_begin_time) == 1
|
||||
assert approx(a.takeoff_time) == 1
|
||||
assert approx(a.output_frames_min_z) == 0.1
|
||||
|
||||
def test_animation_2():
|
||||
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) == []
|
||||
assert animation_lib.get_numbers(a.output_frames) == range(271, 1065)
|
||||
assert approx(a.static_begin_time) == 27.1
|
||||
assert approx(a.takeoff_time) == 1.4
|
||||
assert approx(a.output_frames_min_z) == 0.24386
|
||||
|
||||
def test_animation_3():
|
||||
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) == []
|
||||
assert approx(a.static_begin_time) == 0
|
||||
assert approx(a.takeoff_time) == 0
|
||||
assert approx(a.output_frames_min_z) == 1
|
||||
|
||||
def test_animation_no_file():
|
||||
a.update_frames(config, "zzz.csv")
|
||||
assert a.id == 'No animation'
|
||||
assert a.original_frames == []
|
||||
assert a.output_frames == []
|
||||
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) == []
|
||||
assert animation_lib.get_numbers(a.land_frames) == []
|
||||
assert animation_lib.get_numbers(a.static_end_frames) == []
|
||||
assert a.static_begin_time == 0
|
||||
assert a.takeoff_time == 0
|
||||
assert a.output_frames_min_z is None
|
||||
|
||||
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) == []
|
||||
# print animation_lib.get_numbers(a.output_frames)
|
||||
# print a.static_begin_time
|
||||
# print a.takeoff_time
|
||||
# print a.output_frames_min_z
|
||||
|
||||
shutil.rmtree('animation_config')
|
||||
|
||||
Reference in New Issue
Block a user