Add test modules
This commit is contained in:
parent
ebcb67a0cc
commit
5a0d215789
5 changed files with 163 additions and 0 deletions
|
@ -11,6 +11,7 @@ Import('charles_lib')
|
||||||
files = Split("""
|
files = Split("""
|
||||||
test_basics.c
|
test_basics.c
|
||||||
test_charles.c
|
test_charles.c
|
||||||
|
test_object.c
|
||||||
""")
|
""")
|
||||||
|
|
||||||
test_env = env.Clone()
|
test_env = env.Clone()
|
||||||
|
|
76
test/test_basics.c
Normal file
76
test/test_basics.c
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/* test_basics.c
|
||||||
|
*
|
||||||
|
* Unit tests for the basics module.
|
||||||
|
*
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "basics.h"
|
||||||
|
#include "test_suites.h"
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_vector_init)
|
||||||
|
{
|
||||||
|
Vector3 v = vector_init(1, 2, 3);
|
||||||
|
ck_assert(v.x == 1.0);
|
||||||
|
ck_assert(v.y == 2.0);
|
||||||
|
ck_assert(v.z == 3.0);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_vector_length2)
|
||||||
|
{
|
||||||
|
Vector3 v = vector_init(2, 2, 1);
|
||||||
|
ck_assert(vector_length2(v) == 9.0);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_vector_length)
|
||||||
|
{
|
||||||
|
Vector3 v = vector_init(2, 2, 1);
|
||||||
|
ck_assert(vector_length(v) == 3.0);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_vector_dot)
|
||||||
|
{
|
||||||
|
Vector3 a = vector_init(1, 1, 1);
|
||||||
|
Vector3 b = vector_init(1, 1, 1);
|
||||||
|
ck_assert(vector_dot(a, b) == 3.0);
|
||||||
|
|
||||||
|
a = vector_init(2, 3, 4);
|
||||||
|
b = vector_init(4, 4, 4);
|
||||||
|
ck_assert(vector_dot(a, b) == (2 * 4) + (3 * 4) + (4 * 4));
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_vector_normalize)
|
||||||
|
{
|
||||||
|
Vector3 v = vector_init(1, 0, 0);
|
||||||
|
Vector3 norm_v = vector_normalize(v);
|
||||||
|
ck_assert(v.x == norm_v.x);
|
||||||
|
ck_assert(v.y == norm_v.y);
|
||||||
|
ck_assert(v.z == norm_v.z);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
Suite *
|
||||||
|
test_basics_create_suite()
|
||||||
|
{
|
||||||
|
Suite *s = suite_create("basics");
|
||||||
|
|
||||||
|
TCase *tc_vector = tcase_create("vector");
|
||||||
|
tcase_add_test(tc_vector, test_vector_init);
|
||||||
|
tcase_add_test(tc_vector, test_vector_length2);
|
||||||
|
tcase_add_test(tc_vector, test_vector_length);
|
||||||
|
tcase_add_test(tc_vector, test_vector_dot);
|
||||||
|
tcase_add_test(tc_vector, test_vector_normalize);
|
||||||
|
suite_add_tcase(s, tc_vector);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
38
test/test_charles.c
Normal file
38
test/test_charles.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* test_charles.c
|
||||||
|
*
|
||||||
|
* Entry point for charles unit tests.
|
||||||
|
*
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <check.h>
|
||||||
|
#include "test_suites.h"
|
||||||
|
|
||||||
|
typedef Suite *(*SuiteCreator)();
|
||||||
|
|
||||||
|
SuiteCreator suite_creators[] = {
|
||||||
|
test_basics_create_suite,
|
||||||
|
test_object_create_suite,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, const char *argv[])
|
||||||
|
{
|
||||||
|
SRunner *runner = srunner_create(NULL);
|
||||||
|
|
||||||
|
// Creat the suites and add them to the runner.
|
||||||
|
int ncreators = sizeof(suite_creators) / sizeof(SuiteCreator);
|
||||||
|
for (int i = 0; i < ncreators; i++) {
|
||||||
|
srunner_add_suite(runner, suite_creators[i]());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run ALL the tests!
|
||||||
|
srunner_run_all(runner, CK_VERBOSE);
|
||||||
|
int nfailed = srunner_ntests_failed(runner);
|
||||||
|
|
||||||
|
srunner_free(runner);
|
||||||
|
return (nfailed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
30
test/test_object.c
Normal file
30
test/test_object.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* test_object.c
|
||||||
|
*
|
||||||
|
* Unit tests for the object module.
|
||||||
|
*
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
#include "object.h"
|
||||||
|
#include "test_suites.h"
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST(test_sphere_does_intersect)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
Suite *
|
||||||
|
test_object_create_suite()
|
||||||
|
{
|
||||||
|
Suite *s = suite_create("object");
|
||||||
|
|
||||||
|
TCase *tc_sphere = tcase_create("sphere");
|
||||||
|
tcase_add_test(tc_sphere, test_sphere_does_intersect);
|
||||||
|
suite_add_tcase(s, tc_sphere);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
18
test/test_suites.h
Normal file
18
test/test_suites.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* test_suites.h
|
||||||
|
*
|
||||||
|
* Declarations of test suite creator functions.
|
||||||
|
*
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TEST_SUITES_H__
|
||||||
|
#define __TEST_SUITES_H__
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
|
||||||
|
Suite *test_basics_create_suite();
|
||||||
|
Suite *test_object_create_suite();
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue