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); }
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); }
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); }
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); }
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); }
public static SmProductPriceLadder Build(SmPriceLadder ladder) { return(new SmProductPriceLadder { PriceLadderId = ladder.PriceLadderId, Values = ladder.Values, Type = ladder.Type }); }
public static VmPriceLadder Build(SmPriceLadder model) { return(new VmPriceLadder { PriceLadderId = model.PriceLadderId, Description = model.Description, PriceLadderTypeId = (int)model.Type, Values = model.Values.ToList() }); }
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); }
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); }
public async Task <SmPriceLadder> GetById(int priceLadderId) { var entity = await _priceLadderRepository.GetById(priceLadderId); return(SmPriceLadder.Build(entity)); }