From a0815c8658b4da2dcb1d8b26e82f7d035ab9a75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20M=C3=BCller?= Date: Thu, 4 Jan 2024 12:08:54 +0100 Subject: [PATCH] Add new test vectors --- src/Hardware/Probing.cpp | 34 +++ ut/Hardware/Probing.cpp | 431 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 462 insertions(+), 3 deletions(-) diff --git a/src/Hardware/Probing.cpp b/src/Hardware/Probing.cpp index 788c1ea..79e146a 100644 --- a/src/Hardware/Probing.cpp +++ b/src/Hardware/Probing.cpp @@ -130,12 +130,31 @@ size_t ProbingSet::GetNumberOfStandardProbes() const { template size_t ProbingSet::GetStandardProbeIndex( size_t standard_probe_index) { + if (standard_probe_indices_.empty()) { + throw std::out_of_range( + "Tried to access a standard probe index from an empty vector!"); + } + + if (standard_probe_index >= standard_probe_indices_.size()) { + throw std::out_of_range("Tried to access an invalid standard probe index!"); + } + return standard_probe_indices_[standard_probe_index]; } template ExtensionContainer ProbingSet::GetExtendedProbeIndex( size_t extended_probe_index) { + if (probe_extension_indices_.empty()) { + throw std::out_of_range( + "Tried to access a probe-extension index from an empty vector!"); + } + + if (extended_probe_index >= probe_extension_indices_.size()) { + throw std::out_of_range( + "Tried to access an invalid probe-extension index!"); + } + return probe_extension_indices_[extended_probe_index]; } @@ -154,6 +173,9 @@ size_t ProbingSet::GetNumberOfProbeExtensions() const { return probe_extension_indices_.size(); } +template size_t ProbingSet::GetNumberOfProbeExtensions() + const; + template ExtensionContainer ProbingSet::GetFirstProbeExtension() const { @@ -182,6 +204,9 @@ ProbingSet::GetAllProbeExtensions() const { return probe_extension_indices_; } +template std::vector +ProbingSet::GetAllProbeExtensions() const; + template bool ProbingSet::IsRemovable() const { return contingency_table_.IsRemovable(); @@ -285,18 +310,27 @@ bool ProbingSet::operator<( return (probe_extension_indices_ < other.probe_extension_indices_); } +template bool ProbingSet::operator<( + const ProbingSet&) const; + template bool ProbingSet::operator==( const ProbingSet& other) const { return (probe_extension_indices_ == other.probe_extension_indices_); } +template bool ProbingSet::operator==( + const ProbingSet&) const; + template bool ProbingSet::operator!=( const ProbingSet& other) const { return (probe_extension_indices_ != other.probe_extension_indices_); } +template bool ProbingSet::operator!=( + const ProbingSet&) const; + template bool ProbingSet::Includes( const ProbingSet& other) const { diff --git a/ut/Hardware/Probing.cpp b/ut/Hardware/Probing.cpp index 911e3a1..5fa46f0 100644 --- a/ut/Hardware/Probing.cpp +++ b/ut/Hardware/Probing.cpp @@ -3,9 +3,8 @@ #include -TEST_CASE( - "Test the removing of duplicates from a vector", - "[void RemoveDuplicates(std::vector& extensions)]") { +TEST_CASE("Test the removing of duplicates from a vector", + "[void RemoveDuplicates(std::vector&)]") { SECTION("Empty vector") { std::vector test_vector = {}; std::vector expected_result = {}; @@ -40,4 +39,430 @@ TEST_CASE( Hardware::probing::RemoveDuplicates(test_vector); REQUIRE(test_vector == expected_result); } +} + +TEST_CASE( + "Test the returning of the number of probe extensions in a probing set", + "[size_t ProbingSet::GetNumberOfProbeExtensions() " + "const]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetNumberOfProbeExtensions() == 0); + } + + SECTION("Probing set with one probe extension") { + std::vector test_vector = {5}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetNumberOfProbeExtensions() == 1); + } + + SECTION("Probing set with multiple extensions") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetNumberOfProbeExtensions() == 3); + } +} + +TEST_CASE( + "Test the returning of particular standard probe indices", + "[size_t ProbingSet::GetStandardProbeIndex(size_t)]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH( + probing_set.GetStandardProbeIndex(0), + "Tried to access a standard probe index from an empty vector!"); + } + + SECTION("Probing set with one probe extension and index in range") { + std::vector test_vector = {5}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetStandardProbeIndex(0) == 5); + } + + SECTION("Probing set with one probe extension and index out of range") { + std::vector test_vector = {5}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH(probing_set.GetStandardProbeIndex(1), + "Tried to access an invalid standard probe index!"); + } + + SECTION("Probing set with multiple extensions and indices in range") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetExtendedProbeIndex(0) == 5); + REQUIRE(probing_set.GetExtendedProbeIndex(1) == 6); + REQUIRE(probing_set.GetExtendedProbeIndex(2) == 7); + } + + SECTION("Probing set with multiple extensions and index out of range") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH(probing_set.GetStandardProbeIndex(3), + "Tried to access an invalid standard probe index!"); + } +} + +TEST_CASE( + "Test the returning of particular probe-extension indices", + "[size_t ProbingSet::GetExtendedProbeIndex(size_t)]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH( + probing_set.GetExtendedProbeIndex(0), + "Tried to access a probe-extension index from an empty vector!"); + } + + SECTION("Probing set with one probe extension and index in range") { + std::vector test_vector = {5}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetExtendedProbeIndex(0) == 5); + } + + SECTION("Probing set with one probe extension and index out of range") { + std::vector test_vector = {5}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH(probing_set.GetExtendedProbeIndex(1), + "Tried to access an invalid probe-extension index!"); + } + + SECTION("Probing set with multiple extensions and indices in range") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetExtendedProbeIndex(0) == 5); + REQUIRE(probing_set.GetExtendedProbeIndex(1) == 6); + REQUIRE(probing_set.GetExtendedProbeIndex(2) == 7); + } + + SECTION("Probing set with multiple extensions and index out of range") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH(probing_set.GetExtendedProbeIndex(3), + "Tried to access an invalid probe-extension index!"); + } +} + +TEST_CASE("Test the returning of the first probe extension from a probing set", + "[ExtensionContainer " + "ProbingSet::GetFirstProbeExtension() const]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH( + probing_set.GetFirstProbeExtension(), + "Tried to return the first element of an empty vector!"); + } + + SECTION("Probing set with one probe extension") { + std::vector test_vector = {5}; + unsigned int expected_result = 5; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetFirstProbeExtension() == expected_result); + } + + SECTION("Probing set with multiple extensions") { + std::vector test_vector = {5, 6, 7}; + unsigned int expected_result = 5; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetFirstProbeExtension() == expected_result); + } +} + +TEST_CASE("Test the returning of the last probe extension from a probing set", + "[ExtensionContainer " + "ProbingSet::GetLastProbeExtension() const]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE_THROWS_WITH(probing_set.GetLastProbeExtension(), + "Tried to return the last element of an empty vector!"); + } + + SECTION("Probing set with one probe extension") { + std::vector test_vector = {5}; + unsigned int expected_result = 5; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetLastProbeExtension() == expected_result); + } + + SECTION("Probing set with multiple extensions") { + std::vector test_vector = {5, 6, 7}; + unsigned int expected_result = 7; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetLastProbeExtension() == expected_result); + } +} + +TEST_CASE( + "Test the returning of all probe extension indices from a probing set", + "[std::vector " + "ProbingSet::GetAllProbeExtensions() const]") { + SECTION("Empty probing set") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetAllProbeExtensions() == test_vector); + } + + SECTION("Probing set with multiple extensions") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set(test_vector, + test_vector); + REQUIRE(probing_set.GetAllProbeExtensions() == test_vector); + } +} + +TEST_CASE("Test the greater operator for probing sets", + "bool ProbingSet::operator<(const " + "ProbingSet&) const") { + SECTION("Two empty probing sets") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE_FALSE(probing_set1 < probing_set1); + REQUIRE_FALSE(probing_set2 < probing_set2); + REQUIRE_FALSE(probing_set1 < probing_set2); + REQUIRE_FALSE(probing_set2 < probing_set1); + } + + SECTION("Two equal probing sets") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE_FALSE(probing_set1 < probing_set1); + REQUIRE_FALSE(probing_set2 < probing_set2); + REQUIRE_FALSE(probing_set1 < probing_set2); + REQUIRE_FALSE(probing_set2 < probing_set1); + } + + SECTION("Two probing sets with one different probe-extension index") { + std::vector test_vector1 = {5}; + std::vector test_vector2 = {6}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE(probing_set1 < probing_set2); + REQUIRE_FALSE(probing_set2 < probing_set1); + } + + SECTION("Two probing sets with different probe-extension indices") { + std::vector test_vector1 = {5, 6, 7}; + std::vector test_vector2 = {5, 6, 8}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE(probing_set1 < probing_set2); + REQUIRE_FALSE(probing_set2 < probing_set1); + } +} + +TEST_CASE("Test the equal operator for probing sets", + "bool ProbingSet::operator==(const " + "ProbingSet&) const") { + SECTION("Two empty probing sets") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE(probing_set1 == probing_set1); + REQUIRE(probing_set2 == probing_set2); + REQUIRE(probing_set1 == probing_set2); + REQUIRE(probing_set2 == probing_set1); + } + + SECTION("Two equal probing sets") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE(probing_set1 == probing_set1); + REQUIRE(probing_set2 == probing_set2); + REQUIRE(probing_set1 == probing_set2); + REQUIRE(probing_set2 == probing_set1); + } + + SECTION("Two probing sets with one different probe-extension index") { + std::vector test_vector1 = {5}; + std::vector test_vector2 = {6}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE(probing_set1 == probing_set1); + REQUIRE(probing_set2 == probing_set2); + REQUIRE_FALSE(probing_set1 == probing_set2); + REQUIRE_FALSE(probing_set2 == probing_set1); + } + + SECTION("Two probing sets with different probe-extension indices") { + std::vector test_vector1 = {5, 6, 7}; + std::vector test_vector2 = {5, 6, 8}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE(probing_set1 == probing_set1); + REQUIRE(probing_set2 == probing_set2); + REQUIRE_FALSE(probing_set1 == probing_set2); + REQUIRE_FALSE(probing_set2 == probing_set1); + } +} + +TEST_CASE("Test the not-equal operator for probing sets", + "bool ProbingSet::operator!=(const " + "ProbingSet&) const") { + SECTION("Two empty probing sets") { + std::vector test_vector = {}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE_FALSE(probing_set1 != probing_set1); + REQUIRE_FALSE(probing_set2 != probing_set2); + REQUIRE_FALSE(probing_set1 != probing_set2); + REQUIRE_FALSE(probing_set2 != probing_set1); + } + + SECTION("Two equal probing sets") { + std::vector test_vector = {5, 6, 7}; + Hardware::probing::ProbingSet probing_set1(test_vector, + test_vector); + Hardware::probing::ProbingSet probing_set2(test_vector, + test_vector); + REQUIRE_FALSE(probing_set1 != probing_set1); + REQUIRE_FALSE(probing_set2 != probing_set2); + REQUIRE_FALSE(probing_set1 != probing_set2); + REQUIRE_FALSE(probing_set2 != probing_set1); + } + + SECTION("Two probing sets with one different probe-extension index") { + std::vector test_vector1 = {5}; + std::vector test_vector2 = {6}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE_FALSE(probing_set1 != probing_set1); + REQUIRE_FALSE(probing_set2 != probing_set2); + REQUIRE(probing_set1 != probing_set2); + REQUIRE(probing_set2 != probing_set1); + } + + SECTION("Two probing sets with different probe-extension indices") { + std::vector test_vector1 = {5, 6, 7}; + std::vector test_vector2 = {5, 6, 8}; + Hardware::probing::ProbingSet probing_set1(test_vector1, + test_vector1); + Hardware::probing::ProbingSet probing_set2(test_vector2, + test_vector2); + REQUIRE_FALSE(probing_set1 != probing_set1); + REQUIRE_FALSE(probing_set2 != probing_set2); + REQUIRE(probing_set1 != probing_set2); + REQUIRE(probing_set2 != probing_set1); + } +} + +TEST_CASE("Test if a probing set fully includes another probing set", + "bool ProbingSet::Includes(const " + "ProbingSet&) const") { + SECTION("One probing set includes another probing set at the end") { + std::vector empty_vector = {}; + std::vector test_vector1 = {7,6,5}; + std::vector test_vector2 = {9,8,7,6,5}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE(probing_set2.Includes(probing_set1)); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + } + + SECTION("One probing set includes another probing set in the middle") { + std::vector empty_vector = {}; + std::vector test_vector1 = {8,7,6}; + std::vector test_vector2 = {9,8,7,6,5}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE(probing_set2.Includes(probing_set1)); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + } + + SECTION("One probing set includes another probing set at the end") { + std::vector empty_vector = {}; + std::vector test_vector1 = {9,8,7}; + std::vector test_vector2 = {9,8,7,6,5}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE(probing_set2.Includes(probing_set1)); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + } + + SECTION("One probing set includes another probing set but not continuously") { + std::vector empty_vector = {}; + std::vector test_vector1 = {9,7,5}; + std::vector test_vector2 = {9,8,7,6,5}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE(probing_set2.Includes(probing_set1)); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + } + + SECTION("Non-including probing sets with a single element") { + std::vector empty_vector = {}; + std::vector test_vector1 = {5}; + std::vector test_vector2 = {6}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + REQUIRE_FALSE(probing_set2.Includes(probing_set1)); + } + + SECTION("Non-including probing sets with a multiple elements") { + std::vector empty_vector = {}; + std::vector test_vector1 = {7,6,5,3}; + std::vector test_vector2 = {7,6,4,3}; + Hardware::probing::ProbingSet probing_set1(empty_vector, + test_vector1); + Hardware::probing::ProbingSet probing_set2(empty_vector, + test_vector2); + REQUIRE_FALSE(probing_set1.Includes(probing_set2)); + REQUIRE_FALSE(probing_set2.Includes(probing_set1)); + } } \ No newline at end of file