Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junit5 #901

Merged
merged 17 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 7 additions & 2 deletions app/depict/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
<artifactId>vecmath</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.openscience.cdk.depict;

import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.sgroup.Sgroup;
Expand All @@ -38,7 +38,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class AbbreviationsTest {
class AbbreviationsTest {

private static final SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());

Expand All @@ -47,7 +47,7 @@ static IAtomContainer smi(String smi) throws Exception {
}

@Test
public void potassiumCarbonate() throws Exception {
void potassiumCarbonate() throws Exception {
IAtomContainer mol = smi("[K+].[O-]C(=O)[O-].[K+]");
Abbreviations factory = new Abbreviations();
factory.add("[K+].[O-]C(=O)[O-].[K+] K2CO3");
Expand All @@ -59,7 +59,7 @@ public void potassiumCarbonate() throws Exception {
}

@Test
public void phenyl() throws Exception {
void phenyl() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("CCCCCCC(c1ccccc1)(c1ccccc1)c1ccccc1");
factory.add("*c1ccccc1 Ph");
Expand All @@ -77,7 +77,7 @@ public void phenyl() throws Exception {
}

@Test
public void phenylShouldNotMatchBenzene() throws Exception {
void phenylShouldNotMatchBenzene() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("c1ccccc1");
factory.add("*c1ccccc1 Ph");
Expand All @@ -86,7 +86,7 @@ public void phenylShouldNotMatchBenzene() throws Exception {
}

@Test
public void TFASaltDisconnected() throws Exception {
void TFASaltDisconnected() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("c1ccccc1c1ccccc1.FC(F)(F)C(=O)O");
factory.add("*C(F)(F)F CF3");
Expand All @@ -98,7 +98,7 @@ public void TFASaltDisconnected() throws Exception {
}

@Test
public void TFASaltConnected() throws Exception {
void TFASaltConnected() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("FC(F)(F)C(=O)O");
factory.add("*C(F)(F)F CF3");
Expand All @@ -115,7 +115,7 @@ public void TFASaltConnected() throws Exception {
}

@Test
public void DcmAndTfa() throws Exception {
void DcmAndTfa() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("ClCCl.FC(F)(F)C(=O)O");
factory.add("ClCCl DCM");
Expand All @@ -127,7 +127,7 @@ public void DcmAndTfa() throws Exception {
}

@Test
public void DcmAndTfaNoSingleFrag() throws Exception {
void DcmAndTfaNoSingleFrag() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("ClCCl.FC(F)(F)C(=O)O");
factory.add("ClCCl DCM");
Expand All @@ -139,15 +139,15 @@ public void DcmAndTfaNoSingleFrag() throws Exception {
}

@Test
public void avoidOverZealousAbbreviations() throws Exception {
void avoidOverZealousAbbreviations() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("Clc1ccccc1");
factory.add("*c1ccccc1 Ph");
assertThat(factory.apply(mol), is(0));
}

@Test
public void phenylShouldNotMatchC4H6() throws Exception {
void phenylShouldNotMatchC4H6() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("Oc1ccc(O)cc1");
factory.add("*c1ccccc1 Ph");
Expand All @@ -156,7 +156,7 @@ public void phenylShouldNotMatchC4H6() throws Exception {
}

@Test
public void phenylShouldAbbreviateExplicitHydrogens() throws Exception {
void phenylShouldAbbreviateExplicitHydrogens() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("CCCCc1ccc([H])cc1");
factory.add("*c1ccccc1 Ph");
Expand All @@ -169,7 +169,7 @@ public void phenylShouldAbbreviateExplicitHydrogens() throws Exception {

// some SMARTS foo here :-)
@Test
public void phenylShouldMatchKekuleForm() throws Exception {
void phenylShouldMatchKekuleForm() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("CCCCC1=CC=CC=C1");
factory.add("*c1ccccc1 Ph");
Expand All @@ -182,7 +182,7 @@ public void phenylShouldMatchKekuleForm() throws Exception {

// SMARTS foo not that good
@Test
public void nitroGroups() throws Exception {
void nitroGroups() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("O=N(=O)CCCC[N+]([O-])=O");
factory.add("*N(=O)(=O) NO2");
Expand All @@ -198,7 +198,7 @@ public void nitroGroups() throws Exception {
}

@Test
public void abbreviationsHavePriority() throws Exception {
void abbreviationsHavePriority() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("c1ccccc1CCC");
factory.add("*CCC Pr");
Expand All @@ -209,7 +209,7 @@ public void abbreviationsHavePriority() throws Exception {
}

@Test
public void dontOverwriteExistingSgroups() throws Exception {
void dontOverwriteExistingSgroups() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*CCC Bu");
IAtomContainer mol = smi("c1ccccc1CCC");
Expand All @@ -224,7 +224,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.size(), is(0));
}

@Test public void NHBocFromHeteroCollapse() throws Exception {
@Test
void NHBocFromHeteroCollapse() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(=O)OC(C)(C)C Boc");
IAtomContainer mol = smi("c1ccccc1NC(=O)OC(C)(C)C");
Expand All @@ -235,7 +236,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(8));
}

@Test public void NHBocFromHeteroCollapseExplicitH() throws Exception {
@Test
void NHBocFromHeteroCollapseExplicitH() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(=O)OC(C)(C)C Boc");
IAtomContainer mol = smi("c1ccccc1N([H])C(=O)OC(C)(C)C");
Expand All @@ -246,7 +248,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(9));
}

@Test public void NBocClFromHeteroCollapseExplicit() throws Exception {
@Test
void NBocClFromHeteroCollapseExplicit() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(=O)OC(C)(C)C Boc");
IAtomContainer mol = smi("c1ccccc1N(Cl)C(=O)OC(C)(C)C");
Expand All @@ -257,7 +260,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(9));
}

@Test public void NBoc2FromHeteroCollapse() throws Exception {
@Test
void NBoc2FromHeteroCollapse() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(=O)OC(C)(C)C Boc");
IAtomContainer mol = smi("c1cc2ccccc2cc1N(C(=O)OC(C)(C)C)C(=O)OC(C)(C)C");
Expand All @@ -268,7 +272,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(15));
}

@Test public void iPrFromHeteroCollapse() throws Exception {
@Test
void iPrFromHeteroCollapse() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(C)C iPr");
IAtomContainer mol = smi("[CH3:27][CH:19]([CH3:28])[C:20]1=[N:26][C:23](=[CH:22][S:21]1)[C:24](=[O:25])O");
Expand All @@ -279,7 +284,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(3));
}

@Test public void NBocFromHeteroCollapseExplicitH() throws Exception {
@Test
void NBocFromHeteroCollapseExplicitH() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*C(=O)OC(C)(C)C Boc");
IAtomContainer mol = smi("c1cc2ccccc2ccn1C(=O)OC(C)(C)C");
Expand All @@ -290,7 +296,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getAtoms().size(), is(8));
}

@Test public void SO3minusFromHeteroCollapseNone() throws Exception {
@Test
void SO3minusFromHeteroCollapseNone() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("*S(=O)(=O)[O-] SO3-");
IAtomContainer mol = smi("c1ccccc1N(S(=O)(=O)[O-])S(=O)(=O)[O-]");
Expand All @@ -300,7 +307,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(1).getSubscript(), is("SO3-"));
}

@Test public void hclSaltOfEdci() throws Exception {
@Test
void hclSaltOfEdci() throws Exception {
Abbreviations factory = new Abbreviations();
factory.add("CCN=C=NCCCN(C)C EDCI");
factory.setContractToSingleLabel(true);
Expand All @@ -310,23 +318,26 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getSubscript(), is("EDCI·HCl"));
}

@Test public void SnCl2() throws Exception {
@Test
void SnCl2() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("Cl[Sn]Cl");
List<Sgroup> sgroups = factory.generate(mol);
assertThat(sgroups.size(), is(1));
assertThat(sgroups.get(0).getSubscript(), is("SnCl2"));
}

@Test public void HOOH() throws Exception {
@Test
void HOOH() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("OO");
List<Sgroup> sgroups = factory.generate(mol);
assertThat(sgroups.size(), is(1));
assertThat(sgroups.get(0).getSubscript(), is("HOOH"));
}

@Test public void multipleDisconnectedAbbreviations() throws Exception {
@Test
void multipleDisconnectedAbbreviations() throws Exception {
String smi = "ClCCl.Cl[Pd]Cl.[Fe+2].c1ccc(P([c-]2cccc2)c2ccccc2)cc1.c1ccc(P([c-]2cccc2)c2ccccc2)cc1";
Abbreviations factory = new Abbreviations();
factory.add("ClCCl DCM");
Expand All @@ -338,7 +349,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getSubscript(), is("Pd(dppf)Cl2·DCM"));
}

@Test public void multipleDisconnectedAbbreviations2() throws Exception {
@Test
void multipleDisconnectedAbbreviations2() throws Exception {
String smi = "ClCCl.Cl[Pd]Cl.[Fe+2].c1ccc(P([c-]2cccc2)c2ccccc2)cc1.c1ccc(P([c-]2cccc2)c2ccccc2)cc1";
Abbreviations factory = new Abbreviations();
factory.add("Cl[Pd]Cl.[Fe+2].c1ccc(P([c-]2cccc2)c2ccccc2)cc1.c1ccc(P([c-]2cccc2)c2ccccc2)cc1 Pd(dppf)Cl2");
Expand All @@ -351,7 +363,8 @@ public void dontOverwriteExistingSgroups() throws Exception {
}

// Don't generate NiPr
@Test public void avoidAmbiguity() throws Exception {
@Test
void avoidAmbiguity() throws Exception {
String smi = "C1CCCCC1=NC(C)C";
Abbreviations factory = new Abbreviations();
factory.add("*C(C)C iPr");
Expand All @@ -362,7 +375,7 @@ public void dontOverwriteExistingSgroups() throws Exception {
}

@Test
public void loadFromFile() throws Exception {
void loadFromFile() throws Exception {
Abbreviations factory = new Abbreviations();
assertThat(factory.loadFromFile("obabel_superatoms.smi"), is(27));
assertThat(factory.loadFromFile("/org/openscience/cdk/depict/obabel_superatoms.smi"), is(27));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,61 @@

package org.openscience.cdk.depict;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;

import static org.junit.Assert.*;

public class DepictionTest {
class DepictionTest {

@Test
public void depictAsPs() throws CDKException {
void depictAsPs() throws CDKException {
DepictionGenerator dg = new DepictionGenerator();
SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer ac = sp.parseSmiles("[nH]1cccc1");
String eps = dg.depict(ac).toPsStr();
String nl = System.getProperty("line.separator");
String[] lines = eps.split(nl,3);
assertEquals("%!PS-Adobe-3.0", lines[0]);
assertEquals("%%Creator: FreeHEP Graphics2D Driver", lines[1]);
Assertions.assertEquals("%!PS-Adobe-3.0", lines[0]);
Assertions.assertEquals("%%Creator: FreeHEP Graphics2D Driver", lines[1]);
}

@Test
public void depictAsEps() throws CDKException {
void depictAsEps() throws CDKException {
DepictionGenerator dg = new DepictionGenerator();
SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer ac = sp.parseSmiles("[nH]1cccc1");
String eps = dg.depict(ac).toEpsStr();
String nl = System.getProperty("line.separator");
String[] lines = eps.split(nl,3);
assertEquals("%!PS-Adobe-3.0 EPSF-3.0", lines[0]);
assertEquals("%%BoundingBox: 0 0 28 35", lines[1]);
Assertions.assertEquals("%!PS-Adobe-3.0 EPSF-3.0", lines[0]);
Assertions.assertEquals("%%BoundingBox: 0 0 28 35", lines[1]);
}

@Test
public void depictAsEps2() throws CDKException {
void depictAsEps2() throws CDKException {
DepictionGenerator dg = new DepictionGenerator();
SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer ac = sp.parseSmiles("C1CCCCC1CCCCC");
String eps = dg.depict(ac).toEpsStr();
String nl = System.getProperty("line.separator");
String[] lines = eps.split(nl,3);
assertEquals("%!PS-Adobe-3.0 EPSF-3.0", lines[0]);
assertEquals("%%BoundingBox: 0 0 92 33", lines[1]);
Assertions.assertEquals("%!PS-Adobe-3.0 EPSF-3.0", lines[0]);
Assertions.assertEquals("%%BoundingBox: 0 0 92 33", lines[1]);
}

@Test
public void depictAsSvg() throws CDKException {
void depictAsSvg() throws CDKException {
DepictionGenerator dg = new DepictionGenerator();
SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer ac = sp.parseSmiles("[nH]1cccc1");
String svg = dg.depict(ac).toSvgStr();
String nl = "\n";
String[] lines = svg.split(nl,3);
assertEquals("<?xml version='1.0' encoding='UTF-8'?>", lines[0]);
assertEquals("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">", lines[1]);
Assertions.assertEquals("<?xml version='1.0' encoding='UTF-8'?>", lines[0]);
Assertions.assertEquals("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">", lines[1]);
}

}