<commit_before>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// cache_test.cpp
//
// Identification: tests/common/cache_test.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "harness.h"

#include "backend/common/cache.h"
#include "backend/common/logger.h"
#include "backend/planner/mock_plan.h"

#include "backend/bridge/dml/mapper/mapper.h"

#include <unordered_set>

namespace peloton {
namespace test {

//===--------------------------------------------------------------------===//
// Cache Test
//===--------------------------------------------------------------------===//

class CacheTest : public PelotonTest {};

#define CACHE_SIZE 5

static void fill(
    std::vector<std::shared_ptr<const planner::AbstractPlan> > &vec, int n) {
  for (int i = 0; i < n; i++) {
    std::shared_ptr<const planner::AbstractPlan> plan(
        new MockPlan(), bridge::PlanTransformer::CleanPlan);
    vec.push_back(std::move(plan));
  }
}

/**
 * Test basic functionality
 *
 */
TEST_F(CacheTest, Basic) {
  Cache<uint32_t, const planner::AbstractPlan> cache(
      CACHE_SIZE, bridge::PlanTransformer::CleanPlan, 1);

  EXPECT_EQ(0, cache.size());
  EXPECT_EQ(true, cache.empty());
}

/**
 *  Test find operation
 *
 */
TEST_F(CacheTest, Find) {
  Cache<uint32_t, const planner::AbstractPlan> cache(
      CACHE_SIZE, bridge::PlanTransformer::CleanPlan, 1);<commit_msg>fix memory leak in unit test<commit_after>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// cache_test.cpp
//
// Identification: tests/common/cache_test.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "harness.h"

#include "backend/common/cache.h"
#include "backend/common/logger.h"
#include "backend/planner/mock_plan.h"

#include "backend/bridge/dml/mapper/mapper.h"

#include <unordered_set>

namespace peloton {
namespace test {

//===--------------------------------------------------------------------===//
// Cache Test
//===--------------------------------------------------------------------===//

class CacheTest : public PelotonTest {};

#define CACHE_SIZE 5

static void fill(
    std::vector<std::shared_ptr<const planner::AbstractPlan> > &vec, int n) {
  for (int i = 0; i < n; i++) {
    std::shared_ptr<const planner::AbstractPlan> plan(new MockPlan());
    vec.push_back(std::move(plan));
  }
}

/**
 * Test basic functionality
 *
 */
TEST_F(CacheTest, Basic) {
  Cache<uint32_t, const planner::AbstractPlan> cache(
      CACHE_SIZE, bridge::PlanTransformer::CleanPlan, 1);

  EXPECT_EQ(0, cache.size());
  EXPECT_EQ(true, cache.empty());
}

/**
 *  Test find operation
 *
 */
TEST_F(CacheTest, Find) {
  Cache<uint32_t, const planner::AbstractPlan> cache(
      CACHE_SIZE, bridge::PlanTransformer::CleanPlan, 1);
{'fraction_non_alphanumeric': 0.3245784695201038, 'fraction_numerical': 0.009727626459143969, 'mean_word_length': 1.825091575091575, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '1852159', 'n_tokens_mistral': 913, 'n_tokens_neox': 878, 'n_words': 178}