Roadmap and physics
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dusktest.h"
|
||||
#include "util/memory.h"
|
||||
#include "rpg/physics/physicsbody.h"
|
||||
|
||||
static void test_physicsBodyInit(void **state) {
|
||||
physicsbody_t body;
|
||||
const vec3 position = { 1.0f, 2.0f, 3.0f };
|
||||
const vec3 extents = { 1.0f, 2.0f, 3.0f };
|
||||
physicsBodyInit(&body, position, extents);
|
||||
|
||||
assert_float_equal(body.position[0], 1.0f, 0.0001f);
|
||||
assert_float_equal(body.position[1], 2.0f, 0.0001f);
|
||||
assert_float_equal(body.position[2], 3.0f, 0.0001f);
|
||||
assert_float_equal(body.extents[0], 1.0f, 0.0001f);
|
||||
assert_float_equal(body.extents[1], 2.0f, 0.0001f);
|
||||
assert_float_equal(body.extents[2], 3.0f, 0.0001f);
|
||||
assert_float_equal(body.velocity[0], 0.0f, 0.0001f);
|
||||
assert_float_equal(body.velocity[1], 0.0f, 0.0001f);
|
||||
assert_float_equal(body.velocity[2], 0.0f, 0.0001f);
|
||||
assert_false(body.grounded);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_physicsBodyGetBounds(void **state) {
|
||||
physicsbody_t body;
|
||||
const vec3 position = { 2.0f, 3.0f, 4.0f };
|
||||
const vec3 extents = { 1.0f, 2.0f, 0.5f };
|
||||
physicsBodyInit(&body, position, extents);
|
||||
|
||||
vec3 min, max;
|
||||
physicsBodyGetBounds(&body, min, max);
|
||||
|
||||
assert_float_equal(min[0], 2.0f, 0.0001f);
|
||||
assert_float_equal(min[1], 3.0f, 0.0001f);
|
||||
assert_float_equal(min[2], 4.0f, 0.0001f);
|
||||
assert_float_equal(max[0], 3.0f, 0.0001f);
|
||||
assert_float_equal(max[1], 5.0f, 0.0001f);
|
||||
assert_float_equal(max[2], 4.5f, 0.0001f);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_physicsBodyGetBoundsNegativeCoordinates(void **state) {
|
||||
physicsbody_t body;
|
||||
const vec3 position = { -5.0f, -1.5f, -2.0f };
|
||||
const vec3 extents = { 2.0f, 1.0f, 1.0f };
|
||||
physicsBodyInit(&body, position, extents);
|
||||
|
||||
vec3 min, max;
|
||||
physicsBodyGetBounds(&body, min, max);
|
||||
|
||||
assert_float_equal(min[0], -5.0f, 0.0001f);
|
||||
assert_float_equal(min[1], -1.5f, 0.0001f);
|
||||
assert_float_equal(min[2], -2.0f, 0.0001f);
|
||||
assert_float_equal(max[0], -3.0f, 0.0001f);
|
||||
assert_float_equal(max[1], -0.5f, 0.0001f);
|
||||
assert_float_equal(max[2], -1.0f, 0.0001f);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_physicsBodyInit),
|
||||
cmocka_unit_test(test_physicsBodyGetBounds),
|
||||
cmocka_unit_test(test_physicsBodyGetBoundsNegativeCoordinates),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user