- Java 11
- Maven
- Reformatted Code
- It is necessary to write beautiful formatted code for more understanding of the code by the programmer and other people
- Added
final
to immutable class fields- Many fields, such as
location
orid
for objects are often immutable. They need to be made `final'
- Many fields, such as
- Created the
Location
class because the 2D space in the problem- The description of the problem says that location has 2 coordinates
- Extracted magic numbers and strings to the
Utils
class- The code uses a lot of numeric parameters, as well as string error messages and logs. They must be moved to a separate place so that they can be conveniently changed
- Add
IllegalArgumentException
in theCar
init- Asymmetric validation of the parameter for correctness
- Covered by tests
minDestination
in thegetClosestStation
method can be bigger than 100- Incorrect implementation
- Covered by tests
- Fixed a bug in the
Car.driveTo
- noMath.abs
.- Creating an appropriate method in the
Location
class solves this problem - Covered by tests
- Creating an appropriate method in the
- Fixed a bug in the
addEnergy
method:refuel
must be before the driving to destination- Covered by tests
I've corrected this code, I'm not sure what it was supposed to be, I still don't like some moments in the code. At a minimum, I would not fill in arrays of stations in the code itself. It seems to me that this should happen in tests, each different situation has its own set of points for stations. I would also implement this class a little differently - just 2 arrays of data that can be filled in from tests during init. It would also be logical to create a class “World” or something similar, in which persons, stations and cars would be stored, for example, because I don't like that inside the person there is work with “StationsPool”. This is a more understandable implementation, as well as more convenient for testing.
I like to generate random datasets for testing in order to minimize matches and increase the quality of verification.
badInitTest
- testing thebadInit
method. Checking all throwsdriveToTest
- testing thedriveTo
method. Checking the car's location and energy valuerefuelTest
- testing therefuel
method. Checking the energy value
goToWorkTest
- testing thegoToWork
method. Checking the car's locationgoToHomeTest
- testing thegoToHome
method. Checking the car's locationaddEnergyTest
- testing theaddEnergy
method. Checking the energy valuechangeCarTest
- testing thechangeCar
method. Checking the locations of carstestPerson
- was before
commonTest
- a lot of roads between home and work. testing thegoToHome
method. Checking the car's location