public void ThrowException_WhenCannotWalkToTarget(int startingPoint, int target) { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); var exception = Assert.Throws <ArgumentException>(() => sut.MoveAmphipodFrom(startingPoint).To(target).OrFail()); Assert.Equal("Could not complete path", exception.Message); }
public void ReturnTrue_WhenAskedToMoveToSamePlaceAsOrigin() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); var stayInSamePlace = sut.MoveAmphipodFrom(5).To(5).AndStopOnFail(); Assert.True(stayInSamePlace); }
public void ThrowException_WhenThereIsNoAmphipodAtStartingPoint() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); var exception = Assert.Throws <ArgumentException>(() => sut.MoveAmphipodFrom(0).To(1).OrFail()); Assert.Equal("No amphipod there", exception.Message); }
public void Walk22StepsInSolution() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.MoveAmphipodFrom(23).To(26).OrFail(); sut.MoveAmphipodFrom(22).To(0).OrFail(); sut.MoveAmphipodFrom(17).To(25).OrFail(); sut.MoveAmphipodFrom(16).To(19).OrFail(); sut.MoveAmphipodFrom(15).To(1).OrFail(); sut.MoveAmphipodFrom(11).To(15).OrFail(); sut.MoveAmphipodFrom(10).To(16).OrFail(); sut.MoveAmphipodFrom(9).To(13).OrFail(); sut.MoveAmphipodFrom(8).To(7).OrFail(); sut.MoveAmphipodFrom(13).To(8).OrFail(); sut.MoveAmphipodFrom(19).To(9).OrFail(); sut.MoveAmphipodFrom(25).To(10).OrFail(); sut.MoveAmphipodFrom(21).To(17).OrFail(); sut.MoveAmphipodFrom(20).To(25).OrFail(); sut.MoveAmphipodFrom(7).To(20).OrFail(); sut.MoveAmphipodFrom(5).To(11).OrFail(); sut.MoveAmphipodFrom(4).To(21).OrFail(); sut.MoveAmphipodFrom(3).To(7).OrFail(); sut.MoveAmphipodFrom(1).To(3).OrFail(); sut.MoveAmphipodFrom(0).To(4).OrFail(); sut.MoveAmphipodFrom(7).To(22).OrFail(); sut.MoveAmphipodFrom(25).To(5).OrFail(); Assert.Equal(@"############# #..........D# ###A#B#C#.### #A#B#C#D# #A#B#C#D# #A#B#C#D# #########", sut.ToString()); }
public void NeverReachFinalPosition_WhenInitialAmphipodListIsInvalid() { var flag = false; var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.OnFinalPositionReached((_, __) => flag = true); sut.WalkWith(new [] { 0, 1 }, new System.Collections.Generic.List <(int From, int To)>()); Assert.False(flag); }
public void StayInLastPosition_WhenCannotWalkToTarget() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.MoveAmphipodFrom(5).To(11).AndStopOnFail(); Assert.Equal(@"############# #...B.......# ###.#C#B#D### #D#C#B#A# #D#B#A#C# #A#D#C#A# #########", sut.ToString()); }
public void ReturnToStartingPoint_WhenCannotWalkToTarget(int startingPoint, int target) { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.MoveAmphipodFrom(startingPoint).To(target).OrReturnBack(); Assert.Equal(@"############# #...........# ###B#C#B#D### #D#C#B#A# #D#B#A#C# #A#D#C#A# #########", sut.ToString()); }
public void WalkStep1InSolution() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.MoveAmphipodFrom(23).To(26).OrFail(); Assert.Equal(@"############# #..........D# ###B#C#B#.### #D#C#B#A# #D#B#A#C# #A#D#C#A# #########", sut.ToString()); }
public void Walk4StepsInSolution() { var sut = new AmphipodSorter2(SAMPLE_LONG_MAP); sut.MoveAmphipodFrom(23).To(26).OrFail(); sut.MoveAmphipodFrom(22).To(0).OrFail(); sut.MoveAmphipodFrom(17).To(25).OrFail(); sut.MoveAmphipodFrom(16).To(19).OrFail(); Assert.Equal(@"############# #A......B.BD# ###B#C#.#.### #D#C#.#.# #D#B#A#C# #A#D#C#A# #########", sut.ToString()); }
public void LoadLongMapCorrectly(string map) { var sut = new AmphipodSorter2(map); Assert.Equal(map, sut.ToString()); }