diff options
| author | mo khan <mo.khan@gmail.com> | 2019-11-16 14:30:18 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-11-16 14:30:18 -0700 |
| commit | 0a64fd96c2ef638295675f8fc9e426a11974a07c (patch) | |
| tree | d7a99423586edb8d541a676340bd402be8935116 | |
| parent | 7236a8c4dcf4879a0ed3f961c911cb75b3da64cd (diff) | |
TestDelete
| -rw-r--r-- | dictionary.go | 8 | ||||
| -rw-r--r-- | dictionary_test.go | 12 |
2 files changed, 17 insertions, 3 deletions
diff --git a/dictionary.go b/dictionary.go index 14eddd3..dd443aa 100644 --- a/dictionary.go +++ b/dictionary.go @@ -28,13 +28,12 @@ func (d Dictionary) Add(word, definition string) error { switch err { case ErrorNotFound: d[word] = definition + return nil case nil: return ErrorWordExists default: return err } - - return nil } func (d Dictionary) Update(word, definition string) error { @@ -45,9 +44,12 @@ func (d Dictionary) Update(word, definition string) error { return ErrorWordDoesNotExist case nil: d[word] = definition + return nil default: return err } +} - return nil +func (d Dictionary) Delete(word string) { + delete(d, word) } diff --git a/dictionary_test.go b/dictionary_test.go index a3a9907..9abb8d5 100644 --- a/dictionary_test.go +++ b/dictionary_test.go @@ -68,6 +68,18 @@ func TestUpdate(t *testing.T) { }) } +func TestDelete(t *testing.T) { + word := "test" + dictionary := Dictionary{word: "test definition"} + dictionary.Delete(word) + + _, err := dictionary.Search(word) + + if err != ErrorNotFound { + t.Errorf("Expected %q to be deleted", word) + } +} + func assertStrings(t *testing.T, got, want string) { t.Helper() |
