-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring printer code into functions and adding unit tests #303
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Adding unit tests is good.
Regarding testing the printer, the original implementation was bad because test_percentiles
and print_distribution
are doing the same data process.
I added percentile_iter
and please test it to test the numbers.
And if you want to test outputs, just test the format itself e.g. testing indent (no testing numbers).
src/printer.rs
Outdated
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_percentiles() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just #[test] and no async fn would be enough
src/printer.rs
Outdated
#[tokio::test] | ||
async fn test_print_distribution() { | ||
let style = StyleScheme { | ||
color_enabled: !false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true?
src/printer.rs
Outdated
let values: [f64; 2] = [10.0, 100.0]; | ||
let mut output: Vec<u8> = Vec::new(); | ||
let res = print_distribution(&mut output, &values, style); | ||
assert!(res.is_ok()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer unwrap at above
@hatoo to clarify are you suggesting checking the full output rather than checking if the output contains substrings? The reason I was testing My other thought is that it could be worth moving some of the calculations into functions to allow unit testing, e.g: Lines 208 to 213 in 21aa87d
to something like:
|
No, what I mean is you can test such like the "align"
by only using pure text processing. However, since you think
I feel that's OK 👍
It looks good! |
This is still a work in progress, but I thought that it makes sense to push the work done so far for more immediate feedback. I still need to write more tests and possibly refactor more code into functions. |
@hatoo I've now refactored a large chunk of printer code into functions and added corresponding unit tests, this also has the benefit of re-using the same code for the printer and JSON output. (The only missing component is the I'm now thinking maybe it makes sense to remove the output testing (so far only the Let me know what you think? |
For
Agree. In this PR, please only add calculation tests and add output another in PR if you think it's needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good
I've made these changes, overall I think this is probably enough changes for one PR, and covers the core printer calculations. What are your thoughts @hatoo ? |
LGTM, Thanks! 🚀 |
@hatoo would it be helpful if I work through adding some unit tests? printer -
percentiles
andprint_distribution
tests included as examples of the approach I would use. Let me know what you think?If so I can work through adding more tests as part of this PR.