<commit_before>#include "boost/lexical_cast.hpp"
#include <boost/uuid/uuid_io.hpp>
#include <gtest/gtest.h>

#include "blob.h"
#include "sqlite_back.h"

#include "tools.h"

// special name to tell sqlite to use in-mem db
static std::string const path = ":memory:";

class SqliteBackTests : public ::testing::Test {
 public:
  virtual void SetUp() {
    b = new cyclus::SqliteBack(path);
    r.RegisterBackend(b);
  }

  virtual void TearDown() {
    r.Close();
    delete b;
  }
  cyclus::SqliteBack* b;
  cyclus::Recorder r;
};

TEST_F(SqliteBackTests, MapStrDouble) {
  std::map<std::string, double> m;
  m["one"] = 1.1;
  m["two"] = 2.2;
  m["three"] = 5.5;

  r.NewDatum("monty")
      ->AddVal("count", m)
      ->Record();

  r.Close();
  cyclus::QueryResult qr = b->Query("monty", NULL);
  m = qr.GetVal<std::map<std::string, double> >("count", 0);

  EXPECT_EQ(1.1, m["one"]);
  EXPECT_EQ(2.2, m["two"]);
  EXPECT_EQ(5.5, m["three"]);
}

TEST_F(SqliteBackTests, MapStrPairDoubleMapIntDouble) {
  std::map<std::string, std::pair<double, std::map<int, double> > > m;
  std::map<int, double> ma;
  ma[1] = 1.1;
  ma[2] = 2.2;
  std::map<int, double> mb;
  mb[1] = 1.2;
  mb[3] = 3.3;

  m["one"] = std::make_pair(.41, ma);
  m["two"] = std::make_pair(.42, mb);
  r.NewDatum("monty")->AddVal("count", m)->Record();

  r.Close();
  cyclus::QueryResult qr = b->Query("monty", NULL);<commit_msg>whoops, didnt mean to rm a test<commit_after>#include "boost/lexical_cast.hpp"
#include <boost/uuid/uuid_io.hpp>
#include <gtest/gtest.h>

#include "blob.h"
#include "sqlite_back.h"

#include "tools.h"

// special name to tell sqlite to use in-mem db
static std::string const path = ":memory:";

class SqliteBackTests : public ::testing::Test {
 public:
  virtual void SetUp() {
    b = new cyclus::SqliteBack(path);
    r.RegisterBackend(b);
  }

  virtual void TearDown() {
    r.Close();
    delete b;
  }
  cyclus::SqliteBack* b;
  cyclus::Recorder r;
};

TEST_F(SqliteBackTests, MapStrDouble) {
  std::map<std::string, double> m;
  m["one"] = 1.1;
  m["two"] = 2.2;
  m["three"] = 5.5;

  r.NewDatum("monty")
      ->AddVal("count", m)
      ->Record();

  r.Close();
  cyclus::QueryResult qr = b->Query("monty", NULL);
  m = qr.GetVal<std::map<std::string, double> >("count", 0);

  EXPECT_EQ(1.1, m["one"]);
  EXPECT_EQ(2.2, m["two"]);
  EXPECT_EQ(5.5, m["three"]);
}

TEST_F(SqliteBackTests, MapIntMapStringDouble) {
  std::map<int, std::map<std::string, double> > exp;
  std::map<std::string, double> expa;
  expa["foo"] = 4.2;
  expa["bar"] = 5.2;
  exp[42] = expa;
  std::map<std::string, double> expb;
  expb["foo"] = 4.9;
  expb["baz"] = 5.1;
  exp[65] = expb;

  r.NewDatum("monty")->AddVal("count", exp)->Record();
  r.Close();

  cyclus::QueryResult qr = b->Query("monty", NULL);
  std::map<int, std::map<std::string, double> > obs;
    obs = qr.GetVal<
      std::map<int, std::map<std::string, double> > >("count", 0);
    EXPECT_EQ(obs, exp);
}

TEST_F(SqliteBackTests, MapStrPairDoubleMapIntDouble) {
  std::map<std::string, std::pair<double, std::map<int, double> > > m;
  std::map<int, double> ma;
  ma[1] = 1.1;
  ma[2] = 2.2;
  std::map<int, double> mb;
  mb[1] = 1.2;
  mb[3] = 3.3;

  m["one"] = std::make_pair(.41, ma);
  m["two"] = std::make_pair(.42, mb);
  r.NewDatum("monty")->AddVal("count", m)->Record();

  r.Close();
  cyclus::QueryResult qr = b->Query("monty", NULL);
{'fraction_non_alphanumeric': 0.21888790820829657, 'fraction_numerical': 0.020888496616651958, 'mean_word_length': 4.082212257100149, 'pattern_counts': {'":': 2, '<': 32, '<?xml version=': 0, '>': 47, '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': '4908602', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1428, 'n_words': 275}