mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
examples: add unit testing example
This commit is contained in:
40
examples/system/unit_test/main/example_unit_test_main.c
Normal file
40
examples/system/unit_test/main/example_unit_test_main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Example application which uses testable component.
|
||||
|
||||
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 <stdio.h>
|
||||
#include "esp_system.h"
|
||||
#include "testable.h"
|
||||
|
||||
/* This application has a test subproject in 'test' directory, all the
|
||||
* interesting things happen there. See ../test/main/example_idf_test_runner_test.c
|
||||
* and the makefiles in ../test/ directory.
|
||||
*
|
||||
* This specific app_main function is provided only to illustrate the layout
|
||||
* of a project.
|
||||
*/
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
const int count = 32;
|
||||
const int max = 100;
|
||||
|
||||
printf("In main application. Collecting %d random numbers from 1 to %d:\n", count, max);
|
||||
int *numbers = calloc(count, sizeof(numbers[0]));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
numbers[i] = 1 + esp_random() % (max - 1);
|
||||
printf("%4d ", numbers[i]);
|
||||
if ((i + 1) % 10 == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int mean = testable_mean(numbers, count);
|
||||
printf("\nMean: %d\n", mean);
|
||||
free(numbers);
|
||||
}
|
Reference in New Issue
Block a user