@Test public void calculateThroughput_b(){ Date date = new Date(); List<Throughput> testResult = new ArrayList<Throughput>(); List<PacketInfo> packets = new ArrayList<PacketInfo>(); PacketInfo pktInfo01 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo01.getDir()).thenReturn(PacketDirection.UPLINK); Mockito.when(pktInfo01.getTimeStamp()).thenReturn(date.getTime()+20000.0); packets.add(pktInfo01); PacketInfo pktInfo02 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo02.getDir()).thenReturn(PacketDirection.DOWNLINK); Mockito.when(pktInfo02.getTimeStamp()).thenReturn(date.getTime()+20400.0); packets.add(pktInfo02); PacketInfo pktInfo03 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo03.getDir()).thenReturn(PacketDirection.DOWNLINK); Mockito.when(pktInfo03.getTimeStamp()).thenReturn(date.getTime()+20500.0); packets.add(pktInfo03); PacketInfo pktInfo04 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo04.getDir()).thenReturn(PacketDirection.DOWNLINK); Mockito.when(pktInfo04.getTimeStamp()).thenReturn(date.getTime()+41000.0); packets.add(pktInfo04); PacketInfo pktInfo05 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo05.getDir()).thenReturn(PacketDirection.DOWNLINK); Mockito.when(pktInfo05.getTimeStamp()).thenReturn(date.getTime()+71000.0); packets.add(pktInfo05); PacketInfo pktInfo06 = Mockito.mock(PacketInfo.class); Mockito.when(pktInfo06.getDir()).thenReturn(PacketDirection.UPLINK); Mockito.when(pktInfo06.getTimeStamp()).thenReturn(date.getTime()+72000.0); packets.add(pktInfo06); testResult = throughputCalculator.calculateThroughput(date.getTime()+0.0, date.getTime()+73000.0, 60000.0, packets); assertEquals(2,testResult.size()); }
public List<Throughput> calculateThroughput(double startTime, double endTime, double window, List<PacketInfo> packets) { List<Throughput> result = new ArrayList<Throughput>(); List<PacketInfo> split = new ArrayList<>(); if(window < 0.00001 || endTime-startTime < 0.00001) { return Collections.emptyList(); } double splitStart = startTime; double splitEnd = startTime + window; for (PacketInfo packet : packets) { double stamp = packet.getTimeStamp(); if (stamp < startTime) { continue; } else if (stamp >= endTime) { result.add(getThroughput(splitStart, splitEnd, split)); break; } else if (stamp >= splitEnd) { while (stamp >= splitEnd) { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } split.add(packet); } else if (stamp >= splitStart) { split.add(packet); } } do { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } while (endTime >= splitStart); return result; }
ThroughputCalculatorImpl implements IThroughputCalculator { public List<Throughput> calculateThroughput(double startTime, double endTime, double window, List<PacketInfo> packets) { List<Throughput> result = new ArrayList<Throughput>(); List<PacketInfo> split = new ArrayList<>(); if(window < 0.00001 || endTime-startTime < 0.00001) { return Collections.emptyList(); } double splitStart = startTime; double splitEnd = startTime + window; for (PacketInfo packet : packets) { double stamp = packet.getTimeStamp(); if (stamp < startTime) { continue; } else if (stamp >= endTime) { result.add(getThroughput(splitStart, splitEnd, split)); break; } else if (stamp >= splitEnd) { while (stamp >= splitEnd) { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } split.add(packet); } else if (stamp >= splitStart) { split.add(packet); } } do { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } while (endTime >= splitStart); return result; } }
ThroughputCalculatorImpl implements IThroughputCalculator { public List<Throughput> calculateThroughput(double startTime, double endTime, double window, List<PacketInfo> packets) { List<Throughput> result = new ArrayList<Throughput>(); List<PacketInfo> split = new ArrayList<>(); if(window < 0.00001 || endTime-startTime < 0.00001) { return Collections.emptyList(); } double splitStart = startTime; double splitEnd = startTime + window; for (PacketInfo packet : packets) { double stamp = packet.getTimeStamp(); if (stamp < startTime) { continue; } else if (stamp >= endTime) { result.add(getThroughput(splitStart, splitEnd, split)); break; } else if (stamp >= splitEnd) { while (stamp >= splitEnd) { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } split.add(packet); } else if (stamp >= splitStart) { split.add(packet); } } do { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } while (endTime >= splitStart); return result; }  }
ThroughputCalculatorImpl implements IThroughputCalculator { public List<Throughput> calculateThroughput(double startTime, double endTime, double window, List<PacketInfo> packets) { List<Throughput> result = new ArrayList<Throughput>(); List<PacketInfo> split = new ArrayList<>(); if(window < 0.00001 || endTime-startTime < 0.00001) { return Collections.emptyList(); } double splitStart = startTime; double splitEnd = startTime + window; for (PacketInfo packet : packets) { double stamp = packet.getTimeStamp(); if (stamp < startTime) { continue; } else if (stamp >= endTime) { result.add(getThroughput(splitStart, splitEnd, split)); break; } else if (stamp >= splitEnd) { while (stamp >= splitEnd) { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } split.add(packet); } else if (stamp >= splitStart) { split.add(packet); } } do { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } while (endTime >= splitStart); return result; }  List<Throughput> calculateThroughput(double startTime, double endTime, double window,
			List<PacketInfo> packets); }
ThroughputCalculatorImpl implements IThroughputCalculator { public List<Throughput> calculateThroughput(double startTime, double endTime, double window, List<PacketInfo> packets) { List<Throughput> result = new ArrayList<Throughput>(); List<PacketInfo> split = new ArrayList<>(); if(window < 0.00001 || endTime-startTime < 0.00001) { return Collections.emptyList(); } double splitStart = startTime; double splitEnd = startTime + window; for (PacketInfo packet : packets) { double stamp = packet.getTimeStamp(); if (stamp < startTime) { continue; } else if (stamp >= endTime) { result.add(getThroughput(splitStart, splitEnd, split)); break; } else if (stamp >= splitEnd) { while (stamp >= splitEnd) { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } split.add(packet); } else if (stamp >= splitStart) { split.add(packet); } } do { result.add(getThroughput(splitStart, splitEnd, split)); splitStart = splitEnd; splitEnd = splitStart + window; split = new ArrayList<>(); } while (endTime >= splitStart); return result; }  List<Throughput> calculateThroughput(double startTime, double endTime, double window,
			List<PacketInfo> packets);  }