From 82f5e90aa133b72715945a8b4f4bbb6eaa1b58ff Mon Sep 17 00:00:00 2001 From: Pubmatic-Dhruv-Sonone <83747371+Pubmatic-Dhruv-Sonone@users.noreply.github.com> Date: Tue, 11 May 2021 18:53:14 +0530 Subject: [PATCH] OTT-172: Set default min ads to 1 from 2 (#153) * OTT-172: Set default min ads to 1 from 2 * Adding test cases for impression generation algorithm --- .../ctv/impressions/impression_generator.go | 2 +- .../impressions/maximize_for_duration_test.go | 25 ++++++++++++ .../ctv/impressions/min_max_algorithm_test.go | 40 +++++++++++++++---- .../ctv/impressions/testdata/input.go | 4 ++ .../ctv/impressions/testdata/output.go | 16 ++++++++ openrtb_ext/adpod.go | 2 +- 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/endpoints/openrtb2/ctv/impressions/impression_generator.go b/endpoints/openrtb2/ctv/impressions/impression_generator.go index eb195b39f56..5ad0ff404ea 100644 --- a/endpoints/openrtb2/ctv/impressions/impression_generator.go +++ b/endpoints/openrtb2/ctv/impressions/impression_generator.go @@ -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 } diff --git a/endpoints/openrtb2/ctv/impressions/maximize_for_duration_test.go b/endpoints/openrtb2/ctv/impressions/maximize_for_duration_test.go index 84f3304fb6d..6b7785638ee 100644 --- a/endpoints/openrtb2/ctv/impressions/maximize_for_duration_test.go +++ b/endpoints/openrtb2/ctv/impressions/maximize_for_duration_test.go @@ -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, }}, } diff --git a/endpoints/openrtb2/ctv/impressions/min_max_algorithm_test.go b/endpoints/openrtb2/ctv/impressions/min_max_algorithm_test.go index 5928b430924..01a062fab49 100644 --- a/endpoints/openrtb2/ctv/impressions/min_max_algorithm_test.go +++ b/endpoints/openrtb2/ctv/impressions/min_max_algorithm_test.go @@ -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{}, @@ -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) { @@ -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 + } } diff --git a/endpoints/openrtb2/ctv/impressions/testdata/input.go b/endpoints/openrtb2/ctv/impressions/testdata/input.go index 8c7ae520f8c..3ee64544b95 100644 --- a/endpoints/openrtb2/ctv/impressions/testdata/input.go +++ b/endpoints/openrtb2/ctv/impressions/testdata/input.go @@ -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}, } diff --git a/endpoints/openrtb2/ctv/impressions/testdata/output.go b/endpoints/openrtb2/ctv/impressions/testdata/output.go index 7b97c56f2bc..d7e854fc575 100644 --- a/endpoints/openrtb2/ctv/impressions/testdata/output.go +++ b/endpoints/openrtb2/ctv/impressions/testdata/output.go @@ -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}}, + }, } diff --git a/openrtb_ext/adpod.go b/openrtb_ext/adpod.go index 03b973b6b5f..ac815cda224 100644 --- a/openrtb_ext/adpod.go +++ b/openrtb_ext/adpod.go @@ -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