dict: add delete method
This commit is contained in:
		@ -48,3 +48,7 @@ func (d Dictionary) Update(word, definition string) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d Dictionary) Delete(word string) {
 | 
				
			||||||
 | 
						delete(d, word)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -91,3 +91,18 @@ func TestUpdate(t *testing.T) {
 | 
				
			|||||||
		assertError(t, err, ErrWordDoesNotExist)
 | 
							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)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user