Skip to content

Commit

Permalink
Ad coefficient update for last seen ad (#24253)
Browse files Browse the repository at this point in the history
* coefficient update for last seen ad

unit tests updated

Fix tests

unit tests updated

unit tests updated

* coefficient update for last seen ad

unit tests updated

Fix tests

unit tests updated

unit tests updated

cleaning up unit tests
  • Loading branch information
ptjames authored Jun 25, 2024
1 parent a3a92e2 commit 0f6ee64
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,64 +41,73 @@ TEST_F(BraveAdsEligibleInlineContentAdsV2Test, GetAds) {
// Arrange
CreativeInlineContentAdList creative_ads;

CreativeInlineContentAdInfo creative_ad_1 =
test::BuildCreativeInlineContentAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo-bar1";
const CreativeInlineContentAdInfo creative_ad_1 =
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ads.push_back(creative_ad_1);

CreativeInlineContentAdInfo creative_ad_2 =
test::BuildCreativeInlineContentAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar3";
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent";
creative_ads.push_back(creative_ad_2);

CreativeInlineContentAdInfo creative_ad_3 =
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ad_3.segment = "parent-child";
creative_ads.push_back(creative_ad_3);

database::SaveCreativeInlineContentAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeInlineContentAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
EXPECT_CALL(callback, Run(CreativeInlineContentAdList{creative_ad_1}));
eligible_ads_->GetForUserModel(
UserModelInfo{
IntentUserModelInfo{SegmentList{"foo-bar1", "foo-bar2"}},
IntentUserModelInfo{},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"foo-bar3"}},
InterestUserModelInfo{SegmentList{"untargeted"}},
},
/*dimensions=*/"200x100", callback.Get());
}

TEST_F(BraveAdsEligibleInlineContentAdsV2Test, GetAdsForNoSegments) {
TEST_F(BraveAdsEligibleInlineContentAdsV2Test, GetAdsForNoMatchingSegments) {
// Arrange
CreativeInlineContentAdList creative_ads;

CreativeInlineContentAdInfo creative_ad_1 =
test::BuildCreativeInlineContentAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo";
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ad_1.segment = "parent";
creative_ads.push_back(creative_ad_1);

CreativeInlineContentAdInfo creative_ad_2 =
test::BuildCreativeInlineContentAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar";
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent-child";
creative_ads.push_back(creative_ad_2);

database::SaveCreativeInlineContentAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeInlineContentAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(/*user_model=*/{}, /*dimensions=*/"200x100",
callback.Get());
}

TEST_F(BraveAdsEligibleInlineContentAdsV2Test,
DoNotGetAdsForNonExistentDimensions) {
// Arrange
CreativeInlineContentAdList creative_ads;

const CreativeInlineContentAdInfo creative_ad =
test::BuildCreativeInlineContentAd(/*should_use_random_uuids=*/true);
creative_ads.push_back(creative_ad);

database::SaveCreativeInlineContentAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeInlineContentAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(
UserModelInfo{
IntentUserModelInfo{SegmentList{"intent-foo", "intent-bar"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"interest-foo", "interest-bar"}}},
/*dimensions=*/"?x?", callback.Get());
eligible_ads_->GetForUserModel(UserModelInfo{},
/*dimensions=*/"?x?", callback.Get());
}

TEST_F(BraveAdsEligibleInlineContentAdsV2Test, DoNotGetAdsIfNoEligibleAds) {
Expand All @@ -107,9 +116,9 @@ TEST_F(BraveAdsEligibleInlineContentAdsV2Test, DoNotGetAdsIfNoEligibleAds) {
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(
UserModelInfo{
IntentUserModelInfo{SegmentList{"intent-foo", "intent-bar"}},
IntentUserModelInfo{SegmentList{"parent-child", "parent"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"interest-foo", "interest-bar"}}},
InterestUserModelInfo{SegmentList{"parent-child", "parent"}}},
/*dimensions=*/"200x100", callback.Get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,50 @@ TEST_F(BraveAdsEligibleNewTabPageAdsV2Test, GetAds) {
// Arrange
CreativeNewTabPageAdList creative_ads;

CreativeNewTabPageAdInfo creative_ad_1 =
test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo-bar1";
const CreativeNewTabPageAdInfo creative_ad_1 =
test::BuildCreativeNewTabPageAd(/*should_use_random_uuids=*/true);
creative_ads.push_back(creative_ad_1);

CreativeNewTabPageAdInfo creative_ad_2 =
test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar3";
test::BuildCreativeNewTabPageAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent";
creative_ads.push_back(creative_ad_2);

CreativeNewTabPageAdInfo creative_ad_3 =
test::BuildCreativeNewTabPageAd(/*should_use_random_uuids=*/true);
creative_ad_3.segment = "parent-child";
creative_ads.push_back(creative_ad_3);

database::SaveCreativeNewTabPageAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeNewTabPageAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
EXPECT_CALL(callback, Run(CreativeNewTabPageAdList{creative_ad_1}));
eligible_ads_->GetForUserModel(
UserModelInfo{IntentUserModelInfo{SegmentList{"foo-bar1", "foo-bar2"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"foo-bar3"}}},
UserModelInfo{IntentUserModelInfo{}, LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"untargeted"}}},
callback.Get());
}

TEST_F(BraveAdsEligibleNewTabPageAdsV2Test, GetAdsForNoSegments) {
TEST_F(BraveAdsEligibleNewTabPageAdsV2Test, GetAdsForNoMatchingSegments) {
// Arrange
CreativeNewTabPageAdList creative_ads;

CreativeNewTabPageAdInfo creative_ad_1 =
test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo";
test::BuildCreativeNewTabPageAd(/*should_use_random_uuids=*/true);
creative_ad_1.segment = "parent";
creative_ads.push_back(creative_ad_1);

CreativeNewTabPageAdInfo creative_ad_2 =
test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar";
test::BuildCreativeNewTabPageAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent-child";
creative_ads.push_back(creative_ad_2);

database::SaveCreativeNewTabPageAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeNewTabPageAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(/*user_model=*/{}, callback.Get());
}

Expand All @@ -90,9 +93,9 @@ TEST_F(BraveAdsEligibleNewTabPageAdsV2Test, DoNotGetAdsIfNoEligibleAds) {
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(
UserModelInfo{
IntentUserModelInfo{SegmentList{"intent-foo", "intent-boo"}},
IntentUserModelInfo{SegmentList{"parent-child", "parent"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"interest-foo", "interest-bar"}}},
InterestUserModelInfo{SegmentList{"parent-child", "parent"}}},
callback.Get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ TEST_F(BraveAdsEligibleNotificationAdsV2Test, GetAds) {
CreativeNotificationAdList creative_ads;

CreativeNotificationAdInfo creative_ad_1 =
test::BuildCreativeNotificationAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo-bar1";
test::BuildCreativeNotificationAd(/*should_use_random_uuids=*/true);
creative_ad_1.segment = "parent-child-1";
creative_ads.push_back(creative_ad_1);

CreativeNotificationAdInfo creative_ad_2 =
test::BuildCreativeNotificationAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar3";
test::BuildCreativeNotificationAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent-child-3";
creative_ads.push_back(creative_ad_2);

database::SaveCreativeNotificationAds(creative_ads);
Expand All @@ -56,31 +56,32 @@ TEST_F(BraveAdsEligibleNotificationAdsV2Test, GetAds) {
base::MockCallback<EligibleAdsCallback<CreativeNotificationAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
eligible_ads_->GetForUserModel(
UserModelInfo{IntentUserModelInfo{SegmentList{"foo-bar1", "foo-bar2"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"foo-bar3"}}},
UserModelInfo{
IntentUserModelInfo{SegmentList{"parent-child-1", "parent-child-2"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"parent-child-3"}}},
callback.Get());
}

TEST_F(BraveAdsEligibleNotificationAdsV2Test, GetAdsForNoSegments) {
TEST_F(BraveAdsEligibleNotificationAdsV2Test, GetAdsForNoMatchingSegments) {
// Arrange
CreativeNotificationAdList creative_ads;

CreativeNotificationAdInfo creative_ad_1 =
test::BuildCreativeNotificationAd(/*should_generate_random_uuids=*/true);
creative_ad_1.segment = "foo";
test::BuildCreativeNotificationAd(/*should_use_random_uuids=*/true);
creative_ad_1.segment = "parent";
creative_ads.push_back(creative_ad_1);

CreativeNotificationAdInfo creative_ad_2 =
test::BuildCreativeNotificationAd(/*should_generate_random_uuids=*/true);
creative_ad_2.segment = "foo-bar";
test::BuildCreativeNotificationAd(/*should_use_random_uuids=*/true);
creative_ad_2.segment = "parent-child";
creative_ads.push_back(creative_ad_2);

database::SaveCreativeNotificationAds(creative_ads);

// Act & Assert
base::MockCallback<EligibleAdsCallback<CreativeNotificationAdList>> callback;
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::SizeIs(1)));
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(/*user_model=*/{}, callback.Get());
}

Expand All @@ -90,9 +91,9 @@ TEST_F(BraveAdsEligibleNotificationAdsV2Test, DoNotGetAdsIfNoEligibleAds) {
EXPECT_CALL(callback, Run(/*creative_ads=*/::testing::IsEmpty()));
eligible_ads_->GetForUserModel(
UserModelInfo{
IntentUserModelInfo{SegmentList{"intent-foo", "intent-bar"}},
IntentUserModelInfo{SegmentList{"parent-child", "parent"}},
LatentInterestUserModelInfo{},
InterestUserModelInfo{SegmentList{"interest-foo", "interest-bar"}}},
InterestUserModelInfo{SegmentList{"parent-child", "parent"}}},
callback.Get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEST_F(BraveAdsCreativeAdModelBasedPredictorUtilTest,
.value = false;
expected_creative_ad_predictor_1.input_variable.interest_segment
.parent_matches.value = true;
expected_creative_ad_predictor_1.score = 3.0;
expected_creative_ad_predictor_1.score = 2.0;
expected_creative_ad_predictors.push_back(expected_creative_ad_predictor_1);

CreativeAdModelBasedPredictorInfo<CreativeNotificationAdInfo>
Expand All @@ -101,7 +101,7 @@ TEST_F(BraveAdsCreativeAdModelBasedPredictorUtilTest,
.parent_matches.value = false;
expected_creative_ad_predictor_2.input_variable.last_seen_ad.value =
base::Hours(3);
expected_creative_ad_predictor_2.score = 0.125;
expected_creative_ad_predictor_2.score = 0.0;
expected_creative_ad_predictors.push_back(expected_creative_ad_predictor_2);

CreativeAdModelBasedPredictorInfo<CreativeNotificationAdInfo>
Expand All @@ -119,7 +119,7 @@ TEST_F(BraveAdsCreativeAdModelBasedPredictorUtilTest,
.value = true;
expected_creative_ad_predictor_3.input_variable.interest_segment
.parent_matches.value = true;
expected_creative_ad_predictor_3.score = 3.0;
expected_creative_ad_predictor_3.score = 2.0;
expected_creative_ad_predictors.push_back(expected_creative_ad_predictor_3);

EXPECT_EQ(expected_creative_ad_predictors, creative_ad_predictors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline constexpr base::FeatureParam<double>
inline constexpr base::FeatureParam<double>
kInlineContentAdLastSeenPredictorWeight{
&kCreativeInlineContentAdModelBasedPredictorFeature,
"last_seen_ad_predictor_weight", 1.0};
"last_seen_ad_predictor_weight", 0.0};

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ TEST(BraveAdsCreativeInlineContentAdModelBasedPredictorFeatureTest,
TEST(BraveAdsCreativeInlineContentAdModelBasedPredictorFeatureTest,
DefaultLastSeenAdPredictorWeight) {
// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kInlineContentAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kInlineContentAdLastSeenPredictorWeight.Get());
}

TEST(BraveAdsCreativeInlineContentAdModelBasedPredictorFeatureTest,
Expand All @@ -279,7 +279,7 @@ TEST(BraveAdsCreativeInlineContentAdModelBasedPredictorFeatureTest,
kCreativeInlineContentAdModelBasedPredictorFeature);

// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kInlineContentAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kInlineContentAdLastSeenPredictorWeight.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline constexpr base::FeatureParam<double>
inline constexpr base::FeatureParam<double>
kNewTabPageAdLastSeenPredictorWeight{
&kCreativeNewTabPageAdModelBasedPredictorFeature,
"last_seen_ad_predictor_weight", 1.0};
"last_seen_ad_predictor_weight", 0.0};

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ TEST(BraveAdsCreativeNewTabPageAdModelBasedPredictorFeatureTest,
TEST(BraveAdsCreativeNewTabPageAdModelBasedPredictorFeatureTest,
DefaultLastSeenAdPredictorWeight) {
// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kNewTabPageAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kNewTabPageAdLastSeenPredictorWeight.Get());
}

TEST(BraveAdsCreativeNewTabPageAdModelBasedPredictorFeatureTest,
Expand All @@ -267,7 +267,7 @@ TEST(BraveAdsCreativeNewTabPageAdModelBasedPredictorFeatureTest,
kCreativeNewTabPageAdModelBasedPredictorFeature);

// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kNewTabPageAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kNewTabPageAdLastSeenPredictorWeight.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline constexpr base::FeatureParam<double>
inline constexpr base::FeatureParam<double>
kNotificationAdLastSeenPredictorWeight{
&kCreativeNotificationAdModelBasedPredictorFeature,
"last_seen_ad_predictor_weight", 1.0};
"last_seen_ad_predictor_weight", 0.0};

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ TEST(BraveAdsCreativeNotificationAdModelBasedPredictorFeatureTest,
TEST(BraveAdsCreativeNotificationAdModelBasedPredictorFeatureTest,
DefaultLastSeenAdPredictorWeight) {
// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kNotificationAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kNotificationAdLastSeenPredictorWeight.Get());
}

TEST(BraveAdsCreativeNotificationAdModelBasedPredictorFeatureTest,
Expand All @@ -275,7 +275,7 @@ TEST(BraveAdsCreativeNotificationAdModelBasedPredictorFeatureTest,
kCreativeNotificationAdModelBasedPredictorFeature);

// Act & Assert
EXPECT_DOUBLE_EQ(1.0, kNotificationAdLastSeenPredictorWeight.Get());
EXPECT_DOUBLE_EQ(0.0, kNotificationAdLastSeenPredictorWeight.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CreativeAdModelBasedPredictorLastSeenInputVariableInfo final {

// The time delta since the last time the user saw an ad.
std::optional<base::TimeDelta> value;
double weight = 1.0;
double weight = 0.0;
};

} // namespace brave_ads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(BraveAdsCreativeAdModelBasedPredictorScoringTest,
test::BuildCreativeAdModelBasedPredictorWeights());

// Act & Assert
EXPECT_DOUBLE_EQ(3.2916666666666665,
EXPECT_DOUBLE_EQ(3.0,
ComputeCreativeAdModelBasedPredictorScore(input_variable));
}

Expand Down
Loading

0 comments on commit 0f6ee64

Please sign in to comment.