Skip to content

Fix an issue where we broke out of the width computation to soon #49

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

Closed
wants to merge 1 commit into from

Conversation

tertsdiepraam
Copy link
Member

@tertsdiepraam tertsdiepraam commented Apr 8, 2025

This is what I came up with towards fixing #39. I don't think that issue is completely solvable, because sometimes that's just what the optimal solution looks like.

I added a test that represents the issue I fixed, which I'll explain here.

The test contains these names:

a
b
ccc
ddd

Now imagine we want to fit them into a width of 6, top-to-bottom and with a filling of 2 spaces. The obvious solution is:

a  ccc
b  ddd

But that's not what the current code does. Instead it tries:

a
b
ccc
ddd

Which succeeds and then it tries:

a    ddd
b
ccc

and fails. The assumption made by the code was that there will be no solution with fewer lines, because we would go on to have more columns, which means more width. But, that assumption was clearly no right.

Regarding changing the code, this means that we cannot break early out of the loop. That in turn means that we have to check every possible number of lines. That's slower, but it gives us another opportunity to optimize: we can check the number of lines starting from 1 instead of theoretical_max_number_of_lines, meaning we can break early again.

I then made a bit of a gamble and relaxed theoretical_max_number_of_lines. I'm guessing that we will now find a solution before we hit that, making it kind of useless in this version. So we should spend less time computing it!

At the risk of doing to much at once, this also clean up of some the code around these computations.

@tertsdiepraam tertsdiepraam force-pushed the width-computation-cleanup branch from a945461 to 1734afd Compare April 9, 2025 08:05
@tertsdiepraam
Copy link
Member Author

Closing in favor of #48. I'll be taking the same tests to that branch.

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (c8db34b) to head (1734afd).

Additional details and impacted files
@@    Coverage Diff     @@
##   main   #49   +/-   ##
==========================
==========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tertsdiepraam tertsdiepraam deleted the width-computation-cleanup branch April 10, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant