fix(mock): quantize the wrapping fuel counter - #97
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the handling of the 8-bit fuel counter in the
TripStatsServiceto ensure more accurate and robust fuel consumption calculations, especially in the presence of counter wraps and floating-point imprecision. The main changes include introducing a quantized tick-based delta computation, refactoring the main loop to use this logic, and adding targeted unit tests to validate the new behavior.Fuel counter logic improvements:
_fuel_counter_stepsand_fuel_counter_step_lto the constructor to represent the number of counter steps and the fuel value per step, enabling quantized tick-based calculations._fuel_counter_deltamethod, which accurately computes the fuel delta by quantizing raw float values to counter ticks, properly handling counter wraps, and filtering out implausible jumps._runto use_fuel_counter_deltainstead of the previous float-based delta calculation, improving reliability and code clarity.Testing enhancements: