tested and implemented clone() in StoneTray
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@84 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
f8f75fde6d
commit
88292e9304
2 changed files with 31 additions and 3 deletions
|
@ -209,11 +209,16 @@ public class StoneTray<E extends Sizeable> implements
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
public void pickUp(E object) {
|
public void pickUp(E object) {
|
||||||
objects.remove(object);
|
objects.remove(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoneTray<E> clone() {
|
||||||
|
StoneTray<E> copy = new StoneTray();
|
||||||
|
copy.objects = (HashMap<E, Position>) objects.clone();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,7 @@ public class StoneTrayTest {
|
||||||
for (Pair<Thing, Position> i : testTray) {
|
for (Pair<Thing, Position> i : testTray) {
|
||||||
assertSame(i.getFirst(), secondThing);
|
assertSame(i.getFirst(), secondThing);
|
||||||
}
|
}
|
||||||
|
assertTrue(testTray.iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -185,4 +186,26 @@ public class StoneTrayTest {
|
||||||
assertTrue(testThings.isEmpty());
|
assertTrue(testThings.isEmpty());
|
||||||
assertTrue(testPositions.isEmpty());
|
assertTrue(testPositions.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClone() {
|
||||||
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
testTray.drop(firstThing, new Position(0, 0));
|
||||||
|
Thing secondThing = new Thing(3, 3);
|
||||||
|
testTray.drop(secondThing, new Position(-5, -5));
|
||||||
|
StoneTray<Thing> trayCopy = testTray.clone();
|
||||||
|
|
||||||
|
|
||||||
|
testTray.pickUp(firstThing);
|
||||||
|
for (Pair<Thing, Position> i : testTray) {
|
||||||
|
assertSame(i.getFirst(), secondThing);
|
||||||
|
}
|
||||||
|
assertTrue(testTray.iterator().hasNext());
|
||||||
|
|
||||||
|
trayCopy.pickUp(secondThing);
|
||||||
|
for (Pair<Thing, Position> i : trayCopy) {
|
||||||
|
assertSame(i.getFirst(), firstThing);
|
||||||
|
}
|
||||||
|
assertTrue(trayCopy.iterator().hasNext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue