327768f4ad
Use [33]byte for graph vertex representation. Delete unneeded stuff: 1. DeepEqual for graph comparison 2. EdgePath 3. 2-thread BFS 4. Table transfer messages and neighborhood radius 5. Beacons Refactor: 1. Change ID to Vertex 2. Test use table driven approach 3. Add comments 4. Make graph internal representation private 5. Use wire.OutPoint as EdgeId 6. Decouple routing messages from routing implementation 7. Delete Async methods 8. Delete unneeded channels and priority buffer from manager 9. Delete unneeded interfaces in internal graph realisation 10. Renamed ID to Vertex
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
// Copyright (c) 2016 Bitfury Group Limited
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
|
|
|
package prefix_tree
|
|
|
|
import "testing"
|
|
|
|
func TestPrefixTree(t *testing.T) {
|
|
pt := NewPrefixTree()
|
|
pt.Add("walk")
|
|
pt.Add("hello")
|
|
pt.Add("hi")
|
|
pt.Add("hell")
|
|
pt.Add("world")
|
|
pt.Add("www")
|
|
|
|
shortcut, _ := pt.Shortcut("world")
|
|
if expected := "wo"; shortcut != expected {
|
|
t.Errorf("expected: %s, actual: %s", expected, shortcut)
|
|
}
|
|
|
|
shortcut, _ = pt.Shortcut("www")
|
|
if expected := "ww"; shortcut != expected {
|
|
t.Errorf("expected: %s, actual: %s", expected, shortcut)
|
|
}
|
|
|
|
autocompleted, _ := pt.Autocomplete("wo")
|
|
if expected := "world"; autocompleted != expected {
|
|
t.Errorf("expected: %s, actual: %s", expected, autocompleted)
|
|
}
|
|
|
|
autocompleted, _ = pt.Autocomplete("ww")
|
|
if expected := "www"; autocompleted != expected {
|
|
t.Errorf("expected: %s, actual: %s", expected, autocompleted)
|
|
}
|
|
|
|
pt.Add("123")
|
|
pt.Add("456")
|
|
pt.Add("1234")
|
|
|
|
shortcut, _ = pt.Shortcut("123")
|
|
if expected := "123"; shortcut != expected {
|
|
t.Errorf("expected: %s, actual: %s", expected, shortcut)
|
|
}
|
|
}
|
|
|
|
func TestPrefixTreeOneNode(t *testing.T) {
|
|
pt := NewPrefixTree()
|
|
pt.Add("123")
|
|
shortcut, err := pt.Shortcut("123")
|
|
if err != nil {
|
|
t.Errorf("error getting shortcut for 123: %v, want: %v", err, nil)
|
|
}
|
|
expectedShortcut := "1"
|
|
if shortcut != expectedShortcut {
|
|
t.Errorf("expected: %v, actual: %v", expectedShortcut, shortcut)
|
|
}
|
|
|
|
expectedAutocomplete := "123"
|
|
autocomplete, err := pt.Autocomplete("123")
|
|
|
|
if err != nil {
|
|
t.Errorf("error getting autocomplete for 123: %v, want: %v", err, nil)
|
|
}
|
|
if autocomplete != expectedAutocomplete {
|
|
t.Errorf("expected: %v, actual: %v", expectedAutocomplete, autocomplete)
|
|
}
|
|
|
|
}
|