Exemple #1
0
class TestDisplay(unittest.TestCase):
    """Tests for 'Display' class."""

    def setUp(self):
        """Set up test fixtures, if any."""
        self.conn = MockConn()
        self.mock_kwargs = [-1, -1, self.conn]
        self.display = Display(*self.mock_kwargs)

    def tearDown(self):
        """Tear down test fixtures, if any."""
        del self.display

    def test_set_text(self):
        """Test set_text method."""
        mock_text = "abcd"
        self.display.text = mock_text
        clear_message = parse_message(0x04, 21, -1, (0, 0))
        text_message = parse_message(
            0x04, 17, -1, parse_data(mock_text + '\0', 'string')
        )
        self.assertEqual(
            self.conn.send_list[0],
            clear_message
        )
        self.assertEqual(
            self.conn.send_list[1],
            text_message
        )

    def test_show_variable(self):
        """Test set_variable method."""
        mock_variable = 123
        mock_position = 5
        self.display.show_variable(mock_variable, mock_position, mock_position)
        self.assertEqual(
            self.conn.send_list[0],
            parse_message(0x04, 22, -1, parse_data(
                (mock_variable, mock_position, mock_position), 'display_var'
            ))
        )

    def test_clear(self):
        """Test clear method."""
        self.display.clear()
        clear_message = parse_message(0x04, 21, -1, (0, 0))
        self.assertEqual(self.conn.send_list[0], clear_message)
Exemple #2
0
class TestDisplay(unittest.TestCase):
    """Tests for 'Display' class."""
    def setUp(self):
        """Set up test fixtures, if any."""
        self.send_q = Queue()
        self.mock_kwargs = {"id_": -1, "uuid": -1, "msg_send_q": self.send_q}
        self.display = Display(**self.mock_kwargs)

    def tearDown(self):
        """Tear down test fixtures, if any."""
        del self.display

    def test_set_text(self):
        """Test set_text method."""
        mock_text = "abcd"
        self.display.text = mock_text
        clear_message = parse_message(0x04, 21, -1, (0, 0))
        text_message = parse_message(0x04, 17, -1,
                                     parse_data(mock_text, 'string'))
        self.assertEqual(self.send_q.get(), clear_message)
        self.assertEqual(self.send_q.get(), text_message)

    def test_show_variable(self):
        """Test set_variable method."""
        mock_variable = 123
        mock_position = 5
        self.display.show_variable(mock_variable, mock_position, mock_position)
        self.assertEqual(
            self.send_q.get(),
            parse_message(
                0x04, 22, -1,
                parse_data((mock_variable, mock_position, mock_position),
                           'display_var')))

    def test_clear(self):
        """Test clear method."""
        self.display.clear()
        clear_message = parse_message(0x04, 21, -1, (0, 0))
        self.assertEqual(self.send_q.get(), clear_message)
Exemple #3
0
def update_screen(pos: Tuple[int, int], vel: Tuple[int, int], bar: int,
                  display: Display) -> Tuple[Tuple[int, int], Tuple[int, int]]:
    """Update the screen of the display module after moving the ball

    :param pos: Position of the ball
    :param vel: Velocity of the ball
    :param bar: Position of the bar
    :param display: Reference to display module
    :return: Tuple[Tuple[int, int], Tuple[int, int]]
    """
    display.show_variable(0, pos[0], pos[1])
    display.show_variable(1, bar, 60)
    pos = (pos[0] + vel[0], pos[1] + vel[1])
    if pos[0] < 0 or pos[0] > 40:
        vel = (-vel[0], vel[1])
    if pos[1] < 0 or pos[1] > 55:
        vel = (vel[0], -vel[1])
    if pos[1] < 0:
        pos = (pos[0], 0)
    if pos[0] < 0:
        pos = (0, pos[1])
    return pos, vel