def test_queuesnapshot(self): kv_pairs = get_key_value_pairs(length=self.capacity * 2) # Insert keys for key, value in kv_pairs: self.lrucache.put(key, value) # Keep track of key order manually keys = list(map(lambda item: item[0], kv_pairs[self.capacity:]))[::-1] # Add new element key = get_random_key() value = get_random_string() self.lrucache.put(key, value) keys.pop(-1) keys.insert(0, key) # Access last element self.lrucache.get(keys[-1]) keys.insert(0, keys.pop(-1)) # Update an element rand_index = random.randint(*(0, len(keys) - 1)) self.lrucache.put(keys[rand_index], get_random_string()) keys.insert(0, keys.pop(rand_index)) # Check Linked List self.assertListEqual(keys, get_list(self.lrucache.head))
def test_updatekey(self): key = get_random_key() value = get_random_string() self.lrucache.put(key, value) self.assertEqual(self.lrucache.get(key), value) value = get_random_string() self.lrucache.put(key, value) self.assertEqual(self.lrucache.get(key), value) self.assertEqual(self.lrucache.current_size, 1)
def test_getkey(self): # Add Element to cache key = get_random_key() value = get_random_string() self.lrucache.put(key, value) self.assertEqual(self.lrucache.get(key), value) self.assertEqual(self.lrucache.current_size, 1)
def test_addkey(self): # Add Element to cache key = get_random_key() value = get_random_string() self.lrucache.put(key, value) self.assertEqual(self.lrucache.store[key].value, value) self.assertEqual(self.lrucache.current_size, 1)
def test_deletekey(self): key = get_random_key() value = get_random_string() self.lrucache.put(key, value) self.assertEqual(self.lrucache.current_size, 1) self.lrucache.delete(key) self.assertEqual(self.lrucache.get(key), -1) self.assertEqual(self.lrucache.head, None)
def test_generate_dirname_with_level(self): random_dest_path = '/'.join(utils.get_random_string() for _ in range(3)) self.action.dest_path = random_dest_path self.action.level_folders = ['test'] random_test_path = os.path.join( random_dest_path, self.action.level_folders[self.action.level], ) self.assertEqual(random_test_path, self.action.generate_dirname())
def test_return_std_as_str(self): test_data = utils.get_random_string() payload = 'echo "{0}"'.format(test_data) return_data = self.action.execute_cmdline( cmdline=payload, return_stdout=True, )[:-1] self.assertEqual(test_data, return_data)
def test_generate_dirname_with_chosen_level(self): random_dest_path = '/'.join(utils.get_random_string() for _ in range(3)) self.action.dest_path = random_dest_path self.action.level_folders = ['test', 'example'] level = 1 random_test_path = os.path.join( random_dest_path, self.action.level_folders[level], ) self.assertEqual(random_test_path, self.action.generate_dirname(level=level))
def test_lrukey_update(self): """[Test whcih is the top key after write key update] """ kv_pairs = get_key_value_pairs(length=5) # Insert keys for key, value in kv_pairs: self.lrucache.put(key, value) self.assertEqual(self.lrucache.current_size, len(kv_pairs)) rand_index = random.randint(*(0, len(kv_pairs) - 1)) value = get_random_string() self.lrucache.put(kv_pairs[rand_index][0], value) self.assertEqual(self.lrucache.head.key, kv_pairs[rand_index][0]) self.assertEqual(self.lrucache.head.value, value)
def test_generate_dirname_without_folders(self): random_dest_path = '/'.join(utils.get_random_string() for _ in range(3)) self.action.dest_path = random_dest_path self.assertEqual(random_dest_path, self.action.generate_dirname())
def setUp(self): name = utils.get_random_string() self.action = TarArchiver(name)
def setUp(self): name = utils.get_random_string() self.action = Action(name)