MCPcopy
hub / github.com/google/gvisor / segmentTestCheck

Method segmentTestCheck

pkg/segment/set.go:2119–2141  ·  view source on GitHub ↗

segmentTestCheck returns an error if s is incorrectly sorted, does not contain exactly expectedSegments segments, or contains a segment which fails the passed check. This should be used only for testing, and has been added to this package for templating convenience.

(expectedSegments int, segFunc func(int, Range, Value) error)

Source from the content-addressed store, hash-verified

2117// This should be used only for testing, and has been added to this package for
2118// templating convenience.
2119func (s *Set) segmentTestCheck(expectedSegments int, segFunc func(int, Range, Value) error) error {
2120 havePrev := false
2121 prev := Key(0)
2122 nrSegments := 0
2123 for seg := s.FirstSegment(); seg.Ok(); seg = seg.NextSegment() {
2124 next := seg.Start()
2125 if havePrev && prev >= next {
2126 return fmt.Errorf("incorrect order: key %d (segment %d) >= key %d (segment %d)", prev, nrSegments-1, next, nrSegments)
2127 }
2128 if segFunc != nil {
2129 if err := segFunc(nrSegments, seg.Range(), seg.Value()); err != nil {
2130 return err
2131 }
2132 }
2133 prev = next
2134 havePrev = true
2135 nrSegments++
2136 }
2137 if nrSegments != expectedSegments {
2138 return fmt.Errorf("incorrect number of segments: got %d, wanted %d", nrSegments, expectedSegments)
2139 }
2140 return nil
2141}
2142
2143// countSegments counts the number of segments in the set.
2144//

Callers 8

TestAddRandomFunction · 0.95
TestRemoveRandomFunction · 0.95
TestMaxGapAddRandomFunction · 0.80
TestMaxGapRemoveRandomFunction · 0.80

Calls 8

FirstSegmentMethod · 0.95
KeyTypeAlias · 0.70
StartMethod · 0.65
ErrorfMethod · 0.65
ValueMethod · 0.65
OkMethod · 0.45
NextSegmentMethod · 0.45
RangeMethod · 0.45

Tested by 8

TestAddRandomFunction · 0.76
TestRemoveRandomFunction · 0.76
TestMaxGapAddRandomFunction · 0.64
TestMaxGapRemoveRandomFunction · 0.64