1 /* test_mean.c: Implementation of a testable component.
2 
3    This example code is in the Public Domain (or CC0 licensed, at your option.)
4 
5    Unless required by applicable law or agreed to in writing, this
6    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7    CONDITIONS OF ANY KIND, either express or implied.
8 */
9 
10 #include <limits.h>
11 #include "unity.h"
12 #include "testable.h"
13 
14 #define countof(x) (sizeof(x)/sizeof(x[0]))
15 
16 TEST_CASE("Mean of an empty array is zero", "[mean]")
17 {
18     const int values[] = { 0 };
19     TEST_ASSERT_EQUAL(0, testable_mean(values, 0));
20 }
21 
22 TEST_CASE("Mean of a test vector", "[mean]")
23 {
24     const int v[] = {1, 3, 5, 7, 9};
25     TEST_ASSERT_EQUAL(5, testable_mean(v, countof(v)));
26 }
27 
28 /* This test case currently fails, and developer has added a tag to indicate this.
29  * For the test runner, "[fails]" string does not carry any special meaning.
30  * However it can be used to filter out tests when running.
31  */
32 TEST_CASE("Another test case which fails", "[mean][fails]")
33 {
34     const int v1[] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
35     TEST_ASSERT_EQUAL(INT_MAX, testable_mean(v1, countof(v1)));
36 }
37