@Test public void testLoadSave() throws IOException { Database db = new Database("test", "test.dbl"); Table t1 = new Table("tname"); t1.addColumn("A", CharField.class); t1.addColumn("B", DateField.class); Row r1 = t1.getRowSkeleton(); Calendar calendar = Calendar.getInstance(); calendar.set(70, 0, 0); Date date = calendar.getTime(); r1.insert(1, Cell.makeCell(date)); r1.insert(0, Cell.makeCell("text0")); t1.addRow(r1); db.addTable(t1); db.saveToStorage(); db = new Database("test", "test.dbl"); db.loadFromStorage(); db.loadFromStorage(); System.out.println(db); System.out.println(t1); assertTrue(db.getTable("tname").getHeader().equalsModel(t1.getHeader())); assertTrue(db.getTable("tname").row(0).at(0).getStringData().equals("text0")); assertEquals( db.getTable("tname").row(0).at(1).getStringData(), Cell.makeCell(date).getStringData()); assertEquals(1, t1.size()); }
@Test public void test_checkConditionBlackAnt2() { // Creates a new Ant with colour Red. Ant a = new Ant(w, AntColour.Red); c.addAnt(a); assertTrue(c.checkCondition(Condition.BlackAnt) == false); }
// Tests that calculate food returns 2 when there is 2 blobs of food in the cell. @Test public void test_calculateFoodAmount2() { Cell c = new Cell(); c.addFood(); c.addFood(); assertTrue(c.calculateFoodAmount() == 2); }
@Test public void test_checkConditionBlackAnt() { // Creates a new Ant with colour Black. Ant a = new Ant(w, AntColour.Black); c.addAnt(a); assertTrue(c.checkCondition(Condition.BlackAnt) == true); }
// Tests that calculate food returns 100 when there is 100 blobs of food in the cell. @Test public void test_calculateFoodAmount3() { Cell c = new Cell(); for (int i = 0; i < 100; i++) { c.addFood(); } assertTrue(c.calculateFoodAmount() == 100); }
@Test public void shouldKillAliveCellWhenKillIsCalled() { Cell cell = new Cell(true); cell.kill(); assertEquals(new Cell(false).format(), cell.format()); }
@Test public void shouldRemainDeadWhenKillIsCalledOnDeadCell() { Cell cell = new Cell(false); cell.kill(); assertEquals(new Cell(false).format(), cell.format()); }
@Test public void shouldReviveDeadCellWhenReviveIsCalled() { Cell cell = new Cell(false); cell.revive(); assertEquals(new Cell(true).format(), cell.format()); }
@Test public void shouldRemainAliveWhenReviveIsCalledOnAliveCell() { Cell cell = new Cell(true); cell.revive(); assertEquals(new Cell(true).format(), cell.format()); }
@Test public void aCellAliveTest() { // GIVEN Cell cell = new Cell(); // WHEN boolean status = cell.isAlive(); // THEN assertFalse("A new cell is dead", status); }
@Test public void aCellNextStepTest() { // GIVEN Cell cell = new Cell(); // WHEN boolean status = cell.nextStep(); // THEN assertFalse("With next step, the cell is dead", status); }
public void aDeadCellWith2NeighboursStaysDeadTest() { // GIVEN int numberOfNeighbours = 2; Cell cell = new Cell(false, numberOfNeighbours); // WHEN cell.nextStep(); boolean status = cell.isAlive(); // THEN assertFalse("A cell with 2 neighbours stays dead", status); }
/** Test of evaluateAt method, of class ParameterisedGroup. */ @Test public void testEvaluateAt() throws ParameterException { System.out.println("--- testEvaluateAt..."); // SegmentLocation loc1 = new PostSynapticTerminalLocation(d2.getSegmentId(), 0.5f); assertEquals(0.5, pg1.evaluateAt(cell, d2, 0.5f), 0); assertEquals(15, pg2.evaluateAt(cell, d2, 0.5f), 0); //////// assertEquals(15, pg5.evaluateAt(cell, loc1), 0); // SegmentLocation loc2 = new PostSynapticTerminalLocation(d3.getSegmentId(), 0.5f); assertEquals(5d / 6d, pg1.evaluateAt(cell, d3, 0.5f), 1e-7); assertEquals(25, pg2.evaluateAt(cell, d3, 0.5f), 0); assertEquals(0.5, pg3.evaluateAt(cell, d3, 0.5f), 0); assertEquals(0, pg4.evaluateAt(cell, d3, 0), 0); assertEquals(5, pg4.evaluateAt(cell, d3, 0.5f), 0); SegmentLocation sl1 = new SegmentLocation(d3.getSegmentId(), 0.5f); assertEquals( 25, pg5.evaluateAt(cell, cell.getSegmentWithId(sl1.getSegmentId()), sl1.getFractAlong()), 0); assertEquals(30, pg5.evaluateAt(cell, d3, 1), 0); GenesisCompartmentalisation g = new GenesisCompartmentalisation(); Cell gCell = g.getCompartmentalisation(cell); System.out.println(CellTopologyHelper.printDetails(cell, null)); System.out.println( "Changed from morph: " + cell.getMorphSummary() + ", to morph: " + gCell.getMorphSummary()); System.out.println("getSegmentMapper: " + g.getSegmentMapper()); System.out.println(CellTopologyHelper.printDetails(gCell, null)); SegmentLocation sl1_g = g.getSegmentMapper().mapSegmentLocation(sl1); System.out.println("Mapped: " + sl1 + " to " + sl1_g); assertEquals( 25, pg5.evaluateAt(gCell, gCell.getSegmentWithId(sl1_g.getSegmentId()), sl1_g.getFractAlong()), 0); }
@Test public void aCellLivesWith3NeighboursTest() { // GIVEN int numberOfNeighbours = 3; Cell cell = new Cell(true, numberOfNeighbours); // WHEN cell.nextStep(); boolean status = cell.isAlive(); // THEN assertTrue("A cell with 3 neighbours lives or is reanimated", status); }
@Test public void testCloneBoard() throws Exception { Player p1 = new Player("P1"); Player p2 = new Player("P2"); Cell[][] boardA = Utils.generateInitialBoard(8, 8, p1, p2); Cell cellA = boardA[1][0]; Piece pieceA = cellA.getContents(); Player playerA = pieceA.getPlayer(); Cell[][] boardB = Utils.cloneBoard(boardA); Cell cellB = boardB[1][0]; Piece pieceB = cellB.getContents(); Player playerB = pieceB.getPlayer(); assertNotSame(cellA, cellB); assertNotSame(pieceA, pieceB); assertSame(playerA, playerB); }
@Test public void getTablesSubTest() throws Exception { Database db = new Database("test"); Table t1 = new Table("tname1"); t1.addColumn("A", CharField.class); t1.addColumn("B", IntegerField.class); Row r1 = t1.getRowSkeleton(); r1.insert(0, Cell.makeCell("text1")); r1.insert(1, Cell.makeCell(11)); t1.addRow(r1); r1.insert(0, Cell.makeCell("text2")); r1.insert(1, Cell.makeCell(12)); t1.addRow(r1); r1.insert(0, Cell.makeCell("text3")); r1.insert(1, Cell.makeCell(13)); t1.addRow(r1); Table t2 = new Table("tname2"); t2.addColumn("A", CharField.class); t2.addColumn("B", IntegerField.class); Row r3 = t2.getRowSkeleton(); r3.insert(0, Cell.makeCell("text2")); r3.insert(1, Cell.makeCell(12)); t2.addRow(r3); Table resTable = db.getTablesSub(t1, t2); assertEquals(2, resTable.size()); assertEquals(2, resTable.getHeader().size()); assertEquals(CharField.class, resTable.getHeader().getTypeAt(0)); assertEquals(IntegerField.class, resTable.getHeader().getTypeAt(1)); assertEquals(2, resTable.size()); assertEquals("text1", resTable.getStringRow(0).getCel().get(0)); assertEquals("11", resTable.getStringRow(0).getCel().get(1)); assertEquals("text3", resTable.getStringRow(1).getCel().get(0)); assertEquals("13", resTable.getStringRow(1).getCel().get(1)); }
@Test public void shouldReturnXIfCellIsAliveWhenFormatIsCalled() { Cell cell = new Cell(true); assertEquals("X", cell.format()); }
@Test public void test_isMarkedRed4() { v.mark(4, AntColour.Red); assertTrue(v.isMarked(AntColour.Red, 4)); }
@Test public void test_isMarkedRed3() { v.mark(3, AntColour.Red); assertTrue(v.isMarked(AntColour.Red, 3)); }
@Test public void test_isMarkedRed6() { v.mark(6, AntColour.Red); assertTrue(v.isMarked(AntColour.Red, 6)); }
@Test public void test_isMarkedRed5() { v.mark(5, AntColour.Red); assertTrue(v.isMarked(AntColour.Red, 5)); }
@Test public void shouldReturnTrueIfCellIsAliveWhenIsAliveIsCalled() { Cell cell = new Cell(true); assertTrue(cell.isAlive()); }
@Test public void shouldReturnFalseIfCellIsDeadWhenIsAliveIsCalled() { Cell cell = new Cell(false); assertFalse(cell.isAlive()); }
@Before public void setUp() { System.out.println("--------------- setUp() ParameterisedGroupTest"); cell = new OneSegment("Simple"); d1 = cell.addDendriticSegment( 1, "d1", new Point3f(10, 0, 0), cell.getFirstSomaSegment(), 1, "Sec1", false); d2 = cell.addDendriticSegment(2, "d2", new Point3f(20, 0, 0), d1, 1, "Sec2", false); d3 = cell.addDendriticSegment(7, "d3", new Point3f(20, 10, 0), d2, 1, "Sec3", false); d3.getSection().setStartRadius(3); d1.getSection().setNumberInternalDivisions(4); d2.getSection().setNumberInternalDivisions(3); d3.getSection().setNumberInternalDivisions(5); d3.getSection().addToGroup(tipSection); pg1 = new ParameterisedGroup( "ZeroToOne", Section.DENDRITIC_GROUP, Metric.PATH_LENGTH_FROM_ROOT, ProximalPref.MOST_PROX_AT_0, DistalPref.MOST_DIST_AT_1, "p1"); pg2 = new ParameterisedGroup( "StartToEnd", Section.DENDRITIC_GROUP, Metric.PATH_LENGTH_FROM_ROOT, ProximalPref.NO_TRANSLATION, DistalPref.NO_NORMALISATION, "p2"); pg3 = new ParameterisedGroup( "TipZeroToOne", tipSection, Metric.PATH_LENGTH_FROM_ROOT, ProximalPref.MOST_PROX_AT_0, DistalPref.MOST_DIST_AT_1, "p3"); pg4 = new ParameterisedGroup( "TipToEnd", tipSection, Metric.PATH_LENGTH_FROM_ROOT, ProximalPref.MOST_PROX_AT_0, DistalPref.NO_NORMALISATION, "p4"); pg5 = new ParameterisedGroup( "TipToEnd_PathFromRoot", tipSection, Metric.PATH_LENGTH_FROM_ROOT, ProximalPref.NO_TRANSLATION, DistalPref.NO_NORMALISATION, "p5"); /* pg5 = new ParameterisedGroup("3DDistZeroToOne", Section.ALL, Metric.THREE_D_RADIAL_POSITION, ProximalPref.MOST_PROX_AT_0, DistalPref.MOST_DIST_AT_1);*/ }
@Test public void shouldReturnHiphenIfCellIsDeadWhenFormatIsCalled() { Cell cell = new Cell(false); assertEquals("-", cell.format()); }
@Test public void test_checkConditionRedAnt() { Ant a = new Ant(w, AntColour.Red); c.addAnt(a); assertTrue(c.checkCondition(Condition.RedAnt) == true); }
// Tests that calculate food returns 0 when there is no food in the cell. @Test public void test_calculateFoodAmount() { Cell c = new Cell(); assertTrue(c.calculateFoodAmount() == 0); }
@Test public void test_checkConditionRedAnt2() { Ant a = new Ant(w, AntColour.Black); c.addAnt(a); assertTrue(c.checkCondition(Condition.RedAnt) == false); }
@Test public void test_checkConditionBlackHill() { c.addAntHill(AntColour.Black); assertTrue(c.checkCondition(Condition.BlackHill) == true); }
@Test public void test_isMarkedRed2() { v.mark(2, AntColour.Red); assertTrue(v.isMarked(AntColour.Red, 2)); }