$darkmode
DENOPTIM
SymmetricAPsTest.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.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertNull;
24import static org.junit.jupiter.api.Assertions.assertTrue;
25
26import java.util.HashSet;
27import java.util.Set;
28
29import javax.vecmath.Point3d;
30
31import org.junit.jupiter.api.Test;
32
33public class SymmetricAPsTest
34{
35
36//------------------------------------------------------------------------------
37
38 @Test
39 public void testSameAs() throws Exception
40 {
44 v3.addAPOnAtom(v3.getAtom(0), APClass.make("foo:0"),
45 new Point3d(new double[]{3.0, -1.0, 3.3}));
46
47 assertEquals(1, v1.getSymmetricAPSets().size());
48 assertEquals(1, v2.getSymmetricAPSets().size());
49 assertEquals(1, v3.getSymmetricAPSets().size());
50 SymmetricAPs s1 = v1.getSymmetricAPSets().get(0);
51 SymmetricAPs s2 = v2.getSymmetricAPSets().get(0);
52 SymmetricAPs s3 = v3.getSymmetricAPSets().get(0);
53
54 //Make sure APs are different instances
55 assertFalse(s1.get(0)==s2.get(0));
56
57 assertTrue(s1.sameAs(s1));
58 assertTrue(s1.sameAs(s2));
59 assertFalse(s1.sameAs(s3));
60
61 s2.get(0).setAPClass(APClass.make("different:0"));
62 assertFalse(s1.sameAs(s2));
63 }
64
65//------------------------------------------------------------------------------
66
67 @Test
68 public void testGetSameAsThis() throws Exception
69 {
71
72 // SymmetricAPs with 3 APs
74 v3.addAPOnAtom(v3.getAtom(0), APClass.make("foo:0"),
75 new Point3d(new double[]{3.0, -1.0, 3.3}));
76
77 // Two SymmetricAPs: one line in v1 one different
79 v4.addAPOnAtom(v4.getAtom(2), APClass.make("apc:2"),
80 new Point3d(new double[]{0.0, 0.0, 3.3}));
81
82 assertEquals(1, v1.getSymmetricAPSets().size());
83 assertEquals(1, v3.getSymmetricAPSets().size());
84 assertEquals(2, v4.getSymmetricAPSets().size());
85 SymmetricAPs s1 = v1.getSymmetricAPSets().get(0);
86 SymmetricAPs s3 = v3.getSymmetricAPSets().get(0);
87 SymmetricAPs s4a = v4.getSymmetricAPSets().get(0);
88 SymmetricAPs s4b = v4.getSymmetricAPSets().get(1);
89
90 Set<SymmetricAPs> others = new HashSet<SymmetricAPs>();
91 others.add(s3);
92 others.add(s4a);
93 others.add(s4b);
94 assertTrue(s4b == s1.getSameAs(others));
95
96 others = new HashSet<SymmetricAPs>();
97 others.add(s3);
98 others.add(s4a);
99 assertNull(s1.getSameAs(others));
100
101 others = new HashSet<SymmetricAPs>();
102 others.add(s1);
103 others.add(s3);
104 assertTrue(s1 == s1.getSameAs(others));
105 }
106
107//------------------------------------------------------------------------------
108
109}
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:136
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
AttachmentPoint addAPOnAtom(IAtom srcAtm, APClass apc, Point3d vector)
Add an attachment point to the specifies atom.
Definition: Fragment.java:424
IAtom getAtom(int number)
Definition: Fragment.java:843
List< SymmetricAPs > getSymmetricAPSets()
Definition: Fragment.java:1148
Unit test for DENOPTIMFragment.
static Fragment makeFragmentA()
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
SymmetricAPs getSameAs(Set< SymmetricAPs > others)
Identifies a set of symmetric APs that, although it contains references to different instances of Att...
boolean sameAs(SymmetricAPs other)
Checks if this collection SymmetricAPs is analogous to the other one, i.e., they contain AttachmentPo...
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
abstract List< SymmetricAPs > getSymmetricAPSets()