-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Node test fixtures #2545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
trisyoungs
wants to merge
6
commits into
dissolve2/clean-up-testing-framework
Choose a base branch
from
dissolve2/node-test-fixtures
base: dissolve2/clean-up-testing-framework
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: Node test fixtures #2545
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
acdb574
Start tinkering with a fixture for node testing with round-trip TOML …
trisyoungs d6f6ccf
Fix comment.
trisyoungs d82b2c3
Test fixture with SDF node.
trisyoungs b8e6f65
Exception handling in Node::deserialise().
trisyoungs 1dfc635
Direct type comparison in Parameter::deserialise().
trisyoungs 1506873
Missed overrides.
trisyoungs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2026 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "tests/testGraph.h" | ||
|
|
||
| namespace UnitTest | ||
| { | ||
| class TestGraphFixture : public testing::Test | ||
| { | ||
| public: | ||
| TestGraphFixture() = default; | ||
| ~TestGraphFixture() override = default; | ||
|
|
||
| private: | ||
| // Serialised graph TOML | ||
| SerialisedValue graphTOML_; | ||
|
|
||
| protected: | ||
| // Test graph | ||
| TestGraph testGraph_; | ||
| // Deserialised graph | ||
| DissolveGraph deserialisedGraph_; | ||
| // Current graph target | ||
| OptionalReferenceWrapper<DissolveGraph> currentGraph_; | ||
|
|
||
| private: | ||
| // Serialise the current graph to a TOML | ||
| bool serialiseGraphToTOML() | ||
| { | ||
| try | ||
| { | ||
| testGraph_.serialise("graph", graphTOML_); | ||
| } | ||
| catch (std::exception &ex) | ||
| { | ||
| std::cout << std::format("Failed to serialise graph TOML for test {}:\n", "TODO"); | ||
| std::cout << ex.what() << std::endl; | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| protected: | ||
| // Prepare any necessary test data | ||
| virtual void prepareTestData() = 0; | ||
| // Perform graph construction | ||
| virtual void constructGraph() = 0; | ||
| // Run graph | ||
| virtual void runGraph() = 0; | ||
| // Perform tests on generated data | ||
| virtual void performTests() = 0; | ||
| // Find specified node | ||
| template <class NodeClass> NodeClass *findNode(std::string nodeName) | ||
| { | ||
| EXPECT_TRUE(currentGraph_.has_value()); | ||
| auto *node = currentGraph_.value().get().findNode(nodeName); | ||
| EXPECT_TRUE(node); | ||
| return dynamic_cast<NodeClass *>(node); | ||
| } | ||
|
|
||
| // Go | ||
| void go() | ||
| { | ||
| // Prepare test data | ||
| ASSERT_NO_THROW(prepareTestData()); | ||
|
|
||
| // Set the initial graph target to the test graph | ||
| currentGraph_ = testGraph_; | ||
|
|
||
| // Construct the graph | ||
| ASSERT_NO_THROW(constructGraph()); | ||
| // Run the graph | ||
| ASSERT_NO_THROW(runGraph()); | ||
| // Run the tests | ||
| ASSERT_NO_THROW(performTests()); | ||
| // Serialise graph to TOML | ||
| ASSERT_TRUE(serialiseGraphToTOML()); | ||
|
|
||
| // Switch to the deserialised graph target | ||
| currentGraph_ = deserialisedGraph_; | ||
|
|
||
| // Deserialise from the stored TOML | ||
| ASSERT_NO_THROW(deserialisedGraph_.deserialise(graphTOML_["graph"])); | ||
| // Run the graph | ||
| ASSERT_NO_THROW(runGraph()); | ||
| // Run the tests | ||
| ASSERT_NO_THROW(performTests()); | ||
| } | ||
| }; | ||
| }; // namespace UnitTest | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps go ahead and make this DissolveGraph* ? I know that eventually removing OptionalReferenceWrapper is on the RoadMap.