-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d5fda9
commit 34c717e
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func GenerateRandomFolder() string { | ||
return fmt.Sprintf("folder/subfolder%d", rand.Intn(100000)) | ||
} | ||
|
||
func setupTest(t *testing.T) (*Trie, *assert.Assertions, string) { | ||
trie := NewTrie() | ||
a := assert.New(t) | ||
folderName := GenerateRandomFolder() | ||
return trie, a, folderName | ||
} | ||
|
||
func TestTrie_InsertAndGet(t *testing.T) { | ||
trie, a, folderName := setupTest(t) | ||
trie.Insert(folderName, 1) | ||
|
||
value, exists := trie.Get(folderName) | ||
a.True(exists) | ||
a.Equal(1, value) | ||
} | ||
|
||
func TestTrie_GetNonExistent(t *testing.T) { | ||
trie, a, folderName := setupTest(t) | ||
|
||
_, exists := trie.Get(folderName) | ||
a.False(exists) | ||
} | ||
|
||
func TestTrie_Delete(t *testing.T) { | ||
trie, a, folderName := setupTest(t) | ||
|
||
trie.Insert(folderName, 1) | ||
trie.Delete(folderName) | ||
|
||
_, exists := trie.Get(folderName) | ||
a.False(exists) | ||
} | ||
|
||
func TestTrie_DeletePartialPath(t *testing.T) { | ||
trie, a, folderName := setupTest(t) | ||
trie.Insert(folderName, 1) | ||
deleted := trie.Delete("folder") | ||
a.False(deleted) | ||
} |