-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutator_delete_test.go
79 lines (73 loc) · 1.98 KB
/
mutator_delete_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package mutator
import (
"testing"
)
// Helper function to count the number of deletions
func countDeletions(original, changed string) int {
// Count the number of characters removed
return len(original) - len(changed)
}
// Test for deleteChars
func TestDeleteChars(t *testing.T) {
mutator := New(&Config{
MutationTypes: []MutationType{
NewDeleteMutation(1, 1.0, "all"),
},
})
tests := []struct {
name string
input string
mutationType MutationType
expectedCount int // Expected number of deletions
}{
{
name: "Single Deletion - All",
input: "hello",
mutationType: NewDeleteMutation(1, 1.0, "all"),
expectedCount: 1,
},
{
name: "Multiple Deletions - All",
input: "hello",
mutationType: NewDeleteMutation(2, 1.0, "all"),
expectedCount: 2,
},
{
name: "More Deletions Than Characters - All",
input: "hello",
mutationType: NewDeleteMutation(5, 1.0, "all"),
expectedCount: 5, // In this case, all characters might be deleted
},
{
name: "Delete Letters Only",
input: "hello123!",
mutationType: NewDeleteMutation(2, 1.0, "letters"),
expectedCount: 2,
},
{
name: "Delete Numbers Only",
input: "hello123!",
mutationType: NewDeleteMutation(1, 1.0, "numbers"),
expectedCount: 1,
},
{
name: "Delete Special Characters Only",
input: "hello123!",
mutationType: NewDeleteMutation(1, 1.0, "special"),
expectedCount: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inputRunes := []rune(tt.input)
original := string(inputRunes)
result := mutator.deleteChars(inputRunes, tt.mutationType)
resultStr := string(result)
// Count the number of deletions
deletionCount := countDeletions(original, resultStr)
if deletionCount != tt.expectedCount {
t.Errorf("deleteChars() deleted %d characters, want %d", deletionCount, tt.expectedCount)
}
})
}
}