-
Notifications
You must be signed in to change notification settings - Fork 0
/
persiangenderdetection_test.go
73 lines (66 loc) · 1.85 KB
/
persiangenderdetection_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
package persiangenderdetection
import (
"testing"
)
func TestClearName(t *testing.T) {
tests := []struct {
input string
expected string
}{
{" عــــلی ", "علی"},
{"بیــ🥲ــتا", "بیتا"},
{"محــ🌚ــمد", "محمد"},
{"۱۲۳مهناز۴۵۶", "مهناز"},
{"مهدي-1980", "مهدی"},
{"", ""},
}
for _, test := range tests {
result := clearName(test.input)
if result != test.expected {
t.Errorf("clearName(%s) = %s; expected %s", test.input, result, test.expected)
}
}
}
func TestGetGender(t *testing.T) {
tests := []struct {
name string
expected string
}{
{"آرمان", "MALE"},
{"بابك آذر مهر", "MALE"},
{"بی بی سلطان", "FEMALE"},
{"شیدا علیزاده", "FEMALE"},
{"ممد رضا", "MALE"},
{"پانتهآ عَبّاسی", "FEMALE"},
{"دکتر ندا حسینی", "FEMALE"}, // Name with prefix
{"سید امیر موسوی", "MALE"}, // Name with prefix
{"جناب آقای X", "MALE"}, // Name with prefix
{"سرکار خانم Y", "FEMALE"}, // Name with prefix
{"", "UNKNOWN"}, // Empty name
{"0", "UNKNOWN"}, // Name not in dataset
}
for _, test := range tests {
result := GetGender(test.name)
if result != test.expected {
t.Errorf("GetGender(%s) = %s; expected %s", test.name, result, test.expected)
}
}
}
func TestIsUnwantedRune(t *testing.T) {
tests := []struct {
r rune
expected bool
}{
{'!', true}, // Punctuation
{'آ', false}, // Valid character
{'ـ', false}, // Specific unwanted rune
{'1', true}, // Digit
{'\u200c', false}, // Zero width non-joiner
}
for _, test := range tests {
result := isUnwantedRune(test.r)
if result != test.expected {
t.Errorf("isUnwantedRune(%c) = %t; expected %t", test.r, result, test.expected)
}
}
}