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

Function TestPropertySearchKeysDeterminism

property_test.go:481–497  ·  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

479// reqproof:proptest searchKeys
480// Verifies: SYS-REQ-001 [property]
481func TestPropertySearchKeysDeterminism(t *testing.T) {
482 r := newRNG(jsonSeed + 7)
483 const iterations = 2000
484 for i := 0; i < iterations; i++ {
485 raw := randomBytes(r, 64)
486 key := randKey(r)
487 a := searchKeys(raw, key)
488 b := searchKeys(raw, key)
489 if a != b {
490 t.Fatalf("searchKeys non-deterministic on input %q key=%q: %d vs %d", raw, key, a, b)
491 }
492 // Result is either -1 (not found) or a valid index into raw.
493 if a != -1 && (a < 0 || a >= len(raw)) {
494 t.Fatalf("searchKeys returned out-of-range index %d on input %q (len=%d)", a, raw, len(raw))
495 }
496 }
497}
498
499// ---------------------------------------------------------------------------
500// 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