dict: add delete method
This commit is contained in:
parent
c04a2e1d65
commit
f573268be9
@ -48,3 +48,7 @@ func (d Dictionary) Update(word, definition string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Dictionary) Delete(word string) {
|
||||
delete(d, word)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user