You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/prompts.md
+116Lines changed: 116 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -545,6 +545,122 @@ In the run function, check whether the entries in the cell_params arrays align w
545
545
### output
546
546
Made large changes to multiple functions. See git commit for details.
547
547
548
+
## CA and PP tests
549
+
Now that the MVP functionality is fulfilled, we need to test it. For this, we create numerous tests for both the CA class and the PP class, testing if incorrect arguments raise the correct errors, if any functions raise unwanted errors, but mostly if the update functions work as intended.
550
+
551
+
### prompt
552
+
Add tests for the CA and PP class to the test_ca.py file. Check whether incorrect arguments do not raise errors and if any functions do raise errors. Also, test whether run picks up on cell_params array that do not align by grid. For this, manually change some cell_params array entries before running the simulation. Check whether all errors are informative, in the sense that a user would know how to avoid it next time.
553
+
554
+
Lastly, check whether trivial simulations result in the correct outcome. For example, if both the predator and prey death rates are 1 and the birth rates are below 1, then the grid should go extinct. Also, if the birth rate of the prey and predators are 1 and the death rate of the predators to be 0 we expect the prey to go extinct an the predators to occupy a large number of cells.
555
+
556
+
Create any additional tests if they are unique, meaning it is not tested already, and well-defined, meaning we know the intended behavior and we know how to compare it to the true behavior.
557
+
558
+
### output
559
+
def test_initialization_and_grid_filling():
560
+
rows, cols = 10, 10
561
+
densities = (0.2, 0.1)
562
+
ca = CA(rows, cols, densities, neighborhood="moore", params={}, cell_params={}, seed=42)
563
+
assert ca.grid.shape == (rows, cols)
564
+
assert ca.n_species == len(densities)
565
+
total_cells = rows * cols
566
+
# expected counts use the same rounding as CA.__init__
567
+
expected_counts = [int(round(total_cells * d)) for d in densities]
568
+
# verify actual counts equal expected
569
+
for i, exp in enumerate(expected_counts, start=1):
# run longer to allow predators to consume prey; expect prey extinction
655
+
pp.run(200)
656
+
after_prey = int(np.count_nonzero(pp.grid == 1))
657
+
after_pred = int(np.count_nonzero(pp.grid == 2))
658
+
# after sufficient time, prey should go extinct and predators remain
659
+
assert after_prey == 0
660
+
assert after_pred > 0
661
+
662
+
### changes
663
+
Revealed and fixed error in the PP class' update functions where no parameter key was passed to the _process_reproduction function, resulting in an error.
0 commit comments