diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 59278bf48a..e2cc91c22c 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -326,12 +326,12 @@ bool XyzFormat::write(std::ostream& outStream, const Core::Molecule& mol) } outStream << std::setw(3) << std::left - << Elements::symbol(atom.atomicNumber()) << " " << std::setw(10) - << std::right << std::fixed << std::setprecision(5) - << atom.position3d().x() << " " << std::setw(10) << std::right - << std::fixed << std::setprecision(5) << atom.position3d().y() - << " " << std::setw(10) << std::right << std::fixed - << std::setprecision(5) << atom.position3d().z() << "\n"; + << Elements::symbol(atom.atomicNumber()) << " " << std::setw(15) + << std::right << std::fixed << std::setprecision(10) + << atom.position3d().x() << " " << std::setw(15) << std::right + << std::fixed << std::setprecision(10) << atom.position3d().y() + << " " << std::setw(15) << std::right << std::fixed + << std::setprecision(10) << atom.position3d().z() << "\n"; } return true; diff --git a/tests/io/xyztest.cpp b/tests/io/xyztest.cpp index 457b885ecb..84cce2e7bf 100644 --- a/tests/io/xyztest.cpp +++ b/tests/io/xyztest.cpp @@ -28,11 +28,11 @@ #include #include +using Avogadro::Vector3; using Avogadro::Core::Atom; using Avogadro::Core::Molecule; using Avogadro::Io::FileFormat; using Avogadro::Io::XyzFormat; -using Avogadro::Vector3; // methane.xyz uses atomic symbols to identify atoms TEST(XyzTest, readAtomicSymbols) @@ -119,19 +119,25 @@ TEST(XyzTest, write) std::string output; EXPECT_EQ(xyz.writeString(output, molecule), true); - // The output should be an exact match with the sample file. - std::istringstream outputStream(output); - std::ifstream refStream(AVOGADRO_DATA "/data/methane.xyz"); - char outputChar = '\0'; - char refChar = '\0'; - outputStream >> std::noskipws; - refStream >> std::noskipws; - bool checkedSomething = false; - while ((outputStream >> outputChar) && (refStream >> refChar)) { - ASSERT_EQ(refChar, outputChar); - checkedSomething = true; - } - EXPECT_TRUE(checkedSomething); + // this part is more of a roundtrip test + Molecule readMolecule; + xyz.readString(output, readMolecule); + + // make sure we've got the same thing + EXPECT_EQ(readMolecule.atomCount(), 5); + + // Bond perception will result in 4 bonds + EXPECT_EQ(readMolecule.bondCount(), 4); + + EXPECT_EQ(readMolecule.atom(0).atomicNumber(), 6); + EXPECT_EQ(readMolecule.atom(1).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(2).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(3).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(4).atomicNumber(), 1); + + EXPECT_EQ(readMolecule.atom(4).position3d().x(), -0.51336); + EXPECT_EQ(readMolecule.atom(4).position3d().y(), 0.889165); + EXPECT_EQ(readMolecule.atom(4).position3d().z(), -0.36300); } TEST(XyzTest, modes)