Skip to content

Commit

Permalink
[ads] Refactor epoch operator from [?]:* to [T?]:*
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 29, 2024
1 parent a963d39 commit 94ec559
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ TEST_F(BraveAdsConditionMatcherUtilTest,

TEST_F(BraveAdsConditionMatcherUtilTest, MatchEqualOperatorCondition) {
// Arrange
const ConditionMatcherMap condition_matchers = {{prefs::kServeAdAt, "[=]:7"}};
const ConditionMatcherMap condition_matchers = {
{prefs::kServeAdAt, "[T=]:7"}};

AdvanceClockBy(base::Days(7));

Expand All @@ -56,7 +57,8 @@ TEST_F(BraveAdsConditionMatcherUtilTest, MatchEqualOperatorCondition) {

TEST_F(BraveAdsConditionMatcherUtilTest, DoNotMatchEqualOperatorCondition) {
// Arrange
const ConditionMatcherMap condition_matchers = {{prefs::kServeAdAt, "[=]:7"}};
const ConditionMatcherMap condition_matchers = {
{prefs::kServeAdAt, "[T=]:7"}};

AdvanceClockBy(base::Days(7) - base::Milliseconds(1));

Expand Down Expand Up @@ -127,7 +129,7 @@ TEST_F(BraveAdsConditionMatcherUtilTest,
// Arrange
const ConditionMatcherMap condition_matchers = {
{prefs::kOptedInToNotificationAds, "0"}, // Value is "1" in the pref.
{prefs::kServeAdAt, "[>]:7"}}; // 5 days ago in the pref.
{prefs::kServeAdAt, "[T>]:7"}}; // 5 days ago in the pref.

AdvanceClockBy(base::Days(5));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace brave_ads {

namespace {

constexpr char kEqualOperatorConditionMatcherPrefix[] = "[=]:";
constexpr char kGreaterThanOperatorConditionMatcherPrefix[] = "[>]:";
constexpr char kGreaterThanOrEqualOperatorConditionMatcherPrefix[] = "[≥]:";
constexpr char kLessThanOperatorConditionMatcherPrefix[] = "[<]:";
constexpr char kLessThanOrEqualOperatorConditionMatcherPrefix[] = "[≤]:";
constexpr char kEqualOperatorConditionMatcherPrefix[] = "[T=]:";
constexpr char kGreaterThanOperatorConditionMatcherPrefix[] = "[T>]:";
constexpr char kGreaterThanOrEqualOperatorConditionMatcherPrefix[] = "[T≥]:";
constexpr char kLessThanOperatorConditionMatcherPrefix[] = "[T<]:";
constexpr char kLessThanOrEqualOperatorConditionMatcherPrefix[] = "[T≤]:";

} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
DoNotMatchMalformedOperator) {
// Act & Assert
EXPECT_FALSE(MatchEpochOperator(
"13372214400000000" /*1st October 2024 00:00:00 UTC*/, "[=]: 7 "));
"13372214400000000" /*1st October 2024 00:00:00 UTC*/, "[T=]: 7 "));
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchEqualOperator) {
Expand All @@ -34,7 +34,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchEqualOperator) {
// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[=]:2")); // Event occurred 2 days ago.
"[T=]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, DoNotMatchEqualOperator) {
Expand All @@ -44,7 +44,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, DoNotMatchEqualOperator) {
// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[=]:3")); // Event occurred 2 days ago.
"[T=]:3")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -55,7 +55,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[>]:1")); // Event occurred 2 days ago.
"[T>]:1")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -66,7 +66,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[>]:2")); // Event occurred 2 days ago.
"[T>]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -77,10 +77,10 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≥]:1")); // Event occurred 2 days ago.
"[T≥]:1")); // Event occurred 2 days ago.
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≥]:2")); // Event occurred 2 days ago.
"[T≥]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -91,7 +91,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≥]:3")); // Event occurred 2 days ago.
"[T≥]:3")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchLessThanOperator) {
Expand All @@ -101,7 +101,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchLessThanOperator) {
// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[<]:3")); // Event occurred 2 days ago.
"[T<]:3")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -112,7 +112,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[<]:2")); // Event occurred 2 days ago.
"[T<]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -123,10 +123,10 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≤]:3")); // Event occurred 2 days ago.
"[T≤]:3")); // Event occurred 2 days ago.
EXPECT_TRUE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≤]:2")); // Event occurred 2 days ago.
"[T≤]:2")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -137,7 +137,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
// Act & Assert
EXPECT_FALSE(
MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/,
"[≤]:1")); // Event occurred 2 days ago.
"[T≤]:1")); // Event occurred 2 days ago.
}

TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,
Expand All @@ -147,7 +147,7 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest,

// Act & Assert
EXPECT_FALSE(MatchEpochOperator(
"13372214400000000" /*1st October 2024 00:00:00 UTC*/, "[_]:2"));
"13372214400000000" /*1st October 2024 00:00:00 UTC*/, "[T_]:2"));
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TimeDelta;

namespace brave_ads {

inline constexpr char kEpochOperatorConditionMatcherPrefixPattern[] = "[?]:*";
inline constexpr char kEpochOperatorConditionMatcherPrefixPattern[] = "[T?]:*";

// Parses a number of days from a condition.
std::optional<int> ParseDays(std::string_view condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ class BraveAdsOperatorConditionMatcherUtilInternalTest : public test::TestBase {
TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest,
DoNotParseNegativeDays) {
// Act & Assert
EXPECT_FALSE(ParseDays("[=]:-1"));
EXPECT_FALSE(ParseDays("[T=]:-1"));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest, ParseDayZero) {
// Act & Assert
EXPECT_EQ(0, ParseDays("[=]:0"));
EXPECT_EQ(0, ParseDays("[T=]:0"));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest, ParseDays) {
// Act & Assert
EXPECT_EQ(7, ParseDays("[=]:7"));
EXPECT_EQ(7, ParseDays("[T=]:7"));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest,
DoNotParseNonIntegerDays) {
// Act & Assert
EXPECT_FALSE(ParseDays("[=]:1.5"));
EXPECT_FALSE(ParseDays("[T=]:1.5"));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest,
DoNotParseMalformedDays) {
// Act & Assert
EXPECT_FALSE(ParseDays("[=]: 7 "));
EXPECT_FALSE(ParseDays("[T=]: 7 "));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest,
DoNotParseInvalidDays) {
// Act & Assert
EXPECT_FALSE(ParseDays("[=]:seven"));
EXPECT_FALSE(ParseDays("[T=]:seven"));
}

TEST_F(BraveAdsOperatorConditionMatcherUtilInternalTest, IsUnixEpochTimestamp) {
Expand Down

0 comments on commit 94ec559

Please sign in to comment.