Skip to content

Commit

Permalink
OTT-172: Set default min ads to 1 from 2 (#153)
Browse files Browse the repository at this point in the history
* OTT-172: Set default min ads to 1 from 2

* Adding test cases for impression generation algorithm
  • Loading branch information
Pubmatic-Dhruv-Sonone authored May 11, 2021
1 parent 1dcf910 commit c360511
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
2 changes: 1 addition & 1 deletion endpoints/openrtb2/ctv/impressions/impression_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func computeTimeForEachAdSlot(cfg generator, totalAds int64) int64 {
// of given number. Prefer to return computed timeForEachSlot
// In such case timeForEachSlot no necessarily to be multiples of given number
if cfg.requested.slotMinDuration == cfg.requested.slotMaxDuration {
util.Logf("requested.slotMinDuration = requested.slotMinDuration = %v. Hence, not computing multiples of %v value.", cfg.requested.slotMaxDuration, multipleOf)
util.Logf("requested.slotMinDuration = requested.slotMaxDuration = %v. Hence, not computing multiples of %v value.", cfg.requested.slotMaxDuration, multipleOf)
return timeForEachSlot
}

Expand Down
25 changes: 25 additions & 0 deletions endpoints/openrtb2/ctv/impressions/maximize_for_duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,31 @@ var impressionsTests = []struct {
closedMaxDuration: 74,
closedSlotMinDuration: 12,
closedSlotMaxDuration: 12,
}}, {scenario: "TC56", out: expected{
impressionCount: 1,
freeTime: 0, closedMinDuration: 126,
closedMaxDuration: 126,
closedSlotMinDuration: 126,
closedSlotMaxDuration: 126,
}}, {scenario: "TC57", out: expected{
impressionCount: 1,
freeTime: 0, closedMinDuration: 126,
closedMaxDuration: 126,
closedSlotMinDuration: 126,
closedSlotMaxDuration: 126,
}}, {scenario: "TC58", out: expected{
impressionCount: 4,
freeTime: 0, closedMinDuration: 30,
closedMaxDuration: 90,
closedSlotMinDuration: 15,
closedSlotMaxDuration: 45,
}},
{scenario: "TC59", out: expected{
impressionCount: 1,
freeTime: 45, closedMinDuration: 30,
closedMaxDuration: 90,
closedSlotMinDuration: 15,
closedSlotMaxDuration: 45,
}},
}

Expand Down
40 changes: 33 additions & 7 deletions endpoints/openrtb2/ctv/impressions/min_max_algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,34 @@ var impressionsTestsA2 = []struct {
step4: [][2]int64{},
step5: [][2]int64{},
}},

{scenario: "TC56", out: expectedOutputA2{
step1: [][2]int64{{126, 126}},
step2: [][2]int64{{126, 126}},
step3: [][2]int64{{126, 126}},
step4: [][2]int64{{126, 126}},
step5: [][2]int64{{126, 126}},
}},
{scenario: "TC57", out: expectedOutputA2{
step1: [][2]int64{{126, 126}},
step2: [][2]int64{},
step3: [][2]int64{{126, 126}},
step4: [][2]int64{},
step5: [][2]int64{{126, 126}},
}},
{scenario: "TC58", out: expectedOutputA2{
step1: [][2]int64{{25, 25}, {25, 25}, {20, 20}, {20, 20}},
step2: [][2]int64{{25, 25}, {25, 25}, {20, 20}, {20, 20}},
step3: [][2]int64{{45, 45}, {45, 45}},
step4: [][2]int64{},
step5: [][2]int64{{15, 15}, {15, 15}},
}},
{scenario: "TC59", out: expectedOutputA2{
step1: [][2]int64{{45, 45}},
step2: [][2]int64{},
step3: [][2]int64{},
step4: [][2]int64{{30, 30}},
step5: [][2]int64{{30, 30}},
}},
// {scenario: "TC1" , out: expectedOutputA2{
// step1: [][2]int64{},
// step2: [][2]int64{},
Expand Down Expand Up @@ -470,7 +497,6 @@ var impressionsTestsA2 = []struct {
// // 60, 60, 15, 45, 2, 2
// step5: [][2]int64{{30, 30}, {30, 30}},
// }},

}

func TestGetImpressionsA2(t *testing.T) {
Expand All @@ -486,23 +512,23 @@ func TestGetImpressionsA2(t *testing.T) {
case 0: // algo1 equaivalent
assert.Equal(t, impTest.out.step1, gen.Get())
expectedMergedOutput = appendOptimized(expectedMergedOutput, impTest.out.step1)
break

case 1: // pod duration = pod max duration, no of ads = maxads
assert.Equal(t, impTest.out.step2, gen.Get())
expectedMergedOutput = appendOptimized(expectedMergedOutput, impTest.out.step2)
break

case 2: // pod duration = pod max duration, no of ads = minads
assert.Equal(t, impTest.out.step3, gen.Get())
expectedMergedOutput = appendOptimized(expectedMergedOutput, impTest.out.step3)
break

case 3: // pod duration = pod min duration, no of ads = maxads
assert.Equal(t, impTest.out.step4, gen.Get())
expectedMergedOutput = appendOptimized(expectedMergedOutput, impTest.out.step4)
break

case 4: // pod duration = pod min duration, no of ads = minads
assert.Equal(t, impTest.out.step5, gen.Get())
expectedMergedOutput = appendOptimized(expectedMergedOutput, impTest.out.step5)
break

}

}
Expand Down
4 changes: 4 additions & 0 deletions endpoints/openrtb2/ctv/impressions/testdata/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ var Input = map[string][]int{
"TC52": {68, 72, 12, 18, 2, 4},
"TC53": {126, 126, 1, 20, 1, 7},
"TC55": {1, 74, 12, 12, 1, 6},
"TC56": {126, 126, 126, 126, 1, 1},
"TC57": {126, 126, 126, 126, 1, 3},
"TC58": {30, 90, 15, 45, 2, 4},
"TC59": {30, 90, 15, 45, 1, 1},
}
16 changes: 16 additions & 0 deletions endpoints/openrtb2/ctv/impressions/testdata/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,20 @@ var Scenario = map[string]eout{
MaximizeForDuration: [][2]int64{{12, 12}, {12, 12}, {12, 12}, {12, 12}, {12, 12}, {12, 12}},
MinMaxAlgorithm: [][2]int64{{12, 12}, {12, 12}, {12, 12}, {12, 12}, {12, 12}, {12, 12}},
},
"TC56": {
MaximizeForDuration: [][2]int64{{126, 126}},
MinMaxAlgorithm: [][2]int64{{126, 126}},
},
"TC57": {
MaximizeForDuration: [][2]int64{{126, 126}},
MinMaxAlgorithm: [][2]int64{{126, 126}},
},
"TC58": {
MaximizeForDuration: [][2]int64{{25, 25}, {25, 25}, {20, 20}, {20, 20}},
MinMaxAlgorithm: [][2]int64{{15, 15}, {15, 15}, {15, 20}, {15, 20}, {15, 25}, {15, 25}, {15, 45}, {15, 45}},
},
"TC59": {
MaximizeForDuration: [][2]int64{{45, 45}},
MinMaxAlgorithm: [][2]int64{{30, 30}, {30, 45}},
},
}
2 changes: 1 addition & 1 deletion openrtb_ext/adpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (ext *ExtVideoAdPod) Validate() (err []error) {
func (pod *VideoAdPod) SetDefaultValue() {
//pod.MinAds setting default value
if nil == pod.MinAds {
pod.MinAds = getIntPtr(2)
pod.MinAds = getIntPtr(1)
}

//pod.MaxAds setting default value
Expand Down

0 comments on commit c360511

Please sign in to comment.