Пример #1
0
    def test_at_1_before_total_duration_add_1(self):
        scrolling_content = movement.ScrollingContent(30, 4, 0, 1, 2, 3)
        scrolling_content.reset()
        # total duration == 120
        assert scrolling_content.update(119)  # 1 before end
        assert not scrolling_content.end_of_segment_reached
        assert scrolling_content.x_offset == 2
        assert scrolling_content.y_offset == 7
        assert scrolling_content.current_step_num == 3

        # add 1
        assert not scrolling_content.update(1)  # no changed as end reached
        assert scrolling_content.end_of_segment_reached  # this has changed
        assert scrolling_content.x_offset == 2
        assert scrolling_content.y_offset == 7  # but not this
        assert scrolling_content.current_step_num == 3  # nor this
        assert scrolling_content.elapsed_time == 120
        assert scrolling_content.extra_time_after_end == 0

        # add 1
        assert not scrolling_content.update(1)
        assert scrolling_content.end_of_segment_reached  # no change
        assert scrolling_content.x_offset == 2
        assert scrolling_content.y_offset == 7  # no change
        assert scrolling_content.current_step_num == 3  # no change
        assert scrolling_content.elapsed_time == 120
        assert scrolling_content.extra_time_after_end == 1  # change
Пример #2
0
 def test_reset(self):
     scrolling_content = movement.ScrollingContent(30, 4, -1, 0, 2, 3)
     scrolling_content.reset()
     assert scrolling_content.x_offset == 1  # moves at t=0
     assert scrolling_content.y_offset == 3
     assert scrolling_content.current_step_num == 0
     assert scrolling_content.elapsed_time == 0
     assert scrolling_content.extra_time_after_end == 0
Пример #3
0
 def test_within_step_scroll_left(self):
     scrolling_content = movement.ScrollingContent(30, 4, -1, 0, 2, 3)
     scrolling_content.reset()
     assert not scrolling_content.update(20)
     assert not scrolling_content.end_of_segment_reached
     assert scrolling_content.x_offset == 1
     assert scrolling_content.y_offset == 3
     assert scrolling_content.current_step_num == 0
     assert scrolling_content.elapsed_time == 20
     assert scrolling_content.extra_time_after_end == 0
Пример #4
0
 def test_set_offset_after_end(self):
     scrolling_content = movement.ScrollingContent(30, 4, -1, 0, 2, 3)
     scrolling_content.reset()
     scrolling_content.update(150)
     assert scrolling_content.x_offset == -2
     assert scrolling_content.y_offset == 3
     scrolling_content.set_offset(6, 8)
     scrolling_content.update(60)
     # no further movement
     assert scrolling_content.x_offset == 6
     assert scrolling_content.y_offset == 8
Пример #5
0
    def test_set_offset(self):
        scrolling_content = movement.ScrollingContent(30, 4, -1, 0, 2, 3)
        scrolling_content.reset()
        scrolling_content.update(40)  # at t==40
        assert scrolling_content.x_offset == 0
        assert scrolling_content.y_offset == 3

        scrolling_content.set_offset(6, 8)
        scrolling_content.update(60)  # at t==100
        assert scrolling_content.x_offset == 4
        assert scrolling_content.y_offset == 8
Пример #6
0
def deserialise_ScrollingContent(
    scrolling_content: departure_pb2.ScrollingContent,
) -> movement.ScrollingContent:
    return movement.ScrollingContent(
        step_duration=scrolling_content.step_duration,
        total_steps=scrolling_content.total_steps,
        delta_x_per_step=scrolling_content.delta_x_per_step,
        delta_y_per_step=scrolling_content.delta_y_per_step,
        x_offset_init=scrolling_content.x_offset_init,
        y_offset_init=scrolling_content.y_offset_init,
    )
Пример #7
0
 def test_across_steps_scroll_down(self):
     scrolling_content = movement.ScrollingContent(30, 4, 0, 1, 2, 3)
     scrolling_content.reset()
     assert not scrolling_content.update(20)
     assert not scrolling_content.end_of_segment_reached
     assert scrolling_content.update(50)
     assert not scrolling_content.end_of_segment_reached
     assert scrolling_content.x_offset == 2
     assert scrolling_content.y_offset == 6
     assert scrolling_content.current_step_num == 2
     assert scrolling_content.elapsed_time == 70
     assert scrolling_content.extra_time_after_end == 0
Пример #8
0
 def test_perpetual_scroll(self):
     scrolling_content = movement.ScrollingContent(30, 0, 0, -1, 2, 3)
     scrolling_content.reset()
     assert scrolling_content.update(130)
     assert not scrolling_content.end_of_segment_reached
     assert scrolling_content.x_offset == 2
     assert scrolling_content.y_offset == -2  # moves at t=0, 30, 60, 90, 120
     assert scrolling_content.total_duration == 0
     assert scrolling_content.step_duration == 30
     assert scrolling_content.total_steps == 0
     assert scrolling_content.current_step_num == 0
     assert scrolling_content.elapsed_time == 10
     assert scrolling_content.extra_time_after_end == 0
Пример #9
0
 def test_init(self):
     scrolling_content = movement.ScrollingContent(30, 4, -1, 0, 2, 3)
     assert scrolling_content.x_offset_init == 2
     assert scrolling_content.y_offset_init == 3
     assert scrolling_content.x_offset is None
     assert scrolling_content.y_offset is None
     assert scrolling_content.current_step_num is None
     assert scrolling_content.elapsed_time is None
     assert scrolling_content.extra_time_after_end is None
     assert scrolling_content.total_duration == 120
     assert scrolling_content.step_duration == 30
     assert scrolling_content.total_steps == 4
     assert scrolling_content.delta_x_per_step == -1
     assert scrolling_content.delta_y_per_step == 0
Пример #10
0
 def test_reset_scroll(self):
     scrolling_content = movement.ScrollingContent(30, 4, 0, -1, 2, 3)
     scrolling_content.reset()
     scrolling_content.update(80)
     scrolling_content.update(70)
     # (assume other movements happen, then loop back to this movement)
     scrolling_content.reset()
     scrolling_content.set_offset(8, 9)
     assert not scrolling_content.end_of_segment_reached
     assert scrolling_content.x_offset == 8
     assert scrolling_content.y_offset == 9
     assert scrolling_content.current_step_num == 0
     assert scrolling_content.elapsed_time == 0
     assert scrolling_content.extra_time_after_end == 0
Пример #11
0
    def setup_method(self):
        self.content_pixels = [
            [0, 0, (255, 0, 0)],
            [0, 7, (0, 255, 0)],
            [0, 15, (0, 0, 255)],
        ]

        self.next_content_pixels = [
            [0, 0, (255, 0, 0)],
            [1, 0, (255, 0, 0)],
            [0, 7, (0, 255, 0)],
            [1, 7, (0, 255, 0)],
            [0, 15, (0, 0, 255)],
            [1, 15, (0, 0, 255)],
        ]

        self.board = board.Board(
            board_w=8,
            board_h=8,
            sections=[
                board.BoardSection(
                    output_x=0,
                    output_y=0,
                    output_w=8,
                    output_h=8,
                    content=board.BoardSectionContent(
                        content_pixels=self.content_pixels,
                        content_w=16,
                        content_h=16,
                    ),
                    movement=movement.ScrollingContent(30, 0, 0, -1),
                )
            ],
        )

        self.next_content = board.BoardSectionContent(
            content_pixels=self.next_content_pixels,
            content_w=16,
            content_h=16)
Пример #12
0
 def setup_method(self):
     self.tracker = movement.MovementCycle([
         movement.StaticContent(200),
         movement.ScrollingContent(15, 4, -1, 0)
     ])
Пример #13
0
 def test_update_no_reset(self):
     scrolling_content = movement.ScrollingContent(30, 4, -1, 0)
     with pytest.raises(movement.MovementException):
         scrolling_content.update(20)