https://github.com/coders-school/fan_controller
https://github.com/coders-school/fan_controller
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/coders-school/fan_controller
- Owner: coders-school
- License: gpl-3.0
- Created: 2019-05-13T13:12:37.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T06:46:44.000Z (over 3 years ago)
- Last Synced: 2025-04-04T03:04:02.598Z (over 1 year ago)
- Language: C++
- Size: 170 KB
- Stars: 0
- Watchers: 1
- Forks: 30
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Good programming practices
- Clean code
- Naming conventions
- Code formatting
- KISS
- DRY
- YAGNI
- SOLID
- GRASP
- Testable code
- Dependency injection
- Test doubles: dummy, stub, mock
- TDD
## Description
Your company needs a controller that can properly cool down some other devices. It will use 2 devices: a thermometer to read the temperature and a fan to control.
Your architect has already proposed interfaces.
The SlowThermometer will be used as a thermometer in your product. It provides with a current temperature. It is a vendor implementation and you cannot change it.
Fan must be controlled appropriately and must speed up when the temperature is too high or should be disabled when it is too low. Fan speed (in rpm - rotations per minute) can be set from 1000 to 3000. It can also be equal to 0, what means that the fan is disabled.
The Controller require a termomether and a fan to work. Without them it does not work. It also needs a target temperature and a tolerance. When the temperature is in a range , controller should keep the fan speed at 1000 rpm. When it is below targetTemperature - tolerance, the fan should be disabled. When it is above, the fan speed must must be adjusted by 1 rpm per each 0.001 degree. Max speed is 3000 rpm.
Controller can have an LCD display, which displays current temperature, target temperature and a fan speed. It can also work without a display.
## Assignment
### Propose improvements for the existing code
Write them on a flipchart / notepad.
### Refactor the existing, tested code
1. Never change both implementation and tests, because if tests fails you don't know if tests or implementation are broken
2. Apply your improvements
Spoiler
- missing virtual destructors
- const correctness (const functions, const params, const variables)
- redundant constructors
- broken Rule of 3, 5, 0
- overcomplicated implementation
- dead code
- use default, delete, override
- pass shared_ptrs via
const & -
shared_ptr's constructor ->std::make_shared
### Write a missing part in TDD mode
Write an implementation of a Controller class in TDD using either Catch2 framework in BDD style with Hippomocks as a mocking framework or using GTest with GMock. Remember about good programming practices.
#### Tips
- extract magic values to consts (constexpr)
- use dependency injection to inject artificial thermometer for testing
- use exception to simplify the error handling
- use STL algorithms
- use references instead of raw pointers
- avoid code duplication