當前位置: 首頁>>代碼示例>>Golang>>正文


Golang StringVector.Cut方法代碼示例

本文整理匯總了Golang中container/vector.StringVector.Cut方法的典型用法代碼示例。如果您正苦於以下問題:Golang StringVector.Cut方法的具體用法?Golang StringVector.Cut怎麽用?Golang StringVector.Cut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在container/vector.StringVector的用法示例。


在下文中一共展示了StringVector.Cut方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestMultiFind

func TestMultiFind(t *testing.T) {
	trie := NewTrie()

	// these are part of the matches for the word 'hyphenation'
	trie.AddString(`hyph`)
	trie.AddString(`hen`)
	trie.AddString(`hena`)
	trie.AddString(`henat`)

	expected := new(vector.StringVector)
	expected.Push(`hyph`)
	found := trie.AllSubstrings(`hyphenation`)
	if found.Len() != expected.Len() {
		t.Errorf("expected %v but found %v", *expected, *found)
	}

	expected.Cut(0, expected.Len())
	expected.Push(`hen`)
	expected.Push(`hena`)
	expected.Push(`henat`)
	found = trie.AllSubstrings(`henation`)
	if found.Len() != expected.Len() {
		t.Errorf("expected %v but found %v", *expected, *found)
	}
}
開發者ID:AlanQuatermain,項目名稱:go-trie,代碼行數:25,代碼來源:trie_test.go

示例2: TestMultiFindValue

func TestMultiFindValue(t *testing.T) {
	trie := NewTrie()

	// these are part of the matches for the word 'hyphenation'
	trie.AddPatternString(`hy3ph`)
	trie.AddPatternString(`he2n`)
	trie.AddPatternString(`hena4`)
	trie.AddPatternString(`hen5at`)

	v1 := &vector.IntVector{0, 3, 0, 0}
	v2 := &vector.IntVector{0, 2, 0}
	v3 := &vector.IntVector{0, 0, 0, 4}
	v4 := &vector.IntVector{0, 0, 5, 0, 0}

	expectStr := new(vector.StringVector)
	expectVal := new(vector.Vector) // contains elements of type *vector.IntVector

	expectStr.Push(`hyph`)
	expectVal.Push(v1)
	found, values := trie.AllSubstringsAndValues(`hyphenation`)
	if found.Len() != expectStr.Len() {
		t.Errorf("expected %v but found %v", *expectStr, *found)
	}
	if values.Len() != expectVal.Len() {
		t.Errorf("Length mismatch: expected %v but found %v", *expectVal, *values)
	}
	for i := 0; i < found.Len(); i++ {
		if found.At(i) != expectStr.At(i) {
			t.Errorf("Strings content mismatch: expected %v but found %v", *expectStr, *found)
			break
		}
	}
	for i := 0; i < values.Len(); i++ {
		ev := expectVal.At(i).(*vector.IntVector)
		fv := values.At(i).(*vector.IntVector)
		if ev.Len() != fv.Len() {
			t.Errorf("Value length mismatch: expected %v but found %v", *ev, *fv)
			break
		}
		for i := 0; i < ev.Len(); i++ {
			if ev.At(i) != fv.At(i) {
				t.Errorf("Value mismatch: expected %v but found %v", *ev, *fv)
				break
			}
		}
	}

	expectStr.Cut(0, expectStr.Len())
	expectVal.Cut(0, expectVal.Len())

	expectStr.AppendVector(&vector.StringVector{`hen`, `hena`, `henat`})
	expectVal.Push(v2)
	expectVal.Push(v3)
	expectVal.Push(v4)
	found, values = trie.AllSubstringsAndValues(`henation`)
	if found.Len() != expectStr.Len() {
		t.Errorf("expected %v but found %v", *expectStr, *found)
	}
	if values.Len() != expectVal.Len() {
		t.Errorf("Length mismatch: expected %v but found %v", *expectVal, *values)
	}
	for i := 0; i < found.Len(); i++ {
		if found.At(i) != expectStr.At(i) {
			t.Errorf("Strings content mismatch: expected %v but found %v", *expectStr, *found)
			break
		}
	}
	for i := 0; i < values.Len(); i++ {
		ev := expectVal.At(i).(*vector.IntVector)
		fv := values.At(i).(*vector.IntVector)
		if ev.Len() != fv.Len() {
			t.Errorf("Value length mismatch: expected %v but found %v", *ev, *fv)
			break
		}
		for i := 0; i < ev.Len(); i++ {
			if ev.At(i) != fv.At(i) {
				t.Errorf("Value mismatch: expected %v but found %v", *ev, *fv)
				break
			}
		}
	}
}
開發者ID:AlanQuatermain,項目名稱:go-trie,代碼行數:82,代碼來源:trie_test.go


注:本文中的container/vector.StringVector.Cut方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。