-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,47 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2023 Team Dissolve and contributors | ||
|
||
#include "main/compatibility.h" | ||
#include <functional> | ||
#include <iostream> | ||
|
||
namespace dissolve | ||
{ | ||
|
||
// Upgrade from version zero, which never supported TOML in the first | ||
// place. This exists purely to allow testing the backward | ||
// compatibility code before there is any pass worth checking. | ||
SerialisedValue unrealUpgrade(SerialisedValue contents) | ||
{ | ||
if (contents["pairPotentials"].contains("coulombTruncation")) | ||
contents["pairPotentials"]["coulombTruncation"] = | ||
toml::find<std::string>(contents["pairPotentials"], "coulombTruncation") + "ed"; | ||
|
||
return contents; | ||
} | ||
|
||
// Upgrade a file to the current version. | ||
SerialisedValue backwardsUpgrade(SerialisedValue contents) | ||
{ | ||
using Version::DissolveVersion; | ||
|
||
// A map of version numbers and the corresponding function to | ||
// upgrade the file. | ||
std::map<std::string, std::function<SerialisedValue(SerialisedValue)>> breakingChanges = {{"1.2.0", unrealUpgrade}}; | ||
|
||
DissolveVersion current(toml::find<std::string>(contents, "version")); | ||
|
||
for (auto &[key, value] : breakingChanges) | ||
{ | ||
DissolveVersion next(key); | ||
if (current < next) | ||
{ | ||
contents = value(contents); | ||
current = next; | ||
} | ||
} | ||
|
||
return contents; | ||
} | ||
|
||
} // namespace dissolve |
This file contains 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,14 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2023 Team Dissolve and contributors | ||
|
||
#pragma once | ||
|
||
#include "base/serialiser.h" | ||
#include "main/version.h" | ||
|
||
namespace dissolve | ||
{ | ||
|
||
SerialisedValue backwardsUpgrade(SerialisedValue contents); | ||
|
||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dissolve_add_test(SRC cif.cpp) | ||
dissolve_add_test(SRC intraParameterParse.cpp) | ||
dissolve_add_test(SRC version.cpp) |
This file contains 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,57 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2023 Team Dissolve and contributors | ||
|
||
#include "main/version.h" | ||
#include "base/serialiser.h" | ||
#include "main/dissolve.h" | ||
#include <gtest/gtest.h> | ||
|
||
namespace UnitTest | ||
{ | ||
|
||
TEST(VersionTest, VersionClass) | ||
{ | ||
using Version::DissolveVersion; | ||
DissolveVersion first{"1.10.3"}, second{"2.1.12"}, minor{"2.2.1"}, patch{"2.2.2"}, third{"3.0.0"}; | ||
|
||
// Main sequence | ||
EXPECT_LT(first, second); | ||
EXPECT_LT(second, minor); | ||
EXPECT_LT(minor, patch); | ||
EXPECT_LT(patch, third); | ||
|
||
// Full combinatorial | ||
EXPECT_LT(first, minor); | ||
EXPECT_LT(first, patch); | ||
EXPECT_LT(first, third); | ||
EXPECT_LT(second, minor); | ||
EXPECT_LT(second, patch); | ||
EXPECT_LT(second, third); | ||
EXPECT_LT(minor, third); | ||
} | ||
|
||
TEST(VersionTest, VersionInfo) | ||
{ | ||
CoreData coreData; | ||
Dissolve dissolve(coreData); | ||
dissolve.loadInput("dissolve/input/rdfMethod.txt"); | ||
auto serialised = dissolve.serialise(); | ||
|
||
Version::DissolveVersion fileVersion(serialised["version"].as_string().str), actual(Version::semantic()); | ||
|
||
EXPECT_EQ(fileVersion, actual); | ||
} | ||
|
||
TEST(VersionTest, VersionUpgrade) | ||
{ | ||
CoreData coreData; | ||
Dissolve dissolve(coreData); | ||
|
||
SerialisedValue old; | ||
old["version"] = "0.0.0"; | ||
old["pairPotentials"] = {{"coulombTruncation", "Shift"}}; | ||
|
||
dissolve.deserialise(old); | ||
} | ||
|
||
} // namespace UnitTest |