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