def test_average_bitrate_two_packets(self): for i in range(10): packet_size_bytes = random.uniform(1.0, 8000.0) delay_ms = random.uniform(10.0, 300.0) gap_ms = random.uniform(10.0, 50.0) packet1 = Packet(1, 0.0, packet_size_bytes) packet2 = Packet(2, gap_ms, packet_size_bytes) packet1.arrival_time_ms = delay_ms packet2.arrival_time_ms = gap_ms + delay_ms self.assertNear(average_bitrate_kbps([packet1, packet2]), 8.0 * packet_size_bytes / gap_ms, 0.001)
def test_average_bitrate_single_packet(self): for i in range(10): packet_size_bytes = random.uniform(1.0, 8000.0) delay_ms = random.uniform(10.0, 300.0) packet = Packet(1, 0.0, packet_size_bytes) packet.arrival_time_ms = delay_ms self.assertEqual(average_bitrate_kbps([packet]), 8.0 * packet_size_bytes / delay_ms)
def test_receiving_rate_kbps_single_packet(self): payload_sizes_bytes = [0.0, 500.0, 1200.0] # Empty or non-empty packet. for payload_size_bytes in payload_sizes_bytes: # id and send_time don't matter here. packet = Packet(None, None, payload_size_bytes) for i in range(10): packet.arrival_time_ms = i time_window_ms = random.uniform(100.0, 1000.0) self.assertEqual(receiving_rate_kbps([packet], time_window_ms), 8.0 * packet.payload_size_bytes / time_window_ms)
def test_receiving_rate_kbps_single_packet(self): payload_sizes_bytes = [0.0, 500.0, 1200.0] # Empty or non-empty packet. for payload_size_bytes in payload_sizes_bytes: # id and send_time don't matter here. packet = Packet(None, None, payload_size_bytes) for i in range(10): packet.arrival_time_ms = i time_window_ms = random.uniform(100.0, 1000.0) self.assertEqual( receiving_rate_kbps([packet], time_window_ms), 8.0 * packet.payload_size_bytes / time_window_ms)
def test_loss_ratio_gap_packets(self): packets = [] for i in range(10): # Only id and arrival time matter here packet = Packet(i, None, None) packet.arrival_time_ms = 10.0 * i packets.append(packet) for i in range(20, 30): # Only id and arrival time matter here packet = Packet(i, None, None) packet.arrival_time_ms = 10.0 * i packets.append(packet) # Short time windows won't trigger loss computation. for t in range(0, 200, 10): self.assertEqual(loss_ratio(packets, t), 0.0) for i in range(10): time_window_ms = 200 + 10 * i loss = 1.0 - float(11 + i) / (21 + i) self.assertEqual(loss_ratio(packets, time_window_ms), loss)
def test_loss_ratio_gap_packets(self): packets = [] for i in range(10): # Only id and arrival time matter here packet = Packet(i, None, None) packet.arrival_time_ms = 10.0 * i packets.append(packet) for i in range(20, 30): # Only id and arrival time matter here packet = Packet(i, None, None) packet.arrival_time_ms = 10.0 * i packets.append(packet) # Short time windows won't trigger loss computation. for t in range(0, 200, 10): self.assertEqual(loss_ratio(packets, t), 0.0) for i in range(10): time_window_ms = 200 + 10*i loss = 1.0 - float(11 + i)/(21 + i) self.assertEqual(loss_ratio(packets, time_window_ms), loss)
def test_loss_ratio_single_packet(self): # Only id and arrival time matter here packet = Packet(1, None, None) packet.arrival_time_ms = 10.0 self.assertEqual(loss_ratio([packet], 0.0), 0.0) self.assertEqual(loss_ratio([packet], 50.0), 0.0)