Removing all items

The ItemManager class needs to provide a method to remove all items. Add the following code to ItemManagerTests:

func test_RemoveAll_ResultsInCountsBeZero() { 
  

sut.add(ToDoItem(title: "Foo")) sut.add(ToDoItem(title: "Bar")) sut.checkItem(at: 0) XCTAssertEqual(sut.toDoCount, 1) XCTAssertEqual(sut.doneCount, 1) sut.removeAll() }

This code adds two to-do items to the manager and checks one item. Then, it asserts that the count of the items has the expected values and calls removeAll().

The code does not compile because removeAll() is not implemented yet. Add the minimal implementation needed to make the test code compilable:

func removeAll() { 
} 

Now, add the following assertions to test_RemoveAll_ResultsInCountsBeZero() to check whether the items have been removed:

XCTAssertEqual(sut.toDoCount, 0) 
XCTAssertEqual(sut.doneCount, 0) 

To make this test pass, we need to remove all the items from the underlying arrays. Add the following implementation in removeAll():

toDoItems.removeAll() 
doneItems.removeAll() 

Run the tests. All the tests pass and there is nothing to refactor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.148.105