feat(01-04): add shared Chunk type, Finding struct, Shannon entropy, and MaskKey
- pkg/types/chunk.go: shared Chunk struct breaking engine<->sources circular import - pkg/engine/finding.go: Finding struct with MaskKey for pipeline output - pkg/engine/entropy.go: Shannon entropy function using math.Log2 - pkg/engine/entropy_test.go: TDD tests for Shannon and MaskKey
This commit is contained in:
31
pkg/engine/entropy_test.go
Normal file
31
pkg/engine/entropy_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShannonAllSame(t *testing.T) {
|
||||
assert.InDelta(t, 0.0, Shannon("aaaaaaa"), 0.01)
|
||||
}
|
||||
|
||||
func TestShannonDistinct(t *testing.T) {
|
||||
assert.InDelta(t, 3.0, Shannon("abcdefgh"), 0.1)
|
||||
}
|
||||
|
||||
func TestShannonRealKey(t *testing.T) {
|
||||
assert.GreaterOrEqual(t, Shannon("sk-proj-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr"), 3.5)
|
||||
}
|
||||
|
||||
func TestShannonEmpty(t *testing.T) {
|
||||
assert.Equal(t, 0.0, Shannon(""))
|
||||
}
|
||||
|
||||
func TestMaskKeyNormal(t *testing.T) {
|
||||
assert.Equal(t, "sk-proj-...1234", MaskKey("sk-proj-abc1234"))
|
||||
}
|
||||
|
||||
func TestMaskKeyShort(t *testing.T) {
|
||||
assert.Equal(t, "****", MaskKey("abc"))
|
||||
}
|
||||
Reference in New Issue
Block a user