-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailgenerator_test.go
63 lines (53 loc) · 2.05 KB
/
emailgenerator_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateNegativeEmails(t *testing.T) {
_, err := generateEmails(-1, 0)
assert.Error(t, err, "Didn't receive expected error when -1 email count")
}
func TestGenerateNegativeDuplicatePercentage(t *testing.T) {
_, err := generateEmails(0, -1)
assert.Error(t, err, "Didn't receive expected error when -1 duplicate count")
}
func TestGenerateGreaterDuplicatePercentage(t *testing.T) {
_, err := generateEmails(0, 2)
assert.Error(t, err, "Received expected error when -1 email count")
}
func TestGenerateDefaultEmails(t *testing.T) {
emails, _ := generateEmails(0, 0)
assert.EqualValues(t, 100000, len(emails), "Email count should match 100000")
dupeCount := GetDuplicateCount(emails)
assert.EqualValues(t, 50000, dupeCount, "Duplicate count should be 50000")
}
func TestGenerateSpecifiedEmailCount(t *testing.T) {
emails, _ := generateEmails(380, 0)
assert.EqualValues(t, 380, len(emails), "Email count should match 380")
dupeCount := GetDuplicateCount(emails)
assert.EqualValues(t, 190, dupeCount, "Duplicate count should be 190")
}
func TestGenerateSpecifiedDuplicatePercent(t *testing.T) {
emails, _ := generateEmails(0, 0.5)
assert.EqualValues(t, 100000, len(emails), "Email count should match 100000")
dupeCount := GetDuplicateCount(emails)
assert.EqualValues(t, 50000, dupeCount, "Duplicate count should be 50000")
}
func TestGenerateSpecificEmailAndDuplicateCounts(t *testing.T) {
emails, _ := generateEmails(1128, 0.3)
assert.EqualValues(t, 1128, len(emails), "Email count should match 1128")
dupeCount := GetDuplicateCount(emails)
assert.EqualValues(t, 338, dupeCount, "Duplicate count should be 338")
}
// Helper function to get duplicate count
func GetDuplicateCount(emails []string) int {
keys := make(map[string]bool)
deDupedEmails := []string{}
for _, email := range emails {
if _, value := keys[email]; !value {
keys[email] = true
deDupedEmails = append(deDupedEmails, email) // this returns all of the non dupes
}
}
return len(emails) - len(deDupedEmails)
}