-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPathTest.java
79 lines (64 loc) · 2.35 KB
/
PathTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.redislabs.redisgraph.graph_entities;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.*;
public class PathTest {
private Node buildNode(int id){
Node n = new Node();
n.setId(0);
return n;
}
private Edge buildEdge(int id, int src, int dst){
Edge e = new Edge();
e.setId(id);
e.setSource(src);
e.setDestination(dst);
return e;
}
private List<Node> buildNodeArray(int size) {
return IntStream.range(0, size).mapToObj(i -> buildNode(i)).collect(Collectors.toList());
}
private List<Edge> buildEdgeArray(int size){
return IntStream.range(0, size).mapToObj(i -> buildEdge(i, i, i+1)).collect(Collectors.toList());
}
private Path buildPath(int nodeCount){
return new Path(buildNodeArray(nodeCount), buildEdgeArray(nodeCount-1));
}
@Test
public void testEmptyPath(){
Path path = buildPath(0);
assertEquals(0, path.length());
assertEquals(0, path.nodeCount());
assertThrows(IndexOutOfBoundsException.class, ()->path.getNode(0));
assertThrows(IndexOutOfBoundsException.class, ()->path.getEdge(0));
assertEquals("Path{nodes=[], edges=[]}", path.toString());
}
@Test
public void testSingleNodePath(){
Path path = buildPath(1);
assertEquals(0, path.length());
assertEquals(1, path.nodeCount());
Node n = new Node();
n.setId(0);
assertEquals(n, path.firstNode());
assertEquals(n, path.lastNode());
assertEquals(n, path.getNode(0));
assertEquals("Path{nodes=[Node{labels=[], id=0, propertyMap={}}], edges=[]}", path.toString());
}
@Test
public void testRandomLengthPath(){
int nodeCount = ThreadLocalRandom.current().nextInt(2, 100 + 1);
Path path = buildPath(nodeCount);
assertEquals(buildNodeArray(nodeCount), path.getNodes());
assertEquals(buildEdgeArray(nodeCount-1), path.getEdges());
assertDoesNotThrow(()->path.getEdge(0));
}
@Test
public void hashCodeEqualTest(){
EqualsVerifier.forClass(Path.class).verify();
}
}