Skip to content

Commit

Permalink
added test for another edge condition
Browse files Browse the repository at this point in the history
  • Loading branch information
cainja committed Dec 19, 2024
1 parent 2f107f3 commit b18a4ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
3 changes: 1 addition & 2 deletions test/arcade/patch/agent/cell/PatchCellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ public void checkLocation_locationEmpty_returnTrue() {
assertEquals(true, actual);
}

final Bag createPatchCellsWithVolumeAndCriticalHeight(
int n, double volume, double critHeight) {
final Bag createPatchCellsWithVolumeAndCriticalHeight(int n, double volume, double critHeight) {
Bag bag = new Bag();
for (int i = 0; i < n; i++) {
PatchCellContainer container =
Expand Down
40 changes: 39 additions & 1 deletion test/arcade/patch/agent/cell/PatchCellTissueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final Bag createPatchTissueCellsWithVolumeAndCriticalHeight(
}

@Test
public void findFreeLocations_roomForMultipleCancerCells_returnsCurrentAndOpenLocation() {
public void findFreeLocations_exceedsMaxDensitys_returnsOnlyCurrentLocation() {
doReturn(0.0).when(parametersMock).getDouble(anyString());
doReturn(0).when(parametersMock).getInt(anyString());

Expand Down Expand Up @@ -123,4 +123,42 @@ public void findFreeLocations_roomForMultipleCancerCells_returnsCurrentAndOpenLo
assertTrue(freeLocations.contains(locationMock));
assertFalse(freeLocations.contains(notFreeLocation));
}

@Test
public void findFreeLocations_containsAnotherPopulation_returnsFreeAndCurrentLocation() {
doReturn(0.0).when(parametersMock).getDouble(anyString());
doReturn(0).when(parametersMock).getInt(anyString());

doReturn(1000.).when(locationMock).getVolume();
doReturn(100.).when(locationMock).getArea();

PatchLocation notFreeLocation = mock(PatchLocation.class);
Bag notFreeBag = createPatchTissueCellsWithVolumeAndCriticalHeight(1, 200, 10);
doReturn(notFreeBag).when(gridMock).getObjectsAtLocation(notFreeLocation);
doReturn(1000.).when(notFreeLocation).getVolume();
doReturn(100.).when(notFreeLocation).getArea();
ArrayList<Location> neighborLocations = new ArrayList<>();
neighborLocations.add(notFreeLocation);
doReturn(neighborLocations).when(locationMock).getNeighbors();

PatchCellContainer container =
new PatchCellContainer(
cellID,
cellParent,
cellPop - 1,
cellAge,
cellDivisions,
cellState,
cellVolume,
cellHeight,
cellCriticalVolume,
cellCriticalHeight);
PatchCell cell = new PatchCellTissue(container, locationMock, parametersMock);

Bag freeLocations = cell.findFreeLocations(simMock, false);

assertEquals(2, freeLocations.size());
assertTrue(freeLocations.contains(locationMock));
assertTrue(freeLocations.contains(notFreeLocation));
}
}

0 comments on commit b18a4ac

Please sign in to comment.