SHARE
TWEET

TestClorus.java

a guest Feb 22nd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package creatures;
  2. import org.junit.Test;
  3. import static org.junit.Assert.*;
  4. import java.util.HashMap;
  5. import java.awt.Color;
  6. import huglife.Direction;
  7. import huglife.Action;
  8. import huglife.Occupant;
  9. import huglife.Impassible;
  10. import huglife.Empty;
  11.  
  12. public class TestClorus {
  13.  
  14.     @Test
  15.     public void testBasics() {
  16.         Clorus c = new Clorus(3);
  17.         assertEquals(3, c.energy(), 0.01);
  18.         assertEquals(new Color(34, 0, 231), c.color());
  19.         c.move();
  20.         assertEquals(2.97, c.energy(), 0.01);
  21.         c.move();
  22.         assertEquals(2.94, c.energy(), 0.01);
  23.         c.stay();
  24.         assertEquals(2.93, c.energy(), 0.01);
  25.         c.stay();
  26.         assertEquals(2.92, c.energy(), 0.01);
  27.     }
  28.  
  29.     @Test
  30.     public void testReplicate() {
  31.         // TODO
  32.         Clorus c = new Clorus(10);
  33.         assertEquals(10, c.energy(), 0.01);
  34.         assertEquals(new Color(34, 0, 231), c.color());
  35.         c.replicate();
  36.         assertEquals(5, c.energy(), 0.01);
  37.         assertEquals(new Color(34, 0, 231), c.color());
  38.     }
  39.  
  40.     public void testChoose() {
  41.  
  42.         // No empty adjacent spaces; stay.
  43.         Clorus c = new Clorus(1.2);
  44.         HashMap<Direction, Occupant> surrounded = new HashMap<Direction, Occupant>();
  45.         surrounded.put(Direction.TOP, new Impassible());
  46.         surrounded.put(Direction.BOTTOM, new Impassible());
  47.         surrounded.put(Direction.LEFT, new Impassible());
  48.         surrounded.put(Direction.RIGHT, new Impassible());
  49.  
  50.         Action actual = c.chooseAction(surrounded);
  51.         Action expected = new Action(Action.ActionType.STAY);
  52.  
  53.         assertEquals(expected, actual);
  54.  
  55.  
  56.         // Energy >= 1; replicate towards an empty space.
  57.         c = new Clorus(1.2);
  58.         HashMap<Direction, Occupant> topEmpty = new HashMap<Direction, Occupant>();
  59.         topEmpty.put(Direction.TOP, new Empty());
  60.         topEmpty.put(Direction.BOTTOM, new Impassible());
  61.         topEmpty.put(Direction.LEFT, new Impassible());
  62.         topEmpty.put(Direction.RIGHT, new Impassible());
  63.  
  64.         actual = c.chooseAction(topEmpty);
  65.         expected = new Action(Action.ActionType.REPLICATE, Direction.TOP);
  66.  
  67.         assertEquals(expected, actual);
  68.  
  69.  
  70.         // Energy >= 1; replicate towards an empty space.
  71.         c = new Clorus(1.2);
  72.         HashMap<Direction, Occupant> allEmpty = new HashMap<Direction, Occupant>();
  73.         allEmpty.put(Direction.TOP, new Empty());
  74.         allEmpty.put(Direction.BOTTOM, new Empty());
  75.         allEmpty.put(Direction.LEFT, new Empty());
  76.         allEmpty.put(Direction.RIGHT, new Empty());
  77.  
  78.         actual = c.chooseAction(allEmpty);
  79.         Action unexpected = new Action(Action.ActionType.STAY);
  80.  
  81.         assertNotEquals(unexpected, actual);
  82.  
  83.  
  84.         // Energy < 1; stay.
  85.         c = new Clorus(.99);
  86.  
  87.         actual = c.chooseAction(allEmpty);
  88.         expected = new Action(Action.ActionType.STAY);
  89.  
  90.         assertEquals(expected, actual);
  91.  
  92.  
  93.         // Energy < 1; stay.
  94.         c = new Clorus(.99);
  95.  
  96.         actual = c.chooseAction(topEmpty);
  97.         expected = new Action(Action.ActionType.STAY);
  98.  
  99.         assertEquals(expected, actual);
  100.     }
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top