Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Jun 1, 2024
1 parent 2370fae commit 4bfeeca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Summarizer {
return k.variation == variation && k.version == version;
}

bool operator!=(VariationKey const& k) const { return !(*this == k); }

bool operator<(VariationKey const& k) const {
if (variation < k.variation) {
return true;
Expand All @@ -94,6 +96,8 @@ class Summarizer {
}
return version < k.version;
}

bool operator>(VariationKey const& k) const { return k < *this; }
};

struct State {
Expand Down
46 changes: 46 additions & 0 deletions libs/internal/tests/event_summarizer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,52 @@ TEST(SummarizerTests, ExplicitStartTimeIsCorrect) {
ASSERT_EQ(summarizer.StartTime(), start);
}

TEST(SummarizerTests, VariationKeyOrdering) {
Summarizer::VariationKey a(0, 1);

Check warning on line 39 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:39:30 [readability-identifier-length]

variable name 'a' is too short, expected at least 3 characters
Summarizer::VariationKey b(1, 0);

Check warning on line 40 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:40:30 [readability-identifier-length]

variable name 'b' is too short, expected at least 3 characters

ASSERT_FALSE(a < b);
ASSERT_TRUE(a > b);

ASSERT_FALSE(b > a);
ASSERT_TRUE(b < a);

ASSERT_TRUE(a != b);
ASSERT_FALSE(a == b);
}

TEST(SummarizerTests, VariationKeyEquality) {

Check warning on line 52 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:52:1 [readability-function-cognitive-complexity]

function 'TestBody' has cognitive complexity of 61 (threshold 25)
Summarizer::VariationKey different(2, 2);

std::vector<Summarizer::VariationKey> keys = {
Summarizer::VariationKey(0, 1),
Summarizer::VariationKey(1, 0),
Summarizer::VariationKey(0, 0),
Summarizer::VariationKey(1, 1),
Summarizer::VariationKey(12412, 123),

Check warning on line 60 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:60:34 [cppcoreguidelines-avoid-magic-numbers

12412 is a magic number; consider replacing it with a named constant

Check warning on line 60 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:60:41 [cppcoreguidelines-avoid-magic-numbers

123 is a magic number; consider replacing it with a named constant
Summarizer::VariationKey(324, 5323332)};

Check warning on line 61 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:61:34 [cppcoreguidelines-avoid-magic-numbers

324 is a magic number; consider replacing it with a named constant

Check warning on line 61 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:61:39 [cppcoreguidelines-avoid-magic-numbers

5323332 is a magic number; consider replacing it with a named constant

for (auto const& key : keys) {
Summarizer::VariationKey a = key;

Check warning on line 64 in libs/internal/tests/event_summarizer_test.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/libs/internal/tests/event_summarizer_test.cpp:64:34 [readability-identifier-length]

variable name 'a' is too short, expected at least 3 characters
Summarizer::VariationKey b = key;

ASSERT_EQ(a, b);
ASSERT_EQ(b, a);

ASSERT_FALSE(a != b);
ASSERT_FALSE(b != a);

ASSERT_FALSE(a < b);
ASSERT_FALSE(b < a);

ASSERT_FALSE(a > b);
ASSERT_FALSE(b > a);

ASSERT_NE(key, different);
ASSERT_FALSE(key == different);
}
}

struct EvaluationParams {
std::string feature_key;
Version feature_version;
Expand Down

0 comments on commit 4bfeeca

Please sign in to comment.