$darkmode
DENOPTIM
UndirectedEdgeRelationTest.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;
22import static org.junit.jupiter.api.Assertions.assertTrue;
23
24import org.junit.jupiter.api.Test;
25
26import denoptim.graph.Edge.BondType;
27import denoptim.graph.Vertex.BBType;
28import denoptim.graph.simplified.UndirectedEdge;
29
35
36//------------------------------------------------------------------------------
37
38 @Test
39 public void testUndirectedComparison() throws Exception {
40 EmptyVertex vA = new EmptyVertex();
43 vA.addAP();
44 vA.addAP();
45 AttachmentPoint apA1 = vA.getAP(0);
46 AttachmentPoint apA2 = vA.getAP(1);
47
48 EmptyVertex vB = new EmptyVertex();
51 vB.addAP();
52 vB.addAP();
53 vB.addAP();
54 AttachmentPoint apB1 = vB.getAP(1);
55 AttachmentPoint apB2 = vB.getAP(2);
56
57 EmptyVertex vS = new EmptyVertex();
60 vS.addAP();
61 vS.addAP();
62 AttachmentPoint apS = vS.getAP(0);
63
64 EmptyVertex vC = new EmptyVertex();
67 vC.addAP();
68 vC.addAP();
69 AttachmentPoint apC = vC.getAP(0);
70
71
72 UndirectedEdge ue1 = new UndirectedEdge(apA1, apB2, BondType.UNDEFINED);
73 UndirectedEdge ue2 = new UndirectedEdge(apB2, apA1, BondType.UNDEFINED);
74 assertEquals(0,ue1.compare(ue1),"Self-comparison");
75 assertEquals(0,ue1.compare(ue2),"Inverse edges should be equal (A)");
76 assertEquals(0,ue2.compare(ue1),"Inverse edges should be equal (B)");
77
78
79 UndirectedEdge ues = new UndirectedEdge(apA1, apS, BondType.UNDEFINED);
80 UndirectedEdge uec = new UndirectedEdge(apA1, apC, BondType.UNDEFINED);
81 assertEquals(1,ue1.compare(ues),"Ranking (A)");
82 assertEquals(-1,ues.compare(ue1),"Ranking (Arev)");
83 assertEquals(-1,ue1.compare(uec),"Ranking (B)");
84 assertEquals(1,uec.compare(ue1),"Ranking (Brev)");
85 assertEquals(1,uec.compare(ues),"Ranking (C)");
86 assertEquals(-1,ues.compare(uec),"Ranking (Crev)");
87
88
89 UndirectedEdge ue41 = new UndirectedEdge(apA1, apB1, BondType.SINGLE);
90 UndirectedEdge ue42 = new UndirectedEdge(apA2, apB2, BondType.SINGLE);
91 assertEquals(-1,ue41.compare(ue42),
92 "Different APs lead to different edge (A)");
93 assertEquals(1,ue42.compare(ue41),
94 "Different APs lead to different edge (B)");
95
96
97 UndirectedEdge ue51 = new UndirectedEdge(apA1,apB1, BondType.SINGLE);
98 UndirectedEdge ue52 = new UndirectedEdge(apA1,apB1, BondType.UNDEFINED);
99 assertTrue(0 < ue51.compare(ue52),
100 "Different bond types lead to different edge (A)");
101 assertTrue(0 > ue52.compare(ue51),
102 "Different bond types lead to different edge (B)");
103 }
104
105//------------------------------------------------------------------------------
106
107}
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
An empty vertex has the behaviors of a vertex, but has no molecular structure.
void addAP()
Adds an attachment point with no APClass or other attribute.
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:291
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:305
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
This class represents an undirected version of the edge between two vertices.
Possible chemical bond types an edge can represent.
Definition: Edge.java:303
The type of building block.
Definition: Vertex.java:86