Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test, pytest configuration, removed unnecessary import #46

Merged
merged 6 commits into from
Oct 12, 2022
Merged

Added test, pytest configuration, removed unnecessary import #46

merged 6 commits into from
Oct 12, 2022

Conversation

GrbavaCigla
Copy link
Contributor

@GrbavaCigla GrbavaCigla commented Oct 8, 2022

Resolves #34

@GrbavaCigla
Copy link
Contributor Author

Please let me know if you have an idea for more tests.

Copy link
Collaborator

@ClasherKasten ClasherKasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1:

  • Most important: move the tests into a separate folder named tests/
  • For the rest take a look at the comments I made.

If you have any questions, just ask.

src/tests/__init__.py Outdated Show resolved Hide resolved
src/tests/__init__.py Outdated Show resolved Hide resolved
pytest.ini Outdated Show resolved Hide resolved
@ClasherKasten
Copy link
Collaborator

Please let me know if you have an idea for more tests.

Ideally I want to have a test coverage of 100%.
So simply the idea would be to write tests for every part of the code that isn't covered by the tests. This doesn't have to be achieved with one PR, but this is the goal.
Please tell me if you want to push further commits that add new tests to this PR or if I should merge it after the changes and you open more PRs for new tests (but please don't open a new PR for every single test).

@GrbavaCigla
Copy link
Contributor Author

Thanks for the review.

Also why main.py instead of __main__.py?

@ClasherKasten
Copy link
Collaborator

Also why main.py instead of __main__.py?

main.py is just a normal python module and can be used like one. __main__.py has a special meaning for python. I think simplified __main__.py turns a directory into an executable python module.
As an example suppose you have a directory called some_dir with an __main__.py file which contains all the startup code for the application. You could then use python -m some_dir to run you application.

Copy link
Collaborator

@ClasherKasten ClasherKasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2: I already told you that in the last Round.

OK, something i thought very long about and what is probably my fault. I should've specified that I wanted unittests. This looks more like an integration test. (Fixed the description of the issue)

tests/conftest.py Outdated Show resolved Hide resolved
@GrbavaCigla
Copy link
Contributor Author

Also why main.py instead of __main__.py?

main.py is just a normal python module and can be used like one. __main__.py has a special meaning for python. I think simplified __main__.py turns a directory into an executable python module. As an example suppose you have a directory called some_dir with an __main__.py file which contains all the startup code for the application. You could then use python -m some_dir to run you application.

Exactly, shouldn't this module be executable since project is cli chess?

Anyways, I will fix this tomorrow since it is getting late.

@ClasherKasten
Copy link
Collaborator

Exactly, shouldn't this module be executable since project is cli

If you would've taken a look into README.md in the sections Installation and Usage it is written down how to properly execute it. But yeah, a __main__.py is an option to. So if you want to add, feel free to do so.

@GrbavaCigla
Copy link
Contributor Author

Can you tell me what functions should I unittest because in testMate I am testing isCheckmate?

@ClasherKasten
Copy link
Collaborator

ClasherKasten commented Oct 9, 2022

Can you tell me what functions should I unittest because in testMate I am testing isCheckmate?

Here is a little definition:

A unit test should have no dependencies on code outside the unit tested. You decide what the unit is by looking for the smallest testable part. Where there are dependencies they should be replaced by false objects.
StackOverflow

I think there is a way to isolate the checkmate behavior much better from the rest of the program. And if that's not something you want to do right now, there are enough other parts of the code that need to be tested as well. As an example, Coordinate is completely isolated. Most of the types of pieces can be tested when the board is mocked (or the test for the board is also pushed, or if you have another solution just propose it).

What I'd like to say in conclusion is that it's fine if you want to verify that it actually analyzes, moves and recognizes everything (the whole process and how each small part is put together). But then you shouldn't do it just for checkmate. Just checking that it validates a specific example is not the idea of tests. Tests should cover as many possibilities as possible (which includes edge cases). And currently I don't really see this code covering anything (especially not edge cases).

So if you wanna push tests that look like the one you pushed, keep going. but then keep in mind that you also have to test input, output, behaviour, etc. And don't forget edge cases (invalid input, etc.). Also if you only test set input, then you never test that the AI actually works.

@GrbavaCigla
Copy link
Contributor Author

Yeah, added more tests, but it isn't easy writing 'isolated' tests while everything is entangled in code.

@ClasherKasten
Copy link
Collaborator

Yeah, added more tests, but it isn't easy writing 'isolated' tests while everything is entangled in code.

That's a valid point. So you identified that the problem is in the code. A solution to this could also be to discuss how the code could be changed to be more isolated.

But I don't wanna be so negative. Instead: the new tests look very good and seem to improve coverage quite a bit. 👍
Still I would like an answer if you wanna push more or if I can merge this PR and new ones can be opened for more tests?

@ClasherKasten ClasherKasten mentioned this pull request Oct 12, 2022
@GrbavaCigla
Copy link
Contributor Author

You can merge it :D

@ClasherKasten ClasherKasten merged commit ae65c78 into marcusbuffett:master Oct 12, 2022
@ClasherKasten ClasherKasten added the hacktoberfest-accepted Label for accepted PRs while Hacktoberfest label Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Label for accepted PRs while Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding unittests
2 participants