MCPcopy
hub / github.com/grafana/k6 / TestExecutionSegmentStringSequences

Function TestExecutionSegmentStringSequences

lib/execution_segment_test.go:371–419  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

369}
370
371func TestExecutionSegmentStringSequences(t *testing.T) {
372 t.Parallel()
373 testCases := []struct {
374 seq string
375 expSegments []string
376 expError bool
377 canReverse bool
378 // TODO: checks for least common denominator and maybe striped partitioning
379 }{
380 {seq: "", expSegments: nil},
381 {seq: "0.5", expError: true},
382 {seq: "1,1", expError: true},
383 {seq: "-0.5,1", expError: true},
384 {seq: "1/2,1/2", expError: true},
385 {seq: "1/2,1/3", expError: true},
386 {seq: "0,1,1/2", expError: true},
387 {seq: "0.5,1", expSegments: []string{"1/2:1"}},
388 {seq: "1/2,1", expSegments: []string{"1/2:1"}, canReverse: true},
389 {seq: "1/3,2/3", expSegments: []string{"1/3:2/3"}, canReverse: true},
390 {seq: "0,1/3,2/3", expSegments: []string{"0:1/3", "1/3:2/3"}, canReverse: true},
391 {seq: "0,1/3,2/3,1", expSegments: []string{"0:1/3", "1/3:2/3", "2/3:1"}, canReverse: true},
392 {seq: "0.5,0.7", expSegments: []string{"1/2:7/10"}},
393 {seq: "0.5,0.7,1", expSegments: []string{"1/2:7/10", "7/10:1"}},
394 {seq: "0,1/13,2/13,1/3,1/2,3/4,1", expSegments: []string{
395 "0:1/13", "1/13:2/13", "2/13:1/3", "1/3:1/2", "1/2:3/4", "3/4:1",
396 }, canReverse: true},
397 }
398
399 for _, tc := range testCases {
400 t.Run(tc.seq, func(t *testing.T) {
401 t.Parallel()
402 result, err := NewExecutionSegmentSequenceFromString(tc.seq)
403 if tc.expError {
404 require.Error(t, err)
405 return
406 }
407 require.NoError(t, err)
408 require.Equal(t, len(tc.expSegments), len(result))
409 for i, expStrSeg := range tc.expSegments {
410 expSeg, errl := NewExecutionSegmentFromString(expStrSeg)
411 require.NoError(t, errl)
412 assert.Truef(t, expSeg.Equal(result[i]), "Segment %d (%s) should be equal to %s", i, result[i], expSeg)
413 }
414 if tc.canReverse {
415 assert.Equal(t, result.String(), tc.seq)
416 }
417 })
418 }
419}
420
421func getTestRand(t testing.TB) *rand.Rand {
422 t.Helper()

Callers

nothing calls this directly

Calls 6

EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…