Esempio n. 1
0
        public void Expand_Two_Markdowns_On_Second_And_Fourth_Week_With_Null_First()
        {
            var schedule    = SmDenseSchedule.FromInteger(Convert.ToInt32("1010", 2), 10, 4);
            var priceLadder = new SmPriceLadder
            {
                Values = new [] { 0.1M, 0.5M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };

            var expected = new[]
            {
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new [] { (decimal?)null, 0.1M, 0.1M, 0.5M }, Weeks = new [] { 10, 11, 12, 13 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new [] { (decimal?)null, 0.5M, 0.5M, 0.9M }, Weeks = new [] { 10, 11, 12, 13 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new [] { (decimal?)null, 0.1M, 0.1M, 0.9M }, Weeks = new [] { 10, 11, 12, 13 }
                }
            };

            var result = schedule.Expand(priceLadder);

            result.ShouldAllBeEquivalentTo(expected);
        }
Esempio n. 2
0
        public void Optimise_Constraints_Are_Always_Markdowns()
        {
            char[,] expected =
            {
                { '_', '_', '_', '_' },
                { '_', '_', '_', '_' },
                { 'x', '_', '_', '_' },
                { 'x', 'x', '_', '_' },
                { 'x', 'x', 'x', '_' },
                { '_', 'x', 'x', 'x' },
                { '_', 'x', 'x', 'x' },
                { '_', '_', '_', 'x' },
                { '_', '_', '_', 'x' }
            };

            var priceLadder = new SmPriceLadder
            {
                Values = new[] { 0.1M, 0.2M, 0.3M, 0.4M, 0.5M, 0.6M, 0.7M, 0.8M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };

            var schedule = SmDenseSchedule.FromInteger(170, 1, 8);

            schedule.Constraints = new[]
            {
                SmWeekConstraint.Range(2, 0.3M, 0.5M),
                SmWeekConstraint.Range(6, 0.5M, 0.7M)
            };

            var result = SmDenseSchedule.Optimise(schedule, priceLadder);

            Simplify(priceLadder, schedule, result)
            .Should()
            .Equal(expected, (left, right) => left == right);
        }
Esempio n. 3
0
        public void Expand_Two_Markdowns_Two_Weeks()
        {
            var schedule    = SmDenseSchedule.FromInteger(Convert.ToInt32("11", 2), 10, 2);
            var priceLadder = new SmPriceLadder
            {
                Values = new [] { 0.1M, 0.5M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };

            var expected = new[]
            {
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new decimal?[] { 0.1M, 0.5M }, Weeks = new [] { 10, 11 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new decimal?[] { 0.5M, 0.9M }, Weeks = new [] { 10, 11 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 2, Prices = new decimal?[] { 0.1M, 0.9M }, Weeks = new [] { 10, 11 }
                }
            };

            var result = schedule.Expand(priceLadder);

            result.ShouldAllBeEquivalentTo(expected);
        }
Esempio n. 4
0
        public void Expand_One_Markdown_One_Week()
        {
            var schedule    = SmDenseSchedule.FromInteger(1, 10, 1);
            var priceLadder = new SmPriceLadder
            {
                Values = new [] { 0.1M, 0.5M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };

            var expected = new[]
            {
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 1, Prices = new decimal?[] { 0.1M }, Weeks = new [] { 10 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 1, Prices = new decimal?[] { 0.5M }, Weeks = new [] { 10 }
                },
                new SmSchedulePricePath {
                    LadderType = SmPriceLadderType.Percent, MarkdownCount = 1, Prices = new decimal?[] { 0.9M }, Weeks = new [] { 10 }
                }
            };

            var result = schedule.Expand(priceLadder);

            result.ShouldAllBeEquivalentTo(expected);
        }
Esempio n. 5
0
        public void Optimise_Identifies_All_Potential_Week_Price_Values()
        {
            char[,] expected =
            {
                { 'x', '_', '_', '_' },
                { 'x', 'x', '_', '_' },
                { 'x', 'x', 'x', '_' },
                { 'x', 'x', 'x', 'x' },
                { 'x', 'x', 'x', 'x' },
                { 'x', 'x', 'x', 'x' },
                { '_', 'x', 'x', 'x' },
                { '_', '_', 'x', 'x' },
                { '_', '_', '_', 'x' }
            };

            var priceLadder = new SmPriceLadder
            {
                Values = new [] { 0.1M, 0.2M, 0.3M, 0.4M, 0.5M, 0.6M, 0.7M, 0.8M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };
            var schedule = SmDenseSchedule.FromInteger(170, 1, 8);
            var result   = SmDenseSchedule.Optimise(schedule, priceLadder);

            Simplify(priceLadder, schedule, result)
            .Should()
            .Equal(expected, (left, right) => left == right);
        }
Esempio n. 6
0
 public static SmProductPriceLadder Build(SmPriceLadder ladder)
 {
     return(new SmProductPriceLadder
     {
         PriceLadderId = ladder.PriceLadderId,
         Values = ladder.Values,
         Type = ladder.Type
     });
 }
Esempio n. 7
0
 public static VmPriceLadder Build(SmPriceLadder model)
 {
     return(new VmPriceLadder
     {
         PriceLadderId = model.PriceLadderId,
         Description = model.Description,
         PriceLadderTypeId = (int)model.Type,
         Values = model.Values.ToList()
     });
 }
Esempio n. 8
0
        private static char[,] Simplify(SmPriceLadder priceLadder, SmDenseSchedule schedule, ICollection <Tuple <int, decimal> > test)
        {
            var result = new char[priceLadder.Values.Length, schedule.MarkdownWeeks.Length];

            for (var y = 0; y < priceLadder.Values.Length; y++)
            {
                for (var x = 0; x < schedule.MarkdownWeeks.Length; x++)
                {
                    result[y, x] = test.Contains(Tuple.Create(schedule.MarkdownWeeks[x], priceLadder.Values[y]))
                        ? 'x'
                        : '_';
                }
            }
            return(result);
        }
Esempio n. 9
0
        public void No_Markdowns()
        {
            var schedule    = SmDenseSchedule.NoMarkdowns(10, 13);
            var priceLadder = new SmPriceLadder
            {
                Values = new [] { 0.1M, 0.5M, 0.9M },
                Type   = SmPriceLadderType.Percent
            };

            var expected = new []
            {
                new SmSchedulePricePath
                {
                    LadderType    = SmPriceLadderType.Percent,
                    MarkdownCount = 0,
                    Prices        = new decimal?[] { null, null, null, null },
                    Weeks         = new[] { 10, 11, 12, 13 }
                }
            };

            var result = schedule.Expand(priceLadder);

            result.ShouldBeEquivalentTo(expected);
        }
Esempio n. 10
0
        public async Task <SmPriceLadder> GetById(int priceLadderId)
        {
            var entity = await _priceLadderRepository.GetById(priceLadderId);

            return(SmPriceLadder.Build(entity));
        }