forked from hamzux/station
-
Notifications
You must be signed in to change notification settings - Fork 0
/
station_test.c
87 lines (71 loc) · 2.44 KB
/
station_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "CUnit.h"
#include "Basic.h"
//#include "CUnit/Automated.h"
//#include "CUnit/Console.h"
#include "station.h"
#include <stdio.h> // for printf
/* Test Suite setup and cleanup functions: */
int init_suite(void) { return 0; }
int clean_suite(void) { return 0; }
/************* Test case functions ****************/
//void test_case_sample(void)
//{
// CU_ASSERT(CU_TRUE);
// CU_ASSERT_NOT_EQUAL(2, -1);
// CU_ASSERT_STRING_EQUAL("string #1", "string #1");
// CU_ASSERT_STRING_NOT_EQUAL("string #1", "string #2");
//
// CU_ASSERT(CU_FALSE);
// CU_ASSERT_EQUAL(2, 3);
// CU_ASSERT_STRING_NOT_EQUAL("string #1", "string #1");
// CU_ASSERT_STRING_EQUAL("string #1", "string #2");
//}
void moyenne_test(void) {
CU_ASSERT_DOUBLE_EQUAL( moyenne(20.0,30.0), 25.0,1.0);
CU_ASSERT_DOUBLE_EQUAL( moyenne(30.0,20.0), 25.0,1.0);
}
void aberrant_test(void) {
CU_ASSERT_EQUAL( nb_valeurs_aberrantes(20.0,22.0,24.0), 0);
CU_ASSERT_EQUAL( nb_valeurs_aberrantes(40.0,20.0,22.0), 1);
CU_ASSERT_EQUAL( nb_valeurs_aberrantes(20.0,30.0,40.0), 2);
}
void controller_test(void) {
CU_ASSERT_DOUBLE_EQUAL( controlleur(20.0,22.0,24.0), 22.0,0.1);
CU_ASSERT_DOUBLE_EQUAL( controlleur(40.0,20.0,22.0), 21.0,0.1);
CU_ASSERT_DOUBLE_EQUAL( controlleur(20.0,30.0,40.0), -200.0,0.1);
CU_ASSERT_DOUBLE_EQUAL( controlleur(20.0,40.0,60.0), -100.0,0.1);
}
/************* Test Runner Code goes here **************/
int main ( void )
{
CU_pSuite pSuite = NULL;
/* initialize the CUnit test registry */
if ( CUE_SUCCESS != CU_initialize_registry() )
return CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite( "station_test_suite", init_suite, clean_suite );
if ( NULL == pSuite ) {
CU_cleanup_registry();
return CU_get_error();
}
/* add the tests to the suite */
if ( (NULL == CU_add_test(pSuite, "moyenne_test", moyenne_test)) ||
(NULL == CU_add_test(pSuite, "aberrant_test", aberrant_test))
)
{
CU_cleanup_registry();
return CU_get_error();
}
CU_automated_run_tests();
// Run all tests using the basic interface
/*
// Run all tests using the automated interface
CU_automated_run_tests();
CU_list_tests_to_file();
// Run all tests using the console interface
CU_console_run_tests();
*/
/* Clean up registry and return */
CU_cleanup_registry();
return CU_get_error();
}