From 079857285dae8a2f3f6d98b3925413fd9f05f6d6 Mon Sep 17 00:00:00 2001 From: Michael Wedel Date: Fri, 10 Apr 2015 10:21:11 +0200 Subject: [PATCH] Refs #11510. Fix unit tests. --- .../BraggScattererInCrystalStructureTest.h | 205 +++++++++--------- .../test/CompositeBraggScattererTest.h | 14 +- .../test/IsotropicAtomBraggScattererTest.h | 8 +- 3 files changed, 115 insertions(+), 112 deletions(-) diff --git a/Code/Mantid/Framework/Geometry/test/BraggScattererInCrystalStructureTest.h b/Code/Mantid/Framework/Geometry/test/BraggScattererInCrystalStructureTest.h index 55fec618dfb9..03fb54bbf46b 100644 --- a/Code/Mantid/Framework/Geometry/test/BraggScattererInCrystalStructureTest.h +++ b/Code/Mantid/Framework/Geometry/test/BraggScattererInCrystalStructureTest.h @@ -13,149 +13,152 @@ using namespace Mantid::Kernel; using ::testing::Return; using ::testing::A; -class BraggScattererInCrystalStructureTest : public CxxTest::TestSuite -{ +class BraggScattererInCrystalStructureTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically // This means the constructor isn't called when running other tests - static BraggScattererInCrystalStructureTest *createSuite() { return new BraggScattererInCrystalStructureTest(); } - static void destroySuite( BraggScattererInCrystalStructureTest *suite ) { delete suite; } - + static BraggScattererInCrystalStructureTest *createSuite() { + return new BraggScattererInCrystalStructureTest(); + } + static void destroySuite(BraggScattererInCrystalStructureTest *suite) { + delete suite; + } - void testInitialization() - { - BraggScattererInCrystalStructure_sptr scatterer = getDefaultScatterer(); + void testInitialization() { + BraggScattererInCrystalStructure_sptr scatterer = getDefaultScatterer(); - TS_ASSERT(!scatterer->isInitialized()); - TS_ASSERT_THROWS_NOTHING(scatterer->initialize()); - TS_ASSERT(scatterer->isInitialized()); + TS_ASSERT(!scatterer->isInitialized()); + TS_ASSERT_THROWS_NOTHING(scatterer->initialize()); + TS_ASSERT(scatterer->isInitialized()); - TS_ASSERT(scatterer->existsProperty("Position")); - TS_ASSERT(scatterer->existsProperty("UnitCell")); - TS_ASSERT(scatterer->existsProperty("SpaceGroup")); + TS_ASSERT(scatterer->existsProperty("Position")); + TS_ASSERT(scatterer->existsProperty("UnitCell")); + TS_ASSERT(scatterer->existsProperty("SpaceGroup")); } - void testAfterScattererPropertySet() - { - //BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); - //MockBraggScatterer *mockScatterer = dynamic_cast(scatterer.get()); - //EXPECT_CALL(mockScatterer, afterScattererPropertySet) + void testAfterScattererPropertySet() { + // BraggScattererInCrystalStructure_sptr scatterer = + // getInitializedScatterer(); + // MockBraggScatterer *mockScatterer = dynamic_cast(scatterer.get()); + // EXPECT_CALL(mockScatterer, afterScattererPropertySet) } - void testGetSetPosition() - { - BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); + void testGetSetPosition() { + BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); - V3D goodPosition(0.2, 0.4, 0.3); - TS_ASSERT_THROWS_NOTHING(scatterer->setProperty("Position", goodPosition)); + V3D goodPosition(0.2, 0.4, 1./3.); + scatterer->setProperty("Position", "0.2, 0.4, 1/3"); - V3D testPos; - TS_ASSERT_THROWS_NOTHING(testPos = scatterer->getPosition()); - TS_ASSERT_EQUALS(testPos, goodPosition); + V3D testPos; + TS_ASSERT_THROWS_NOTHING(testPos = scatterer->getPosition()); + TS_ASSERT_EQUALS(testPos, goodPosition); - V3D badPosition(1.2, 4.3, -6.2); - TS_ASSERT_THROWS_NOTHING(scatterer->setProperty("Position", badPosition)); - TS_ASSERT_THROWS_NOTHING(testPos = scatterer->getPosition()); - TS_ASSERT_DIFFERS(testPos, badPosition); - TS_ASSERT_EQUALS(testPos, V3D(0.2, 0.3, 0.8)); + V3D badPosition(1.2, 4.3, -6.2); + TS_ASSERT_THROWS_NOTHING( + scatterer->setProperty("Position", "[1.2, 4.3, -6.2]")); + TS_ASSERT_THROWS_NOTHING(testPos = scatterer->getPosition()); + TS_ASSERT_DIFFERS(testPos, badPosition); + TS_ASSERT_EQUALS(testPos, V3D(0.2, 0.3, 0.8)); } - void testGetSetCell() - { - BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); + void testGetSetCell() { + BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); - UnitCell cell(5.43, 5.43, 5.43); + UnitCell cell(5.43, 5.43, 5.43); - TS_ASSERT_THROWS_NOTHING(scatterer->setProperty("UnitCell", unitCellToStr(cell))); - TS_ASSERT_EQUALS(scatterer->getCell().getG(), cell.getG()); + TS_ASSERT_THROWS_NOTHING( + scatterer->setProperty("UnitCell", unitCellToStr(cell))); + TS_ASSERT_EQUALS(scatterer->getCell().getG(), cell.getG()); } - void testGetSetSpaceGroup() - { - BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); + void testGetSetSpaceGroup() { + BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); - SpaceGroup_const_sptr testGroup = SpaceGroupFactory::Instance().createSpaceGroup("P m -3 m"); + SpaceGroup_const_sptr testGroup = + SpaceGroupFactory::Instance().createSpaceGroup("P m -3 m"); - TS_ASSERT_THROWS_NOTHING(scatterer->setProperty("SpaceGroup", "P m -3 m")); - TS_ASSERT_EQUALS(scatterer->getSpaceGroup()->hmSymbol(), testGroup->hmSymbol()); + TS_ASSERT_THROWS_NOTHING(scatterer->setProperty("SpaceGroup", "P m -3 m")); + TS_ASSERT_EQUALS(scatterer->getSpaceGroup()->hmSymbol(), + testGroup->hmSymbol()); } - void testEquivalentPositions() - { - BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); + void testEquivalentPositions() { + BraggScattererInCrystalStructure_sptr scatterer = getInitializedScatterer(); - V3D generalPosition(0.3, 0.32, 0.45); + V3D generalPosition(0.3, 0.32, 0.45); - // No space group set - no equivalent positions - scatterer->setProperty("Position", generalPosition); - TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), 1); - TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().front(), generalPosition); + // No space group set - no equivalent positions + scatterer->setProperty("Position", "[0.3, 0.32, 0.45]"); + TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), 1); + TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().front(), + generalPosition); - // Assigning a space group must cause recalculation of equivalent positions - SpaceGroup_const_sptr testGroup = SpaceGroupFactory::Instance().createSpaceGroup("P m -3 m"); - scatterer->setProperty("SpaceGroup", "P m -3 m"); + // Assigning a space group must cause recalculation of equivalent positions + SpaceGroup_const_sptr testGroup = + SpaceGroupFactory::Instance().createSpaceGroup("P m -3 m"); + scatterer->setProperty("SpaceGroup", "P m -3 m"); - TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), testGroup->order()); + TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), + testGroup->order()); - // Re-setting the position also recalculates - V3D specialPosition(0.0, 0.0, 0.0); + // Re-setting the position also recalculates + V3D specialPosition(0.0, 0.0, 0.0); - scatterer->setProperty("Position", specialPosition); - // Pm-3m does not contain translations, so (0,0,0) is not transformed by any symmetry operation of the group - TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), 1); - TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().front(), specialPosition); + scatterer->setProperty("Position", "[0, 0, 0]"); + // Pm-3m does not contain translations, so (0,0,0) is not transformed by any + // symmetry operation of the group + TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().size(), 1); + TS_ASSERT_EQUALS(scatterer->getEquivalentPositions().front(), + specialPosition); } - void testUnitCellStringValidator() - { - IValidator_sptr validator = boost::make_shared(); - - // non-working examples - TS_ASSERT_DIFFERS(validator->isValid("1.0"), ""); - TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0"), ""); - TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0"), ""); - TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0 1.0"), ""); - TS_ASSERT_DIFFERS(validator->isValid("1.0.3 1.0 1.0"), ""); - - // Working examples - TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0"), ""); - TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0"), ""); - TS_ASSERT_EQUALS(validator->isValid("1 2 3 90 90 90"), ""); - TS_ASSERT_EQUALS(validator->isValid("1.1 2.2 3.2 90 90 90"), ""); - TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0 "), ""); + void testUnitCellStringValidator() { + IValidator_sptr validator = boost::make_shared(); + + // non-working examples + TS_ASSERT_DIFFERS(validator->isValid("1.0"), ""); + TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0"), ""); + TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0"), ""); + TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0 1.0"), ""); + TS_ASSERT_DIFFERS(validator->isValid("1.0.3 1.0 1.0"), ""); + + // Working examples + TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0"), ""); + TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0"), ""); + TS_ASSERT_EQUALS(validator->isValid("1 2 3 90 90 90"), ""); + TS_ASSERT_EQUALS(validator->isValid("1.1 2.2 3.2 90 90 90"), ""); + TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0 "), ""); } private: - BraggScattererInCrystalStructure_sptr getDefaultScatterer() - { - boost::shared_ptr mockScatterer = boost::make_shared(); - EXPECT_CALL(*mockScatterer, afterScattererPropertySet(A())) - .WillRepeatedly(Return()); - - return mockScatterer; + BraggScattererInCrystalStructure_sptr getDefaultScatterer() { + boost::shared_ptr mockScatterer = + boost::make_shared(); + EXPECT_CALL(*mockScatterer, + afterScattererPropertySet(A())) + .WillRepeatedly(Return()); + + return mockScatterer; } - BraggScattererInCrystalStructure_sptr getInitializedScatterer() - { - BraggScattererInCrystalStructure_sptr raw = getDefaultScatterer(); - raw->initialize(); + BraggScattererInCrystalStructure_sptr getInitializedScatterer() { + BraggScattererInCrystalStructure_sptr raw = getDefaultScatterer(); + raw->initialize(); - return raw; + return raw; } - class MockBraggScatterer : public BraggScattererInCrystalStructure - { + class MockBraggScatterer : public BraggScattererInCrystalStructure { public: - MockBraggScatterer() : BraggScattererInCrystalStructure() { } - ~MockBraggScatterer() { } + MockBraggScatterer() : BraggScattererInCrystalStructure() {} + ~MockBraggScatterer() {} - MOCK_CONST_METHOD0(name, std::string()); - MOCK_CONST_METHOD0(clone, BraggScatterer_sptr()); - MOCK_CONST_METHOD1(calculateStructureFactor, StructureFactor(const V3D&)); - MOCK_METHOD1(afterScattererPropertySet, void(const std::string &)); + MOCK_CONST_METHOD0(name, std::string()); + MOCK_CONST_METHOD0(clone, BraggScatterer_sptr()); + MOCK_CONST_METHOD1(calculateStructureFactor, StructureFactor(const V3D &)); + MOCK_METHOD1(afterScattererPropertySet, void(const std::string &)); }; - }; - #endif /* MANTID_GEOMETRY_BRAGGSCATTERERINCRYSTALSTRUCTURETEST_H_ */ diff --git a/Code/Mantid/Framework/Geometry/test/CompositeBraggScattererTest.h b/Code/Mantid/Framework/Geometry/test/CompositeBraggScattererTest.h index 30439be9570b..c43ddd4bcf67 100644 --- a/Code/Mantid/Framework/Geometry/test/CompositeBraggScattererTest.h +++ b/Code/Mantid/Framework/Geometry/test/CompositeBraggScattererTest.h @@ -34,8 +34,8 @@ class CompositeBraggScattererTest : public CxxTest::TestSuite TS_ASSERT_THROWS_NOTHING(CompositeBraggScatterer_sptr scatterer = CompositeBraggScatterer::create()); std::vector scatterers; - scatterers.push_back(getInitializedScatterer("Si", V3D(0.35, 0, 0))); - scatterers.push_back(getInitializedScatterer("Si", V3D(0.25, 0.25, 0.25))); + scatterers.push_back(getInitializedScatterer("Si", "0.35, 0, 0")); + scatterers.push_back(getInitializedScatterer("Si", "1/4, 1/4, 1/4")); CompositeBraggScatterer_sptr scatterer = CompositeBraggScatterer::create(scatterers); TS_ASSERT_EQUALS(scatterer->nScatterers(), 2); @@ -64,7 +64,7 @@ class CompositeBraggScattererTest : public CxxTest::TestSuite CompositeBraggScatterer_sptr scatterer = CompositeBraggScatterer::create(); TS_ASSERT_EQUALS(scatterer->propertyCount(), 0); - IsotropicAtomBraggScatterer_sptr siOne = getInitializedScatterer("Si", V3D(0, 0, 0)); + IsotropicAtomBraggScatterer_sptr siOne = getInitializedScatterer("Si", "[0, 0, 0]"); TS_ASSERT_DIFFERS(siOne->getSpaceGroup()->hmSymbol(), spaceGroup->hmSymbol()); size_t oldCount = scatterer->nScatterers(); @@ -128,7 +128,7 @@ class CompositeBraggScattererTest : public CxxTest::TestSuite SpaceGroup_const_sptr spaceGroup = SpaceGroupFactory::Instance().createSpaceGroup("P 1 2/m 1"); CompositeBraggScatterer_sptr coll = CompositeBraggScatterer::create(); - coll->addScatterer(getInitializedScatterer("Si", V3D(0.2, 0.3, 0.4), 0.01267)); + coll->addScatterer(getInitializedScatterer("Si", "[0.2, 0.3, 0.4]", 0.01267)); coll->setProperty("SpaceGroup", spaceGroup->hmSymbol()); coll->setProperty("UnitCell", unitCellToStr(cell)); @@ -146,7 +146,7 @@ class CompositeBraggScattererTest : public CxxTest::TestSuite } private: - IsotropicAtomBraggScatterer_sptr getInitializedScatterer(const std::string &element, const V3D &position, double U = 0.0, double occ = 1.0) + IsotropicAtomBraggScatterer_sptr getInitializedScatterer(const std::string &element, const std::string &position, double U = 0.0, double occ = 1.0) { IsotropicAtomBraggScatterer_sptr scatterer = boost::make_shared(); scatterer->initialize(); @@ -161,8 +161,8 @@ class CompositeBraggScattererTest : public CxxTest::TestSuite CompositeBraggScatterer_sptr getCompositeScatterer() { std::vector scatterers; - scatterers.push_back(getInitializedScatterer("Si", V3D(0.35, 0, 0))); - scatterers.push_back(getInitializedScatterer("Si", V3D(0.25, 0.25, 0.25))); + scatterers.push_back(getInitializedScatterer("Si", "[0.35, 0, 0]")); + scatterers.push_back(getInitializedScatterer("Si", "1/4, 1/4, 1/4")); return CompositeBraggScatterer::create(scatterers); } diff --git a/Code/Mantid/Framework/Geometry/test/IsotropicAtomBraggScattererTest.h b/Code/Mantid/Framework/Geometry/test/IsotropicAtomBraggScattererTest.h index 8a17e6a3271d..f8481161c28b 100644 --- a/Code/Mantid/Framework/Geometry/test/IsotropicAtomBraggScattererTest.h +++ b/Code/Mantid/Framework/Geometry/test/IsotropicAtomBraggScattererTest.h @@ -78,7 +78,7 @@ class IsotropicAtomBraggScattererTest : public CxxTest::TestSuite void testCreate() { - IsotropicAtomBraggScatterer_sptr isotropic = getInitializedScatterer("Si", V3D(0.3, 0.1, 0.12), 1.0, 0.5); + IsotropicAtomBraggScatterer_sptr isotropic = getInitializedScatterer("Si", "[0.3, 0.1, 0.12]", 1.0, 0.5); TS_ASSERT(isotropic); TS_ASSERT_EQUALS(isotropic->getElement(), "Si"); @@ -92,7 +92,7 @@ class IsotropicAtomBraggScattererTest : public CxxTest::TestSuite UnitCell cell(5.43, 5.43, 5.43); SpaceGroup_const_sptr spaceGroup = SpaceGroupFactory::Instance().createSpaceGroup("P m -3 m"); - IsotropicAtomBraggScatterer_sptr scatterer = getInitializedScatterer("H", V3D(1.0, 0, 0), 0.0); + IsotropicAtomBraggScatterer_sptr scatterer = getInitializedScatterer("H", "[1, 0, 0]", 0.0); scatterer->setProperty("U", 3.04); scatterer->setProperty("Occupancy", 0.5); scatterer->setProperty("UnitCell", unitCellToStr(cell)); @@ -116,7 +116,7 @@ class IsotropicAtomBraggScattererTest : public CxxTest::TestSuite void testCalculateStructureFactor() { - IsotropicAtomBraggScatterer_sptr scatterer = getInitializedScatterer("Si", V3D(0.0, 0.0, 0.0), 0.0); + IsotropicAtomBraggScatterer_sptr scatterer = getInitializedScatterer("Si", "0, 0, 0", 0.0); double bSi = scatterer->getNeutronAtom().coh_scatt_length_real; @@ -192,7 +192,7 @@ class IsotropicAtomBraggScattererTest : public CxxTest::TestSuite return scatterer; } - IsotropicAtomBraggScatterer_sptr getInitializedScatterer(const std::string &element, const V3D &position, double U = 0.0, double occ = 1.0) + IsotropicAtomBraggScatterer_sptr getInitializedScatterer(const std::string &element, const std::string &position, double U = 0.0, double occ = 1.0) { IsotropicAtomBraggScatterer_sptr scatterer = getInitializedScatterer();