Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/classes/species.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,34 @@ class Species : public Serialisable
// Return vector of SpeciesBond
std::vector<SpeciesBond> &bonds();
const std::vector<SpeciesBond> &bonds() const;
// Return the SpeciesBond between the specified SpeciesAtom indices, if it exists
OptionalReferenceWrapper<SpeciesBond> getBond(const SpeciesAtom *i, const SpeciesAtom *j);
// Return the SpeciesBond between the specified SpeciesAtoms / indices, if it exists
OptionalReferenceWrapper<const SpeciesBond> getBond(const SpeciesAtom *i, const SpeciesAtom *j) const;
OptionalReferenceWrapper<const SpeciesBond> getBond(int i, int j) const;
// Remove bonds crossing periodic boundaries
void removePeriodicBonds();
// Return vector of SpeciesAngle
std::vector<SpeciesAngle> &angles();
const std::vector<SpeciesAngle> &angles() const;
// Return the SpeciesAngle between the specified SpeciesAtom indices, if it exists
OptionalReferenceWrapper<SpeciesAngle> getAngle(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k);
// Return the SpeciesAngle between the specified SpeciesAtoms / indices, if it exists
OptionalReferenceWrapper<const SpeciesAngle> getAngle(const SpeciesAtom *i, const SpeciesAtom *j,
const SpeciesAtom *k) const;
OptionalReferenceWrapper<const SpeciesAngle> getAngle(int i, int j, int k) const;
// Return vector of SpeciesTorsion
std::vector<SpeciesTorsion> &torsions();
const std::vector<SpeciesTorsion> &torsions() const;
// Return the SpeciesTorsion between the specified SpeciesAtom indices, if it exists
OptionalReferenceWrapper<SpeciesTorsion> getTorsion(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k,
const SpeciesAtom *l);
// Return the SpeciesTorsion between the specified SpeciesAtoms / indices, if it exists
OptionalReferenceWrapper<const SpeciesTorsion> getTorsion(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k,
const SpeciesAtom *l) const;
OptionalReferenceWrapper<const SpeciesTorsion> getTorsion(int i, int j, int k, int l) const;
// Return vector of SpeciesImproper
std::vector<SpeciesImproper> &impropers();
const std::vector<SpeciesImproper> &impropers() const;
// Add a new improper term between the specified atoms
SpeciesImproper &addImproper(SpeciesAtom *i, SpeciesAtom *j, SpeciesAtom *k, SpeciesAtom *l);
// Return the SpeciesImproper between the specified SpeciesAtom indices, if it exists
OptionalReferenceWrapper<SpeciesImproper> getImproper(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k,
const SpeciesAtom *l);
// Return the SpeciesImproper between the specified SpeciesAtoms /indices, if it exists
OptionalReferenceWrapper<const SpeciesImproper> getImproper(const SpeciesAtom *i, const SpeciesAtom *j,
const SpeciesAtom *k, const SpeciesAtom *l) const;
OptionalReferenceWrapper<const SpeciesImproper> getImproper(int i, int j, int k, int l) const;
// Clear forcefield data from intramolecular terms
void clearIntramolecularForcefieldTerms();

Expand Down
1 change: 1 addition & 0 deletions src/classes/speciesIntra.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ template <class Intra, class Functions> class SpeciesIntra : public Serialisable
SpeciesIntra(SpeciesIntra &&source) = delete;
SpeciesIntra &operator=(const SpeciesIntra &source)
{
parent_ = source.parent_;
interactionPotential_ = source.interactionPotential_;
commonTerm_ = source.commonTerm_;
attached_[0] = source.attached_[0];
Expand Down
33 changes: 23 additions & 10 deletions src/classes/species_intra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ std::vector<SpeciesBond> &Species::bonds() { return bonds_; }
const std::vector<SpeciesBond> &Species::bonds() const { return bonds_; }

// Return the SpeciesBond between the specified SpeciesAtoms, if it exists
OptionalReferenceWrapper<SpeciesBond> Species::getBond(const SpeciesAtom *i, const SpeciesAtom *j)
OptionalReferenceWrapper<const SpeciesBond> Species::getBond(const SpeciesAtom *i, const SpeciesAtom *j) const
{
auto it = std::find_if(bonds_.begin(), bonds_.end(), [i, j](auto &bond) { return bond.matches(i, j); });
if (it == bonds_.end())
return {};

return *it;
}
OptionalReferenceWrapper<const SpeciesBond> Species::getBond(int i, int j) const
{
return getBond(&atoms_.at(i), &atoms_.at(j));
}

// Remove bonds crossing periodic boundaries
void Species::removePeriodicBonds()
Expand All @@ -46,23 +50,28 @@ std::vector<SpeciesAngle> &Species::angles() { return angles_; }
const std::vector<SpeciesAngle> &Species::angles() const { return angles_; }

// Return the SpeciesAngle between the specified SpeciesAtoms, if it exists
OptionalReferenceWrapper<SpeciesAngle> Species::getAngle(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k)
OptionalReferenceWrapper<const SpeciesAngle> Species::getAngle(const SpeciesAtom *i, const SpeciesAtom *j,
const SpeciesAtom *k) const
{
auto it = std::find_if(angles_.begin(), angles_.end(), [i, j, k](auto &angle) { return angle.matches(i, j, k); });
if (it == angles_.end())
return {};

return *it;
}
OptionalReferenceWrapper<const SpeciesAngle> Species::getAngle(int i, int j, int k) const
{
return getAngle(&atoms_.at(i), &atoms_.at(j), &atoms_.at(k));
}

// Return vector of SpeciesTorsions
std::vector<SpeciesTorsion> &Species::torsions() { return torsions_; }

const std::vector<SpeciesTorsion> &Species::torsions() const { return torsions_; }

// Return the SpeciesTorsion between the specified SpeciesAtoms, if it exists
OptionalReferenceWrapper<SpeciesTorsion> Species::getTorsion(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k,
const SpeciesAtom *l)
OptionalReferenceWrapper<const SpeciesTorsion> Species::getTorsion(const SpeciesAtom *i, const SpeciesAtom *j,
const SpeciesAtom *k, const SpeciesAtom *l) const
{
auto it =
std::find_if(torsions_.begin(), torsions_.end(), [i, j, k, l](auto &torsion) { return torsion.matches(i, j, k, l); });
Expand All @@ -71,6 +80,10 @@ OptionalReferenceWrapper<SpeciesTorsion> Species::getTorsion(const SpeciesAtom *

return *it;
}
OptionalReferenceWrapper<const SpeciesTorsion> Species::getTorsion(int i, int j, int k, int l) const
{
return getTorsion(&atoms_.at(i), &atoms_.at(j), &atoms_.at(k), &atoms_.at(l));
}

// Return vector of SpeciesImproper
std::vector<SpeciesImproper> &Species::impropers() { return impropers_; }
Expand All @@ -80,10 +93,6 @@ const std::vector<SpeciesImproper> &Species::impropers() const { return improper
// Add a new improper term between the specified atoms
SpeciesImproper &Species::addImproper(SpeciesAtom *i, SpeciesAtom *j, SpeciesAtom *k, SpeciesAtom *l)
{
auto optImproper = getImproper(i, j, k, l);
if (optImproper)
return *optImproper;

auto &improper = impropers_.emplace_back(this, i, j, k, l);

// Must inform the atoms now that they are involved in a new improper
Expand All @@ -96,8 +105,8 @@ SpeciesImproper &Species::addImproper(SpeciesAtom *i, SpeciesAtom *j, SpeciesAto
}

// Return the SpeciesImproper between the specified SpeciesAtoms, if it exists
OptionalReferenceWrapper<SpeciesImproper> Species::getImproper(const SpeciesAtom *i, const SpeciesAtom *j, const SpeciesAtom *k,
const SpeciesAtom *l)
OptionalReferenceWrapper<const SpeciesImproper> Species::getImproper(const SpeciesAtom *i, const SpeciesAtom *j,
const SpeciesAtom *k, const SpeciesAtom *l) const
{
auto it = std::find_if(impropers_.begin(), impropers_.end(),
[i, j, k, l](auto &improper) { return improper.matches(i, j, k, l); });
Expand All @@ -106,6 +115,10 @@ OptionalReferenceWrapper<SpeciesImproper> Species::getImproper(const SpeciesAtom

return *it;
}
OptionalReferenceWrapper<const SpeciesImproper> Species::getImproper(int i, int j, int k, int l) const
{
return getImproper(&atoms_.at(i), &atoms_.at(j), &atoms_.at(k), &atoms_.at(l));
}

// Clear intramolecular forcefield terms
void Species::clearIntramolecularForcefieldTerms()
Expand Down
9 changes: 8 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function(dissolve_add_test)
target_link_libraries(
${TEST_NAME}
PUBLIC ${WHOLE_ARCHIVE_FLAG} ${BASIC_LINK_LIBS} ${MODULENOGUI_LINK_LIBS} ${NO_WHOLE_ARCHIVE_FLAG}
PRIVATE ${CORE_LINK_LIBS} GTest::gtest_main
PRIVATE ${CORE_LINK_LIBS} testing GTest::gtest_main
)

if(DISSOLVE_UNIT_TEST_GUI)
Expand All @@ -62,6 +62,13 @@ function(dissolve_add_test)

endfunction()

add_library(testing testing.cpp testGraph.cpp testing.h testGraph.h)
target_link_libraries(testing PRIVATE GTest::gtest_main)
target_include_directories(
testing PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR} ${CONAN_INCLUDE_DIRS_GTEST}
${CONAN_INCLUDE_DIRS_PUGIXML}
)

# Add unit test subdirectories
add_subdirectory(algorithms)
add_subdirectory(classes)
Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/array3DIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "templates/algorithms.h"
#include "templates/array3D.h"
#include <gtest/gtest.h>
#include <iostream>

#include "iostream"
namespace UnitTest
{

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "templates/algorithms.h"
#include <array>
#include <gtest/gtest.h>
#include <string_view>
#include <vector>

namespace UnitTest
Expand Down
5 changes: 3 additions & 2 deletions tests/classes/cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Copyright (c) 2026 Team Dissolve and contributors

#include "classes/atomType.h"
#include "classes/configuration.h"
#include "classes/species.h"
#include "kernels/energy.h"
#include "main/dissolve.h"
#include "math/mathFunc.h"
#include "tests/graphData.h"
#include <gtest/gtest.h>
#include "nodes/species.h"
#include "tests/testGraph.h"

namespace UnitTest
{
Expand Down
5 changes: 3 additions & 2 deletions tests/classes/cells3.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 Team Dissolve and contributors

#include "classes/configuration.h"
#include "kernels/energy.h"
#include "nodes/species.h"
#include "templates/algorithms.h"
#include "tests/graphData.h"
#include <gtest/gtest.h>
#include "tests/testGraph.h"

namespace UnitTest
{
Expand Down
4 changes: 2 additions & 2 deletions tests/classes/cells4.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 Team Dissolve and contributors

#include "tests/graphData.h"
#include <gtest/gtest.h>
#include "classes/configuration.h"
#include "tests/testGraph.h"

namespace UnitTest
{
Expand Down
3 changes: 1 addition & 2 deletions tests/classes/doubleKeyedMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Copyright (c) 2026 Team Dissolve and contributors

#include "templates/doubleKeyedMap.h"
#include <gtest/gtest.h>
#include <tests/testData.h>
#include "tests/testing.h"

namespace UnitTest
{
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/empiricalFormula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2026 Team Dissolve and contributors

#include "classes/empiricalFormula.h"
#include "tests/testData.h"
#include "classes/species.h"
#include <gtest/gtest.h>

TEST(EmpiricalFormulaTest, Order)
Expand Down
42 changes: 19 additions & 23 deletions tests/classes/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#include "math/history.h"
#include "nodes/number.h"
#include "tests/graphData.h"
#include "tests/testData.h"
#include <gtest/gtest.h>
#include "nodes/species.h"
#include "tests/testGraph.h"

namespace UnitTest
{
Expand Down Expand Up @@ -80,11 +79,11 @@ TEST(History, CustomClass)
for (auto n = 1; n <= 5; ++n)
{
sum += n;
EXPECT_TRUE(DissolveSystemTest::checkData1D(d * (sum / n), "Original", a.push(d * n, avgLength), "Averaged"));
EXPECT_TRUE(testData1D(d * (sum / n), "Original", a.push(d * n, avgLength), "Averaged"));
}

tomlRoundTrip(a, b);
EXPECT_TRUE(DissolveSystemTest::checkData1D(a.average(), "A", b.average(), "B"));
EXPECT_TRUE(testData1D(a.average(), "A", b.average(), "B"));
}

TEST(History, CustomClassWithInitialiser)
Expand Down Expand Up @@ -131,15 +130,13 @@ TEST(History, CustomClassWithInitialiser)
for (auto n = 0; n < 3; ++n)
{
auto avg = a.push(p, avgLength);
EXPECT_TRUE(testData1D(p.partials().get("Ar//Ar"), "Partial", avg.partials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D(p.boundPartials().get("Ar//Ar"), "BoundPartial", avg.boundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D(p.boundTotal(), "BoundTotal", avg.boundTotal(), "Averaged"));
EXPECT_TRUE(
DissolveSystemTest::checkData1D(p.partials().get("Ar//Ar"), "Partial", avg.partials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(p.boundPartials().get("Ar//Ar"), "BoundPartial",
avg.boundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(p.boundTotal(), "BoundTotal", avg.boundTotal(), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(p.unboundPartials().get("Ar//Ar"), "UnboundPartial",
avg.unboundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(p.unboundTotal(), "UnboundTotal", avg.unboundTotal(), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(p.total(), "Total", avg.total(), "Averaged"));
testData1D(p.unboundPartials().get("Ar//Ar"), "UnboundPartial", avg.unboundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D(p.unboundTotal(), "UnboundTotal", avg.unboundTotal(), "Averaged"));
EXPECT_TRUE(testData1D(p.total(), "Total", avg.total(), "Averaged"));
}

// Accumulate opposite trig values - just test partials as the totals are not automatically modified by PartialSet
Expand All @@ -149,21 +146,20 @@ TEST(History, CustomClassWithInitialiser)
for (auto n = 1; n <= 3; ++n)
{
auto avg = a.push(p, avgLength);
EXPECT_TRUE(
DissolveSystemTest::checkData1D(p.partials().get("Ar//Ar"), "Partial", avg.partials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D((dcos * (avgLength - n) - dsin * n) / avgLength, "BoundPartial",
avg.boundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(DissolveSystemTest::checkData1D((dsin * (avgLength - n) - dcos * n) / avgLength, "UnboundPartial",
avg.unboundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D(p.partials().get("Ar//Ar"), "Partial", avg.partials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D((dcos * (avgLength - n) - dsin * n) / avgLength, "BoundPartial",
avg.boundPartials().get("Ar//Ar"), "Averaged"));
EXPECT_TRUE(testData1D((dsin * (avgLength - n) - dcos * n) / avgLength, "UnboundPartial",
avg.unboundPartials().get("Ar//Ar"), "Averaged"));
}

tomlRoundTrip(a, b);
auto avgA = a.average();
auto avgB = b.average();
EXPECT_TRUE(DissolveSystemTest::checkData1D(avgA.boundPartials().get("Ar//Ar"), "BoundPartialA",
avgB.boundPartials().get("Ar//Ar"), "BoundPartialB"));
EXPECT_TRUE(DissolveSystemTest::checkData1D(avgA.unboundPartials().get("Ar//Ar"), "UnboundPartialA",
avgB.unboundPartials().get("Ar//Ar"), "UnboundPartialB"));
EXPECT_TRUE(
testData1D(avgA.boundPartials().get("Ar//Ar"), "BoundPartialA", avgB.boundPartials().get("Ar//Ar"), "BoundPartialB"));
EXPECT_TRUE(testData1D(avgA.unboundPartials().get("Ar//Ar"), "UnboundPartialA", avgB.unboundPartials().get("Ar//Ar"),
"UnboundPartialB"));
}

} // namespace UnitTest
1 change: 0 additions & 1 deletion tests/classes/neta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "data/elements.h"
#include "data/ff/ff.h"
#include "templates/algorithms.h"
#include "tests/testData.h"
#include <format>
#include <gtest/gtest.h>

Expand Down
5 changes: 2 additions & 3 deletions tests/classes/neutronWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include "classes/neutronWeights.h"
#include "classes/isotopologueSet.h"
#include "tests/graphData.h"
#include "classes/species.h"
#include "tests/tempFile.h"
#include "tests/testData.h"
#include <gtest/gtest.h>
#include "tests/testing.h"

namespace UnitTest
{
Expand Down
1 change: 0 additions & 1 deletion tests/classes/potentialSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "classes/atomType.h"
#include "math/data1D.h"
#include "math/history.h"
#include "tests/testData.h"
#include <gtest/gtest.h>

namespace UnitTest
Expand Down
1 change: 0 additions & 1 deletion tests/classes/speciesSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "classes/site.h"
#include "classes/species.h"
#include "tests/testData.h"
#include <gtest/gtest.h>

namespace UnitTest
Expand Down
3 changes: 1 addition & 2 deletions tests/classes/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#include "classes/structure.h"
#include "nodes/calculateBonding.h"
#include "tests/graphData.h"
#include "tests/testGraph.h"
#include <cmath>
#include <gtest/gtest.h>

namespace UnitTest
{
Expand Down
Loading
Loading