@Override
    public AdjacencyList setWeight(int source, int target, double weight) {
        if (digraph) {
            for (Edge edge : graph[source]) {
                if (edge.v2 == target) {
                    edge.weight = weight;
                    return this;
                }
            }
        } else {
            for (Edge edge : graph[source]) {
                if ((edge.v1 == source && edge.v2 == target) || (edge.v2 == source && edge.v1 == target)) {
                    edge.weight = weight;
                    return this;
                }
            }
        }

        addEdge(source, target, weight);
        return this;
    }
@Test
    public void testSetWeight() {
        System.out.println("setWeight");
        g4.setWeight(1, 4, 5.7);
        assertEquals(5.7, g4.getWeight(1, 4), 1E-10);
        assertEquals(1.0, g4.getWeight(4, 1), 1E-10);

        g8.setWeight(1, 4, 5.7);
        assertEquals(5.7, g8.getWeight(1, 4), 1E-10);
        assertEquals(5.7, g8.getWeight(4, 1), 1E-10);
    }