Commit 0a64fd9

mo khan <mo.khan@gmail.com>
2019-11-16 21:30:18
TestDelete
1 parent 7236a8c
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)
 }
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()