From 70b86284a4c98b068e7119f906564929c262cbb9 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 09:42:42 +0100 Subject: [PATCH 1/3] Windows Probleme beim Erstellen von einer File, deshalb schlaegt Test fehl. --- src/main/java/src/TasksFrame.java | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 2fc7fb0..0ec3aa5 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -6,6 +6,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; +import java.util.LinkedList; public class TasksFrame extends JFrame { @@ -72,6 +73,68 @@ public class TasksFrame extends JFrame { 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)); + } + }); + + + } + + private int ePhi(Integer n) { + + LinkedList menge = new LinkedList<>(); + + for(int k =1; k<=n; k++){ + if(ggt(k, n)== 1){ + menge.add(k); + } + } + return menge.size(); + } + + private 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() { From fc3d1c0e6c02b37ab59c60dd388a5172ea547fed Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 10:02:28 +0100 Subject: [PATCH 2/3] Test ePhi-Funktion --- src/main/java/src/TasksFrame.java | 4 ++-- src/test/java/src/TasksFrameTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 0ec3aa5..f3058a4 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -109,7 +109,7 @@ public class TasksFrame extends JFrame { } - private int ePhi(Integer n) { + public int ePhi(Integer n) { LinkedList menge = new LinkedList<>(); @@ -121,7 +121,7 @@ public class TasksFrame extends JFrame { return menge.size(); } - private int ggt(int a, int b) { + public int ggt(int a, int b) { int h; if (a == 0) return 0; diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ebe61ca..96efb8a 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -46,6 +46,18 @@ class TasksFrameTest { 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); + } } From 9c965ca24db52daaf1e73a207b3d0e4240ec3f27 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 10:08:48 +0100 Subject: [PATCH 3/3] Test ggT-Funktion --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 96efb8a..b9a277f 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -58,6 +58,17 @@ class TasksFrameTest { 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); + } }