Skip to content

Commit 97a820e

Browse files
committed
New test and make fields public
1 parent 783ce48 commit 97a820e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

tool/formula/src/main/java/org/openscience/cdk/tools/manipulator/MolecularFormulaManipulator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,10 @@ public static double getTotalMassNumber(IMolecularFormula formula) {
821821
return mass;
822822
}
823823

824-
private static final int MolWeight = 0x1;
825-
private static final int AverageWeight = 0x2;
826-
private static final int MonoIsotopic = 0x3;
827-
private static final int MostAbundant = 0x4;
824+
public static final int MolWeight = 0x1;
825+
public static final int AverageWeight = 0x2;
826+
public static final int MonoIsotopic = 0x3;
827+
public static final int MostAbundant = 0x4;
828828

829829
private static double getExactMass(IsotopeFactory isofact, IIsotope atom) {
830830
if (atom.getExactMass() != null)

tool/formula/src/test/java/org/openscience/cdk/tools/manipulator/MolecularFormulaManipulatorTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,24 +1214,24 @@ public void testImplicitH() throws Exception {
12141214
Assert.assertEquals("C6H6", MolecularFormulaManipulator.getString(f));
12151215

12161216
}
1217-
1217+
12181218
@Test public void noNullPointerExceptionForExactMassOfRGroups() throws Exception {
12191219
IMolecularFormula formula = new MolecularFormula();
12201220
formula.addIsotope(new Isotope("C"));
12211221
formula.addIsotope(new Isotope("H"), 3);
12221222
formula.addIsotope(new Isotope("R"));
12231223
assertThat(MolecularFormulaManipulator.getTotalExactMass(formula),
12241224
closeTo(15.0234, 0.01));
1225-
}
1226-
1225+
}
1226+
12271227
@Test public void noNullPointerExceptionForMassOfRGroups() throws Exception {
12281228
IMolecularFormula formula = new MolecularFormula();
12291229
formula.addIsotope(new Isotope("C"));
12301230
formula.addIsotope(new Isotope("H"), 3);
12311231
formula.addIsotope(new Isotope("R"));
12321232
assertThat(MolecularFormulaManipulator.getTotalMassNumber(formula),
12331233
closeTo(15.0, 0.01));
1234-
}
1234+
}
12351235

12361236
@Test public void noNullPointerExceptionForMajorMassOfRGroups() throws Exception {
12371237
IMolecularFormula formula = new MolecularFormula();
@@ -1249,7 +1249,7 @@ public void testImplicitH() throws Exception {
12491249
mf.addIsotope(carbon, 10);
12501250
MolecularFormulaManipulator.getNaturalExactMass(mf);
12511251
}
1252-
1252+
12531253
@Test public void acceptMinusAsInput() throws Exception {
12541254
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
12551255
IMolecularFormula mf = MolecularFormulaManipulator.getMolecularFormula("[PO4]3–",
@@ -1387,6 +1387,25 @@ public void getMostAbundant() {
13871387
is("[12]C6[79]Br3[81]Br3"));
13881388
}
13891389

1390+
1391+
private static void assertMass(String str, double expMass, int flav) {
1392+
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
1393+
IMolecularFormula mf =
1394+
MolecularFormulaManipulator.getMolecularFormula(str, bldr);
1395+
double act = MolecularFormulaManipulator.getMass(mf, flav);
1396+
assertThat(act, is(closeTo(expMass, 0.01)));
1397+
}
1398+
1399+
@Test
1400+
public void C6Br6() {
1401+
assertMass("C6Br6", 551.485, MolWeight);
1402+
assertMass("C6Br6", 545.510, MonoIsotopic);
1403+
assertMass("C6Br6", 551.503, MostAbundant);
1404+
assertMass("[12]C4[13]C2Br6", 553.427, MolWeight);
1405+
assertMass("[12]C4[13]C2Br6", 547.516, MonoIsotopic);
1406+
assertMass("[12]C4[13]C2Br6", 553.510, MostAbundant);
1407+
}
1408+
13901409
// Iron has 4 stable isotopes, 54 @ 5.85%, 56 @ 91.57%, 57 @ 2.12%, and
13911410
// 58 @ 0.28%. Given 100 iron's we expected ~6 @ 54, ~92 @ 56 and 2 @ 57
13921411
@Test

0 commit comments

Comments
 (0)