Überladen von Methoden

kleinerRech
Kai Sellmann 2023-05-29 18:36:34 +02:00
parent 148bcb09c2
commit c2990decf9
2 changed files with 25 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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));
}
}