example_unit_test_main.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Example application which uses testable component.
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include "esp_random.h"
  9. #include "testable.h"
  10. /* This application has a test subproject in 'test' directory, all the
  11. * interesting things happen there. See ../test/main/example_idf_test_runner_test.c
  12. * and the makefiles in ../test/ directory.
  13. *
  14. * This specific app_main function is provided only to illustrate the layout
  15. * of a project.
  16. */
  17. void app_main(void)
  18. {
  19. const int count = 32;
  20. const int max = 100;
  21. printf("In main application. Collecting %d random numbers from 1 to %d:\n", count, max);
  22. int *numbers = calloc(count, sizeof(numbers[0]));
  23. for (int i = 0; i < count; ++i) {
  24. numbers[i] = 1 + esp_random() % (max - 1);
  25. printf("%4d ", numbers[i]);
  26. if ((i + 1) % 10 == 0) {
  27. printf("\n");
  28. }
  29. }
  30. int mean = testable_mean(numbers, count);
  31. printf("\nMean: %d\n", mean);
  32. free(numbers);
  33. }