tresinformal / drakkar

The tresinformal video game called 'Drakkar'
GNU General Public License v3.0
11 stars 4 forks source link

Standardize the method to test whether error is within tolerance. #595

Closed EvoLandEco closed 1 year ago

EvoLandEco commented 1 year ago

It was an idea raised when we were reviewing @TheoPannetier 's code yesterday. Throughout the code base there exist various method in the tests to test whether the error produced (due to computer arithmetic errors) is within the tolerance.

Example 1

assert(predicted_player_position.get_y() - get_y(p) < 0.001
   &&predicted_player_position.get_y() - get_y(p) > -0.001);

Example 2

double error_x = abs(get_x(c) - default_speed);
double error_y = abs(get_y(c) - 0);
assert(error_x < 0.00001);
assert(error_y < 0.00001);

Our opinion is that we should standardize the method, as well as the tolerance value. To make it easier, we might need to implement a utility function to do the job, to save a lot of time of people writing redundant code.

EvoLandEco commented 1 year ago

Similar to #594