From 15b8ed6731012adc1fffe5254bc4b2ae16878f76 Mon Sep 17 00:00:00 2001 From: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:26:41 +0500 Subject: [PATCH] fixed github issue 3821 for string shannon entropy test (#3824) * fixed github issue 3821 for string shannon entropy test * ahrav is legend --- pkg/detectors/falsepositives_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/detectors/falsepositives_test.go b/pkg/detectors/falsepositives_test.go index a90672892042..7d3cedafc479 100644 --- a/pkg/detectors/falsepositives_test.go +++ b/pkg/detectors/falsepositives_test.go @@ -154,14 +154,14 @@ func TestStringShannonEntropy(t *testing.T) { args: args{ input: "aaaaaaaaaaaaaaaaaaaaaaaaaaab", }, - want: 0.22228483068568816, + want: 0.22, }, { name: "entropy 3", args: args{ input: "aaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaab", }, - want: 0.22228483068568816, + want: 0.22, }, { name: "empty", @@ -173,8 +173,11 @@ 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 { - t.Errorf("StringShannonEntropy() = %v, want %v", got, tt.want) + 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) } }) }