From c2990decf976f7a7d73842f1e80beb3fb9a62122 Mon Sep 17 00:00:00 2001 From: Kai Sellmann <2210892@stud.hs-mannheim.de> Date: Mon, 29 May 2023 18:36:34 +0200 Subject: [PATCH] =?UTF-8?q?=C3=9Cberladen=20von=20Methoden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vererbung/ueberladen_summe/Summator.java | 15 ++++++++++++++ .../ueberladen_summe/test/SummatorTest.java | 20 +++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sources/src/main/java/pr2/vererbung/ueberladen_summe/Summator.java b/sources/src/main/java/pr2/vererbung/ueberladen_summe/Summator.java index f69bfe5..8f77dfb 100644 --- a/sources/src/main/java/pr2/vererbung/ueberladen_summe/Summator.java +++ b/sources/src/main/java/pr2/vererbung/ueberladen_summe/Summator.java @@ -2,4 +2,19 @@ package pr2.vererbung.ueberladen_summe; public class Summator { + public int sum(int a, int b) { + return a + b; + } + + public int sum(int a, int b, int c) { + return a + b + c; + } + + public int sum(int a, int b, int c, int d) { + return a + b + c + d; + } + + public int sum(int a, int b, int c, int d, int e) { + return a + b + c + d + e; + } } diff --git a/sources/src/main/java/pr2/vererbung/ueberladen_summe/test/SummatorTest.java b/sources/src/main/java/pr2/vererbung/ueberladen_summe/test/SummatorTest.java index 5d3496b..059053f 100644 --- a/sources/src/main/java/pr2/vererbung/ueberladen_summe/test/SummatorTest.java +++ b/sources/src/main/java/pr2/vererbung/ueberladen_summe/test/SummatorTest.java @@ -9,15 +9,15 @@ public class SummatorTest { @Test void testSum() { -// TODO: Einkommentieren -// Summator s = new Summator(); -// assertEquals(3, s.sum(1, 2)); -// assertEquals(1, s.sum(-1, 2)); -// assertEquals(6, s.sum(1, 2, 3)); -// assertEquals(0, s.sum(1, 2, -3)); -// assertEquals(10, s.sum(1, 2, 3, 4)); -// assertEquals(2, s.sum(1, 2, 3, -4)); -// assertEquals(15, s.sum(1, 2, 3, 4, 5)); -// assertEquals(5, s.sum(1, 2, 3, 4, -5)); + + Summator s = new Summator(); + assertEquals(3, s.sum(1, 2)); + assertEquals(1, s.sum(-1, 2)); + assertEquals(6, s.sum(1, 2, 3)); + assertEquals(0, s.sum(1, 2, -3)); + assertEquals(10, s.sum(1, 2, 3, 4)); + assertEquals(2, s.sum(1, 2, 3, -4)); + assertEquals(15, s.sum(1, 2, 3, 4, 5)); + assertEquals(5, s.sum(1, 2, 3, 4, -5)); } }