v2.9
This commit is contained in:
10
lib/Vector/examples/PlatformIO/test/README
Normal file
10
lib/Vector/examples/PlatformIO/test/README
Normal file
@ -0,0 +1,10 @@
|
||||
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
|
60
lib/Vector/examples/PlatformIO/test/test_vector.cpp
Normal file
60
lib/Vector/examples/PlatformIO/test/test_vector.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// test_vector.cpp
|
||||
//
|
||||
//
|
||||
// Authors:
|
||||
// Darsey Litzenberger dlitz@dlitz.net
|
||||
// ----------------------------------------------------------------------------
|
||||
#include <unity.h>
|
||||
#include <Vector.h>
|
||||
|
||||
static void test_vector_size() {
|
||||
int storage[8] = { 21, 42, 84, 0, 0, 0, 0, 0 };
|
||||
Vector<int> v(storage, 3);
|
||||
TEST_ASSERT_EQUAL(8, v.max_size());
|
||||
TEST_ASSERT_EQUAL(3, v.size());
|
||||
v.push_back(10);
|
||||
v.push_back(20);
|
||||
v.push_back(30);
|
||||
TEST_ASSERT_EQUAL(6, v.size());
|
||||
v.pop_back();
|
||||
TEST_ASSERT_EQUAL(5, v.size());
|
||||
}
|
||||
|
||||
static void test_vector_iterator() {
|
||||
int storage[8] = { 21, 42, 84, 0, 0, 0, 0, 0 };
|
||||
Vector<int> v(storage, 3);
|
||||
|
||||
const int expected[3] = { 21, 42, 84 };
|
||||
int i=0;
|
||||
for (auto it = v.begin(); it != v.end(); ++it, ++i) {
|
||||
TEST_ASSERT_EQUAL(expected[i], *it);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(3, i);
|
||||
}
|
||||
|
||||
static void runTests() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_vector_size);
|
||||
RUN_TEST(test_vector_iterator);
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
void setup() {
|
||||
runTests();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
#else /* !defined(ARDUINO) */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
runTests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !defined(ARDUINO) */
|
Reference in New Issue
Block a user