Browse Source

Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	src/test/java/src/TasksFrameTest.java
remotes/origin/develop
fdai7460 2 years ago
parent
commit
4b6807ef85
  1. 63
      src/main/java/src/TasksFrame.java
  2. 35
      src/test/java/src/TasksFrameTest.java

63
src/main/java/src/TasksFrame.java

@ -6,6 +6,7 @@ import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
public class TasksFrame extends JFrame { public class TasksFrame extends JFrame {
@ -74,6 +75,68 @@ public class TasksFrame extends JFrame {
setupLeibnizR(1000); setupLeibnizR(1000);
setupEulerschePhiFunk();
}
private void setupEulerschePhiFunk() {
JPanel jPanel = setupPanel("Eulersche Phi Funktion");
Button button = new Button("Calc Phi");
button.setVisible(true);
button.setBounds(120, 50, 100, 30);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 40, 60, 20);
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10, 90, 60, 30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int r = ePhi(Integer.valueOf(jTextField.getText()));
jLabel.setText(String.valueOf(r));
}
});
}
public int ePhi(Integer n) {
LinkedList<Object> menge = new LinkedList<>();
for(int k =1; k<=n; k++){
if(ggt(k, n)== 1){
menge.add(k);
}
}
return menge.size();
}
public int ggt(int a, int b) {
int h;
if (a == 0) return 0;
if (b == 0) return 0;
do {
h = a % b;
a = b;
b = h;
} while (b != 0);
return a;
} }
private void setupHelloWorld() { private void setupHelloWorld() {

35
src/test/java/src/TasksFrameTest.java

@ -7,16 +7,14 @@ import static org.junit.jupiter.api.Assertions.*;
class TasksFrameTest { class TasksFrameTest {
@Test @Test
void setupLeibnizR()
{
void setupLeibnizR() {
TasksFrame tasksFrame = new TasksFrame(); TasksFrame tasksFrame = new TasksFrame();
double x = tasksFrame.setupLeibnizR(100000); double x = tasksFrame.setupLeibnizR(100000);
assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x); assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x);
} }
@Test @Test
void setupDiff()
{
void setupDiff(){
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int diff = frame.calcDiff(6, 7); int diff = frame.calcDiff(6, 7);
assertEquals(-1, diff); assertEquals(-1, diff);
@ -27,8 +25,7 @@ class TasksFrameTest {
} }
@Test @Test
void setupSumm()
{
void setupSumm(){
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int sum1 = frame.calcSumm(23, 11); int sum1 = frame.calcSumm(23, 11);
assertEquals(34, sum1); assertEquals(34, sum1);
@ -39,8 +36,7 @@ class TasksFrameTest {
} }
@Test @Test
void setupSumFromTo()
{
void setupSumFromTo(){
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int p1= frame.sumCalc(1,5); int p1= frame.sumCalc(1,5);
assertEquals(15,p1); assertEquals(15,p1);
@ -50,6 +46,29 @@ class TasksFrameTest {
assertEquals(3,p3); assertEquals(3,p3);
} }
@Test
void test_ePhi(){
TasksFrame tasksFrame = new TasksFrame();
int i = tasksFrame.ePhi( 10);
assertEquals(4, i);
int a = tasksFrame.ePhi(25);
assertEquals(20, a);
int b = tasksFrame.ePhi(15);
assertEquals(8, b);
int c = tasksFrame.ePhi(35);
assertEquals(24, c);
}
@Test
void test_ggt(){
TasksFrame tasksFrame = new TasksFrame();
int ggt1 = tasksFrame.ggt(4, 20);
assertEquals(4, ggt1);
int ggt2 = tasksFrame.ggt(205, 120);
assertEquals(5, ggt2);
int ggt3 = tasksFrame.ggt(262, 599);
assertEquals(1, ggt3);
}
@Test @Test
void setupArea() void setupArea()
{ {

Loading…
Cancel
Save