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.

157 lines
3.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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. // Hier werden die Tests gemacht
  9. // der erste prüft eingach nur, ob tests im allgemeinen möglich sind!
  10. // Die annderen testen die Funktionenn in der ausgelagerten Klasse zur besseren
  11. // Übersicht
  12. // Testest
  13. @Test
  14. void test() {
  15. assertTrue(true);
  16. }
  17. // PrimZahlen
  18. @Test
  19. public void testPrimBis100() {
  20. ByteArrayOutputStream out = new ByteArrayOutputStream();
  21. System.setOut(new PrintStream(out));
  22. FunktionenAusgelagert.PrimBis100();
  23. 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());
  24. }
  25. // Binärrechner
  26. @Test
  27. public void testAddition() {
  28. int result = FunktionenAusgelagert.calculate("1010", "1011", '+');
  29. assertEquals(10101, result);
  30. }
  31. @Test
  32. public void testSubtraction() {
  33. int result = FunktionenAusgelagert.calculate("1010", "1011", '-');
  34. result++;
  35. if (result < 0 || result > 0) {
  36. assertTrue(true);
  37. }
  38. }
  39. @Test
  40. public void testMultiplication() {
  41. int result = FunktionenAusgelagert.calculate("1010", "1011", '*');
  42. result++;
  43. if (result < 0 || result > 0) {
  44. assertTrue(true);
  45. }
  46. }
  47. @Test
  48. public void testDivision() {
  49. int result = FunktionenAusgelagert.calculate("1010", "1011", '/');
  50. assertEquals(0, result);
  51. }
  52. @Test
  53. public void testInvalidOperation() {
  54. int result = FunktionenAusgelagert.calculate("1010", "1011", '%');
  55. assertEquals(0, result);
  56. }
  57. // Taschenrechner
  58. @Test
  59. public void testAddition1() {
  60. double result = 2 + 3.5;
  61. assertEquals(5.5, result, 0);
  62. }
  63. @Test
  64. public void testSubtraction1() {
  65. double result = 5 - 3.5;
  66. assertEquals(1.5, result, 0);
  67. }
  68. @Test
  69. public void testMultiplication1() {
  70. double result = 5 * 3.5;
  71. assertEquals(17.5, result, 0);
  72. }
  73. @Test
  74. public void testDivision1() {
  75. double result = 15 / 10;
  76. assertEquals(1, result, 0);
  77. }
  78. // Fakultaet
  79. @Test
  80. public void testFakultaetmitPositerZahl() {
  81. String input = "5\n";
  82. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  83. System.setIn(in);
  84. ByteArrayOutputStream out = new ByteArrayOutputStream();
  85. System.setOut(new PrintStream(out));
  86. FunktionenAusgelagert.Fakultaet();
  87. assertEquals("120\n", out.toString());
  88. }
  89. @Test
  90. public void testFakultaetMItNull() {
  91. String input = "0\n";
  92. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  93. System.setIn(in);
  94. ByteArrayOutputStream out = new ByteArrayOutputStream();
  95. System.setOut(new PrintStream(out));
  96. FunktionenAusgelagert.Fakultaet();
  97. assertTrue(true);
  98. }
  99. // Schaltjahr
  100. @Test
  101. public void testSchaltjahr() {
  102. ByteArrayInputStream in = new ByteArrayInputStream("2000\n".getBytes());
  103. ByteArrayOutputStream out = new ByteArrayOutputStream();
  104. System.setIn(in);
  105. System.setOut(new PrintStream(out));
  106. FunktionenAusgelagert.schaltjahr();
  107. assertEquals("Welches Jahr möchtest du untersuchen?\nSchaltjahr!\n", out.toString());
  108. }
  109. @Test
  110. public void testNumber() {
  111. int expected = 0;
  112. int actual = getNumber();
  113. assertEquals(expected, actual);
  114. }
  115. private int getNumber() {
  116. return 0;
  117. }
  118. @Test
  119. public void testTimer() {
  120. int actualTime = (int) (Math.random() * 10 + 1);
  121. int estimatedTime = (int) (Math.random() * 10 + 1);
  122. int difference = Math.abs(actualTime - estimatedTime);
  123. difference--;
  124. boolean result = true;
  125. result = true;
  126. assertTrue(result);
  127. }
  128. @Test
  129. void testtest() {
  130. assertTrue(true);
  131. }
  132. }