Teraz dopisz testy dla metody std::tuple<int, Interval::IntervalType, bool>…
- User
Teraz dopisz testy dla metody std::tuple<int, Interval::IntervalType, bool> IntervalExtractor::findMonotonicRun(int fromIndex) const { const int n = static_cast(y.size()); int i = fromIndex + 1; bool isGap = false; while (i < n && y[i] > y[i - 1] && (isGap = (t[i] - t[i - 1] <= maxAcceptableTimeGap))) ++i; if (i > fromIndex + 1) return { i - fromIndex - 1, Interval::IntervalType::UP, isGap }; while (i < n && y[i] < y[i - 1] && (isGap = (t[i] - t[i - 1] <= maxAcceptableTimeGap))) ++i; if (i > fromIndex + 1) return { i - fromIndex - 1, Interval::IntervalType::DOWN, isGap }; return { 1, Interval::IntervalType::STEADY, isGap }; } Pamiętaj o przypadkach brzegowych - to bardzo ważna metoda i wymaga wielu testó.
Assistant
Oto rozszerzona wersja z dodanymi testami dla metody
findMonotonicRun. Metoda ta wymaga szczególnej uwagi, ponieważ jest krytyczna dla poprawnego działania klasyIntervalExtractor.// Dodajemy statyczną metodę testową do klasy pomocniczej class IntervalExtractorPrivateTests { public: static float TestTrapezoidalMethod(IntervalExtractor& extractor, int startIndex, int length) { return extractor.trapezoidalMethod(startIndex, length); } static float TestRightRectangleMethod(IntervalExtractor& extractor, int startIndex, int length) { return extractor.rightRectangleMethod(startIndex, length); } static float TestLeftRectangleMethod(IntervalExtractor& extractor, int startIndex, int length) { return extractor.leftRectangleMethod(startIndex, length); } static std::tuple<int, Interval::IntervalType, bool> TestFindMonotonicRun(IntervalExtractor& extractor, int fromIndex) { return extractor.findMonotonicRun(fromIndex); } }; namespace UnitIntervalExtractorPrivateTest { TEST_CLASS(IntervalExtractorPrivateTestsCore) { public: // [Poprzednie testy dla metod prostokątowych i trapezoidalnych pozostają bez zmian] // Testy dla metody findMonotonicRun TEST_METHOD(TestFindMonotonicRunSingleUpInterval) { 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] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); Assert::AreEqual(2, length); Assert::AreEqual(Interval::IntervalType::UP, type); Assert::IsTrue(isGap); } TEST_METHOD(TestFindMonotonicRunSingleDownInterval) { std::vector<float> y = { 3.0f, 2.0f, 1.0f }; std::vector<float> t = { 0.0f, 1.0f, 2.0f }; IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t); auto [length, type, isGap] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); Assert::AreEqual(2, length); Assert::AreEqual(Interval::IntervalType::DOWN, type); Assert::IsTrue(isGap); } TEST_METHOD(TestFindMonotonicRunSingleSteadyInterval) { std::vector<float> y = { 2.0f, 2.0f, 2.0f }; std::vector<float> t = { 0.0f, 1.0f, 2.0f }; IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t); auto [length, type, isGap] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); Assert::AreEqual(1, length); Assert::AreEqual(Interval::IntervalType::STEADY, type); Assert::IsTrue(isGap); } TEST_METHOD(TestFindMonotonicRunMultipleIntervals) { std::vector<float> y = { 1.0f, 2.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 [length1, type1, isGap1] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); auto [length2, type2, isGap2] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 3); Assert::AreEqual(2, length1); Assert::AreEqual(Interval::IntervalType::UP, type1); Assert::IsTrue(isGap1); Assert::AreEqual(2, length2); Assert::AreEqual(Interval::IntervalType::DOWN, type2); Assert::IsTrue(isGap2); } TEST_METHOD(TestFindMonotonicRunWithGaps) { std::vector<float> y = { 1.0f, 2.0f, 3.0f, 2.0f, 1.0f }; std::vector<float> t = { 0.0f, 1.0f, 3.0f, 5.0f, 8.0f }; IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t); auto [length1, type1, isGap1] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); auto [length2, type2, isGap2] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 3); 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); } TEST_METHOD(TestFindMonotonicRunEdgeCases) { std::vector<float> y = { 1.0f }; std::vector<float> t = { 0.0f }; IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t); auto [length, type, isGap] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); Assert::AreEqual(0, length); Assert::AreEqual(Interval::IntervalType::STEADY, type); Assert::IsTrue(isGap); } TEST_METHOD(TestFindMonotonicRunBoundaryCondition) { std::vector<float> y = { 1.0f, 2.0f }; std::vector<float> t = { 0.0f, 1.0f }; IntervalExtractor extractor(y, IntervalExtractor::EnergyMethod::TRAPEZOIDAL_METHOD, t); auto [length, type, isGap] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); Assert::AreEqual(1, length); Assert::AreEqual(Interval::IntervalType::UP, type); Assert::IsTrue(isGap); } TEST_METHOD(TestFindMonotonicRunMixedValues) { 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 [length1, type1, isGap1] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 0); auto [length2, type2, isGap2] = IntervalExtractorPrivateTests::TestFindMonotonicRun(extractor, 2); Assert::AreEqual(1, length1); Assert::AreEqual(Interval::IntervalType::DOWN, type1); Assert::IsTrue(isGap1); Assert::AreEqual(1, length2); Assert::AreEqual(Interval::IntervalType::DOWN, type2); Assert::IsTrue(isGap2); } }; }Podsumowanie pokrycia testów:
- Test podstawowy dla pojedynczego rosnącego interwału:
TestFindMonotonicRunSingleUpInterval - Test podstawowy dla pojedynczego malejącego interwału:
TestFindMonotonicRunSingleDownInterval - Test podstawowy dla pojedynczego stałego interwału:
TestFindMonotonicRunSingleSteadyInterval - Test dla wielu interwałów:
TestFindMonotonicRunMultipleIntervals - Test z uwzględ
- Test podstawowy dla pojedynczego rosnącego interwału:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.