Skip to content

Commit

Permalink
Fix unit test for new XYZ precision
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 29, 2024
1 parent 22dacf2 commit f94d30d
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tests/io/xyztest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include <sstream>
#include <string>

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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f94d30d

Please sign in to comment.