コード例 #1
0
    def test_single_thread_insertion_test_few_unique_keys(self):
        print(
            '\nRunning single threaded insertion test with few unique keys\n')
        self.dictionary = Dictionary()
        self.reference = dict()
        self.insert_random(10000, 0, 1)

        self.assert_insertion_tests_passed()
コード例 #2
0
    def test_multi_thread_insertion_test_few_unique_keys(self):
        print('\nRunning multi threaded insertion test with few unique keys\n')
        self.dictionary = Dictionary()
        self.reference = dict()

        threads = [
            Thread(target=self.insert_random,
                   args=(1000, 0, 1),
                   kwargs={'thread_id': i}) for i in range(1, 11)
        ]

        for t in threads:
            t.start()

        for t in threads:
            t.join()

        self.assert_insertion_tests_passed()
コード例 #3
0
    def test_popitem(self):
        print('\nRunning popitem test\n')
        self.dictionary = Dictionary()
        n = 10000
        self.fill_dict_with_ints(n)

        t1 = self.popitem_all()
        t2 = self.delete_all(n)

        t1.join()
        t2.join()

        msg = "'popitem(): dictionary is empty'"
        excpt_msg = t1.ret_val[0]

        self.assertEqual(
            excpt_msg,
            msg,
            msg="Popitem returned '{}', should return '{}'".format(
                excpt_msg, msg))
コード例 #4
0
    def test_pop(self):
        print('\nRunning pop test\n')
        self.dictionary = Dictionary()
        n = 10000
        default = 2
        self.fill_dict_with_ints(n)

        t1 = self.pop_all(n, default)
        t2 = self.delete_all(n)

        t1.join()
        t2.join()

        ret_val, value, expected = t1.ret_val[0]

        self.assertTrue(
            ret_val,
            msg="pop returned {}, expected to return {} or {}".format(
                value,
                expected,
                default,
            ))