Skip to content

Commit 2bf8ea0

Browse files
generatedunixname478564801243445facebook-github-bot
authored andcommitted
Add tests to cover changes in D81283852
Summary: This diff is automatically generated by [Devmate for Testing](https://fburl.com/dm4t-diff-time). Help us improve by reviewing the diff! It adds more tests to cover changes in `FixedSizeIndex.cpp` in D81283852. You can find additional information here: P1923418155. Review this diff as you would review your peer's code. If the tests are useful to you: * **To land them as is**, accept the diff. It will be landed automatically when the parent diff is landed. * **To add them to the original diff D81283852**, run `testcompose get ...` as shown below. This diff will then be auto-abandoned when you land the original diff. * Alternatively, you can also commandeer the diff, make changes and land it yourself. https://our.intern.facebook.com/intern/testcompose/merge-diffs/ If the tests are not useful, send the diff **Back to Author**. The diff will then be auto-abandoned. Write any feedback (positive and negative) about this diff in the comments. Our team uses it to improve the tool. Read more about the diff-time Devmate for Testing in [the wiki](https://fburl.com/dm4t-diff-time). Questions and feedback are welcome in [the support group](https://fb.workplace.com/groups/mm4tfeedback). Reviewed By: byahn0996 Differential Revision: D81314250 fbshipit-source-id: d96ae611a1eb47743b878cd3a64c5f4b0cde799d
1 parent 1442769 commit 2bf8ea0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

cachelib/navy/block_cache/tests/FixedSizeIndexTest.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,52 @@ TEST(FixedSizeIndex, MemFootprintRangeTest) {
237237
EXPECT_EQ(range.maxUsedBytes, rangeEmpty.maxUsedBytes);
238238
}
239239

240+
TEST(FixedSizeIndex, Reset) {
241+
FixedSizeIndex index{1, 8, 16};
242+
243+
// Insert some items
244+
for (int i = 0; i < 100; i++) {
245+
index.insert(i, i + 100, 200);
246+
// Verify items are in the index
247+
EXPECT_TRUE(index.lookup(i).found());
248+
EXPECT_EQ(i + 100, index.lookup(i).address());
249+
}
250+
251+
// Reset the index
252+
index.reset();
253+
254+
// Verify all items are removed
255+
for (int i = 0; i < 100; i++) {
256+
EXPECT_FALSE(index.lookup(i).found());
257+
}
258+
}
259+
260+
TEST(FixedSizeIndex, ComputeSize) {
261+
FixedSizeIndex index{1, 8, 16};
262+
263+
// Initially the size should be 0
264+
EXPECT_EQ(0, index.computeSize());
265+
266+
// Insert some items
267+
const int numItems = 50;
268+
for (int i = 0; i < numItems; i++) {
269+
index.insert(i, i + 100, 200);
270+
// Verify items are in the index
271+
EXPECT_TRUE(index.lookup(i).found());
272+
}
273+
274+
// Verify the size matches the number of items inserted
275+
EXPECT_EQ(numItems, index.computeSize());
276+
277+
// Remove some items
278+
const int numToRemove = 20;
279+
for (int i = 0; i < numToRemove; i++) {
280+
index.remove(i);
281+
EXPECT_FALSE(index.lookup(i).found());
282+
}
283+
284+
// Verify the size is updated correctly
285+
EXPECT_EQ(numItems - numToRemove, index.computeSize());
286+
}
287+
240288
} // namespace facebook::cachelib::navy::tests

0 commit comments

Comments
 (0)