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

QueenAttackCalculatorTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 final 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. @Ignore
  15. @Test
  16. public void testCoordinateWithNegativeRankNotAllowed() {
  17. expectedException.expect(IllegalArgumentException.class);
  18. expectedException.expectMessage("Coordinate must have positive rank.");
  19. new BoardCoordinate(-2, 2);
  20. }
  21. @Ignore
  22. @Test
  23. public void testCoordinateWithRankGreaterThan7NotAllowed() {
  24. expectedException.expect(IllegalArgumentException.class);
  25. expectedException.expectMessage("Coordinate must have rank <= 7.");
  26. new BoardCoordinate(8, 4);
  27. }
  28. @Ignore
  29. @Test
  30. public void testCoordinateWithNegativeFileNotAllowed() {
  31. expectedException.expect(IllegalArgumentException.class);
  32. expectedException.expectMessage("Coordinate must have positive file.");
  33. new BoardCoordinate(2, -2);
  34. }
  35. @Ignore
  36. @Test
  37. public void testCoordinateWithFileGreaterThan7NotAllowed() {
  38. expectedException.expect(IllegalArgumentException.class);
  39. expectedException.expectMessage("Coordinate must have file <= 7.");
  40. new BoardCoordinate(4, 8);
  41. }
  42. @Ignore
  43. @Test
  44. public void testNullCoordinateNotAllowed() {
  45. expectedException.expect(IllegalArgumentException.class);
  46. expectedException.expectMessage("You must supply valid board coordinates for both Queens.");
  47. new QueenAttackCalculator(null, new BoardCoordinate(0, 7));
  48. }
  49. @Ignore
  50. @Test
  51. public void testQueensMustNotOccupyTheSameSquare() {
  52. expectedException.expect(IllegalArgumentException.class);
  53. expectedException.expectMessage("Queens may not occupy the same board coordinate.");
  54. new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(2, 2));
  55. }
  56. @Ignore
  57. @Test
  58. public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
  59. final QueenAttackCalculator calculator
  60. = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
  61. assertFalse(calculator.canQueensAttackOneAnother());
  62. }
  63. @Ignore
  64. @Test
  65. public void testQueensCanAttackOnTheSameRank() {
  66. final QueenAttackCalculator calculator
  67. = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
  68. assertTrue(calculator.canQueensAttackOneAnother());
  69. }
  70. @Ignore
  71. @Test
  72. public void testQueensCanAttackOnTheSameFile() {
  73. final QueenAttackCalculator calculator
  74. = new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
  75. assertTrue(calculator.canQueensAttackOneAnother());
  76. }
  77. @Ignore
  78. @Test
  79. public void testQueensCanAttackOnFirstDiagonal() {
  80. final QueenAttackCalculator calculator
  81. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(0, 4));
  82. assertTrue(calculator.canQueensAttackOneAnother());
  83. }
  84. @Ignore
  85. @Test
  86. public void testQueensCanAttackOnSecondDiagonal() {
  87. final QueenAttackCalculator calculator
  88. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(3, 1));
  89. assertTrue(calculator.canQueensAttackOneAnother());
  90. }
  91. @Ignore
  92. @Test
  93. public void testQueensCanAttackOnThirdDiagonal() {
  94. final QueenAttackCalculator calculator
  95. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(1, 1));
  96. assertTrue(calculator.canQueensAttackOneAnother());
  97. }
  98. @Ignore
  99. @Test
  100. public void testQueensCanAttackOnFourthDiagonal() {
  101. final QueenAttackCalculator calculator
  102. = new QueenAttackCalculator(new BoardCoordinate(2, 2), new BoardCoordinate(5, 5));
  103. assertTrue(calculator.canQueensAttackOneAnother());
  104. }
  105. }