public Pouring Perform(Pouring pouring) { if (!CanPerform(pouring)) { throw new InvalidOperationException(); } var stateCopy = pouring.State.ToArray(); stateCopy[index] = 0; return new Pouring(pouring.Capacities, stateCopy, pouring, this); }
public Pouring Perform(Pouring pouring) { if(!CanPerform(pouring)) { throw new InvalidOperationException(); } var pourAmount = Math.Min(pouring.State[@from], pouring.Capacities[to] - pouring.State[to]); var stateCopy = pouring.State.ToArray(); stateCopy[@from] = stateCopy[@from] - pourAmount; stateCopy[to] = stateCopy[to] + pourAmount; return new Pouring(pouring.Capacities, stateCopy, pouring, this); }
public void Test_can_empty_and_can_pour() { var capacities = new[] {5, 3}; var generator = new PouringGenerator(capacities.Length); var pouring = new Pouring(capacities, new[] {0, 2}, null, null); var generation = generator.GetNextGeneration(pouring).ToArray(); var expectedGeneration = new[] { new Pouring(capacities, new[] {0, 0}, pouring, new Empty(1)), new Pouring(capacities, new[] {capacities[0], 2}, pouring, new Fill(0)), new Pouring(capacities, new[] {0, capacities[1]}, pouring, new Fill(1)), new Pouring(capacities, new[] {2, 0}, pouring, new Pour(1, 0)), }; CollectionAssert.AreEquivalent(expectedGeneration, generation); }
public void MoveWasMade(Pouring pouring) { VialSetHistory.RegisterMove(pouring); RefreshControls(); }
public bool CanPerform(Pouring pouring) { return pouring.State[@from] > 0 && pouring.State[to] < pouring.Capacities[to]; }
public bool CanPerform(Pouring pouring) { return pouring.State[index] > 0; }
public void Test_only_one_capacity_set() { var value = 4; var capacities = new[] { 5 }; var pouringGeneratorFactory = MockRepository.GenerateStrictMock<IPouringGeneratorFactory>(); var pouringGenerator = MockRepository.GenerateStrictMock<IPouringGenerator>(); var solver = new Solver( pouringGeneratorFactory ); pouringGeneratorFactory .Expect(f => f.Create(capacities.Length)) .Return(pouringGenerator); var solutionPouring = new Pouring(capacities, new[] { value }, null, null); pouringGenerator .Stub(g => g.GetNextGeneration(null)) .IgnoreArguments() .Return(new[] { solutionPouring, }); var solutions = solver .SolutionSequence(value, capacities) .ToArray(); Assert.AreEqual(1, solutions.Length); Assert.AreEqual(solutionPouring, solutions[0].States().Last()); }
public bool CanPerform(Pouring pouring) { return true; }