Skip to content

Commit

Permalink
Refactor west-const tests/testoscar
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 13, 2024
1 parent fcc9bab commit 6602fd4
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 271 deletions.
2 changes: 1 addition & 1 deletion tests/testoscar/Maths/TestCoordinateAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ INSTANTIATE_TEST_SUITE_P(

TEST_P(CoordinateAxisParsingTestFixture, Check)
{
ParsingTestCase const tc = GetParam();
const ParsingTestCase tc = GetParam();
ASSERT_EQ(CoordinateAxis::try_parse(tc.input), tc.expected) << "input = " << tc.input;
}
6 changes: 3 additions & 3 deletions tests/testoscar/Maths/TestCoordinateDirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST(CoordinateDirection, DirectionReturnsExpectedResults)

TEST(CoordinateDirection, AreOrderedAsExpected)
{
auto const expectedOrder = std::to_array({
const auto expectedOrder = std::to_array({
CoordinateDirection::minus_x(),
CoordinateDirection::x(),
CoordinateDirection::minus_y(),
Expand Down Expand Up @@ -216,7 +216,7 @@ INSTANTIATE_TEST_SUITE_P(

TEST_P(ParsingTestFixture, Check)
{
ParsingTestCase const tc = GetParam();
const ParsingTestCase tc = GetParam();
ASSERT_EQ(CoordinateDirection::try_parse(tc.input), tc.expected) << "input = " << tc.input;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ INSTANTIATE_TEST_SUITE_P(

TEST_P(PrintingTestFixture, Check)
{
PrintingTestCase const tc = GetParam();
const PrintingTestCase tc = GetParam();
std::stringstream ss;
ss << tc.input;
ASSERT_EQ(ss.str(), tc.expected);
Expand Down
8 changes: 4 additions & 4 deletions tests/testoscar/Maths/TestPlaneFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ TEST(signed_distance_between, ProducesExpectedAnswersInExampleCases)
float expected;
};

auto const cases = std::to_array<TestCase>({
const auto cases = std::to_array<TestCase>({
// origin // normal // point // expected signed distance
{{Vec3{}, Vec3{0.0f, 1.0f, 0.0f}}, Vec3{0.0f, 0.5f, 0.0f}, 0.5f },
{{Vec3{}, Vec3{0.0f, 1.0f, 0.0f}}, Vec3{0.0f, -0.5f, 0.0f}, -0.5f },
{{Vec3{1.0f}, Vec3{0.0f, 1.0f, 0.0f}}, Vec3{0.0f, 0.25f, 0.0f}, -0.75f },
{{Vec3{1.0f}, Vec3{1.0f, 0.0f, 0.0f}}, Vec3{0.0f, 0.25f, 0.0f}, -1.0f },
});

for (auto const& [plane, point, expected] : cases) {
for (const auto& [plane, point, expected] : cases) {
ASSERT_NEAR(signed_distance_between(plane, point), expected, epsilon_v<float>);
}
}
Expand All @@ -36,7 +36,7 @@ TEST(is_in_front_of, ProducesExpectedAnswersInExampleCases)
bool expected;
};

auto const cases = std::to_array<TestCase>({
const auto cases = std::to_array<TestCase>({
// origin // normal // min // max // is in front of plane?
{{Vec3{}, Vec3{ 0.0f, 1.0f, 0.0f}}, {{ 1.0f, 1.0f, 1.0f}, { 2.0f, 2.0f, 2.0f}}, true},
{{Vec3{}, Vec3{ 0.0f, 1.0f, 0.0f}}, {{-2.0f, -2.0f, -2.0f}, {-1.0f, -1.0f, -1.0f}}, false},
Expand All @@ -55,7 +55,7 @@ TEST(is_in_front_of, ProducesExpectedAnswersInExampleCases)



for (auto const& [plane, aabb, expected] : cases) {
for (const auto& [plane, aabb, expected] : cases) {
ASSERT_EQ(is_in_front_of(plane, aabb), expected) << "plane = " << plane << ", aabb = " << aabb << " (dimensions_of = " << dimensions_of(aabb) << ", half_widths . normal = " << dot(half_widths_of(aabb), abs(plane.normal)) << ", signed distance = " << signed_distance_between(plane, centroid_of(aabb)) << ')';
}
}
6 changes: 2 additions & 4 deletions tests/testoscar/Platform/TestAppSettingValueType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ TEST(AppSettingValue, StringValueToBoolReturnsExpectedBoolValues)

TEST(AppSettingValue, ColorValueToStringReturnsSameAsToHtmlStringRGBA)
{
auto const colors = std::to_array(
{
const auto colors = std::to_array({
Color::red(),
Color::magenta(),
});

for (auto const& color : colors)
{
for (const auto& color : colors) {
ASSERT_EQ(AppSettingValue{color}.to_string(), to_html_string_rgba(color));
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testoscar/Platform/TestResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace
m_State{std::move(state_)}
{}
private:
ResourceStream impl_open(ResourcePath const& p) override
ResourceStream impl_open(const ResourcePath& p) override
{
m_State->lastOpenCallArg = p;
return ResourceStream{};
}

std::function<std::optional<ResourceDirectoryEntry>()> impl_iterate_directory(ResourcePath const&) override
std::function<std::optional<ResourceDirectoryEntry>()> impl_iterate_directory(const ResourcePath&) override
{
return []() { return std::nullopt; };
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testoscar/Platform/TestResourceStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace
return std::string{beg, end};
}

std::string slurp(std::filesystem::path const& p)
std::string slurp(const std::filesystem::path& p)
{
std::ifstream fs{p, std::ios::binary};
return slurp(fs);
Expand All @@ -40,14 +40,14 @@ TEST(ResourceStream, WhenDefaultConstructedHasNameNullstream)

TEST(ResourceStream, WhenConstructedFromFilepathCreatesStreamThatReadsFile)
{
auto const path = std::filesystem::path{OSC_TESTING_RESOURCES_DIR} / "awesomeface.png";
const auto path = std::filesystem::path{OSC_TESTING_RESOURCES_DIR} / "awesomeface.png";
ResourceStream rs{path};

ASSERT_TRUE(slurp(rs) == slurp(path));
}

TEST(ResourceStream, WhenConstructedFromFilepathHasNameEqualtoFilename)
{
auto const path = std::filesystem::path{OSC_TESTING_RESOURCES_DIR} / "awesomeface.png";
const auto path = std::filesystem::path{OSC_TESTING_RESOURCES_DIR} / "awesomeface.png";
ASSERT_EQ(ResourceStream{path}.name(), path.filename().string());
}
3 changes: 1 addition & 2 deletions tests/testoscar/TestingHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace
{
std::vector<decltype(f())> rv;
rv.reserve(n);
for (size_t i = 0; i < n; ++i)
{
for (size_t i = 0; i < n; ++i) {
rv.push_back(f());
}
return rv;
Expand Down
11 changes: 5 additions & 6 deletions tests/testoscar/TestingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace osc::testing
std::vector<uint16_t> GenerateIndices(size_t start, size_t end);

template<std::ranges::range T, std::ranges::range U>
bool ContainersEqual(T const& a, U const& b)
bool ContainersEqual(const T& a, const U& b)
{
using std::begin;
using std::end;
Expand All @@ -52,23 +52,22 @@ namespace osc::testing
}

template<std::ranges::range Range, class UnaryOperation>
requires std::invocable<UnaryOperation, typename Range::value_type const&>
auto MapToVector(Range const& src, UnaryOperation op)
requires std::invocable<UnaryOperation, const typename Range::value_type&>
auto MapToVector(const Range& src, UnaryOperation op)
{
using std::begin;
using std::end;

std::vector<std::remove_const_t<std::remove_reference_t<decltype(op(std::declval<decltype(*begin(src))>()))>>> rv;
rv.reserve(std::distance(begin(src), end(src)));
for (auto const& el : src)
{
for (const auto& el : src) {
rv.push_back(op(el));
}
return rv;
}

template<class T>
std::vector<T> ResizedVectorCopy(std::vector<T> const& v, size_t newSize, T const& filler = {})
std::vector<T> ResizedVectorCopy(const std::vector<T>& v, size_t newSize, const T& filler = {})
{
std::vector<T> rv;
rv.reserve(newSize);
Expand Down
14 changes: 7 additions & 7 deletions tests/testoscar/Utils/TestAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST(lookup_or_nullptr, WorksWithStdMap)

TEST(lookup_or_nullptr, WorksWithConstQualifiedStdUnorderedMap)
{
std::unordered_map<int, int> const um{
const std::unordered_map<int, int> um{
{20, 30},
{-1, 98},
{5, 10},
Expand Down Expand Up @@ -138,28 +138,28 @@ TEST(lookup_or_nullptr, CanMutateViaReturnedPointer)

TEST(min_element, WorksAsExpected)
{
auto const els = std::to_array({1, 5, 8, -4, 13});
const auto els = std::to_array({1, 5, 8, -4, 13});
ASSERT_EQ(rgs::min_element(els), els.begin() + 3);
}

TEST(min, WorksAsExpected)
{
auto const els = std::to_array({1, 5, 8, -4, 13});
const auto els = std::to_array({1, 5, 8, -4, 13});
ASSERT_EQ(rgs::min(els), -4);
}

TEST(minmax_element, WorksAsExpected)
{
auto const els = std::to_array({1, 5, 8, -4, -4, 13, 13, 13});
auto const [minit, maxit] = rgs::minmax_element(els);
const auto els = std::to_array({1, 5, 8, -4, -4, 13, 13, 13});
const auto [minit, maxit] = rgs::minmax_element(els);
ASSERT_EQ(minit, els.begin() + 3);
ASSERT_EQ(maxit, els.end() - 1);
}

TEST(minmax, WorksAsExpected)
{
auto const els = std::to_array({1, 5, 8, -4, -4, 13, 13, 13});
auto const [min, max] = rgs::minmax(els);
const auto els = std::to_array({1, 5, 8, -4, -4, 13, 13, 13});
const auto [min, max] = rgs::minmax(els);
ASSERT_EQ(min, -4);
ASSERT_EQ(max, 13);
}
Expand Down
11 changes: 5 additions & 6 deletions tests/testoscar/Utils/TestCStringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ using namespace osc::literals;

TEST(CStringView, WhenPassedNullCstringYieldsEmptyCStringView)
{
char const* p = nullptr;
const char* p = nullptr;
ASSERT_TRUE(CStringView{p}.empty());
}

TEST(CStringView, WhenPassedNullCStringYieldsNonNullCStr)
{
char const* p = nullptr;
const char* p = nullptr;
ASSERT_NE(CStringView{p}.c_str(), nullptr);
}

Expand All @@ -43,13 +43,12 @@ TEST(CStringView, WhenConstructedFromNullptrYieldsNonNullCStr)

TEST(CStringView, ThreeWayComparisonBehavesIdenticallyToStringViewComparision)
{
auto const svs = std::to_array<char const*>({ "x", "somestring", "somethingelse", "", "_i hope it works ;)" });
auto sameThreeWayResultWithAllOtherElements = [&svs](char const* elCStr)
const auto svs = std::to_array<const char*>({ "x", "somestring", "somethingelse", "", "_i hope it works ;)" });
auto sameThreeWayResultWithAllOtherElements = [&svs](const char* elCStr)
{
std::string_view sv{elCStr};
CStringView csv{elCStr};
for (char const* otherCStr : svs)
{
for (const char* otherCStr : svs) {
ASSERT_EQ(sv <=> std::string_view{otherCStr}, csv <=> CStringView{otherCStr});
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/testoscar/Utils/TestFileChangePoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace osc;
// that something not-quite-right has happened
TEST(FileChangePoller, CtorDoesNotThrowExceptionIfGivenInvalidPath)
{
std::string const path = "doesnt-exist";
const std::string path = "doesnt-exist";

// constructing with an invalid path shouldn't throw
ASSERT_NO_THROW({ FileChangePoller(std::chrono::milliseconds{0}, path); });
Expand All @@ -26,7 +26,7 @@ TEST(FileChangePoller, CtorDoesNotThrowExceptionIfGivenInvalidPath)
// that something not-quite-right has happened
TEST(FileChangePoller, ChangeWasDetectedDoesNotThrowExceptionIfGivenInvalidPath)
{
std::string const path = "doesnt-exist";
const std::string path = "doesnt-exist";

// construct it with an invalid path
FileChangePoller p{std::chrono::milliseconds{0}, path};
Expand Down
Loading

0 comments on commit 6602fd4

Please sign in to comment.