Using Unity (a special library for C for Unit tests)

This commit is contained in:
andrey 2026-01-22 18:18:03 +07:00
parent 857d79e572
commit fd7c6c91cd
10 changed files with 4638 additions and 24 deletions

View file

@ -49,6 +49,8 @@
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="main.h" />
<Unit filename="test_utilities.h" />
<Unit filename="tests/complex.c">
<Option compilerVar="CC" />
</Unit>
@ -229,6 +231,11 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/versor/versor_swap.h" />
<Unit filename="unity/unity.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="unity/unity.h" />
<Unit filename="unity/unity_internals.h" />
<Extensions />
</Project>
</CodeBlocks_project_file>

View file

@ -1,28 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include "helpers.h"
#include "main.h"
#include "tests/utilities.h"
#include "tests/vector2.h"
#include "tests/vector3.h"
#include "tests/complex.h"
#include "tests/quaternion.h"
#include "tests/versor.h"
#include "unity/unity.h"
void setUp()
{
}
void tearDown()
{
}
int main()
{
test_utilities();
test_vector2();
test_vector3();
test_complex();
test_quaternion();
test_versor();
return 0;
}

View file

@ -0,0 +1,8 @@
#ifndef BGC_TEST_MAIN_H_INCLUDED
#define BGC_TEST_MAIN_H_INCLUDED
void setUp();
void tearDown();
#endif

View file

@ -0,0 +1,8 @@
#ifndef BGC_TEST_UTILITIES_H_INCLUDED
#define BGC_TEST_UTILITIES_H_INCLUDED
#include "unity/unity.h"
#endif

View file

@ -11,9 +11,10 @@ void test_complex()
test_complex_is_zero();
test_complex_is_unit();
test_complex_modulus();
/*
test_complex_add();
test_complex_subtract();
test_complex_multiply();
test_complex_divide();
*/
}

View file

@ -1,4 +1,4 @@
#include "vector2.h"
#include "./vector2.h"
void test_vector2()
{
@ -11,11 +11,12 @@ void test_vector2()
test_vector2_is_zero();
test_vector2_is_unit();
test_vector2_modulus();
/*
test_vector2_add();
test_vector2_subtract();
test_vector2_multiply();
test_vector2_divide();
*/
}

View file

@ -1,4 +1,6 @@
#include "vector3.h"
#include "./vector3.h"
#include "./../helpers.h"
void test_vector3()
{
@ -11,9 +13,10 @@ void test_vector3()
test_vector3_is_zero();
test_vector3_is_unit();
test_vector3_modulus();
/*
test_vector3_add();
test_vector3_subtract();
test_vector3_multiply();
test_vector3_divide();
*/
}

File diff suppressed because it is too large Load diff

View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -0,0 +1,698 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#ifndef UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
#define UNITY_VERSION_MAJOR 2
#define UNITY_VERSION_MINOR 6
#define UNITY_VERSION_BUILD 2
#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD)
#ifdef __cplusplus
extern "C"
{
#endif
#include "unity_internals.h"
/*-------------------------------------------------------
* Test Setup / Teardown
*-------------------------------------------------------*/
/* These functions are intended to be called before and after each test.
* If using unity directly, these will need to be provided for each test
* executable built. If you are using the test runner generator and/or
* Ceedling, these are optional. */
void setUp(void);
void tearDown(void);
/* These functions are intended to be called at the beginning and end of an
* entire test suite. suiteTearDown() is passed the number of tests that
* failed, and its return value becomes the exit code of main(). If using
* Unity directly, you're in charge of calling these if they are desired.
* If using Ceedling or the test runner generator, these will be called
* automatically if they exist. */
void suiteSetUp(void);
int suiteTearDown(int num_failures);
/*-------------------------------------------------------
* Test Reset and Verify
*-------------------------------------------------------*/
/* These functions are intended to be called before or during tests in order
* to support complex test loops, etc. Both are NOT built into Unity. Instead
* the test runner generator will create them. resetTest will run teardown and
* setup again, verifying any end-of-test needs between. verifyTest will only
* run the verification. */
void resetTest(void);
void verifyTest(void);
/*-------------------------------------------------------
* Configuration Options
*-------------------------------------------------------
* All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above.
* Integers/longs/pointers
* - Unity attempts to automatically discover your integer sizes
* - define UNITY_EXCLUDE_STDINT_H to stop attempting to look in <stdint.h>
* - define UNITY_EXCLUDE_LIMITS_H to stop attempting to look in <limits.h>
* - If you cannot use the automatic methods above, you can force Unity by using these options:
* - define UNITY_SUPPORT_64
* - set UNITY_INT_WIDTH
* - set UNITY_LONG_WIDTH
* - set UNITY_POINTER_WIDTH
* Floats
* - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
* - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
* - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
* - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons
* - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default)
* - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
* - define UNITY_DOUBLE_TYPE to specify something other than double
* - define UNITY_EXCLUDE_FLOAT_PRINT to trim binary size, won't print floating point values in errors
* Output
* - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
* - define UNITY_DIFFERENTIATE_FINAL_FAIL to print FAILED (vs. FAIL) at test end summary - for automated search for failure
* Optimization
* - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge