String.h
This commit is contained in:
@@ -37,6 +37,10 @@ static void test_mathNextPowTwo(void **state) {
|
||||
|
||||
// Max Value
|
||||
assert_int_equal(mathNextPowTwo(0xFFFFFFFF), 1);
|
||||
|
||||
// Edge: value just below and above a power of two
|
||||
assert_int_equal(mathNextPowTwo(255), 256);
|
||||
assert_int_equal(mathNextPowTwo(257), 512);
|
||||
}
|
||||
|
||||
static void test_mathMax(void **state) {
|
||||
@@ -80,6 +84,13 @@ static void test_mathMax(void **state) {
|
||||
assert_float_equal(mathMax(-1.5f, 0), 0.0f, 0.0001f);
|
||||
assert_float_equal(mathMax(500, -333.5f), 500.0f, 0.0001f);
|
||||
assert_float_equal(mathMax(-333.5f, 500), 500.0f, 0.0001f);
|
||||
|
||||
// Equal values
|
||||
assert_int_equal(mathMax(5, 5), 5);
|
||||
assert_float_equal(mathMax(2.5f, 2.5f), 2.5f, 0.0001f);
|
||||
|
||||
// Special float values
|
||||
assert_float_equal(mathMax(-0.0f, 0.0f), 0.0f, 0.0001f);
|
||||
}
|
||||
|
||||
static void test_mathMin(void **state) {
|
||||
@@ -124,6 +135,13 @@ static void test_mathMin(void **state) {
|
||||
assert_float_equal(mathMin(-1.5f, 0), -1.5f, 0.0001f);
|
||||
assert_float_equal(mathMin(500, -333.5f), -333.5f, 0.0001f);
|
||||
assert_float_equal(mathMin(-333.5f, 500), -333.5f, 0.0001f);
|
||||
|
||||
// Equal values
|
||||
assert_int_equal(mathMin(5, 5), 5);
|
||||
assert_float_equal(mathMin(2.5f, 2.5f), 2.5f, 0.0001f);
|
||||
|
||||
// Special float values
|
||||
assert_float_equal(mathMin(-0.0f, 0.0f), -0.0f, 0.0001f);
|
||||
}
|
||||
|
||||
static void test_mathClamp(void **state) {
|
||||
@@ -172,6 +190,16 @@ static void test_mathClamp(void **state) {
|
||||
assert_float_equal(mathClamp(-5.5f, -10, -1), -5.5f, 0.0001f); // Within
|
||||
assert_float_equal(mathClamp(-15.5f, -10, -1), -10.0f, 0.0001f);// Below
|
||||
assert_float_equal(mathClamp(0.0f, -10, -1), -1.0f, 0.0001f); // Above
|
||||
|
||||
// Edge: value equals min or max
|
||||
assert_int_equal(mathClamp(1, 1, 10), 1);
|
||||
assert_int_equal(mathClamp(10, 1, 10), 10);
|
||||
assert_float_equal(mathClamp(1.0f, 1.0f, 10.0f), 1.0f, 0.0001f);
|
||||
assert_float_equal(mathClamp(10.0f, 1.0f, 10.0f), 10.0f, 0.0001f);
|
||||
|
||||
// Edge: min > max (undefined, but should return min or max)
|
||||
assert_int_equal(mathClamp(5, 10, 1), 1); // Should clamp to upper
|
||||
assert_float_equal(mathClamp(5.0f, 10.0f, 1.0f), 1.0f, 0.0001f);
|
||||
}
|
||||
|
||||
static void test_mathAbs(void **state) {
|
||||
@@ -192,6 +220,12 @@ static void test_mathAbs(void **state) {
|
||||
// Negative floats
|
||||
assert_float_equal(mathAbs(-5.5f), 5.5f, 0.0001f);
|
||||
assert_float_equal(mathAbs(-100.25f), 100.25f, 0.0001f);
|
||||
|
||||
// Edge: -0.0f
|
||||
assert_float_equal(mathAbs(-0.0f), 0.0f, 0.0001f);
|
||||
|
||||
// INT_MIN edge case is NOT handled due to two's complement overflow
|
||||
assert_int_equal(mathAbs(INT32_MIN + 1), 2147483647);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user