Skip to content
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

fix: selection of required and not required items #308

Merged
merged 1 commit into from
Apr 1, 2022

Conversation

augustas
Copy link
Contributor

@augustas augustas commented Mar 30, 2022

Fixed and issue with item/section selection algorithm. Whenever required and non-required are in the route, the selection would go wrong and required item got selected several times.

Related to : https://oat-sa.atlassian.net/browse/TR-3645

How to test

  • take a test attached to the linked ticket
  • make sure that the execution does not freeze during the test and can be completed, 5 items are presented

Companion legacy PR :

@@ -74,12 +74,13 @@ public function select()

if ($withReplacement === false) {
unset($selectionBag[$baseIndex]);
$selectionBag = array_values($selectionBag);
Copy link
Member

@wazelin wazelin Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 95 has the same issue, I believe.

WDYT of reversing the logic here, and populating the $selectionBag values in a foreach loop, while iterating over $selectableRoutes, instead of setting all the values there, and then unsetting the unwanted ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Line 95 doesn't have this issue, because the index to access the reindexed array is calculated on each iteration, and not fixed by a foreach.
I would keep the overall implementation the same, for me it makes sense to pick out the required items and then randomly pick as much as needed from the leftovers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, true. I wasn't paying enough attention.
Thanks for elaborating!

@augustas augustas requested a review from wazelin March 30, 2022 10:28
Copy link
Contributor

@poyuki poyuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master
  • Commits are following conventional commits
  • Changelog is updated according to changes (if applicable)
  • Documentation is updated according to changes (if applicable)

Copy link
Member

@wazelin wazelin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master

@augustas augustas merged commit 5125b38 into develop Apr 1, 2022
@augustas augustas deleted the fix/TR-3645/basic-selection-required-items branch April 1, 2022 07:27
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.

None yet

3 participants