1 /* Example application which uses 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 <stdio.h>
11 #include "esp_system.h"
12 #include "testable.h"
13
14 /* This application has a test subproject in 'test' directory, all the
15 * interesting things happen there. See ../test/main/example_idf_test_runner_test.c
16 * and the makefiles in ../test/ directory.
17 *
18 * This specific app_main function is provided only to illustrate the layout
19 * of a project.
20 */
21
app_main(void)22 void app_main(void)
23 {
24 const int count = 32;
25 const int max = 100;
26
27 printf("In main application. Collecting %d random numbers from 1 to %d:\n", count, max);
28 int *numbers = calloc(count, sizeof(numbers[0]));
29 for (int i = 0; i < count; ++i) {
30 numbers[i] = 1 + esp_random() % (max - 1);
31 printf("%4d ", numbers[i]);
32 if ((i + 1) % 10 == 0) {
33 printf("\n");
34 }
35 }
36
37 int mean = testable_mean(numbers, count);
38 printf("\nMean: %d\n", mean);
39 free(numbers);
40 }
41