Init: Rattenfalle
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "StatusLed.h"
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(void) {}
|
||||
|
||||
void tearDown(void) {}
|
||||
|
||||
int LED_PIN = LED_BUILTIN;
|
||||
|
||||
void test_LedStaysDark(void) {
|
||||
StatusLed dut(LED_PIN);
|
||||
|
||||
for (size_t i = 0; i < 30; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(LOW, digitalRead(LED_PIN));
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
void test_LedIsConstantOn(void) {
|
||||
StatusLed dut(LED_PIN);
|
||||
|
||||
dut.Set(StatusLed::Mode::SteadyOn);
|
||||
for (size_t i = 0; i < 30; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_PIN));
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
void test_LedBlinks(void) {
|
||||
StatusLed dut(LED_PIN);
|
||||
|
||||
dut.Set(StatusLed::Mode::Blinking);
|
||||
for (size_t n = 0; n < 2; n++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_PIN));
|
||||
delay(20);
|
||||
}
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(LOW, digitalRead(LED_PIN));
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_LedBlinks_InverseLogic(void) {
|
||||
StatusLed dut(LED_PIN, StatusLed::LedLogic::Inverted);
|
||||
|
||||
dut.Set(StatusLed::Mode::Blinking);
|
||||
for (size_t n = 0; n < 2; n++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(LOW, digitalRead(LED_PIN));
|
||||
delay(20);
|
||||
}
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
dut.Tick();
|
||||
TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_PIN));
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// NOTE!!! Wait for >2 secs
|
||||
// if board doesn't support software reset via Serial.DTR/RTS
|
||||
delay(2000);
|
||||
|
||||
UNITY_BEGIN(); // IMPORTANT LINE!
|
||||
RUN_TEST(test_LedStaysDark);
|
||||
RUN_TEST(test_LedIsConstantOn);
|
||||
RUN_TEST(test_LedBlinks);
|
||||
RUN_TEST(test_LedBlinks_InverseLogic);
|
||||
UNITY_END(); // stop unit testing
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
Import("env")
|
||||
|
||||
def after_upload(source, target, env):
|
||||
import time
|
||||
time.sleep(2)
|
||||
|
||||
env.AddPostAction("upload", after_upload)
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "RotatingIndex.hpp"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
if (RUN_ALL_TESTS())
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, Construction) {
|
||||
RotatingIndex<int> sut(4);
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, InitialState) {
|
||||
RotatingIndex<int> sut(4);
|
||||
ASSERT_EQ(sut.GetIndex(), 0);
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, TestOverflowWithGetIndexMethod) {
|
||||
RotatingIndex<int> sut(4);
|
||||
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 0);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 1);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 2);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 3);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 0);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 1);
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, TestOverflowWithCheckIfRevolvesMethod) {
|
||||
RotatingIndex<int> sut(4);
|
||||
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_TRUE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, GetIndexReturnsCorrectValue) {
|
||||
RotatingIndex<int> sut(4);
|
||||
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 0);
|
||||
ASSERT_EQ(sut.GetIndex(), 1);
|
||||
ASSERT_EQ(sut.GetIndexAndIncrement(), 1);
|
||||
ASSERT_EQ(sut.GetIndex(), 2);
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, TestReset) {
|
||||
RotatingIndex<int> sut(4);
|
||||
|
||||
sut.GetIndexAndIncrement();
|
||||
sut.ResetIndex();
|
||||
ASSERT_EQ(sut.GetIndex(), 0);
|
||||
}
|
||||
|
||||
TEST(RotatingIndex, TestDifferentTypeAndMaximum) {
|
||||
RotatingIndex<short> sut(6);
|
||||
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_TRUE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
ASSERT_FALSE(sut.IncrementAndCheckIfRevolves());
|
||||
}
|
||||
Reference in New Issue
Block a user