def test_multiple_packets(self): packets: List[Packet] = read_packets("110100010100101001000100100") self.assertEqual(len(packets), 2) first, second = packets self.assertEqual(first.packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(first.data), 10) self.assertEqual(second.packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(second.data), 20)
def test_multiple_packets_count_bound(self): packets: List[Packet] = read_packets( "110100010100101001000100100110100010100101001000100100", max_count=3) self.assertEqual(len(packets), 3) first, second, third = packets self.assertEqual(first.packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(first.data), 10) self.assertEqual(second.packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(second.data), 20) self.assertEqual(third.packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(third.data), 10)
def test_count_operator(self): packets = read_packets( "11101110000000001101010000001100100000100011000001100000") self.assertEqual(len(packets), 1) packet = packets[0] self.assertNotEqual(packet.packet_type, PacketType.LITERAL) self.assertEqual(packet.packet_version, 7) self.assertEqual(len(packet.packets), 3) sub_packets: List[Packet] = [sub for sub in packet.packets] self.assertEqual(sub_packets[0].packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(sub_packets[0].data), 1) self.assertEqual(sub_packets[1].packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(sub_packets[1].data), 2) self.assertEqual(sub_packets[2].packet_type, PacketType.LITERAL) self.assertEqual(bin_to_dex(sub_packets[2].data), 3)
def test_bin_parser(self): self.assertEqual(bin_to_dex("110"), 6) self.assertEqual(bin_to_dex("100"), 4) self.assertEqual(bin_to_dex("011111100101"), 2021)