1 /* mean.c: Implementation of a mean function of testable component.
2 See test/test_mean.c for the associated unit test.
3
4 This example code is in the Public Domain (or CC0 licensed, at your option.)
5
6 Unless required by applicable law or agreed to in writing, this
7 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 CONDITIONS OF ANY KIND, either express or implied.
9 */
10
11 #include "testable.h"
12
13
testable_mean(const int * values,int count)14 int testable_mean(const int* values, int count)
15 {
16 if (count == 0) {
17 return 0;
18 }
19 int sum = 0;
20 for (int i = 0; i < count; ++i) {
21 sum += values[i];
22 }
23 return sum / count;
24 }
25