1 package uk.ac.cam.ch.wwmm.opsin;
2 import static org.junit.Assert.*;
3 
4 import org.junit.AfterClass;
5 import org.junit.BeforeClass;
6 import org.junit.Test;
7 
8 import uk.ac.cam.ch.wwmm.opsin.OpsinResult.OPSIN_RESULT_STATUS;
9 
10 public class NameToStructureConfigurationsTest {
11 
12 		private static NameToStructure n2s;
13 
14 		@BeforeClass
setUp()15 		public static void setUp() {
16 			n2s = NameToStructure.getInstance();
17 		}
18 
19 		@AfterClass
cleanUp()20 		public static void cleanUp() {
21 			n2s = null;
22 		}
23 
24 		@Test
testAllowRadicals()25 		public void testAllowRadicals() throws StructureBuildingException {
26 			NameToStructureConfig n2sConfig = NameToStructureConfig.getDefaultConfigInstance();
27 			n2sConfig.setAllowRadicals(false);
28 			OpsinResult or = n2s.parseChemicalName("methyl", n2sConfig);
29 			assertEquals(OPSIN_RESULT_STATUS.FAILURE, or.getStatus());
30 
31 			n2sConfig.setAllowRadicals(true);
32 			or = n2s.parseChemicalName("methyl", n2sConfig);
33 			assertEquals(OPSIN_RESULT_STATUS.SUCCESS, or.getStatus());
34 		}
35 
36 		@Test
testOutputRadicalsAsWildCards()37 		public void testOutputRadicalsAsWildCards() throws StructureBuildingException {
38 			NameToStructureConfig n2sConfig = NameToStructureConfig.getDefaultConfigInstance();
39 			n2sConfig.setAllowRadicals(true);
40 			n2sConfig.setOutputRadicalsAsWildCardAtoms(false);
41 			OpsinResult or = n2s.parseChemicalName("methyl", n2sConfig);
42 			assertEquals("[CH3]", or.getSmiles());
43 
44 			n2sConfig.setOutputRadicalsAsWildCardAtoms(true);
45 			or = n2s.parseChemicalName("methyl", n2sConfig);
46 			assertEquals("C*", or.getSmiles());
47 		}
48 
49 		@Test
testInterpretAcidsWithoutTheWordAcid()50 		public void testInterpretAcidsWithoutTheWordAcid() throws StructureBuildingException {
51 			NameToStructureConfig n2sConfig = NameToStructureConfig.getDefaultConfigInstance();
52 			n2sConfig.setInterpretAcidsWithoutTheWordAcid(false);
53 			OpsinResult or = n2s.parseChemicalName("acetic", n2sConfig);
54 			assertEquals(OPSIN_RESULT_STATUS.FAILURE, or.getStatus());
55 
56 			n2sConfig.setInterpretAcidsWithoutTheWordAcid(true);
57 			or = n2s.parseChemicalName("acetic", n2sConfig);
58 			assertEquals(OPSIN_RESULT_STATUS.SUCCESS, or.getStatus());
59 		}
60 
61 		@Test
testWarnRatherThanFailOnUninterpretableStereochemistry()62 		public void testWarnRatherThanFailOnUninterpretableStereochemistry() throws StructureBuildingException {
63 			NameToStructureConfig n2sConfig = NameToStructureConfig.getDefaultConfigInstance();
64 			n2sConfig.setWarnRatherThanFailOnUninterpretableStereochemistry(false);
65 			OpsinResult or = n2s.parseChemicalName("(R)-2,2'-Bis(diphenylphosphino)-1,1'-binaphthyl", n2sConfig);
66 			assertEquals(OPSIN_RESULT_STATUS.FAILURE, or.getStatus());
67 
68 			n2sConfig.setWarnRatherThanFailOnUninterpretableStereochemistry(true);
69 			or = n2s.parseChemicalName("(R)-2,2'-Bis(diphenylphosphino)-1,1'-binaphthyl", n2sConfig);
70 			assertEquals(OPSIN_RESULT_STATUS.WARNING, or.getStatus());
71 		}
72 }
73