def test_worst_case(self):
        n = phone_book.MAX_QUERIES
        contacts = {}
        fake = Factory.create()
        for i in range(phone_book.MAX_NUMBER, phone_book.MAX_NUMBER - (n // 2),
                       -1):
            contacts[i] = fake.first_name()[:phone_book.MAX_NAME_LEN]

        numbers = contacts.keys()
        # Create n // 2 add queries
        add_queries = [
            phone_book.Query(('add', str(num), name))
            for num, name in contacts.items()
        ]

        # Create n // 4 del queries
        _nums = list(numbers)
        random.shuffle(_nums)
        del_queries = [
            phone_book.Query(('del', str(num))) for num in _nums[:n // 4]
        ]

        # Create n // 4 find queries
        random.shuffle(_nums)
        find_queries = [
            phone_book.Query(('find', str(num))) for num in _nums[:n // 4]
        ]

        queries = add_queries + del_queries + find_queries
        random.shuffle(queries)
        expected = self.process_queries_dict(queries)
        result = phone_book.process_queries(queries)
        assert result == expected
    def test_worst_case(self):
        n = phone_book.MAX_QUERIES
        contacts = {}
        fake = Factory.create()
        for i in range(phone_book.MAX_NUMBER, phone_book.MAX_NUMBER-(n//2), -1):
            contacts[i] = fake.first_name()[:phone_book.MAX_NAME_LEN]

        numbers = contacts.keys()
        # Create n // 2 add queries
        add_queries = [phone_book.Query(('add', str(num), name))
                       for num, name in contacts.items()]

        # Create n // 4 del queries
        _nums = list(numbers)
        random.shuffle(_nums)
        del_queries = [phone_book.Query(('del', str(num)))
                       for num in _nums[:n // 4]]

        # Create n // 4 find queries
        random.shuffle(_nums)
        find_queries = [phone_book.Query(('find', str(num)))
                        for num in _nums[:n // 4]]

        queries = add_queries + del_queries + find_queries
        random.shuffle(queries)
        expected = self.process_queries_dict(queries)
        result = phone_book.process_queries(queries)
        assert result == expected
 def test_one_find(self):
     test_input = ["find 911"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == ["not found"]
 def test_one_del(self):
     test_input = ["del 911"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == []
 def test_one_add(self):
     test_input = ["add 911 police"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == []
 def test_samples(self, test_input, expected):
     queries = [phone_book.Query(q.split()) for q in test_input]
     exp = self.process_queries_dict(queries)
     assert exp == expected
     result = phone_book.process_queries(queries)
     assert result == expected
 def test_one_find(self):
     test_input = ["find 911"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == ["not found"]
 def test_one_del(self):
     test_input = ["del 911"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == []
 def test_one_add(self):
     test_input = ["add 911 police"]
     queries = [phone_book.Query(q.split()) for q in test_input]
     result = phone_book.process_queries(queries)
     assert result == []
 def test_samples(self, test_input, expected):
     queries = [phone_book.Query(q.split()) for q in test_input]
     exp = self.process_queries_dict(queries)
     assert exp == expected
     result = phone_book.process_queries(queries)
     assert result == expected