### Question:
NetworkLatency { protected int getLatency(Node from, Node to, int delta) { if (from == to) { return 1; } int base = from.extraLatency + to.extraLatency; base += getExtendedLatency(from, to, delta); return Math.max(1, base); }  @Override String toString(); static MeasuredNetworkLatency estimateLatency(Network net, final int rounds); static MeasuredNetworkLatency estimateP2PLatency(P2PNetwork<?> net, final int rounds); static MeasuredNetworkLatency estimateLatency(
      Network net, PeerGetter pg, final int rounds);  }### Answer:
@Test public void testAwsLatency() { NetworkLatency nl = new NetworkLatency.AwsRegionNetworkLatency(); Geo geoInfo = new GeoAWS(); Random rd = new Random(); for (String r1 : NetworkLatency.AwsRegionNetworkLatency.cities()) { NodeBuilder b1 = new NodeBuilder.NodeBuilderWithCity(Collections.singletonList(r1), geoInfo); Node n1 = new Node(rd, b1); for (String r2 : NetworkLatency.AwsRegionNetworkLatency.cities()) { NodeBuilder b2 = new NodeBuilder.NodeBuilderWithCity(Collections.singletonList(r2), geoInfo); Node n2 = new Node(rd, b2); int l = nl.getLatency(n1, n2, 0); if (r1.equals(r2)) { Assert.assertEquals(1, l); } else { Assert.assertTrue(r1 + " -> " + r2 + ": " + l, l > 1); } } } }
@Test public void testIC3NetworkLatency() { NetworkLatency nl = new NetworkLatency.IC3NetworkLatency(); Node a0 = new Node(new Random(0), new NodeBuilder()); Node a00 = new Node(new Random(0), new NodeBuilder()); Assert.assertEquals(NetworkLatency.IC3NetworkLatency.S10 / 2, nl.getLatency(a0, a00, 0)); NodeBuilder nb = new NodeBuilder() { @Override public int getX(int rdi) { return Node.MAX_X / 2; } @Override public int getY(int rdi) { return Node.MAX_Y / 2; } }; Node a1 = new Node(new Random(0), nb); Assert.assertEquals(NetworkLatency.IC3NetworkLatency.SW / 2, nl.getLatency(a0, a1, 0)); Assert.assertEquals(NetworkLatency.IC3NetworkLatency.SW / 2, nl.getLatency(a1, a0, 0)); }
@Test public void testCitiesLatency() { CSVLatencyReader lr = new CSVLatencyReader(); Assert.assertTrue(lr.cities().size() > 0); NodeBuilder nb = new NodeBuilder.NodeBuilderWithCity(lr.cities(), new GeoAllCities()); NetworkLatency nl = new NetworkLatency.NetworkLatencyByCity(); Random rd = new Random(); List<Node> ln = new ArrayList<>(); for (int i = 0; i < 100; i++) { ln.add(new Node(rd, nb)); } for (Node f : ln) { for (Node t : ln) { int l = nl.getLatency(f, t, 1); if (f == t) { Assert.assertEquals(1, l); } else if (f.cityName.equals(t.cityName)) { Assert.assertTrue(l > 0); } else { Assert.assertTrue( "l=" + l + ", from=" + f.fullToString() + ", to=" + t.fullToString(), l > 0); } } } }