You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.0 KiB

  1. package LernProgramm;
  2. import static org.junit.jupiter.api.Assertions.*;
  3. import java.io.ByteArrayInputStream;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.PrintStream;
  6. import org.junit.jupiter.api.Test;
  7. class testProgramm {
  8. @Test
  9. void test() {
  10. assertTrue(true);
  11. }
  12. @Test
  13. public void testPrimBis100() {
  14. ByteArrayOutputStream out = new ByteArrayOutputStream();
  15. System.setOut(new PrintStream(out));
  16. ProgrammMain.PrimBis100();
  17. assertEquals("2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 ", out.toString());
  18. }
  19. @Test
  20. public void testAddition() {
  21. int result = ProgrammMain.calculate("1010", "1011", '+');
  22. assertEquals(10101, result);
  23. }
  24. @Test
  25. public void testSubtraction() {
  26. int result = ProgrammMain.calculate("1010", "1011", '-');
  27. result++;
  28. if (result <0 || result >0) {
  29. assertTrue(true);
  30. }
  31. }
  32. @Test
  33. public void testMultiplication() {
  34. int result = ProgrammMain.calculate("1010", "1011", '*');
  35. result++;
  36. if (result <0 || result >0) {
  37. assertTrue(true);
  38. }
  39. }
  40. @Test
  41. public void testDivision() {
  42. int result = ProgrammMain.calculate("1010", "1011", '/');
  43. assertEquals(0, result);
  44. }
  45. @Test
  46. public void testInvalidOperation() {
  47. int result = ProgrammMain.calculate("1010", "1011", '%');
  48. assertEquals(0, result);
  49. }
  50. @Test
  51. public void testAddition1() {
  52. double result = 2 + 3.5;
  53. assertEquals(5.5, result, 0);
  54. }
  55. @Test
  56. public void testSubtraction1() {
  57. double result = 5-3.5;
  58. assertEquals(1.5, result, 0);
  59. }
  60. @Test
  61. public void testMultiplication1() {
  62. double result = 5*3.5;
  63. assertEquals(17.5, result, 0);
  64. }
  65. @Test
  66. public void testDivision1() {
  67. double result = 15/10;
  68. assertEquals(1, result, 0);
  69. }
  70. @Test
  71. public void testFakultaetWithPositiveNumber() {
  72. String input = "5\n";
  73. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  74. System.setIn(in);
  75. ByteArrayOutputStream out = new ByteArrayOutputStream();
  76. System.setOut(new PrintStream(out));
  77. FunktionenAusgelagert.Fakultaet();
  78. assertEquals("120\n", out.toString());
  79. }
  80. @Test
  81. public void testFakultaetWithZero() {
  82. String input = "0\n";
  83. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  84. System.setIn(in);
  85. ByteArrayOutputStream out = new ByteArrayOutputStream();
  86. System.setOut(new PrintStream(out));
  87. FunktionenAusgelagert.Fakultaet();
  88. assertTrue(true);
  89. }
  90. @Test
  91. public void testSchaltjahr() {
  92. ByteArrayInputStream in = new ByteArrayInputStream("2000\n".getBytes());
  93. ByteArrayOutputStream out = new ByteArrayOutputStream();
  94. System.setIn(in);
  95. System.setOut(new PrintStream(out));
  96. FunktionenAusgelagert.schaltjahr();
  97. assertEquals("Welches Jahr möchtest du untersuchen?\nSchaltjahr!\n", out.toString());
  98. }
  99. }