esp-idf/examples/system/unit_test/components/testable/mean.c

25 wiersze
632 B
C

/* mean.c: Implementation of a mean function of testable component.
See test/test_mean.c for the associated unit test.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "testable.h"
int testable_mean(const int* values, int count)
{
if (count == 0) {
return 0;
}
int sum = 0;
for (int i = 0; i < count; ++i) {
sum += values[i];
}
return sum / count;
}