<commit_before>#include "catch.hpp"

#include <storage/cache.h>

using namespace cheesebase;

SCENARIO("Reading and writing to cache.")
{
  GIVEN("A cache")
  {
    Cache cache{ "test.db", OpenMode::create_always, 8 };
  }
}<commit_msg>add simple Cache test case<commit_after>#include "catch.hpp"

#include <storage/cache.h>

using namespace cheesebase;

SCENARIO("Reading and writing to cache.")
{
  GIVEN("A cache")
  {
    Cache cache{ "test.db", OpenMode::create_always, 8 };
    
    WHEN("data is written to a page")
    {
      const PageNr page{ 5 };
      const size_t offset{ 100 };
      const std::string test{ "ABCDEFGHIJKLMNOP" };
      {
        auto p = cache.write(page);
        std::copy(test.begin(), test.end(), p.get_write().data() + offset);
      }
      
      THEN("same data can be read")
      {
        auto p = cache.read(page);
        REQUIRE(std::equal(test.begin(), test.end(), p.get().data() + offset));
      }

      AND_WHEN("many other pages are read")
      {
        for (PageNr i = 0; i < 20; ++i)
          cache.read(i);

        THEN("same data can sill be read")
        {
          auto p = cache.read(page);
          REQUIRE(std::equal(test.begin(), test.end(), p.get().data() + offset));
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.15943172849250198, 'fraction_numerical': 0.007103393843725336, 'mean_word_length': 2.3994638069705094, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '621781', 'n_tokens_mistral': 453, 'n_tokens_neox': 432, 'n_words': 105}