1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.edge;
2021import com.google.common.collect.Lists;
22import org.apache.hadoop.io.DoubleWritable;
23import org.apache.hadoop.io.LongWritable;
24import org.junit.Before;
25import org.junit.Test;
2627import java.util.Collection;
28import java.util.List;
2930importstatic org.apache.giraph.graph.TestVertexAndEdges.instantiateOutEdges;
31importstatic org.junit.Assert.assertEquals;
3233/**34 * Tests {@link OutEdges} implementations that disallow parallel edges.35 */36publicclassTestStrictGraphEdges {
37/** {@link OutEdges} classes to be tested. */38private Collection<Class<? extends OutEdges>> edgesClasses =
39 Lists.newArrayList();
4041 @Before
42publicvoid setUp() {
43 edgesClasses.add(HashMapEdges.class);
44 edgesClasses.add(LongDoubleHashMapEdges.class);
45 }
4647/**48 * Ensures that all strict graph {@link OutEdges} implementations49 * disallow parallel edges.50 */51 @Test
52publicvoid testParallelEdges() {
53for (Class<? extends OutEdges> edgesClass : edgesClasses) {
54 testParallelEdgesClass(edgesClass);
55 }
56 }
5758privatevoid testParallelEdgesClass(
59 Class<? extends OutEdges> edgesClass) {
60 OutEdges<LongWritable, DoubleWritable> edges =
61 instantiateOutEdges(edgesClass);
6263// Initial edges list contains parallel edges.64 List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
65 EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
66 EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
67 EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
68 EdgeFactory.create(new LongWritable(2), new DoubleWritable(20)));
6970 edges.initialize(initialEdges);
7172// Only one of the two parallel edges should be left.73 assertEquals(3, edges.size());
7475// Adding a parallel edge shouldn't change the number of edges.76 edges.add(EdgeFactory.create(new LongWritable(3), new DoubleWritable(30)));
77 assertEquals(3, edges.size());
78 }
79 }