diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-02-01 18:02:51 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-08 11:35:16 +0000 |
| commit | e8e3023880fc4f8be85c1d1c689fd1fc9a77d60e (patch) | |
| tree | 5023445786bac6ed65f81e7b2aecfbcdfdf1298a /prog/mutation.go | |
| parent | 7569a4b27c46c85a9d942b650db87e034774bf42 (diff) | |
prog: swap array elements during mutation
Diffstat (limited to 'prog/mutation.go')
| -rw-r--r-- | prog/mutation.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/prog/mutation.go b/prog/mutation.go index 07b524fe2..47b682342 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -416,8 +416,14 @@ func mutateBufferSize(r *randGen, arg *DataArg, minLen, maxLen uint64) { } func (t *ArrayType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) { - // TODO: swap elements of the array a := arg.(*GroupArg) + if len(a.Inner) > 1 && r.oneOf(5) { + // Swap array elements. + for r.nOutOf(2, 3) { + i, j := r.Intn(len(a.Inner)), r.Intn(len(a.Inner)) + a.Inner[i], a.Inner[j] = a.Inner[j], a.Inner[i] + } + } count := uint64(0) switch t.Kind { case ArrayRandLen: |
