From 48b33d5a587073f5667e72f734fb80f98288563c Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 30 Jun 2024 13:17:34 +0200 Subject: [PATCH] add tets for list --- .gitignore | 2 ++ platformio.ini | 16 ++++++++++++++++ test/README | 11 +++++++++++ test/utils.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 platformio.ini create mode 100644 test/README create mode 100644 test/utils.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..968a41b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pio/ +.vscode/ diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..ad67c12 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = native + +[env:native] +platform = native +debug_build_flags = -std=c++11 diff --git a/test/README b/test/README new file mode 100644 index 0000000..b94d089 --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/test/utils.cpp b/test/utils.cpp new file mode 100644 index 0000000..966d90c --- /dev/null +++ b/test/utils.cpp @@ -0,0 +1,42 @@ +#include +#include "utils.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_add(void) { + List list; + int value = 10; + list.add(&value); + TEST_ASSERT_EQUAL(value, *list.last->t); + TEST_ASSERT_EQUAL_PTR(list.first, list.last); + + int value2 = 12; + list.add(&value2); + TEST_ASSERT_EQUAL(value2, *list.last->t); + TEST_ASSERT_EQUAL_PTR(list.first->next, list.last); +} + +void test_empty(void) { + List list; + int value = 10; + list.add(&value); + list.add(&value); + list.empty(); + TEST_ASSERT_EQUAL_PTR(nullptr, list.first); + TEST_ASSERT_EQUAL_PTR(list.first, list.last); +} + +int main(int argc, char **argv) { + UNITY_BEGIN(); + RUN_TEST(test_add); + RUN_TEST(test_empty); + UNITY_END(); + + return 0; +}