Skip to content

Commit

Permalink
Added UT
Browse files Browse the repository at this point in the history
  • Loading branch information
ashruti-msft committed Oct 18, 2024
1 parent 5d5fda9 commit 34c717e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions common/trieForDirPath_test.go
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)
}

0 comments on commit 34c717e

Please sign in to comment.