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

QueenAttackCalculatorTest.java 4.3KB

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