Exemplo n.º 1
0
        internal void GivenCalculationTypeIsSetToFlat_TheBreaksAvailabilityAreCalculatedProperlyForEachCompetitorBasedOnInputData()
        {
            var input  = GetSampleDataForEachCompetitorWhenCalculationTypeIsFlat();
            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Flat,
                                                                                SponsorshipApplicability.EachCompetitor);

            Assert.Equal(new ProductExternalReference[] { "P330", "P220", "A110", "A20" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(8, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(9, output.AvailabilitiesForCompetitors["P220"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["A110"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["A20"]);

            input.AddCompetitorToSpotByCount("C3", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Flat,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Equal(new ProductExternalReference[] { "P330", "P220", "A110", "A20" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(7, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(8, output.AvailabilitiesForCompetitors["P220"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["A110"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["A20"]);

            input.AddCompetitorToSpotByCount("C1", 2);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Flat,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Equal(new ProductExternalReference[] { "P330", "P220" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(5, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(6, output.AvailabilitiesForCompetitors["P220"]);
        }
Exemplo n.º 2
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToAllCompetitorsButTheAllowedNumberOfTheCompetitorsIsLeesThanOne_ThenNoCompetitorWillBeAllowed()
        {
            var input  = GetSampleDataForAllCompetitorsWithLessThanOneAvailibityForCompetitorsWhenCalculationTypeIsPercentage();
            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.AllCompetitors);

            Assert.Empty(output.AvailabilitiesForCompetitors);
        }
Exemplo n.º 3
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToEachCompetitor_TheBreaksAvailabilityForEachCompetitorsIsCalculatedProperlyComparingToSponsoredProduct()
        {
            var input = GetSampleDataForEachCompetitorWithLessThanOneAvailibityForCompetitorWhenCalculationTypeIsPercentage();

            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.EachCompetitor);

            Assert.Empty(output.AvailabilitiesForCompetitors);
        }
Exemplo n.º 4
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToAllCompetitorsAndThereIsNoSponsoredProduct_TheBreaksAvailabilityForEachCompetitorsIsSetToMaximumValuePossible()
        {
            var input  = GetSampleDataForAllCompetitorsWithNoSponsoredWhenCalculationTypeIsPercentage();
            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.AllCompetitors);

            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "C3", "C4", "C5", "C6", "C7", "P330", "P220", "A110", "A20" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C3"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C4"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C5"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C6"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C7"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P220"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A110"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A20"]);

            input.AddCompetitorToSpotByCount("C1", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.AllCompetitors);
            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "C3", "C4", "C5", "C6", "C7", "P330", "P220", "A110", "A20" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C3"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C4"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C5"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C6"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C7"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P220"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A110"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A20"]);

            input.AddCompetitorToSpotByCount("C3", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.AllCompetitors);
            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "C3", "C4", "C5", "C6", "C7", "P330", "P220", "A110", "A20" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C3"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C4"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C5"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C6"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["C7"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["P220"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A110"]);
            Assert.Equal(double.MaxValue, output.AvailabilitiesForCompetitors["A20"]);
        }
Exemplo n.º 5
0
        public void SetupTimelineRunningTotals(
            IImmutableList <Break> breaks)
        {
            foreach (var timeline in _timelines)
            {
                if (timeline.CalculationType == SponsorshipCalculationType.None ||
                    timeline.CalculationType == SponsorshipCalculationType.Exclusive)
                {
                    continue;
                }

                foreach (var advertiser in timeline.AdvertiserIdentifiers)
                {
                    timeline.RunningTotals
                    .SetRestrictionValueForAdvertiserIdentifier(
                        advertiser.advertiserIdentifier,
                        advertiser.restrictionValue);
                }

                foreach (var clash in timeline.ClashExternalReferences)
                {
                    timeline.RunningTotals
                    .SetRestrictionValueForClashCode(
                        clash.clashExternalReference,
                        clash.restrictionValue);
                }

                timeline.RestrictionLimits = SponsorshipLimitsCalculator.CalculateRestrictionLimits(
                    timeline.RunningTotals,
                    timeline.CalculationType,
                    timeline.Applicability);

                timeline.BreakExternalReferences =
                    breaks.Where(b =>
                                 timeline.DateTimeRange.Overlays(
                                     (
                                         b.ScheduledDate,
                                         b.ScheduledDate.Add(b.Duration.ToTimeSpan())
                                     )
                                     ))
                    .Select(b => b.ExternalBreakRef)
                    .ToList();
            }
        }
Exemplo n.º 6
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToEachCompetitorButTheAllowedNumberOfTheCompetitorIsLessThanOne_ThenTheCompetitorWillBeRemovedFromTheListOfCompetitorsWithAvailability()
        {
            var input = GetSampleDataForEachCompetitorWhenCalculationTypeIsPercentage();

            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.EachCompetitor);

            Assert.Equal(new ProductExternalReference[] { "P330", "P220" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(4, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(9, output.AvailabilitiesForCompetitors["P220"]);

            input.AddCompetitorToSpotByCount("C1", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Equal(new ProductExternalReference[] { "P330", "P220" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(3, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(9, output.AvailabilitiesForCompetitors["P220"]);

            input.AddCompetitorToSpotByCount("C2", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Equal(new ProductExternalReference[] { "P330", "P220" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(3, output.AvailabilitiesForCompetitors["P330"]);
            Assert.Equal(8, output.AvailabilitiesForCompetitors["P220"]);

            input.AddCompetitorToSpotByCount("C1", 3);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Equal(new ProductExternalReference[] { "P220" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(8, output.AvailabilitiesForCompetitors["P220"]);

            input.AddCompetitorToSpotByCount("C2", 8);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.EachCompetitor);
            Assert.Empty(output.AvailabilitiesForCompetitors);
        }
Exemplo n.º 7
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToEachCompetitor_TheBreaksAvailabilityForEachCompetitorsIsCalculatedByRoundingUpAnyValueToTheClosestRoundNumber()
        {
            var input = GetSampleDataForEachCompetitorWithCompetitorsAvalibityInDecimalWhenCalculationTypeIsPercentage();

            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.EachCompetitor);

            Assert.Equal(new ProductExternalReference[] { "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11", "P12", "P13", }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P2"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P3"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P4"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P5"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P6"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P7"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P8"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P9"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P10"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P11"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P12"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P13"]);
        }
Exemplo n.º 8
0
        internal void GivenCalculationTypeIsSetToPercentageWhenTheApplicabilityIsSetToAllCompetitors_TheBreaksAvailabilityForAllCompetitorsIsCalculatedProperlyComparingToSponsoredProduct()
        {
            var input = GetSampleDataForAllCompetitorsWhenCalculationTypeIsPercentage();

            var output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                                SponsorshipCalculationType.Percentage,
                                                                                SponsorshipApplicability.AllCompetitors);

            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "P330" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(3, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(3, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(3, output.AvailabilitiesForCompetitors["P330"]);

            input.AddCompetitorToSpotByCount("C1", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.AllCompetitors);
            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "P330" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(2, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(2, output.AvailabilitiesForCompetitors["P330"]);

            input.AddCompetitorToSpotByCount("C2", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.AllCompetitors);
            Assert.Equal(new ProductExternalReference[] { "C1", "C2", "P330" }, output.AvailabilitiesForCompetitors.Keys.ToArray());
            Assert.Equal(1, output.AvailabilitiesForCompetitors["C1"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["C2"]);
            Assert.Equal(1, output.AvailabilitiesForCompetitors["P330"]);

            input.AddCompetitorToSpotByCount("C1", 1);
            output = SponsorshipLimitsCalculator.CalculateRestrictionLimits(input,
                                                                            SponsorshipCalculationType.Percentage,
                                                                            SponsorshipApplicability.AllCompetitors);
            Assert.Empty(output.AvailabilitiesForCompetitors);
        }