Browse Source

Fakultaet rechner mit Test

remotes/origin/develop
fdai7460 2 years ago
parent
commit
d09f0c42fa
  1. 17
      src/main/java/src/TasksFrame.java
  2. 14
      src/test/java/src/TasksFrameTest.java

17
src/main/java/src/TasksFrame.java

@ -100,6 +100,8 @@ public class TasksFrame extends JFrame {
}
private void setupExponent() {
JPanel jPanel = setupPanel("Potenzrechner");
@ -732,6 +734,8 @@ public class TasksFrame extends JFrame {
}
public int calcArea(int a, int b)
{
int area = a * b;
@ -745,7 +749,6 @@ public class TasksFrame extends JFrame {
}
public void setupSumFromTo(){
JPanel jPanel = setupPanel("Sum from to");
@ -797,6 +800,18 @@ public class TasksFrame extends JFrame {
return sum+to;
}
public int Fakultaet(int a){
int sum = 0;
int faku=1;
while ( sum <a ) {
sum = sum + 1 ;
faku = faku * sum ;
}
if(sum == 0){
faku = 0;
}
return faku;
}

14
src/test/java/src/TasksFrameTest.java

@ -7,12 +7,24 @@ import static org.junit.jupiter.api.Assertions.*;
class TasksFrameTest {
@Test
void setupLeibnizR() {
void setupPI() {
TasksFrame tasksFrame = new TasksFrame();
double x = tasksFrame.setupPI(100000);
assertEquals(Math.PI, x*4, 0.0001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x*4);
}
@Test
void setupFakult()
{
TasksFrame tasksFrame = new TasksFrame();
int x = tasksFrame.Fakultaet(5);
assertEquals(120,x);
int x2 = tasksFrame.Fakultaet(1);
assertEquals(1,x2);
int x3 = tasksFrame.Fakultaet(0);
assertEquals(0,x3);
}
@Test
void setupDiff(){
TasksFrame frame = new TasksFrame();

Loading…
Cancel
Save