oving4
This commit is contained in:
89
src/main/java/oving4/Person.java
Normal file
89
src/main/java/oving4/Person.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package oving4;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private char gender;
|
||||
private Person mother;
|
||||
private Person father;
|
||||
private ArrayList<Person> children;
|
||||
|
||||
Person() {
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
char getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
Person getMother() {
|
||||
return mother;
|
||||
}
|
||||
|
||||
Person getFather() {
|
||||
return father;
|
||||
}
|
||||
|
||||
int getChildCount() {
|
||||
return children.size();
|
||||
}
|
||||
|
||||
Person getChild(int n) {
|
||||
if (n < 0 || n >= children.size()) {
|
||||
throw new IllegalArgumentException("invalid index");
|
||||
}
|
||||
return children.get(n);
|
||||
}
|
||||
|
||||
void addChild(Person p) {
|
||||
if (isMale()) {
|
||||
p.father = this;
|
||||
} else {
|
||||
p.mother = this;
|
||||
}
|
||||
children.add(p);
|
||||
}
|
||||
|
||||
void removeChild(Person p) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
if (p.name == children.get(i).name) {
|
||||
children.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (p.isMale() && this.father == p) {
|
||||
this.father = null;
|
||||
return;
|
||||
}
|
||||
if (p.isFemale() && this.mother == p) {
|
||||
this.mother = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void setMother(Person p) {
|
||||
mother = p;
|
||||
}
|
||||
|
||||
void setFather(Person p) {
|
||||
father = p;
|
||||
}
|
||||
|
||||
boolean isMale() {
|
||||
if (gender == 'M') {
|
||||
return true;
|
||||
}
|
||||
if (gender == 'F') {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal gender");
|
||||
}
|
||||
|
||||
boolean isFemale() {
|
||||
return !isMale();
|
||||
}
|
||||
}
|
||||
37
src/main/java/oving4/testing/CoffeeCupTest.java
Normal file
37
src/main/java/oving4/testing/CoffeeCupTest.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package oving4.testing;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CoffeeCupTest {
|
||||
|
||||
private CoffeeCup coffee;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
coffee = new CoffeeCup();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Constructor")
|
||||
public void testConstructor() {
|
||||
assertEquals(0, coffee.getCapacity());
|
||||
assertEquals(0, coffee.getCurrentVolume());
|
||||
coffee.increaseCupSize(10);
|
||||
assertEquals(10, coffee.getCapacity());
|
||||
coffee.fillCoffee(10);
|
||||
assertEquals(10, coffee.getCurrentVolume());
|
||||
coffee.drinkCoffee(10);
|
||||
assertEquals(0, coffee.getCurrentVolume());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("volume cannot be null")
|
||||
public void testAddChildException() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user