本文整理汇总了C++中Molecule::formula方法的典型用法代码示例。如果您正苦于以下问题:C++ Molecule::formula方法的具体用法?C++ Molecule::formula怎么用?C++ Molecule::formula使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Molecule
的用法示例。
在下文中一共展示了Molecule::formula方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
TEST(HydrogenToolsTest, adjustHydrogens_adjustments)
{
for (int i = 0; i < 3; ++i) {
HydrogenTools::Adjustment adjustment;
std::string expectedFormula;
switch (i) {
case 0:
adjustment = HydrogenTools::Add;
expectedFormula = "C2H14";
break;
case 1:
adjustment = HydrogenTools::Remove;
expectedFormula = "C2H5";
break;
case 2:
adjustment = HydrogenTools::AddAndRemove;
expectedFormula = "C2H8";
break;
}
Molecule mol;
Atom C1 = mol.addAtom(6); // Overbond this atom
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
mol.addBond(C1, mol.addAtom(1));
Atom C2 = mol.addAtom(6); // Underbond this atom
mol.addBond(C2, mol.addAtom(1));
EXPECT_EQ(std::string("C2H11"), mol.formula());
HydrogenTools::adjustHydrogens(mol, adjustment);
EXPECT_EQ(expectedFormula, mol.formula());
}
}
示例2:
TEST(HydrogenToolsTest, adjustHydrogens_C2H4O)
{
Molecule mol;
Atom C1 = mol.addAtom(6);
Atom C2 = mol.addAtom(6);
Atom O1 = mol.addAtom(8);
mol.addBond(C1, C2, 1);
mol.addBond(C2, O1, 2);
HydrogenTools::adjustHydrogens(mol);
EXPECT_EQ(7, mol.atomCount());
EXPECT_EQ(6, mol.bondCount());
EXPECT_EQ(std::string("C2H4O"), mol.formula());
}