mirror of
https://github.com/mfocko/blog.git
synced 2024-12-05 02:06:13 +01:00
162 lines
5.3 KiB
Markdown
162 lines
5.3 KiB
Markdown
---
|
|
id: seminar-10
|
|
title: 10th seminar
|
|
description: |
|
|
Finding bugs in a hangman.
|
|
---
|
|
|
|
[Source](pathname:///files/c/bonuses/10.tar.gz)
|
|
|
|
## Introduction
|
|
|
|
For this bonus you are given almost finished project - The Hangman Game. Your
|
|
task is to try the game, in case you find any bugs point them out and cover as
|
|
much of the game as possible with tests.
|
|
|
|
For this bonus you can get at maximum 2 K₡.
|
|
|
|
| Item | Bonus |
|
|
| ---------------------------------------------- | ----- |
|
|
| Fixing bugs from failing tests | 0.25 |
|
|
| `word_guessed` | 0.50 |
|
|
| Hidden bug | 0.50 |
|
|
| Extending tests, undetectable bugs or evil bug | 0.37 |
|
|
| Refactor | 0.38 |
|
|
|
|
## Project
|
|
|
|
Project consists of 2 source files - `hangman.c` and `main.c`.
|
|
|
|
`main.c` is quite short and concise, there is nothing for you to do.
|
|
|
|
`hangman.c` contains implementation of the game. In case you feel lost, consult
|
|
the documentation in `hangman.h` that represents an interface that can be used
|
|
for implementing the game.
|
|
|
|
Apart from those sources this project is a bit more complicated. _Game loop_ is
|
|
realised via single encapsulated function that complicates the testing. Because
|
|
of that, there are 2 kinds of tests:
|
|
|
|
- _Unit tests_ - that are present in `test_hangman.c` and can be run via:
|
|
|
|
```
|
|
$ make check-unit
|
|
```
|
|
|
|
They cover majorly functions that can be tested easily via testing framework.
|
|
|
|
- _Functional tests_ - same as in `seminar-08` and are focused on testing the
|
|
program as whole. Basic smoke test is already included in `usage` test case.
|
|
|
|
They can be run via:
|
|
|
|
```
|
|
$ make check-functional
|
|
```
|
|
|
|
When testing `hangman` function (the game loop), it is suggested to create
|
|
functional tests.
|
|
|
|
When submitting the files for review, please leave out functional tests that
|
|
were given as a part of the assignment, so that it is easier to navigate, I
|
|
will drag the common files myself. :)
|
|
|
|
> Whole test suite can be run via:
|
|
>
|
|
> ```
|
|
> $ make check
|
|
> ```
|
|
|
|
### Summary of the gameplay
|
|
|
|
1. Secret word gets chosen from the file that's path is given as an argument.
|
|
2. You get 8 guesses.
|
|
3. Invalid characters don't count.
|
|
4. Already guessed characters don't count, even if not included in the secret.
|
|
5. You can guess the whole word at once
|
|
- If you get it right, you won, game ends.
|
|
- If you don't get it right, you get to see the secret, game ends.
|
|
6. In case of end of input, game finishes via force.
|
|
7. In case of invalid input, no guesses are subtracted, game carries on.
|
|
8. Letters and words are not case sensitive.
|
|
|
|
## Suggested workflow
|
|
|
|
As we have talked about on the seminar, I suggest you to follow
|
|
_Test-Driven Development_
|
|
in this case.
|
|
|
|
![TDD workflow](/files/c/bonuses/10/tdd_lifecycle.png)
|
|
|
|
In our current scenario we are already in the stage of refactoring and fixing the
|
|
bugs. Therefore try to follow this succession of steps:
|
|
|
|
1. Try to reproduce the bug.
|
|
2. Create a test that proves the presence of the bug.
|
|
3. Fix the bug.
|
|
|
|
In case you are submitting the bonus via GitLab, it is helpful to commit tests
|
|
before commiting the fixes, so that it is apparent that the bug is manifested.
|
|
Example of `git log` (notice that the first line represents latest commit):
|
|
|
|
```
|
|
feat: Implement fizz_buzzer
|
|
test: Add tests for fizz_buzzer
|
|
fix: Fix NULL-check in print_name
|
|
test: Add test for NULL in print_name
|
|
```
|
|
|
|
## Tasks
|
|
|
|
As to your tasks, there are multiple things wrong in this project.
|
|
|
|
1. There are 2 "bugs" that cannot be detected via tests, i.e. they are not bugs
|
|
that affect functionality of the game.
|
|
|
|
2. There is one evil bug in `get_word`. It is not required to be fixed ;) Assign
|
|
it the lowest priority.
|
|
|
|
3. There are some tests failing. Please try to figure it out, so you have green
|
|
tests for the rest :)
|
|
|
|
4. We have gotten a bug report for `word_guessed`, all we got is
|
|
|
|
> doesn't work when there are too many `a`s
|
|
|
|
Please try to replicate the bug and create a tests, so we don't get any
|
|
regression later on.
|
|
|
|
5. One hidden bug :) Closely non-specified, we cannot reproduce it and we were
|
|
drunk while playing the game, so we don't remember a thing. :/
|
|
|
|
6. Try to cover as much code via the tests as possible. We are not going to look
|
|
at the metrics, but DRY is violated a lot, so as a last task try to remove as
|
|
much of the duplicit code as possible.
|
|
|
|
Tests should help you a lot in case there are some regressions.
|
|
|
|
---
|
|
|
|
In case you wonder why there are always 3 same words in the file with words, it
|
|
is because of the `get_word` bug. It is not a bug that can be easily fixed, so
|
|
it is a not requirement at all and you can still get all points for the bonus ;)
|
|
|
|
## Dictionary
|
|
|
|
- [Functional tests](https://en.wikipedia.org/wiki/Functional_testing)
|
|
- [Smoke test](https://en.wikipedia.org/wiki/Smoke_testing_%28software%29)
|
|
- [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
|
|
|
|
## Submitting
|
|
|
|
In case you have any questions, feel free to reach out to me.
|
|
|
|
---
|
|
|
|
<!-- Ideally submit the assignment through the merge request. Step-by-step tutorial
|
|
is present [here](../mr). For setting assignee my xlogin is `xfocko`.
|
|
|
|
In case you do not want to experiment on GitLab, send me the source code via
|
|
email, but please prefix subject with: `[PB071/14][seminar-10]`
|
|
|
|
Deadline for the submission of the bonus is **May 17 24:00**. -->
|