using SantaClausInc.Core; namespace SantaClausInc.Test; public sealed class SleighTests { [Fact] public void Construction() { const string City = "Salzburg"; var sleigh = new Sleigh(5, City); sleigh.TargetCity.Should().Be(City); } [Fact] public void Load_Single() { var sleigh = new Sleigh(5, "Graz"); sleigh.Load(CreateParcelPile(true)) .Should().BeTrue("enough capacity, can load this pile"); } [Fact] public void Load_Multiple() { var sleigh = new Sleigh(4, "Graz"); for (var i = 0; i < 4; i++) { sleigh.Load(CreateParcelPile(i % 2 == 0)) .Should().BeTrue("still enough capacity"); } sleigh.Load(CreateParcelPile(true)) .Should().BeFalse("capacity exceeded"); } [Fact] public void ExecuteTour() { var sleigh = new Sleigh(5, "Bregenz"); sleigh.Load(CreateParcelPile(true)); sleigh.Load(CreateParcelPile(false)); var tourPlan = sleigh.ExecuteTour(); tourPlan.Should().NotBeNull(); tourPlan.Count.Should().Be(10); for (var i = 0; i < tourPlan.Count; i++) { var (expected, reason) = i switch { 0 => ("#01: Travelling to city Bregenz", "first sleigh has to travel to destination city"), 1 => (" #02: Moving to house with ID 10", "unloading starts at back of the sleight, last in, first out"), 2 => (" #03: Putting into chimney: Doll for Martin (age 11)", "topmost parcel goes in first"), 3 => (" #04: Putting into chimney: Lego for Martin (age 11)", "then the next parcel - mind the indents"), 4 => (" #05: Moving to house with ID 5", "done with this house, moving to the next"), 5 => (" #06: Putting into chimney: Raspberry for Maria (age 16)", "starting to process last pile on sleigh"), 6 => (" #07: Putting into chimney: Doll for Maria (age 16)", "processing next parcel"), 7 => (" #08: Putting into chimney: Board Game for Maria (age 16)", "processing next parcel"), 8 => (" #09: Putting into chimney: Car for Maria (age 16)", "last parcel in pile and the last pile"), 9 => ("#10: Tour done, returning to Northpole HQ", "completed"), _ => (null, "shouldn't exist") }; tourPlan[i].Should().Be(expected, reason); } } private static Stack CreateParcelPile(bool setOne) { var children = SampleData.CreateSampleChildren(); var pile = new Stack(); var childId = setOne ? 4 : 9; var child = children[childId]; if (child is null) { Assert.Fail($"Child with id {childId} not found"); } if (setOne) { pile.Push(new Parcel(child, "Car")); pile.Push(new Parcel(child, "Board Game")); pile.Push(new Parcel(child, "Doll")); pile.Push(new Parcel(child, "Raspberry")); } else { pile.Push(new Parcel(child, "Lego")); pile.Push(new Parcel(child, "Doll")); } return pile; } }