HI,

To quickly create non-regression tests on cases with high combinatorics, I
use approvaltests <https://approvaltests.com/>.
You execute code with all cases and for each, you write the value in a
file. You just have to check that this file is always the same after a test
execution to make the test passed.

I made an example you can see here:
https://github.com/sfauvel/freecol/blob/test_with_approvals/test/src/net/sf/freecol/common/model/ColonyProductionApprovalsTest.java
There is 2 tests:
One is a very basic test (testGetPotentialProduction) that produces a text
file with raw data (testGetPotentialProduction.approved.txt
<https://github.com/sfauvel/freecol/blob/test_with_approvals/test/src/net/sf/freecol/common/model/ColonyProductionApprovalsTest.testGetPotentialProduction.approved.txt>)
. Simple to produce but not easy to interpret cases.
The second one is more complicated to generate but it creates an asciidoc
file that makes a non regression reference and can be used as documentation
when converted to HTML. Many cases can be represented in a concise way. You
can see the result here:
testGetPotentialProductionInReadableTable.approved.adoc
<https://github.com/sfauvel/freecol/blob/test_with_approvals/test/src/net/sf/freecol/common/model/ColonyProductionApprovalsTest.testGetPotentialProductionInReadableTable.approved.adoc>.


I'm not sure about all the cases you want to test and how to generate them
but If you think this approach could help, I can explain in more detail or
complete those tests to cover more cases..

Best regards
*Sébastien Fauvel*


Le sam. 3 sept. 2022 à 10:51, Stian Grenborgen <
stian...@student.matnat.uio.no> a écrit :

> Hi again,
>
> I have found that getPotentialProduction/getMaximumPotential for
> Tile/BuildingType produces different results than the actual production
> (ColonyTile/Building) even when the results should be the same.
>
> When looking into the code I have noticed all sorts of issues with
> modifiers not being applied. Some of these issues only affect methods used
> by the AI, while other issues affect the actual production. For example, an
> expert farmer never gets the additional (expert) bonus from the grain
> resource.
>
> I think the best solution for these problems is having a separate class
> for calculating production/consumption -- and that this class gets the list
> of modifiers for the colony and player as parameters. This way, we can use
> the same code everywhere (potential, maximum and actual production) and
> Tile+ColonyTile+Building+Colony gets simplified.
>
> The main problem with the rewrite is lack of tests for the correct tile
> production values ... so it would be really helpful if someone would make
> tables/lists with the correct values for each combination of:
> * Tile type
> * Resource
> * Tile improvements (plow, minor river, major river and/or road)
> * Worker type (unattended, petty criminal, indentured servant, colonist,
> convert, expert)
> * Liberty bonuses (-2, -1, 0, +1, +2)
>
> That's lots of combinations and numbers ... but only having a complete set
> for one resource (grain) would help immensely. Please do tell if you can
> help make these tables/lists :-)
>
>
> Best wishes,
> Stian Grenborgen
>
> _______________________________________________
> Freecol-developers mailing list
> Freecol-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freecol-developers
>
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to