Skip to content
Permalink
Browse files
improve test
  • Loading branch information
coderzc committed Dec 28, 2021
1 parent cc8ea12 commit 086c355e58a45219f797ff870464c9ea1cc0237b
Showing 4 changed files with 86 additions and 20 deletions.
@@ -79,8 +79,8 @@ public int hashCode() {
@Override
public String toString() {
return new ToStringBuilder(this).append("type", this.type)
.append("path", this.path)
.append("struct", this.struct)
.toString();
.append("path", this.path)
.append("struct", this.struct)
.toString();

Check warning on line 84 in computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/loader/FileInputSplit.java

Codecov / codecov/patch

computer-core/src/main/java/com/baidu/hugegraph/computer/core/input/loader/FileInputSplit.java#L81-L84

Added lines #L81 - L84 were not covered by tests
}
}
@@ -20,7 +20,6 @@
package com.baidu.hugegraph.computer.algorithm.centrality.degree;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
@@ -32,31 +31,28 @@
import com.baidu.hugegraph.computer.core.graph.edge.Edge;
import com.baidu.hugegraph.computer.core.graph.value.DoubleValue;
import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
import com.baidu.hugegraph.computer.core.output.hdfs.HdfsOutput;
import com.google.common.collect.Streams;

public class DegreeCentralityTest extends AlgorithmTestBase {

@Test
public void testRunAlgorithm() throws InterruptedException {
runAlgorithm(DegreeCentralityTestParams.class.getName(),
DegreeCentrality.OPTION_WEIGHT_PROPERTY, "rate");
DegreeCentralityTestOutput.assertResult();

runAlgorithm(DegreeCentralityTestParams.class.getName());
runAlgorithm(DegreeCentralityParams.class.getName(),
DegreeCentrality.OPTION_WEIGHT_PROPERTY,
"rate",
ComputerOptions.OUTPUT_CLASS.name(),
DegreeCentralityTestOutput.class.getName());
DegreeCentralityTestOutput.assertResult();
}

public static class DegreeCentralityTestParams
extends DegreeCentralityParams {

@Override
public void setAlgorithmParameters(Map<String, String> params) {
params.put(ComputerOptions.OUTPUT_CLASS.name(),
DegreeCentralityTestOutput.class.getName());
params.put(ComputerOptions.INPUT_SOURCE_TYPE.name(),
"loader");
super.setAlgorithmParameters(params);
}
@Test
public void testRunAlgorithmFromHdfs() throws InterruptedException {
runAlgorithm(DegreeCentralityParams.class.getName(),
ComputerOptions.OUTPUT_CLASS.name(),
HdfsOutput.class.getName(),
ComputerOptions.INPUT_SOURCE_TYPE.name(),
"loader");
}

public static class DegreeCentralityTestOutput
@@ -0,0 +1,69 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.computer.core.input;

import org.junit.Test;
import org.mockito.Mockito;

import com.baidu.hugegraph.computer.core.input.loader.FileInputSplit;
import com.baidu.hugegraph.loader.constant.ElemType;
import com.baidu.hugegraph.loader.mapping.InputStruct;
import com.baidu.hugegraph.testutil.Assert;

public class FileInputSplitTest {

@Test
public void testConstructor() {
InputStruct inputStruct = Mockito.mock(InputStruct.class);
FileInputSplit split = new FileInputSplit(ElemType.VERTEX, inputStruct,
"/tmp/test");
Assert.assertEquals("/tmp/test", split.path());
Assert.assertEquals(inputStruct, split.struct());
Assert.assertSame(ElemType.VERTEX, split.type());
}

@Test
public void testEquals() {
InputStruct inputStruct = Mockito.mock(InputStruct.class);
FileInputSplit split1 = new FileInputSplit(ElemType.VERTEX, inputStruct,
"/tmp/test");
FileInputSplit split2 = new FileInputSplit(ElemType.VERTEX, inputStruct,
"/tmp/test");
Assert.assertEquals(split1, split1);
Assert.assertEquals(split1, split2);

Assert.assertNotEquals(split1, null);
Assert.assertNotEquals(split1, new Object());

Assert.assertEquals(InputSplit.END_SPLIT, InputSplit.END_SPLIT);
Assert.assertNotEquals(InputSplit.END_SPLIT, split1);
}

@Test
public void testHashCode() {
InputStruct inputStruct = Mockito.mock(InputStruct.class);
FileInputSplit split1 = new FileInputSplit(ElemType.VERTEX, inputStruct,
"/tmp/test");
FileInputSplit split2 = new FileInputSplit(ElemType.VERTEX, inputStruct,
"/tmp/test");
Assert.assertEquals(split1.hashCode(), split2.hashCode());
}

}
@@ -25,6 +25,7 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
InputSplitTest.class,
FileInputSplitTest.class,
InputSplitDataTest.class,
HugeConverterTest.class
})

0 comments on commit 086c355

Please sign in to comment.