lots of exercises in java... from https://github.com/exercism/java

QueenAttackCalculatorTest.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import org.junit.Ignore;
  2. import org.junit.Rule;
  3. import org.junit.Test;
  4. import org.junit.rules.ExpectedException;
  5. import static org.junit.Assert.assertFalse;
  6. import static org.junit.Assert.assertTrue;
  7. public class QueenAttackCalculatorTest {
  8. /*
  9. * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
  10. * ExpectedExceptions in particular.
  11. */
  12. @Rule
  13. public ExpectedException expectedException = ExpectedException.none();
  14. @Test
  15. public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
  16. final QueenAttackCalculator calculator
  17. = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
  18. assertFalse(calculator.canQueensAttackOneAnother());
  19. }
  20. @Ignore("Remove to run test")
  21. @Test
  22. public void testQueensCanAttackOnTheSameRank() {
  23. final QueenAttackCalculator calculator
  24. = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
  25. assertTrue(calculator.canQueensAttackOneAnother());
  26. }
  27. @Ignore("Remove to run test")
  28. @Test
  29. public void testQueensCanAttackOnTheSameFile() {
  30. final QueenAttackCalculator calculator
  31. = new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
  32. assertTrue(calculator.canQueensAttackOneAnother());
  33. }
  34. @Ignore("Remove to run test")
  35. @Test
  36. public void testQueensCanAttackOnFirstDiagonal() {
  37. final QueenAttackCalculator calculator
  38. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(0, 4));
  39. assertTrue(calculator.canQueensAttackOneAnother());
  40. }
  41. @Ignore("Remove to run test")
  42. @Test
  43. public void testQueensCanAttackOnSecondDiagonal() {
  44. final QueenAttackCalculator calculator
  45. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(3, 1));
  46. assertTrue(calculator.canQueensAttackOneAnother());
  47. }
  48. @Ignore("Remove to run test")
  49. @Test
  50. public void testQueensCanAttackOnThirdDiagonal() {
  51. final QueenAttackCalculator calculator
  52. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(1, 1));
  53. assertTrue(calculator.canQueensAttackOneAnother());
  54. }
  55. @Ignore("Remove to run test")
  56. @Test
  57. public void testQueensCanAttackOnFourthDiagonal() {
  58. final QueenAttackCalculator calculator
  59. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(5, 5));
  60. assertTrue(calculator.canQueensAttackOneAnother());
  61. }
  62. @Ignore("Remove to run test")
  63. @Test
  64. public void testCoordinateWithNegativeRankNotAllowed() {
  65. expectedException.expect(IllegalArgumentException.class);
  66. expectedException.expectMessage("Coordinate must have positive rank.");
  67. new BoardCoordinate(-2, 2);
  68. }
  69. @Ignore("Remove to run test")
  70. @Test
  71. public void testCoordinateWithRankGreaterThan7NotAllowed() {
  72. expectedException.expect(IllegalArgumentException.class);
  73. expectedException.expectMessage("Coordinate must have rank <= 7.");
  74. new BoardCoordinate(8, 4);
  75. }
  76. @Ignore("Remove to run test")
  77. @Test
  78. public void testCoordinateWithNegativeFileNotAllowed() {
  79. expectedException.expect(IllegalArgumentException.class);
  80. expectedException.expectMessage("Coordinate must have positive file.");
  81. new BoardCoordinate(2, -2);
  82. }
  83. @Ignore("Remove to run test")
  84. @Test
  85. public void testCoordinateWithFileGreaterThan7NotAllowed() {
  86. expectedException.expect(IllegalArgumentException.class);
  87. expectedException.expectMessage("Coordinate must have file <= 7.");
  88. new BoardCoordinate(4, 8);
  89. }
  90. @Ignore("Remove to run test")
  91. @Test
  92. public void testNullCoordinateNotAllowed() {
  93. expectedException.expect(IllegalArgumentException.class);
  94. expectedException.expectMessage("You must supply valid board coordinates for both Queens.");
  95. new QueenAttackCalculator(null, new BoardCoordinate(0, 7));
  96. }
  97. @Ignore("Remove to run test")
  98. @Test
  99. public void testQueensMustNotOccupyTheSameSquare() {
  100. expectedException.expect(IllegalArgumentException.class);
  101. expectedException.expectMessage("Queens may not occupy the same board coordinate.");
  102. new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(2, 2));
  103. }
  104. }