Oto kompleksowe testy jednostkowe dla metody findMonotonicRun, uwzględniające wszystkie przypadki brzegowe i typowe scenariusze:
namespace UnitIntervalExtractorPrivateTest
{
TEST_CLASS(IntervalExtractorPrivateTestsCore)
{
public:
// ... (poprzednie testy pozostają bez zmian)
// Testy dla metody findMonotonicRun
TEST_METHOD(TestFindMonotonicRunIncreasingSequence)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(4, length);
Assert::AreEqual(Interval::IntervalType::UP, type);
Assert::IsFalse(isGap);
}
TEST_METHOD(TestFindMonotonicRunDecreasingSequence)
{
std::vector<float> y = { 5.0f, 4.0f, 3.0f, 2.0f, 1.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(4, length);
Assert::AreEqual(Interval::IntervalType::DOWN, type);
Assert::IsFalse(isGap);
}
TEST_METHOD(TestFindMonotonicRunSteadySequence)
{
std::vector<float> y = { 2.0f, 2.0f, 2.0f, 2.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length);
Assert::AreEqual(Interval::IntervalType::STEADY, type);
Assert::IsFalse(isGap);
}
TEST_METHOD(TestFindMonotonicRunMixedSequence)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 2.0f, 1.0f, 2.0f, 3.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
// Testujemy różne pozycje startowe
auto [length1, type1, isGap1] = extractor.findMonotonicRun(0);
auto [length2, type2, isGap2] = extractor.findMonotonicRun(2);
auto [length3, type3, isGap3] = extractor.findMonotonicRun(4);
Assert::AreEqual(2, length1);
Assert::AreEqual(Interval::IntervalType::UP, type1);
Assert::IsFalse(isGap1);
Assert::AreEqual(2, length2);
Assert::AreEqual(Interval::IntervalType::DOWN, type2);
Assert::IsFalse(isGap2);
Assert::AreEqual(2, length3);
Assert::AreEqual(Interval::IntervalType::UP, type3);
Assert::IsFalse(isGap3);
}
TEST_METHOD(TestFindMonotonicRunWithGaps)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 4.0f, 5.0f }; // Przerwa między 2.0 a 4.0
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t, 1.5f);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length); // Powinno przerwać na pierwszej przerwie
Assert::AreEqual(Interval::IntervalType::UP, type);
Assert::IsTrue(isGap); // Ostatni sprawdzony przedział miał przerwę
}
TEST_METHOD(TestFindMonotonicRunEdgeCases)
{
// Przypadek 1: Pojedynczy element
{
std::vector<float> y = { 1.0f };
std::vector<float> t = { 0.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length);
Assert::AreEqual(Interval::IntervalType::STEADY, type);
Assert::IsFalse(isGap);
}
// Przypadek 2: Ostatni element
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(2);
Assert::AreEqual(1, length);
Assert::AreEqual(Interval::IntervalType::STEADY, type);
Assert::IsFalse(isGap);
}
// Przypadek 3: Pusty wektor (powinno użyć domyślnego pustego wektora)
{
std::vector<float> empty;
IntervalExtractor extractor(empty, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, empty);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length);
Assert::AreEqual(Interval::IntervalType::STEADY, type);
Assert::IsFalse(isGap);
}
}
TEST_METHOD(TestFindMonotonicRunWithTimeGaps)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.5f, 4.0f, 6.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t, 1.2f);
// Testujemy różne pozycje startowe
auto [length1, type1, isGap1] = extractor.findMonotonicRun(0);
auto [length2, type2, isGap2] = extractor.findMonotonicRun(2);
Assert::AreEqual(2, length1);
Assert::AreEqual(Interval::IntervalType::UP, type1);
Assert::IsFalse(isGap1);
Assert::AreEqual(1, length2);
Assert::AreEqual(Interval::IntervalType::UP, type2);
Assert::IsTrue(isGap2); // Przerwa między 3.5 a 4.0 jest większa niż maxAcceptableTimeGap
}
TEST_METHOD(TestFindMonotonicRunWithDifferentTimeGaps)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 5.0f }; // Przerwa 2.0 na końcu
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t, 1.5f);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(3, length); // Powinno przerwać na ostatniej przerwie
Assert::AreEqual(Interval::IntervalType::UP, type);
Assert::IsTrue(isGap);
}
TEST_METHOD(TestFindMonotonicRunWithMaxTimeGap)
{
std::vector<float> y = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t, 0.5f);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length); // Powinno przerwać na pierwszej przerwie (1.0-0.0=1.0 > 0.5)
Assert::AreEqual(Interval::IntervalType::UP, type);
Assert::IsTrue(isGap);
}
TEST_METHOD(TestFindMonotonicRunWithNonMonotonicData)
{
std::vector<float> y = { 1.0f, 3.0f, 2.0f, 4.0f, 3.0f, 5.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
// Testujemy różne pozycje startowe
auto [length1, type1, isGap1] = extractor.findMonotonicRun(0);
auto [length2, type2, isGap2] = extractor.findMonotonicRun(1);
auto [length3, type3, isGap3] = extractor.findMonotonicRun(2);
Assert::AreEqual(1, length1);
Assert::AreEqual(Interval::IntervalType::UP, type1);
Assert::IsFalse(isGap1);
Assert::AreEqual(1, length2);
Assert::AreEqual(Interval::IntervalType::DOWN, type2);
Assert::IsFalse(isGap2);
Assert::AreEqual(2, length3);
Assert::AreEqual(Interval::IntervalType::UP, type3);
Assert::IsFalse(isGap3);
}
TEST_METHOD(TestFindMonotonicRunWithEqualValues)
{
std::vector<float> y = { 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 4.0f };
std::vector<float> t = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(1, length);
Assert::AreEqual(Interval::IntervalType::STEADY, type);
Assert::IsFalse(isGap);
}
TEST_METHOD(TestFindMonotonicRunWithLargeDataSet)
{
std::vector<float> y;
std::vector<float> t;
for (int i = 0; i < 100; ++i) {
y.push_back(static_cast<float>(i));
t.push_back(static_cast<float>(i));
}
IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t);
auto [length, type, isGap] = extractor.findMonotonicRun(0);
Assert::AreEqual(99, length);
Assert::AreEqual(Interval::IntervalType::UP, type);
Assert::IsFalse(isGap);
}
};
}
Testy obejmują wszystkie kluczowe przypadki dla metody findMonotonicRun:
- Sekwencje rosnące i malejące - podstawowe przypadki użycia
- Sekwencje stałe - sprawdzenie zachowania dla wartości stałych
- Sekwencje mieszane - testowanie różnych wzorców w danych
- Przypadki z przerwami czasowymi - testowanie zachowania przy różnych przerwach czasowych
- Przypadki brzegowe:
- Pojedynczy element
- Ostatni element
- Pusty wektor
- Duże zestawy danych
- Różne wartości maxAcceptableTimeGap - testowanie zachowania przy różnych wartościach maksymalnej dopuszczalnej przerwy
- Dane niemonotoniczne - testowanie zachowania przy nieregularnych danych
- Równe wartości - testowanie zachowania przy powtarzających się wartościach
Każdy test sprawdza wszystkie trzy zwracane wartości (długość, typ i flagę przerwy) i zawiera komentarze wyjaśniające oczekiwane wyniki. Testy są zaprojektowane tak, aby pokryć wszystkie możliwe scenariusze użycia tej metody.