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

fixed github issue 3821 for string shannon entropy test #3824

Merged

Conversation

kashifkhan0771
Copy link
Contributor

Description:

This issue fixes the issue #3821 by rounding the output of shannon entropy output to two digits to avoid unnecessary precision.

Screenshot from 2024-12-30 15-35-43

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@kashifkhan0771 kashifkhan0771 requested a review from a team as a code owner December 30, 2024 10:37
@kashifkhan0771 kashifkhan0771 linked an issue Dec 30, 2024 that may be closed by this pull request
@@ -173,7 +174,8 @@ func TestStringShannonEntropy(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StringShannonEntropy(tt.args.input); got != tt.want {
got := roundToTwoDigits(StringShannonEntropy(tt.args.input))
Copy link
Collaborator

@ahrav ahrav Dec 30, 2024

Choose a reason for hiding this comment

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

suggestion: I think we can rely on our testing package (testify) to handle most of the heavy lifting here.

Ex:

got := StringShannonEntropy(tt.args.input)
if len(tt.args.input) > 0 && tt.want != 0 {
    assert.InEpsilon(t, tt.want, got, 0.1)
} else {
    assert.Equal(t, tt.want, got)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's cool! I didn't know about InEpsilon. Thanks for sharing. I updated the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I only just learned about it last week too. 😅

@kashifkhan0771 kashifkhan0771 merged commit 15b8ed6 into trufflesecurity:main Dec 31, 2024
13 checks passed
@kashifkhan0771 kashifkhan0771 deleted the fix/github-issue-3821 branch December 31, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Flaky TestStringShannonEntropy test
2 participants