Überladen von Methoden
parent
148bcb09c2
commit
c2990decf9
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue