MCPcopy Create free account
hub / github.com/buger/jsonparser / TestPropertySearchKeysDeterminism

Function TestPropertySearchKeysDeterminism

property_test.go:594–610  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Property: searchKeys is deterministic and bounded on arbitrary bytes --------------------------------------------------------------------------- reqproof:proptest searchKeys Verifies: SYS-REQ-001 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

592// reqproof:proptest searchKeys
593// Verifies: SYS-REQ-001 [property]
594func TestPropertySearchKeysDeterminism(t *testing.T) {
595 r := newRNG(jsonSeed + 7)
596 const iterations = 2000
597 for i := 0; i < iterations; i++ {
598 raw := randomBytes(r, 64)
599 key := randKey(r)
600 a := searchKeys(raw, key)
601 b := searchKeys(raw, key)
602 if a != b {
603 t.Fatalf("searchKeys non-deterministic on input %q key=%q: %d vs %d", raw, key, a, b)
604 }
605 // Result is either -1 (not found) or a valid index into raw.
606 if a != -1 && (a < 0 || a >= len(raw)) {
607 t.Fatalf("searchKeys returned out-of-range index %d on input %q (len=%d)", a, raw, len(raw))
608 }
609 }
610}
611
612// ---------------------------------------------------------------------------
613// Property: findKeyStart is deterministic on arbitrary bytes

Callers

nothing calls this directly

Calls 4

newRNGFunction · 0.85
randomBytesFunction · 0.85
randKeyFunction · 0.85
searchKeysFunction · 0.85

Tested by

no test coverage detected