本文整理汇总了C#中Solver.SolvePuzzle方法的典型用法代码示例。如果您正苦于以下问题:C# Solver.SolvePuzzle方法的具体用法?C# Solver.SolvePuzzle怎么用?C# Solver.SolvePuzzle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.SolvePuzzle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Board
public void SolvePuzzle_GivenAPieceFeederThatFeedsAWrongPermutationThenACorrectPermutation_SolvesThePuzzleOnTheSecondPermutation()
{
// Arrange
var board = new Board(TestBoardSize);
var solver = new Solver();
var mockPieceFeeder = new Mock<IPieceFeeder>();
mockPieceFeeder.SetupGet(x => x.Permutations).Returns(
new[]
{
new[]
{
new RotatedPiece(Piece.TestPieceA, Orientation.North),
new RotatedPiece(Piece.TestPieceB, Orientation.North),
new RotatedPiece(Piece.TestPieceC, Orientation.North),
new RotatedPiece(Piece.TestPieceD, Orientation.North)
},
new[]
{
new RotatedPiece(Piece.TestPieceA, Orientation.North),
new RotatedPiece(Piece.TestPieceC, Orientation.North),
new RotatedPiece(Piece.TestPieceD, Orientation.North),
new RotatedPiece(Piece.TestPieceB, Orientation.North)
}
});
mockPieceFeeder.SetupGet(x => x.Pieces).Returns(new[] {Piece.TestPieceA, Piece.TestPieceB, Piece.TestPieceC, Piece.TestPieceD});
// Act
var actual = solver.SolvePuzzle(board, mockPieceFeeder.Object);
// Assert
Assert.That(actual.Solved, Is.True);
Assert.That(actual.Iterations, Is.EqualTo(2));
Assert.That(board.IsSolved(), Is.True);
mockPieceFeeder.Verify(x => x.Permutations, Times.Once());
}
示例2: SolvePuzzle_GivenASinglePermutationOfPiecesNotInTheCorrectOrderAndOrientation_DoesNotSolveThePuzzle
public void SolvePuzzle_GivenASinglePermutationOfPiecesNotInTheCorrectOrderAndOrientation_DoesNotSolveThePuzzle()
{
// Arrange
var board = new Board(TestBoardSize);
var solver = new Solver();
var mockPieceFeeder = new Mock<IPieceFeeder>();
mockPieceFeeder.SetupGet(x => x.Permutations).Returns(
new[]
{
new[]
{
new RotatedPiece(Piece.TestPieceA, Orientation.North),
new RotatedPiece(Piece.TestPieceB, Orientation.North),
new RotatedPiece(Piece.TestPieceC, Orientation.North),
new RotatedPiece(Piece.TestPieceD, Orientation.North)
}
});
mockPieceFeeder.SetupGet(x => x.Pieces).Returns(new[] { Piece.TestPieceA, Piece.TestPieceB, Piece.TestPieceC, Piece.TestPieceD });
// Act
var actual = solver.SolvePuzzle(board, mockPieceFeeder.Object);
// Assert
Assert.That(actual.Solved, Is.False);
Assert.That(actual.Iterations, Is.EqualTo(1));
Assert.That(board.IsSolved(), Is.False);
}
示例3: SolvePuzzle_GivenInsaneData_ThrowsException
public void SolvePuzzle_GivenInsaneData_ThrowsException()
{
// Arrange
var board = new Board(TestBoardSize);
var solver = new Solver();
var pieceFeeder = new PieceFeeder(Piece.TestPieceA, Piece.TestPieceB, Piece.TestPieceC);
// Act, Assert
Assert.Throws<InvalidOperationException>(() => solver.SolvePuzzle(board, pieceFeeder));
}
示例4: SolvePuzzle_GivenAPieceFeederThatIncludesTheCorrectPermutation_ReturnsTheCorrectPermutation
public void SolvePuzzle_GivenAPieceFeederThatIncludesTheCorrectPermutation_ReturnsTheCorrectPermutation()
{
// Arrange
var board = new Board(TestBoardSize);
var solver = new Solver();
var mockPieceFeeder = new Mock<IPieceFeeder>();
mockPieceFeeder.SetupGet(x => x.Permutations).Returns(
new[]
{
new[]
{
new RotatedPiece(Piece.TestPieceA, Orientation.North),
new RotatedPiece(Piece.TestPieceB, Orientation.North),
new RotatedPiece(Piece.TestPieceC, Orientation.North),
new RotatedPiece(Piece.TestPieceD, Orientation.North)
},
new[]
{
new RotatedPiece(Piece.TestPieceA, Orientation.North),
new RotatedPiece(Piece.TestPieceC, Orientation.North),
new RotatedPiece(Piece.TestPieceD, Orientation.North),
new RotatedPiece(Piece.TestPieceB, Orientation.North)
}
});
mockPieceFeeder.SetupGet(x => x.Pieces).Returns(new[] { Piece.TestPieceA, Piece.TestPieceB, Piece.TestPieceC, Piece.TestPieceD });
// Act
var actual = solver.SolvePuzzle(board, mockPieceFeeder.Object);
var solution = actual.Solution.ToArray();
// Assert
Assert.That(solution[0].Piece, Is.SameAs(Piece.TestPieceA));
Assert.That(solution[0].Orientation, Is.EqualTo(Orientation.North));
Assert.That(solution[1].Piece, Is.SameAs(Piece.TestPieceC));
Assert.That(solution[1].Orientation, Is.EqualTo(Orientation.North));
Assert.That(solution[2].Piece, Is.SameAs(Piece.TestPieceD));
Assert.That(solution[2].Orientation, Is.EqualTo(Orientation.North));
Assert.That(solution[3].Piece, Is.SameAs(Piece.TestPieceB));
Assert.That(solution[3].Orientation, Is.EqualTo(Orientation.North));
}