using AfterHours.Economy; using NUnit.Framework; namespace AfterHours.Tests { public sealed class PricingServiceTests { [Test] public void AtOrBelowRecommendedPrice_EveryoneBuys() { Assert.AreEqual(1f, PricingService.PurchaseProbability(10f, 12f), 0.0001f); Assert.AreEqual(1f, PricingService.PurchaseProbability(12f, 12f), 0.0001f); } [Test] public void AtRejectionThreshold_NobodyBuys() { float price = 12f * PricingService.RejectionThreshold; Assert.AreEqual(0f, PricingService.PurchaseProbability(price, 12f), 0.0001f); } [Test] public void DemandFallsMonotonically() { float previous = 1f; for (float price = 12f; price < 21f; price += 0.5f) { float current = PricingService.PurchaseProbability(price, 12f); Assert.LessOrEqual(current, previous); previous = current; } } [Test] public void SmallMarkupHurtsLessThanLargeOne() { float small = 1f - PricingService.PurchaseProbability(13f, 12f); float large = 1f - PricingService.PurchaseProbability(19f, 12f); Assert.Less(small, large * 0.5f); } [Test] public void ExpectedProfitPeaksAboveWholesale() { float best = 0f, bestPrice = 0f; for (float price = 5f; price < 21f; price += 0.25f) { float profit = PricingService.ExpectedProfitPerUnit(price, 12f, 5f); if (profit > best) { best = profit; bestPrice = price; } } Assert.Greater(bestPrice, 5f); Assert.Greater(best, 0f); } } }