Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package creatures;
- import org.junit.Test;
- import static org.junit.Assert.*;
- import java.util.HashMap;
- import java.awt.Color;
- import huglife.Direction;
- import huglife.Action;
- import huglife.Occupant;
- import huglife.Impassible;
- import huglife.Empty;
- public class TestClorus {
- @Test
- public void testBasics() {
- Clorus c = new Clorus(3);
- assertEquals(3, c.energy(), 0.01);
- assertEquals(new Color(34, 0, 231), c.color());
- c.move();
- assertEquals(2.97, c.energy(), 0.01);
- c.move();
- assertEquals(2.94, c.energy(), 0.01);
- c.stay();
- assertEquals(2.93, c.energy(), 0.01);
- c.stay();
- assertEquals(2.92, c.energy(), 0.01);
- }
- @Test
- public void testReplicate() {
- // TODO
- Clorus c = new Clorus(10);
- assertEquals(10, c.energy(), 0.01);
- assertEquals(new Color(34, 0, 231), c.color());
- c.replicate();
- assertEquals(5, c.energy(), 0.01);
- assertEquals(new Color(34, 0, 231), c.color());
- }
- public void testChoose() {
- // No empty adjacent spaces; stay.
- Clorus c = new Clorus(1.2);
- HashMap<Direction, Occupant> surrounded = new HashMap<Direction, Occupant>();
- surrounded.put(Direction.TOP, new Impassible());
- surrounded.put(Direction.BOTTOM, new Impassible());
- surrounded.put(Direction.LEFT, new Impassible());
- surrounded.put(Direction.RIGHT, new Impassible());
- Action actual = c.chooseAction(surrounded);
- Action expected = new Action(Action.ActionType.STAY);
- assertEquals(expected, actual);
- // Energy >= 1; replicate towards an empty space.
- c = new Clorus(1.2);
- HashMap<Direction, Occupant> topEmpty = new HashMap<Direction, Occupant>();
- topEmpty.put(Direction.TOP, new Empty());
- topEmpty.put(Direction.BOTTOM, new Impassible());
- topEmpty.put(Direction.LEFT, new Impassible());
- topEmpty.put(Direction.RIGHT, new Impassible());
- actual = c.chooseAction(topEmpty);
- expected = new Action(Action.ActionType.REPLICATE, Direction.TOP);
- assertEquals(expected, actual);
- // Energy >= 1; replicate towards an empty space.
- c = new Clorus(1.2);
- HashMap<Direction, Occupant> allEmpty = new HashMap<Direction, Occupant>();
- allEmpty.put(Direction.TOP, new Empty());
- allEmpty.put(Direction.BOTTOM, new Empty());
- allEmpty.put(Direction.LEFT, new Empty());
- allEmpty.put(Direction.RIGHT, new Empty());
- actual = c.chooseAction(allEmpty);
- Action unexpected = new Action(Action.ActionType.STAY);
- assertNotEquals(unexpected, actual);
- // Energy < 1; stay.
- c = new Clorus(.99);
- actual = c.chooseAction(allEmpty);
- expected = new Action(Action.ActionType.STAY);
- assertEquals(expected, actual);
- // Energy < 1; stay.
- c = new Clorus(.99);
- actual = c.chooseAction(topEmpty);
- expected = new Action(Action.ActionType.STAY);
- assertEquals(expected, actual);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement