Compare commits
No commits in common. "61aa84c691e45019ab637006f6ecc3469c062c6a" and "3fe77430f2f8d1b52597c7278edb7f0e6267ccc9" have entirely different histories.
61aa84c691
...
3fe77430f2
13
dict.go
13
dict.go
@ -25,8 +25,6 @@ func NewChineseDict(filePath string) (*ChineseDict, error) {
|
|||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
buf := make([]byte, 0, bufio.MaxScanTokenSize)
|
|
||||||
scanner.Buffer(buf, 5*1024*1024) // 5MB buffer to handle long lines
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := strings.TrimSpace(scanner.Text())
|
||||||
if line != "" { // Skip empty lines
|
if line != "" { // Skip empty lines
|
||||||
@ -77,17 +75,6 @@ func (cd *ChineseDict) GetRandomCharacter() rune {
|
|||||||
return 0 // Return null rune if no lines available
|
return 0 // Return null rune if no lines available
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cd.lines) == 1 {
|
|
||||||
if cd.currentLineIndex == -1 {
|
|
||||||
cd.selectNewRandomLine()
|
|
||||||
}
|
|
||||||
// Get random index
|
|
||||||
randomIndex := rand.Intn(len(cd.currentLineRunes))
|
|
||||||
cd.currentCharIndex = randomIndex + 1 // Move index forward for next call, align with multiline version for testing
|
|
||||||
|
|
||||||
return cd.currentLineRunes[randomIndex]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep track of attempts to avoid infinite recursion
|
// Keep track of attempts to avoid infinite recursion
|
||||||
maxAttempts := len(cd.lines) * 2 // Try each line at least twice
|
maxAttempts := len(cd.lines) * 2 // Try each line at least twice
|
||||||
attempts := 0
|
attempts := 0
|
||||||
|
|||||||
70
dict_test.go
70
dict_test.go
@ -48,32 +48,6 @@ func TestDictE2E(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDictE2ESingleLineVer(t *testing.T) {
|
|
||||||
dict, err := NewChineseDict("random_char.txt")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("NewChineseDict failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for range 1000 {
|
|
||||||
char := dict.GetRandomCharacter()
|
|
||||||
fmt.Printf("%c", char)
|
|
||||||
if char == 0 {
|
|
||||||
t.Error("GetRandomCharacter returned null rune")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
count := dict.GetCharacterCount()
|
|
||||||
if count == 0 {
|
|
||||||
t.Error("GetCharacterCount returned 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
count = dict.GetLineCount()
|
|
||||||
if count == 0 {
|
|
||||||
t.Error("GetLineCount returned 0")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewChineseDict(t *testing.T) {
|
func TestNewChineseDict(t *testing.T) {
|
||||||
testContent := `大家好大家好,家人们晚上好
|
testContent := `大家好大家好,家人们晚上好
|
||||||
先点点关注不迷路,点个小红心
|
先点点关注不迷路,点个小红心
|
||||||
@ -450,47 +424,3 @@ Another行with more混合content。`
|
|||||||
|
|
||||||
t.Logf("Got %d Chinese and %d English characters", chineseCount, englishCount)
|
t.Logf("Got %d Chinese and %d English characters", chineseCount, englishCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSingleLineContent(t *testing.T) {
|
|
||||||
testContent := `华枝睾吸虫豆卷叶野螟小叶榕木`
|
|
||||||
//黄眉企鹅五房` for multiline false test
|
|
||||||
|
|
||||||
tmpFile := createTestDictFile(t, testContent)
|
|
||||||
defer os.Remove(tmpFile)
|
|
||||||
|
|
||||||
dict, err := NewChineseDict(tmpFile)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("NewChineseDict failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
runeInPosition := 0
|
|
||||||
currentPosition := -1
|
|
||||||
|
|
||||||
for range 100 {
|
|
||||||
char := dict.GetRandomCharacter()
|
|
||||||
if char == 0 {
|
|
||||||
t.Error("Got null character")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !dict.isValidCharacter(char) {
|
|
||||||
t.Errorf("Got invalid character: '%c' (U+%04X)", char, char)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if char == '华' || char == '黄' {
|
|
||||||
currentPosition = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentPosition+1 == dict.currentCharIndex {
|
|
||||||
runeInPosition++
|
|
||||||
currentPosition++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if runeInPosition == 100 {
|
|
||||||
t.Error("GetRandomCharacter is not random enough, always returning characters in sequence")
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("Rune in position: %d", runeInPosition)
|
|
||||||
}
|
|
||||||
|
|||||||
2
main.go
2
main.go
@ -68,7 +68,7 @@ func main() {
|
|||||||
setConsoleUTF8()
|
setConsoleUTF8()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("MITM Proxy Server v1.5")
|
fmt.Println("MITM Proxy Server v1.4")
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
config, err := loadConfig("config.toml")
|
config, err := loadConfig("config.toml")
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user