MCPcopy
hub / github.com/google/go-cmp / generateStrings

Function generateStrings

cmp/internal/diff/diff_test.go:310–338  ·  view source on GitHub ↗
(n int, px, py, pm float32, seed int64)

Source from the content-addressed store, hash-verified

308}
309
310func generateStrings(n int, px, py, pm float32, seed int64) (string, string) {
311 if px+py+pm > 1.0 {
312 panic("invalid probabilities")
313 }
314 py += px
315 pm += py
316
317 b := make([]byte, n)
318 r := rand.New(rand.NewSource(seed))
319 r.Read(b)
320
321 var x, y []byte
322 for len(b) > 0 {
323 switch p := r.Float32(); {
324 case p < px: // UniqueX
325 x = append(x, b[0])
326 case p < py: // UniqueY
327 y = append(y, b[0])
328 case p < pm: // Modified
329 x = append(x, 'A'+(b[0]%26))
330 y = append(y, 'a'+(b[0]%26))
331 default: // Identity
332 x = append(x, b[0])
333 y = append(y, b[0])
334 }
335 b = b[1:]
336 }
337 return string(x), string(y)
338}
339
340func testStrings(t *testing.T, x, y string) EditScript {
341 es := Difference(len(x), len(y), func(ix, iy int) Result {

Callers 2

TestDifferenceFuzzFunction · 0.85
BenchmarkDifferenceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected