void ComposedElementTest::testOperatorNotEqual() { // initializes alphabet Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); // initializes elements Element elementH(*hydrogen); Element elementO(*oxygen); Element elementC(*carbon); elements_container elements; elements[elementH] = 4; elements[elementO] = 2; elements[elementC] = 2; // checks case with different elements composed_element_type molecule1(elements); elements[elementH] = 5; composed_element_type molecule1_not_equal(elements); CPPUNIT_ASSERT(molecule1 != molecule1_not_equal); // checks case with different sequences composed_element_type molecule3("C2H4O2", cho), molecule3_not_equal("C2H3O2", cho); CPPUNIT_ASSERT(molecule3 != molecule3_not_equal); }
void ComposedElementTest::testOperatorMinus() { // initializes alphabet Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); composed_element_type molecule1("H10O6", cho), molecule2("O4H4", cho); molecule1 -= molecule2; CPPUNIT_ASSERT_EQUAL(molecule1.getElements().size(), static_cast<elements_container::size_type>(2)); CPPUNIT_ASSERT_EQUAL(molecule1.getElementAbundance("O"), static_cast<elements_container::mapped_type>(2)); CPPUNIT_ASSERT_EQUAL(molecule1.getElementAbundance("H"), static_cast<elements_container::mapped_type>(6)); composed_element_type molecule3("O8H2", cho), molecule4("O6H7C5", cho); molecule3 -= molecule4; CPPUNIT_ASSERT_EQUAL(molecule3.getElements().size(), static_cast<elements_container::size_type>(1)); CPPUNIT_ASSERT_EQUAL(molecule3.getElementAbundance("O"), static_cast<elements_container::mapped_type>(2)); }
void ComposedElementTest::testOperatorEqual() { // checks for type of constructors with sequence Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); composed_element_type molecule1("H4C2O2", cho); composed_element_type molecule1_equal("H4C2O2", cho); CPPUNIT_ASSERT(molecule1 == molecule1_equal); // checks for type of constructors with elements Element elementH(*hydrogen); Element elementO(*oxygen); Element elementC(*carbon); elements_container elements; elements[elementH] = 4; elements[elementO] = 2; elements[elementC] = 2; // checks for type of constructors with elements and random sequence order composed_element_type molecule2(elements); composed_element_type molecule2_equal(elements); CPPUNIT_ASSERT(molecule2 == molecule2_equal); }
void ComposedElementTest::testUpdateIsotopeDistribution() { Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); std::vector<unsigned int> decomposition; decomposition.push_back(static_cast<unsigned int>(4)); decomposition.push_back(static_cast<unsigned int>(2)); decomposition.push_back(static_cast<unsigned int>(2)); // initializes molecule without setting isotope distribution and sequence composed_element_type molecule(decomposition, cho); molecule.updateIsotopeDistribution(); isotopes_type isodistr = molecule.getIsotopeDistribution(); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(0), static_cast<mass_type>(60.02113), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(1), static_cast<mass_type>(61.0245862), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(2), static_cast<mass_type>(62.0254827), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(3), static_cast<mass_type>(63.0288285), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(0), static_cast<abundance_type>(0.972690002), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(1), static_cast<abundance_type>(0.0231608083), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(2), static_cast<abundance_type>(0.00405304857), 1.0e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(3), static_cast<abundance_type>(9.1561898e-05), 1.0e-6); }
void ComposedElementTest::testConstructorDecompositionAlphabet() { Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); std::vector<unsigned int> decomposition; decomposition.push_back(static_cast<unsigned int>(3)); decomposition.push_back(static_cast<unsigned int>(2)); decomposition.push_back(static_cast<unsigned int>(1)); composed_element_type molecule(decomposition, cho); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("C"), static_cast<elements_container::mapped_type>(2)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("H"), static_cast<elements_container::mapped_type>(3)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("O"), static_cast<elements_container::mapped_type>(1)); // checks if isotope distribution is not yet initialized CPPUNIT_ASSERT(molecule.getIsotopeDistribution().empty()); // checks if sequence is not yet initialized CPPUNIT_ASSERT(molecule.getSequence().empty()); }
void ComposedElementTest::testConstructorTexNotationSequenceAlphabet() { Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); composed_element_type molecule("C_{2}H_{4}O_{2}", cho, composed_element_type::TEX_NOTATION_MOLECULE_SEQUENCE_TYPE); CPPUNIT_ASSERT_EQUAL(molecule.getSequence(), static_cast<name_type>("C_{2}H_{4}O_{2}")); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("C"), static_cast<elements_container::mapped_type>(2)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("H"), static_cast<elements_container::mapped_type>(4)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("O"), static_cast<elements_container::mapped_type>(2)); // checks if isotope distribution is not yet initialized CPPUNIT_ASSERT(molecule.getIsotopeDistribution().empty()); }
void ComposedElementTest::testConstructorSequenceAlphabet() { Alphabet cho; cho.push_back(*hydrogen); cho.push_back(*carbon); cho.push_back(*oxygen); composed_element_type molecule("C2H4O2", cho); CPPUNIT_ASSERT_EQUAL(molecule.getSequence(), static_cast<name_type>("C2H4O2")); CPPUNIT_ASSERT_EQUAL(molecule.getElements().size(), static_cast<elements_container::size_type>(3)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("C"), static_cast<elements_container::mapped_type>(2)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("H"), static_cast<elements_container::mapped_type>(4)); CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("O"), static_cast<elements_container::mapped_type>(2)); // checks if isotope distribution is not yet initialized CPPUNIT_ASSERT(molecule.getIsotopeDistribution().empty()); }