$darkmode
DENOPTIM
RingTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph;
20
21import static org.junit.jupiter.api.Assertions.assertEquals;
22
23import java.util.ArrayList;
24import java.util.List;
25
26import org.junit.jupiter.api.Test;
27
34public class RingTest {
35
36//------------------------------------------------------------------------------
37
38 @Test
39 public void testUndirectedComparison() throws Exception
40 {
41 List<Vertex> lst = new ArrayList<Vertex>();
42 for (int i=0; i<5; i++)
43 {
44 EmptyVertex v = new EmptyVertex();
46 lst.add(v);
47 }
48 Ring r = new Ring(lst);
49
50 EmptyVertex newV = new EmptyVertex();
51 r.insertVertex(newV, lst.get(0), lst.get(1));
52 assertEquals(1,r.indexOf(newV));
53
54 EmptyVertex newV2 = new EmptyVertex();
55 r.insertVertex(newV2, lst.get(2), lst.get(1));
56 assertEquals(2,r.indexOf(newV2));
57 }
58
59//------------------------------------------------------------------------------
60
61 @Test
62 public void testGetDistance() throws Exception
63 {
64 List<Vertex> lst = new ArrayList<Vertex>();
65 for (int i=0; i<5; i++)
66 {
67 EmptyVertex v = new EmptyVertex();
69 lst.add(v);
70 }
71 Ring r = new Ring(lst);
72
73 assertEquals(3,r.getDistance(lst.get(0), lst.get(3)));
74 assertEquals(3,r.getDistance(lst.get(3), lst.get(0)));
75 }
76
77
78//------------------------------------------------------------------------------
79
80 @Test
81 public void testGetCloserVertex() throws Exception
82 {
83 List<Vertex> lst = new ArrayList<Vertex>();
84 for (int i=0; i<10; i++)
85 {
86 EmptyVertex v = new EmptyVertex();
88 lst.add(v);
89 }
90 Ring r = new Ring(lst);
91
94 assertEquals(r.getVertexAtPosition(4), v);
95
96
99 assertEquals(r.getVertexAtPosition(4), v);
100
103 assertEquals(r.getVertexAtPosition(4), v);
104
107 assertEquals(r.getVertexAtPosition(4), v);
108
109
112 assertEquals(r.getVertexAtPosition(8), v);
113
116 assertEquals(r.getVertexAtPosition(8), v);
117
120 assertEquals(r.getVertexAtPosition(8), v);
121
122
124 assertEquals(r.getVertexAtPosition(8), v);
125
127 assertEquals(r.getVertexAtPosition(4), v);
128 }
129
130//------------------------------------------------------------------------------
131}
An empty vertex has the behaviors of a vertex, but has no molecular structure.
This class represents the closure of a ring in a spanning tree.
Definition: Ring.java:40
Vertex getCloserToHead(Vertex vA, Vertex vB)
Chooses among the two given vertices the one that is closer to the head vertex.
Definition: Ring.java:349
Vertex getVertexAtPosition(int i)
Definition: Ring.java:107
int getDistance(Vertex v1, Vertex v2)
Measures how many edges there are between two edges along the sequence of vertices that defined this ...
Definition: Ring.java:325
int indexOf(Vertex v)
Returns the index of the first occurrence of the specified element in this ring, or -1 if this list d...
Definition: Ring.java:122
boolean insertVertex(int position, Vertex newLink)
Adds a vertex to the ring, in the given position.
Definition: Ring.java:275
Vertex getCloserTo(Vertex vA, Vertex vB, Vertex vT)
Chooses among the two given vertices the one that is closer to the target vertex.
Definition: Ring.java:378
Vertex getCloserToTail(Vertex vA, Vertex vB)
Chooses among the two given vertices the one that is closer to the tail vertex.
Definition: Ring.java:363
void testUndirectedComparison()
Definition: RingTest.java:39
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:291