-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathprogramming_language_test.go
More file actions
79 lines (67 loc) · 1.89 KB
/
programming_language_test.go
File metadata and controls
79 lines (67 loc) · 1.89 KB
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 faker
import (
"regexp"
"testing"
)
func TestProgrammingLanguageName(t *testing.T) {
f := New()
pl := f.ProgrammingLanguage()
names := make([]string, 0, len(languageVersions))
for lang := range languageVersions {
names = append(names, lang)
}
ExpectInString(t, pl.Name(), names)
}
func TestProgrammingLanguageVersion(t *testing.T) {
f := New()
pl := f.ProgrammingLanguage()
name := pl.Name()
ExpectInString(t, pl.Version(name), languageVersions[name])
}
func TestProgrammingLanguageVariableName(t *testing.T) {
f := New()
pl := f.ProgrammingLanguage()
pattern := regexp.MustCompile(`^[_a-zA-Z][_a-zA-Z0-9]*$`)
// Test multiple generations
for i := 0; i < 100; i++ {
name := pl.VariableName()
Expect(t, true, pattern.MatchString(name))
}
}
func TestProgrammingLanguageVariableNameWithLength(t *testing.T) {
f := New()
pl := f.ProgrammingLanguage()
pattern := regexp.MustCompile(`^[_a-zA-Z][_a-zA-Z0-9]*$`)
// Test different lengths
lengths := []int{1, 5, 10, 20, 50}
for _, length := range lengths {
name := pl.VariableNameWithLength(length)
Expect(t, true, pattern.MatchString(name))
Expect(t, length, len(name))
}
// Test invalid length (should default to 1)
name := pl.VariableNameWithLength(0)
Expect(t, 1, len(name))
}
func TestProgrammingLanguageVariableNameDistribution(t *testing.T) {
f := New()
pl := f.ProgrammingLanguage()
// Generate 1000 names and check their distribution
names := make(map[string]int)
totalNames := 1000
for i := 0; i < totalNames; i++ {
name := pl.VariableName()
names[name]++
}
// Check that we have a reasonable number of unique names
uniqueNames := len(names)
Expect(t, true, uniqueNames >= totalNames/2)
// Check that no single name appears too frequently
maxOccurrences := 0
for _, count := range names {
if count > maxOccurrences {
maxOccurrences = count
}
}
Expect(t, true, maxOccurrences <= totalNames/10)
}