Skip to content

Commit

Permalink
fix([trash collection]): fix cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukiMoriarty committed Jun 18, 2024
1 parent d4c8e0e commit e4dd2a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions calmapf/src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ bool Cache::_is_cargo_in_coming_cache(Vertex* cargo) {

bool Cache::_is_garbage_collection(int group) {
for (uint i = 0; i < is_empty[group].size(); i++) {
if (is_empty[group][i]) return true;
if (is_empty[group][i]) return false;
}
return false;
return true;
}

bool Cache::look_ahead_cache(Vertex* cargo) {
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ TEST(Cache, cache_LRU_single_port_test)
ASSERT_EQ(true, cache._is_cargo_in_coming_cache(cargo_4));
ASSERT_EQ(false, cache._is_cargo_in_coming_cache(cargo_5));

// Test `_is_garbage_collection`
ASSERT_EQ(true, cache._is_garbage_collection(0));

// Test `try_cache_cargo(Vertex* cargo)`
// We will get lock block cache_1 with cargo_1
// LRU_cnt: (4, 2, 1)
Expand All @@ -108,6 +111,12 @@ TEST(Cache, cache_LRU_single_port_test)
ASSERT_EQ(CacheAccessResult(false, unloading_port), cache.try_insert_cache(cargo_1, port_list[0]));
ASSERT_EQ(CacheAccessResult(false, unloading_port), cache.try_insert_cache(cargo_4, port_list[0]));
ASSERT_EQ(2, cache._get_cache_evited_policy_index(0));

// Test `try_cache_garbage_collection`
ASSERT_EQ(CacheAccessResult(true, cache_3), cache.try_cache_garbage_collection(cargo_5));

// Test `clear_cargo_from_cache`
ASSERT_EQ(true, cache.clear_cargo_from_cache(cargo_3, cache_3));
ASSERT_EQ(CacheAccessResult(true, cache_3), cache.try_insert_cache(cargo_5, port_list[0]));
ASSERT_EQ(cargo_5, cache.node_coming_cargo[0][2]);

Expand Down Expand Up @@ -215,6 +224,9 @@ TEST(Cache, cache_FIFO_single_port_test)
ASSERT_EQ(true, cache._is_cargo_in_coming_cache(cargo_4));
ASSERT_EQ(false, cache._is_cargo_in_coming_cache(cargo_5));

// Test `_is_garbage_collection`
ASSERT_EQ(true, cache._is_garbage_collection(0));

// Test `try_cache_cargo(Vertex* cargo)`
// We will get lock block cache_1 with cargo_1
// FIFO_cnt: (3, 2, 1)
Expand All @@ -227,6 +239,13 @@ TEST(Cache, cache_FIFO_single_port_test)
ASSERT_EQ(CacheAccessResult(false, unloading_port), cache.try_insert_cache(cargo_1, port_list[0]));
ASSERT_EQ(CacheAccessResult(false, unloading_port), cache.try_insert_cache(cargo_4, port_list[0]));
ASSERT_EQ(2, cache._get_cache_evited_policy_index(0));

// Test `try_cache_garbage_collection`
ASSERT_EQ(CacheAccessResult(true, cache_3), cache.try_cache_garbage_collection(cargo_5));

// Test `clear_cargo_from_cache`
ASSERT_EQ(true, cache.clear_cargo_from_cache(cargo_3, cache_3));

ASSERT_EQ(CacheAccessResult(true, cache_3), cache.try_insert_cache(cargo_5, port_list[0]));
ASSERT_EQ(cargo_5, cache.node_coming_cargo[0][2]);

Expand Down

0 comments on commit e4dd2a0

Please sign in to comment.