def test_inserted(self): r = RecentlyUsedList() r.add_used_item('shoes') r.add_used_item('clothes') r.add_used_item('shoes') r.add_used_item('accessories') self.assertTrue(len(r.recently_used) > 0)
def test_duplicates(self): r = RecentlyUsedList() r.add_used_item('shoes') r.add_used_item('clothes') r.add_used_item('shoes') r.add_used_item('accessories') self.assertEquals(len(r.recently_used), 3)
def test_recently_used_list_with_overflow(): rul = RecentlyUsedList(limit=1) rul.add('A') assert len(rul) == 1 rul.add('B') assert len(rul) == 1 rul = RecentlyUsedList(limit=10) for i in range(1, 20): rul.add(str(i)) assert len(rul) == 10 assert rul.items == [ '19', '18', '17', '16', '15', '14', '13', '12', '11', '10' ]
def test_adding_exist_item_should_move_to_top(self): recents = RecentlyUsedList() recents.add_item('A') recents.add_item('B') recents.add_item('A') top_item = recents.get_top_item() self.assertEqual(top_item, 'A') self.assertEqual(recents.size(), 2)
def test_lookup_item_by_index(self): recents = RecentlyUsedList() recents.add_item('A') recents.add_item('B') recents.add_item('C') recents.add_item('D') item_1 = recents.get_item(1) self.assertEqual(item_1, 'C') item_2 = recents.get_item(2) self.assertEqual(item_2, 'B')
def test_most_recent(self): r = RecentlyUsedList() r.add_used_item('shoes') r.add_used_item('clothes') r.add_used_item('shoes') r.add_used_item('accessories') self.assertEquals(r.get_recently_used_item(), 'accessories')
def test_most_recently_added_item_is_top(self): recents = RecentlyUsedList() recents.add_item('A') recents.add_item('B') top_item = recents.get_top_item() self.assertEqual(top_item, 'B')
def test_bounded_capacity(self): recents = RecentlyUsedList(5) recents.add_item('A') recents.add_item('B') recents.add_item('C') recents.add_item('D') recents.add_item('E') self.assertEqual(recents.size(), 5) self.assertEqual(recents.get_bottom_item(), 'A') recents.add_item('F') self.assertEqual(recents.size(), 5) self.assertEqual(recents.get_bottom_item(), 'B')
def test_list_is_initially_empty(self): recents = RecentlyUsedList() self.assertEqual(recents.size(), 0)
def test_lookup_item_out_of_range(self): recents = RecentlyUsedList() recents.add_item('A') recents.add_item('B') self.assertRaises(IndexError, recents.get_item, 5)
def test_least_recently_added_item_is_bottom(self): recents = RecentlyUsedList() recents.add_item('A') recents.add_item('B') bottom_item = recents.get_bottom_item() self.assertEqual(bottom_item, 'A')
def test_recently_used_list(): rul = RecentlyUsedList() assert len(rul) == 0 rul.add('A') assert len(rul) == 1 rul.add('B') assert len(rul) == 2 assert rul[0] == 'B' assert rul[-1] == 'A' rul.add('B') assert len(rul) == 2 assert rul[0] == 'B' assert rul[1] == 'A' rul.add('A') assert len(rul) == 2 assert rul[0] == 'A' assert rul[1] == 'B' with pytest.raises(TypeError): rul.add() with pytest.raises(ValueError): rul.add('') with pytest.raises(ValueError): rul.add(True) with pytest.raises(ValueError): rul.add(object)