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

TriangleTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import org.junit.Test;
  2. import org.junit.Ignore;
  3. import org.junit.Rule;
  4. import org.junit.rules.ExpectedException;
  5. import static org.junit.Assert.assertEquals;
  6. public class TriangleTest {
  7. @Rule
  8. public final ExpectedException thrown = ExpectedException.none();
  9. @Test
  10. public void equilateralTriangleHaveEqualSides() throws TriangleException {
  11. Triangle triangle = new Triangle(2, 2, 2);
  12. assertEquals(TriangleKind.EQUILATERAL, triangle.getKind());
  13. }
  14. @Ignore
  15. @Test
  16. public void largerEquilateralTrianglesAlsoHaveEqualSides() throws TriangleException {
  17. Triangle triangle = new Triangle(10, 10, 10);
  18. assertEquals(TriangleKind.EQUILATERAL, triangle.getKind());
  19. }
  20. @Ignore
  21. @Test
  22. public void isoscelesTrianglesHaveLastTwoSidesEqual() throws TriangleException {
  23. Triangle triangle = new Triangle(3, 4, 4);
  24. assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
  25. }
  26. @Ignore
  27. @Test
  28. public void isoscelesTrianglesHaveFirstAndLastSidesEqual() throws TriangleException {
  29. Triangle triangle = new Triangle(4, 3, 4);
  30. assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
  31. }
  32. @Ignore
  33. @Test
  34. public void isoscelesTrianglesHaveTwoFirstSidesEqual() throws TriangleException {
  35. Triangle triangle = new Triangle(4, 4, 3);
  36. assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
  37. }
  38. @Ignore
  39. @Test
  40. public void isoscelesTrianglesHaveInFactExactlyTwoSidesEqual() throws TriangleException {
  41. Triangle triangle = new Triangle(10, 10, 2);
  42. assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
  43. }
  44. @Ignore
  45. @Test
  46. public void scaleneTrianglesHaveNoEqualSides() throws TriangleException {
  47. Triangle triangle = new Triangle(3, 4, 5);
  48. assertEquals(TriangleKind.SCALENE, triangle.getKind());
  49. }
  50. @Ignore
  51. @Test
  52. public void scaleneTrianglesHaveNoEqualSidesAtLargerScaleEither() throws TriangleException {
  53. Triangle triangle = new Triangle(10, 11, 12);
  54. assertEquals(TriangleKind.SCALENE, triangle.getKind());
  55. }
  56. @Ignore
  57. @Test
  58. public void scaleneTrianglesHaveNoEqualSidesInDescendingOrderEither() throws TriangleException {
  59. Triangle triangle = new Triangle(5, 4, 2);
  60. assertEquals(TriangleKind.SCALENE, triangle.getKind());
  61. }
  62. @Ignore
  63. @Test
  64. public void verySmallTrianglesAreLegal() throws TriangleException {
  65. Triangle triangle = new Triangle(0.4, 0.6, 0.3);
  66. assertEquals(TriangleKind.SCALENE, triangle.getKind());
  67. }
  68. @Ignore
  69. @Test
  70. public void trianglesWithNoSizeAreIllegal() throws TriangleException {
  71. thrown.expect(TriangleException.class);
  72. new Triangle(0, 0, 0);
  73. }
  74. @Ignore
  75. @Test
  76. public void trianglesWithNegativeSidesAreIllegal() throws TriangleException {
  77. thrown.expect(TriangleException.class);
  78. new Triangle(3, 4, -5);
  79. }
  80. @Ignore
  81. @Test
  82. public void trianglesViolatingTriangleInequalityAreIllegal() throws TriangleException {
  83. thrown.expect(TriangleException.class);
  84. new Triangle(1, 1, 3);
  85. }
  86. @Ignore
  87. @Test
  88. public void trianglesViolatingTriangleInequalityAreIllegal2() throws TriangleException {
  89. thrown.expect(TriangleException.class);
  90. new Triangle(2, 4, 2);
  91. }
  92. @Ignore
  93. @Test
  94. public void trianglesViolatingTriangleInequalityAreIllegal3() throws TriangleException {
  95. thrown.expect(TriangleException.class);
  96. new Triangle(7, 3, 2);
  97. }
  98. }