-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutator_utils.go
48 lines (44 loc) · 1.33 KB
/
mutator_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package mutator
// getValidDeletePositions returns valid positions for deletion based on the mutation type
func (m *Mutator) getValidDeletePositions(runes []rune, mutationType MutationType) []int {
var positions []int
for i, r := range runes {
if m.shouldMutate(r, mutationType) {
positions = append(positions, i)
}
}
return positions
}
// getMutationProb returns the probability of mutation for the given mutation type
func (m *Mutator) getMutationProb(mutationType MutationType) float64 {
if mutationType.MutationProb > 0 {
return mutationType.MutationProb
}
return m.GlobalMutationProb
}
// shouldMutate checks if a rune should be mutated based on the mutation type
func (m *Mutator) shouldMutate(r rune, mutationType MutationType) bool {
if mutationType.Any {
return true
}
if mutationType.Letters && isLetter(r) {
return true
}
if mutationType.Numbers && isNumber(r) {
return true
}
if mutationType.Special && isSpecialChar(r) {
return true
}
return false
}
// getValidChangeCasePositions returns valid positions for case change based on the mutation type
func (m *Mutator) getValidChangeCasePositions(runes []rune, mutationType MutationType) []int {
var positions []int
for i, r := range runes {
if m.shouldMutate(r, mutationType) && isLetter(r) {
positions = append(positions, i)
}
}
return positions
}