schrum2 / EvoCraft-SCOPE

0 stars 0 forks source link

Unit tests for fitness_functions.py #47

Closed schrum2 closed 2 years ago

schrum2 commented 2 years ago

It turns out pytest is pretty easy to use. After installing it with from the requirements file, look at test_util.py and see how it works. Just run pytest in the project directory to execute the tests.

You will need to make a new file test_fitness_functions.py that contains functions test_type_count and test_type_target. Each will need to initialize a Minecraft server client connection (as done in the constructors for the two breeder classes), and use that to artificially create some shapes, before then using the fitness functions to retrieve the calculated scores.

Running these tests will only work if a Minecraft server is running on the local machine. That could be an issue eventually, but for now don't worry about it. Do keep in mind that this will put shapes into your Minecraft world. You make want to make sure that you empty the space before and after. You might also want to place the shapes somewhere else in the world than around (0,5,0), which is where most of our shapes evolve.

alejmedinajr commented 2 years ago

There are now 4 shapes that were created to test type_countfitness function. All 4 pass (the code is a little bit ugly however) unit test shapes .

alejmedinajr commented 2 years ago

Made unit tests for type_targetusing the same shapes (but around 100 spaces away in the z coordinate). I still need to display a better message when the tests are run while the server is not connected.

alejmedinajr commented 2 years ago

Both of the tests are now in try/except blocks in the case that the server is not connected.

New [more clear] error message produced when running the tests without successfully being connected to the server:

error message .