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.

103 lines
1.8 KiB

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. }