/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testRemove_1() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newIsotope("C"), 1); formulaMin.addIsotope(builder.newIsotope("H"), 1); formulaMin.addIsotope(builder.newIsotope("N"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newIsotope("C"), 4); formulaMax.addIsotope(builder.newIsotope("H"), 12); formulaMax.addIsotope(builder.newIsotope("N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newIsotope("C"), 3); mf1.addIsotope(builder.newIsotope("H"), 10); mf1.addIsotope(builder.newIsotope("N"), 1); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newIsotope("C"), 1); mf2.addIsotope(builder.newIsotope("H"), 1); mf2.addIsotope(builder.newIsotope("N"), 1); IMolecularFormula mf3 = new MolecularFormula(); mf3.addIsotope(builder.newIsotope("C"), 4); mf3.addIsotope(builder.newIsotope("H"), 12); mf3.addIsotope(builder.newIsotope("N"), 2); IMolecularFormula mf4 = new MolecularFormula(); mf4.addIsotope(builder.newIsotope("C"), 7); mf4.addIsotope(builder.newIsotope("H"), 10); mf4.addIsotope(builder.newIsotope("N"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); formulaSet.addMolecularFormula(mf3); formulaSet.addMolecularFormula(mf4); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); /*the mf4 is excluded from the limits*/ Assert.assertEquals(3, newMFSet.size()); Assert.assertEquals( MolecularFormulaManipulator.getString(mf1), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(0))); Assert.assertEquals( MolecularFormulaManipulator.getString(mf2), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(1))); Assert.assertEquals( MolecularFormulaManipulator.getString(mf3), MolecularFormulaManipulator.getString(newMFSet.getMolecularFormula(2))); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testContains_IMolecularFormulaSet_IMolecularFormula() { IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newIsotope("C"), 4); mf1.addIsotope(builder.newIsotope("H"), 12); mf1.addIsotope(builder.newIsotope("N"), 1); mf1.addIsotope(builder.newIsotope("O"), 4); IMolecularFormula mf3 = new MolecularFormula(); mf3.addIsotope(builder.newIsotope("C"), 9); mf3.addIsotope(builder.newIsotope("H"), 5); mf3.addIsotope(builder.newIsotope("O"), 7); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf3); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newIsotope("C"), 4); mf2.addIsotope(builder.newIsotope("H"), 12); mf2.addIsotope(builder.newIsotope("N"), 1); mf2.addIsotope(builder.newIsotope("O"), 4); IMolecularFormula mf4 = new MolecularFormula(); mf4.addIsotope(builder.newIsotope("C"), 4); IIsotope hyd = builder.newIsotope("H"); hyd.setExactMass(2.0032342); mf4.addIsotope(hyd, 12); mf4.addIsotope(builder.newIsotope("N"), 1); mf4.addIsotope(builder.newIsotope("O"), 4); Assert.assertTrue(MolecularFormulaSetManipulator.contains(formulaSet, mf2)); Assert.assertFalse(MolecularFormulaSetManipulator.contains(formulaSet, mf4)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testRemove_IMolecularFormulaSet_MolecularFormulaRange() { MolecularFormulaRange formulaRange = new MolecularFormulaRange(); formulaRange.addIsotope(builder.newIsotope("C"), 0, 4); formulaRange.addIsotope(builder.newIsotope("H"), 0, 12); formulaRange.addIsotope(builder.newIsotope("N"), 0, 2); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newIsotope("C"), 1); mf2.addIsotope(builder.newIsotope("H"), 11); mf2.addIsotope(builder.newIsotope("N"), 1); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newIsotope("C"), 3); mf1.addIsotope(builder.newIsotope("H"), 10); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); formulaSet.addMolecularFormula(mf2); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaRange); /*the mf2 is excluded from the limits. It doesn't contain N*/ Assert.assertEquals(2, newMFSet.size()); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testRemove_IMolecularFormulaSet_IMolecularFormula_IMolecularFormula() { IMolecularFormula formulaMin = new MolecularFormula(); formulaMin.addIsotope(builder.newIsotope("C"), 1); formulaMin.addIsotope(builder.newIsotope("H"), 1); formulaMin.addIsotope(builder.newIsotope("O"), 1); IMolecularFormula formulaMax = new MolecularFormula(); formulaMax.addIsotope(builder.newIsotope("C"), 4); formulaMax.addIsotope(builder.newIsotope("H"), 12); formulaMax.addIsotope(builder.newIsotope("N"), 2); IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newIsotope("C"), 3); mf1.addIsotope(builder.newIsotope("H"), 10); mf1.addIsotope(builder.newIsotope("N"), 1); IMolecularFormulaSet formulaSet = new MolecularFormulaSet(); formulaSet.addMolecularFormula(mf1); IMolecularFormulaSet newMFSet = MolecularFormulaSetManipulator.remove(formulaSet, formulaMin, formulaMax); Assert.assertNull(newMFSet); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetMinOccurrenceElements_IMolecularFormulaSet() { IMolecularFormula mf1 = new MolecularFormula(); /*C4H12NO4*/ mf1.addIsotope(builder.newIsotope("C"), 4); mf1.addIsotope(builder.newIsotope("H"), 12); mf1.addIsotope(builder.newIsotope("N"), 1); mf1.addIsotope(builder.newIsotope("O"), 4); IMolecularFormula mf2 = new MolecularFormula(); /*C7H20N4O2*/ mf2.addIsotope(builder.newIsotope("C"), 7); mf2.addIsotope(builder.newIsotope("H"), 20); mf2.addIsotope(builder.newIsotope("N"), 4); mf2.addIsotope(builder.newIsotope("O"), 2); IMolecularFormula mf3 = new MolecularFormula(); /*C9H5O7*/ mf3.addIsotope(builder.newIsotope("C"), 9); mf3.addIsotope(builder.newIsotope("H"), 5); mf3.addIsotope(builder.newIsotope("O"), 7); IMolecularFormulaSet mfSet = new MolecularFormulaSet(); mfSet.addMolecularFormula(mf1); mfSet.addMolecularFormula(mf2); mfSet.addMolecularFormula(mf3); IMolecularFormula molecularFormula = MolecularFormulaSetManipulator.getMinOccurrenceElements(mfSet); /* Result: C4H5NO2 */ Assert.assertEquals(12, MolecularFormulaManipulator.getAtomCount(molecularFormula)); Assert.assertEquals(4, molecularFormula.getIsotopeCount()); Assert.assertEquals(4, molecularFormula.getIsotopeCount(builder.newIsotope("C"))); Assert.assertEquals(5, molecularFormula.getIsotopeCount(builder.newIsotope("H"))); Assert.assertEquals(1, molecularFormula.getIsotopeCount(builder.newIsotope("N"))); Assert.assertEquals(2, molecularFormula.getIsotopeCount(builder.newIsotope("O"))); }