github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/trie/ac/ac_test.go (about)

     1  package ac
     2  
     3  import "testing"
     4  
     5  func TestAC(t *testing.T) {
     6  	a := NewAC()
     7  
     8  	a.Insert(".baidu.")
     9  	a.Insert(".google.")
    10  	a.Insert("www.google.com")
    11  	a.Insert("music.163.com")
    12  	a.Insert("music.163")
    13  	a.Insert("163.com")
    14  	a.Insert("a")
    15  	a.Insert("aa")
    16  	a.Insert("aaa")
    17  	a.Insert("aaaa")
    18  	a.Insert("aaaaa")
    19  	a.BuildFail()
    20  
    21  	t.Log(a.searchLongest("www.baidu.aaaaa.com"))
    22  	t.Log(a.searchLongest("www.google.baidu.com"))
    23  	t.Log(a.searchLongest("www.goaoaga.com"))
    24  	t.Log(a.searchLongest("a.www.google.com"))
    25  	t.Log(a.searchLongest("music.163.com"))
    26  	t.Log(a.searchLongest("s.163.com"))
    27  	t.Log(a.searchLongest("music.163.net"))
    28  }
    29  
    30  func TestAC2(t *testing.T) {
    31  	a := NewAC()
    32  	a.Insert("she")
    33  	a.Insert("he")
    34  	a.Insert("hers")
    35  	a.Insert("his")
    36  	a.BuildFail()
    37  
    38  	t.Log(a.search("ushers"))
    39  }