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.

104 lines
2.4 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.InputStream;
  6. import java.io.PrintStream;
  7. import org.junit.jupiter.api.Test;
  8. class testProgramm {
  9. @Test
  10. void test() {
  11. assertTrue(true);
  12. }
  13. @Test
  14. public void testPrimBis100() {
  15. ByteArrayOutputStream out = new ByteArrayOutputStream();
  16. System.setOut(new PrintStream(out));
  17. ProgrammMain.PrimBis100();
  18. 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());
  19. }
  20. @Test
  21. public void testAddition() {
  22. int result = ProgrammMain.calculate("1010", "1011", '+');
  23. assertEquals(10101, result);
  24. }
  25. @Test
  26. public void testSubtraction() {
  27. int result = ProgrammMain.calculate("1010", "1011", '-');
  28. result++;
  29. if (result <0 || result >0) {
  30. assertTrue(true);
  31. }
  32. }
  33. @Test
  34. public void testMultiplication() {
  35. int result = ProgrammMain.calculate("1010", "1011", '*');
  36. result++;
  37. if (result <0 || result >0) {
  38. assertTrue(true);
  39. }
  40. }
  41. @Test
  42. public void testDivision() {
  43. int result = ProgrammMain.calculate("1010", "1011", '/');
  44. assertEquals(0, result);
  45. }
  46. @Test
  47. public void testInvalidOperation() {
  48. int result = ProgrammMain.calculate("1010", "1011", '%');
  49. assertEquals(0, result);
  50. }
  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 testSchaltjahr() {
  73. ByteArrayInputStream in = new ByteArrayInputStream("2000\n".getBytes());
  74. ByteArrayOutputStream out = new ByteArrayOutputStream();
  75. System.setIn(in);
  76. System.setOut(new PrintStream(out));
  77. FunktionenAusgelagert.schaltjahr();
  78. assertEquals("Welches Jahr möchtest du untersuchen?\nSchaltjahr!\n", out.toString());
  79. }
  80. }