Skip to content

Conversation

@eugenesmlv
Copy link
Contributor

PR Summary

Added -Shuffle switch to Get-Random command. Also added test for this feature.

PR Context

Fix #11022

PR Checklist

Copy link
Collaborator

@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

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

Couple minor comments, looks pretty solid overall.

Nice work! 😊 💖

Comment on lines 162 to 167
$randomNumber[0] | Should -BeIn 1, 2, 3, 5, 8, 13
$randomNumber[1] | Should -BeIn 1, 2, 3, 5, 8, 13
$randomNumber[2] | Should -BeIn 1, 2, 3, 5, 8, 13
$randomNumber[3] | Should -BeIn 1, 2, 3, 5, 8, 13
$randomNumber[4] | Should -BeIn 1, 2, 3, 5, 8, 13
$randomNumber[5] | Should -BeIn 1, 2, 3, 5, 8, 13
Copy link
Collaborator

Choose a reason for hiding this comment

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

From memory you can shorten these tests to just $randomNumber | Should -BeIn 1, 2, 3, 5, 8, 13

#region Shuffle parameter

/// <summary>
/// If specified, then the command will return all input objects in randomized order.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll need to phrase this with Gets or sets whether the command (...) in order to satisfy CodeFactor.

At some point we'll have to go back through and align the other parameter descriptions with that format, but no need to go that far for this PR. 🙂


private const string RandomNumberParameterSet = "RandomNumberParameterSet";
private const string RandomListItemParameterSet = "RandomListItemParameterSet";
private const string ShuffleSet = "ShuffleSet";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private const string ShuffleSet = "ShuffleSet";
private const string ShuffleSet = "ShuffleParameterSet";

Just to keep it in the same vein as the existing parameter set names, really. 🙂

Comment on lines 54 to 55
else if (ParameterSetName.Equals(GetRandomCommand.RandomListItemParameterSet, StringComparison.OrdinalIgnoreCase) ||
ParameterSetName.Equals(GetRandomCommand.ShuffleSet, StringComparison.OrdinalIgnoreCase))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where a condition like this is necessary, most other (recent) areas of the codebase have it with the || starting the following line. Also, you can just do a straight == on these. Not sure why the original code bothered to check without case sensitivity; the parameter set names shouldn't end up in a different casing to how they're defined as far as I'm aware. Something like the following should be sufficient:

else if (ParameterSetName == GetRandomCommand.RandomListItemParameterSet
    || ParameterSetName == GetRandomCommand.ShuffleSet)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly just in general I have no idea why this code is written in this way, I can't think of a case where this is especially important but no reason to go changing the rest of this now I suppose. Never really thought checking parameter set names would be performance-intensive. 🤔

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 18, 2019
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 18, 2019
@eugenesmlv
Copy link
Contributor Author

Thanks for the review! Fixed.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 18, 2019
@adityapatwardhan adityapatwardhan changed the title Add -Shuffle switch to Get-Random command Add -Shuffle switch to Get-Random command Apr 13, 2020
@adityapatwardhan adityapatwardhan merged commit 07620b4 into PowerShell:master Apr 15, 2020
@adityapatwardhan
Copy link
Member

@eugenesmlv Thank you for your contribution!

@adityapatwardhan adityapatwardhan added this to the 7.1.0-preview.2 milestone Apr 15, 2020
@eugenesmlv eugenesmlv deleted the get-random-shuffle-switch branch April 16, 2020 11:55
@ghost
Copy link

ghost commented Apr 23, 2020

🎉v7.1.0-preview.2 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a -Shuffle switch to Get-Random for convenient collection shuffling

4 participants