Integrate Refactor solver sources and dual MSVC CMake builds
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -19,8 +20,68 @@ fesa::Diagnostic ModelDiagnostic() {
|
||||
"Beam length must be positive."};
|
||||
}
|
||||
|
||||
struct CopyOnlyPayload {
|
||||
explicit CopyOnlyPayload(int initial_value) : value{initial_value} {}
|
||||
CopyOnlyPayload(const CopyOnlyPayload& other)
|
||||
: value{other.value}, copies{other.copies + 1} {}
|
||||
|
||||
int value;
|
||||
int copies = 0;
|
||||
};
|
||||
|
||||
struct TransferPayload {
|
||||
explicit TransferPayload(int initial_value) : value{initial_value} {}
|
||||
TransferPayload(const TransferPayload& other)
|
||||
: value{other.value}, copies{other.copies + 1}, moves{other.moves} {}
|
||||
TransferPayload(TransferPayload&& other) noexcept
|
||||
: value{other.value}, copies{other.copies}, moves{other.moves + 1} {
|
||||
other.value = -1;
|
||||
}
|
||||
|
||||
int value;
|
||||
int copies = 0;
|
||||
int moves = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(CoreDiagnostics, ResultOwnsCopyOnlyPayloadWithoutIntermediateCopy) {
|
||||
CopyOnlyPayload source{23};
|
||||
auto result = fesa::Result<CopyOnlyPayload>::Success(source);
|
||||
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
EXPECT_TRUE(result.GetStatus().IsOk());
|
||||
EXPECT_EQ(result.Value().value, 23);
|
||||
EXPECT_EQ(result.Value().copies, 2);
|
||||
result.Value().value = 42;
|
||||
EXPECT_EQ(source.value, 23);
|
||||
EXPECT_EQ(source.copies, 0);
|
||||
}
|
||||
|
||||
TEST(CoreDiagnostics, ResultTransfersOwnedPayloadDirectlyIntoValue) {
|
||||
TransferPayload source{17};
|
||||
const auto from_lvalue = fesa::Result<TransferPayload>::Success(source);
|
||||
EXPECT_EQ(source.value, 17);
|
||||
EXPECT_EQ(source.copies, 0);
|
||||
EXPECT_EQ(source.moves, 0);
|
||||
EXPECT_EQ(from_lvalue.Value().value, 17);
|
||||
EXPECT_EQ(from_lvalue.Value().copies, 1);
|
||||
EXPECT_EQ(from_lvalue.Value().moves, 1);
|
||||
|
||||
const auto from_temporary =
|
||||
fesa::Result<TransferPayload>::Success(TransferPayload{29});
|
||||
EXPECT_EQ(from_temporary.Value().value, 29);
|
||||
EXPECT_EQ(from_temporary.Value().copies, 0);
|
||||
EXPECT_EQ(from_temporary.Value().moves, 1);
|
||||
|
||||
auto owned = std::make_unique<int>(31);
|
||||
const auto move_only =
|
||||
fesa::Result<std::unique_ptr<int>>::Success(std::move(owned));
|
||||
EXPECT_EQ(owned, nullptr);
|
||||
ASSERT_NE(move_only.Value(), nullptr);
|
||||
EXPECT_EQ(*move_only.Value(), 31);
|
||||
}
|
||||
|
||||
TEST(CoreDiagnostics, ResultEnforcesValueErrorExclusivity) {
|
||||
const fesa::Status ok = fesa::Status::Ok();
|
||||
EXPECT_TRUE(ok.IsOk());
|
||||
|
||||
Reference in New Issue
Block a user