Files
libultraship/tests/utils_tests.cpp
CopilotandKenix3 59da65504d test: add comprehensive test coverage across libultraship (#1066)
* test: add comprehensive test coverage for utility modules

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* chore: plan ResourceManager/ArchiveManager test additions

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* chore: plan maximum coverage test additions

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* test: add comprehensive coverage — glob, splitText, Path/DiskFile, resource types/factories, Archive self tests, ResourceLoader, ResourceManager helpers

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* test: address PR review suggestions and splitText leak

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/44c1e76b-581e-4593-b8bc-a60be4c0dd9f

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* Changes before error encountered

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/44c1e76b-581e-4593-b8bc-a60be4c0dd9f

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

* style: apply clang-format to remaining test files

Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/1a9e1a9f-2efb-449b-91a3-8c8372053c64

Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>
2026-04-15 18:46:45 -04:00

104 lines
2.9 KiB
C++

#include <gtest/gtest.h>
#include "ship/utils/Utils.h"
// ============================================================
// Ship::Math::clamp
// ============================================================
TEST(MathClamp, ValueBelowMinClampsToMin) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(-10.0f, 0.0f, 1.0f), 0.0f);
}
TEST(MathClamp, ValueAboveMaxClampsToMax) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(5.0f, 0.0f, 1.0f), 1.0f);
}
TEST(MathClamp, ValueInRangeUnchanged) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(0.5f, 0.0f, 1.0f), 0.5f);
}
TEST(MathClamp, ValueAtMinEdge) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(0.0f, 0.0f, 1.0f), 0.0f);
}
TEST(MathClamp, ValueAtMaxEdge) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(1.0f, 0.0f, 1.0f), 1.0f);
}
TEST(MathClamp, NegativeRange) {
EXPECT_FLOAT_EQ(Ship::Math::clamp(-3.0f, -5.0f, -1.0f), -3.0f);
}
// ============================================================
// Ship::Math::HashCombine
// ============================================================
TEST(MathHashCombine, SameInputGivesSameOutput) {
size_t a = Ship::Math::HashCombine(42u, 100u);
size_t b = Ship::Math::HashCombine(42u, 100u);
EXPECT_EQ(a, b);
}
TEST(MathHashCombine, DifferentOrderedInputsAreDeterministic) {
size_t a1 = Ship::Math::HashCombine(1u, 2u);
size_t a2 = Ship::Math::HashCombine(1u, 2u);
size_t b1 = Ship::Math::HashCombine(2u, 1u);
size_t b2 = Ship::Math::HashCombine(2u, 1u);
EXPECT_EQ(a1, a2);
EXPECT_EQ(b1, b2);
}
TEST(MathHashCombine, ZeroAndZero) {
// Just make sure it doesn't crash and produces a value
size_t result = Ship::Math::HashCombine(0u, 0u);
(void)result; // result value is implementation-defined
}
// ============================================================
// Ship::Math::IsNumber
// ============================================================
TEST(MathIsNumber, IntegerString) {
EXPECT_TRUE(Ship::Math::IsNumber<int>("42"));
}
TEST(MathIsNumber, NegativeIntegerString) {
EXPECT_TRUE(Ship::Math::IsNumber<int>("-7"));
}
TEST(MathIsNumber, FloatStringAsFloat) {
EXPECT_TRUE(Ship::Math::IsNumber<float>("3.14"));
}
TEST(MathIsNumber, FloatStringAsInt) {
EXPECT_FALSE(Ship::Math::IsNumber<int>("3.14"));
}
TEST(MathIsNumber, AlphaStringIsNotNumber) {
EXPECT_FALSE(Ship::Math::IsNumber<int>("abc"));
}
// ============================================================
// Ship::toLowerCase
// ============================================================
TEST(ToLowerCase, AllUppercase) {
EXPECT_EQ(Ship::toLowerCase("HELLO"), "hello");
}
TEST(ToLowerCase, MixedCase) {
EXPECT_EQ(Ship::toLowerCase("HeLLo WoRLd"), "hello world");
}
TEST(ToLowerCase, AlreadyLowercase) {
EXPECT_EQ(Ship::toLowerCase("already"), "already");
}
TEST(ToLowerCase, EmptyString) {
EXPECT_EQ(Ship::toLowerCase(""), "");
}
TEST(ToLowerCase, WithDigitsAndSymbols) {
EXPECT_EQ(Ship::toLowerCase("ABC123!"), "abc123!");
}