dict: add delete method

This commit is contained in:
vinchent 2024-09-17 11:35:22 +02:00
parent c04a2e1d65
commit f573268be9
2 changed files with 19 additions and 0 deletions

View File

@ -48,3 +48,7 @@ func (d Dictionary) Update(word, definition string) error {
}
return nil
}
func (d Dictionary) Delete(word string) {
delete(d, word)
}

View File

@ -91,3 +91,18 @@ func TestUpdate(t *testing.T) {
assertError(t, err, ErrWordDoesNotExist)
})
}
func TestDelete(t *testing.T) {
t.Run("delete a word", func(t *testing.T) {
word := "test"
def := "this is just a test"
dict := Dictionary{word: def}
dict.Delete(word)
_, err := dict.Search(word)
if err == nil {
t.Fatal("expected to get an error")
}
assertError(t, err, ErrNotFound)
})
}