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.

168 lines
3.3 KiB

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. @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. FunktionenAusgelagert.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 = FunktionenAusgelagert.calculate("1010", "1011", '+');
  22. assertEquals(10101, result);
  23. }
  24. @Test
  25. public void testSubtraction() {
  26. int result = FunktionenAusgelagert.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 = FunktionenAusgelagert.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 = FunktionenAusgelagert.calculate("1010", "1011", '/');
  43. assertEquals(0, result);
  44. }
  45. @Test
  46. public void testInvalidOperation() {
  47. int result = FunktionenAusgelagert.calculate("1010", "1011", '%');
  48. assertEquals(0, result);
  49. }
  50. // Taschenrechner
  51. @Test
  52. public void testAddition1() {
  53. double result = 2 + 3.5;
  54. assertEquals(5.5, result, 0);
  55. }
  56. @Test
  57. public void testSubtraction1() {
  58. double result = 5 - 3.5;
  59. assertEquals(1.5, result, 0);
  60. }
  61. @Test
  62. public void testMultiplication1() {
  63. double result = 5 * 3.5;
  64. assertEquals(17.5, result, 0);
  65. }
  66. @Test
  67. public void testDivision1() {
  68. double result = 15 / 10;
  69. assertEquals(1, result, 0);
  70. }
  71. @Test
  72. public void testFakultaetWithPositiveNumber() {
  73. String input = "5\n";
  74. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  75. System.setIn(in);
  76. ByteArrayOutputStream out = new ByteArrayOutputStream();
  77. System.setOut(new PrintStream(out));
  78. FunktionenAusgelagert.Fakultaet();
  79. assertEquals("120\n", out.toString());
  80. }
  81. @Test
  82. public void testFakultaetWithZero() {
  83. String input = "0\n";
  84. ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
  85. System.setIn(in);
  86. ByteArrayOutputStream out = new ByteArrayOutputStream();
  87. System.setOut(new PrintStream(out));
  88. FunktionenAusgelagert.Fakultaet();
  89. assertTrue(true);
  90. // Schaltjahr
  91. @Test
  92. public void testSchaltjahr() {
  93. ByteArrayInputStream in = new ByteArrayInputStream("2000\n".getBytes());
  94. ByteArrayOutputStream out = new ByteArrayOutputStream();
  95. System.setIn(in);
  96. System.setOut(new PrintStream(out));
  97. FunktionenAusgelagert.schaltjahr();
  98. assertEquals("Welches Jahr möchtest du untersuchen?\nSchaltjahr!\n", out.toString());
  99. }
  100. @Test
  101. public void testNumber() {
  102. int expected = 0;
  103. int actual = getNumber();
  104. assertEquals(expected, actual);
  105. }
  106. private int getNumber() {
  107. return 0;
  108. }
  109. @Test
  110. public void testTimer() {
  111. int actualTime = (int) (Math.random() * 10 + 1);
  112. int estimatedTime = (int) (Math.random() * 10 + 1);
  113. int difference = Math.abs(actualTime - estimatedTime);
  114. difference--;
  115. boolean result = true;
  116. result = true;
  117. assertTrue(result);
  118. }
  119. @Test
  120. void testtest() {
  121. assertTrue(true);
  122. }
  123. }