diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-04-26 22:24:33 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-04-26 22:24:33 +0200 |
commit | ee87ac11a9351be87b06090eff97a045d55277a9 (patch) | |
tree | 0dee6872873267621deefe14cdac98d0dc60f7b1 /streamingvisitors | |
parent | 93ad9f1cc6dfbd6b3b2c62de49bf688b485c0e8f (diff) |
Rewrite streamingvisitors hit collector unit test to use gtest.
Diffstat (limited to 'streamingvisitors')
-rw-r--r-- | streamingvisitors/src/tests/hitcollector/CMakeLists.txt | 1 | ||||
-rw-r--r-- | streamingvisitors/src/tests/hitcollector/hitcollector_test.cpp | 75 |
2 files changed, 27 insertions, 49 deletions
diff --git a/streamingvisitors/src/tests/hitcollector/CMakeLists.txt b/streamingvisitors/src/tests/hitcollector/CMakeLists.txt index dbec820a462..cda718c40dd 100644 --- a/streamingvisitors/src/tests/hitcollector/CMakeLists.txt +++ b/streamingvisitors/src/tests/hitcollector/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(streamingvisitors_hitcollector_test_app TEST hitcollector_test.cpp DEPENDS streamingvisitors + GTest::GTest ) vespa_add_test(NAME streamingvisitors_hitcollector_test_app COMMAND streamingvisitors_hitcollector_test_app) diff --git a/streamingvisitors/src/tests/hitcollector/hitcollector_test.cpp b/streamingvisitors/src/tests/hitcollector/hitcollector_test.cpp index 791ec01162f..059d3c9f597 100644 --- a/streamingvisitors/src/tests/hitcollector/hitcollector_test.cpp +++ b/streamingvisitors/src/tests/hitcollector/hitcollector_test.cpp @@ -1,5 +1,4 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/datatype/documenttype.h> @@ -10,6 +9,7 @@ #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/value_codec.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/objects/nbostream.h> using namespace document; @@ -26,9 +26,9 @@ using vespalib::eval::Value; namespace streaming { -class HitCollectorTest : public vespalib::TestApp +class HitCollectorTest : public ::testing::Test { -private: +protected: void assertHit(SearchResult::RankType expRank, uint32_t hitNo, SearchResult & rs); void assertHit(SearchResult::RankType expRank, uint32_t expDocId, uint32_t hitNo, SearchResult & rs); void addHit(HitCollector &hc, uint32_t docId, double score, @@ -43,10 +43,8 @@ private: DocumentType _docType; std::vector<vsm::StorageDocument::UP> _backedHits; -public: HitCollectorTest(); - ~HitCollectorTest(); - int Main() override; + ~HitCollectorTest() override; }; HitCollectorTest::HitCollectorTest() @@ -70,8 +68,8 @@ HitCollectorTest::assertHit(SearchResult::RankType expRank, uint32_t expDocId, u const char * gDocId; SearchResult::RankType rank; lDocId = rs.getHit(hitNo, gDocId, rank); - EXPECT_EQUAL(rank, expRank); - EXPECT_EQUAL(lDocId, expDocId); + EXPECT_EQ(rank, expRank); + EXPECT_EQ(lDocId, expDocId); } void @@ -85,8 +83,7 @@ HitCollectorTest::addHit(HitCollector &hc, uint32_t docId, double score, const c _backedHits.push_back(std::move(sdoc)); } -void -HitCollectorTest::testSimple() +TEST_F(HitCollectorTest, simple) { HitCollector hc(5); @@ -107,8 +104,7 @@ HitCollectorTest::testSimple() } } -void -HitCollectorTest::testGapsInDocId() +TEST_F(HitCollectorTest, gaps_in_docid) { HitCollector hc(5); @@ -129,8 +125,7 @@ HitCollectorTest::testGapsInDocId() assertHit(18, 8, 4, sr); } -void -HitCollectorTest::testHeapProperty() +TEST_F(HitCollectorTest, heap_property) { { HitCollector hc(3); @@ -173,8 +168,7 @@ HitCollectorTest::testHeapProperty() } } -void -HitCollectorTest::testHeapPropertyWithSorting() +TEST_F(HitCollectorTest, heap_property_with_sorting) { std::vector<char> sortData; sortData.push_back('a'); @@ -224,8 +218,7 @@ HitCollectorTest::testHeapPropertyWithSorting() } } -void -HitCollectorTest::testEmpty() +TEST_F(HitCollectorTest, empty) { HitCollector hc(0); addHit(hc, 0, 0); @@ -270,8 +263,7 @@ public: }; MyRankProgram::~MyRankProgram() = default; -void -HitCollectorTest::testFeatureSet() +TEST_F(HitCollectorTest, feature_set) { HitCollector hc(3); @@ -287,41 +279,41 @@ HitCollectorTest::testFeatureSet() renames["bar"] = "qux"; vespalib::FeatureSet::SP sf = hc.getFeatureSet(rankProgram, resolver, renames); - EXPECT_EQUAL(sf->getNames().size(), 3u); - EXPECT_EQUAL(sf->getNames()[0], "foo"); - EXPECT_EQUAL(sf->getNames()[1], "qux"); - EXPECT_EQUAL(sf->getNames()[2], "baz"); - EXPECT_EQUAL(sf->numFeatures(), 3u); - EXPECT_EQUAL(sf->numDocs(), 3u); + EXPECT_EQ(sf->getNames().size(), 3u); + EXPECT_EQ(sf->getNames()[0], "foo"); + EXPECT_EQ(sf->getNames()[1], "qux"); + EXPECT_EQ(sf->getNames()[2], "baz"); + EXPECT_EQ(sf->numFeatures(), 3u); + EXPECT_EQ(sf->numDocs(), 3u); { const auto * f = sf->getFeaturesByDocId(1); ASSERT_TRUE(f != NULL); - EXPECT_EQUAL(f[0].as_double(), 11); // 10 + docId - EXPECT_EQUAL(f[1].as_double(), 31); // 30 + docId + EXPECT_EQ(f[0].as_double(), 11); // 10 + docId + EXPECT_EQ(f[1].as_double(), 31); // 30 + docId } { const auto * f = sf->getFeaturesByDocId(3); ASSERT_TRUE(f != NULL); EXPECT_TRUE(f[0].is_double()); EXPECT_TRUE(!f[0].is_data()); - EXPECT_EQUAL(f[0].as_double(), 13); + EXPECT_EQ(f[0].as_double(), 13); EXPECT_TRUE(f[1].is_double()); EXPECT_TRUE(!f[1].is_data()); - EXPECT_EQUAL(f[1].as_double(), 33); + EXPECT_EQ(f[1].as_double(), 33); EXPECT_TRUE(!f[2].is_double()); EXPECT_TRUE(f[2].is_data()); { nbostream buf(f[2].as_data().data, f[2].as_data().size); auto actual = spec_from_value(*SimpleValue::from_stream(buf)); auto expect = TensorSpec("tensor(x{})").add({{"x", "a"}}, 23); - EXPECT_EQUAL(actual, expect); + EXPECT_EQ(actual, expect); } } { const auto * f = sf->getFeaturesByDocId(4); ASSERT_TRUE(f != NULL); - EXPECT_EQUAL(f[0].as_double(), 14); - EXPECT_EQUAL(f[1].as_double(), 34); + EXPECT_EQ(f[0].as_double(), 14); + EXPECT_EQ(f[1].as_double(), 34); } ASSERT_TRUE(sf->getFeaturesByDocId(0) == NULL); ASSERT_TRUE(sf->getFeaturesByDocId(2) == NULL); @@ -334,21 +326,6 @@ HitCollectorTest::testFeatureSet() assertHit(30, 4, 2, sr); } -int -HitCollectorTest::Main() -{ - TEST_INIT("hitcollector_test"); - - testSimple(); - testGapsInDocId(); - testHeapProperty(); - testHeapPropertyWithSorting(); - testEmpty(); - testFeatureSet(); - - TEST_DONE(); -} - } // namespace streaming -TEST_APPHOOK(streaming::HitCollectorTest) +GTEST_MAIN_RUN_ALL_TESTS() |