Skip to content

Commit

Permalink
[ads] Add SmartNTT [T≠] epoch operator conditon matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 30, 2024
1 parent e6e34fb commit 366e9e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace brave_ads {
namespace {

constexpr char kEqualOperatorConditionMatcherPrefix[] = "[T=]:";
constexpr char kNotEqualOperatorConditionMatcherPrefix[] = "[T≠]:";
constexpr char kGreaterThanOperatorConditionMatcherPrefix[] = "[T>]:";
constexpr char kGreaterThanOrEqualOperatorConditionMatcherPrefix[] = "[T≥]:";
constexpr char kLessThanOperatorConditionMatcherPrefix[] = "[T<]:";
Expand Down Expand Up @@ -50,6 +51,10 @@ bool MatchEpochOperator(const std::string_view value,
return time_delta->InDays() == days;
}

if (condition.starts_with(kNotEqualOperatorConditionMatcherPrefix)) {
return time_delta->InDays() != days;
}

if (condition.starts_with(kGreaterThanOperatorConditionMatcherPrefix)) {
return time_delta->InDays() > days;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, DoNotMatchEqualOperator) {
"[T=]:3")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchNotEqualOperator) {
// Arrange
AdvanceClockTo(test::TimeFromUTCString("3 October 2024"));

// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[T≠]:3")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
DoNotMatchNotEqualOperator) {
// Arrange
AdvanceClockTo(test::TimeFromUTCString("3 October 2024"));

// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[T≠]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
MatchGreaterThanOperator) {
// Arrange
Expand Down

0 comments on commit 366e9e0

Please sign in to comment.