<commit_before>#include <BaseEvent.h>
#include <Filter.h>
#include <MetaFilter.h>
#include <MetaEvent.h>

#include <vector>
#include <algorithm>
#include <sstream>

namespace tests {

namespace filterTestSuite {

using namespace ::id::attribute;
using namespace filter;

class FilterTestSuite : public ::testing::Test {
  public:
    using Event = BaseEvent<>;
    Event trueEvent, falseEvent, compEvent;
    using TimeAttr = Event::findAttribute<Time>::type;
    const TimeAttr c0 = {{{ 1024 }}};
    FilterTestSuite() {
      trueEvent.attribute(Time()).value()  = {{{1050}}};
      compEvent.attribute(Time())  = c0;
      falseEvent.attribute(Time()).value() = {{{100}}};
    }
};

TEST_F(FilterTestSuite, basicExpressionTest){
  auto filter0 = e0[Time()] > c0;
  auto filter1 = e0[Time()] < c0;
  auto filter2 = e0[Time()] == c0;
  auto filter3 = e0[Time()] != c0;
  auto filter4 = e0[Time()] >= c0;
  auto filter5 = e0[Time()] <= c0;

  EXPECT_TRUE(filter0(trueEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent)) << "False positive";
  EXPECT_TRUE(filter1(falseEvent))  << "False negative";
  EXPECT_FALSE(filter1(trueEvent)) << "False positive";
  EXPECT_FALSE(filter2(falseEvent))  << "False positive";
  EXPECT_FALSE(filter2(trueEvent)) << "False positive";
  EXPECT_TRUE(filter3(trueEvent))  << "False negative";
  EXPECT_TRUE(filter3(falseEvent)) << "False negative";
  EXPECT_TRUE(filter4(trueEvent))  << "False negative";
  EXPECT_FALSE(filter4(falseEvent)) << "False positive";
  EXPECT_TRUE(filter5(falseEvent))  << "False negative";
  EXPECT_FALSE(filter5(trueEvent)) << "False positive";
}

TEST_F(FilterTestSuite, extendedExpressionTest){
  auto filter0 = e0[Time()] > e1[Time()];
  auto filter1 = e0[Time()] < e1[Time()];
  auto filter2 = e0[Time()] == e1[Time()];
  auto filter3 = e0[Time()] != e1[Time()];
  auto filter4 = e0[Time()] >= e1[Time()];
  auto filter5 = e0[Time()] <= e1[Time()];

  EXPECT_TRUE(filter0(trueEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter1(falseEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter1(trueEvent, compEvent)) << "False positive";
  EXPECT_FALSE(filter2(falseEvent, compEvent))  << "False positive";
  EXPECT_FALSE(filter2(trueEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter3(trueEvent, compEvent))  << "False negative";
  EXPECT_TRUE(filter3(falseEvent, compEvent)) << "False negative";
  EXPECT_TRUE(filter4(trueEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter4(falseEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter5(falseEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter5(trueEvent, compEvent)) << "False positive";
}

TEST_F(FilterTestSuite, compositeExpressionTest){
  auto baseFilter = e0[Time()] > c0;
  auto filter0 = baseFilter(e0) && !baseFilter(e1);
  auto filter1 = baseFilter(e0) || baseFilter(e1);

  EXPECT_TRUE(filter0(trueEvent, falseEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent, falseEvent)) << "False positive";
  EXPECT_TRUE(filter1(trueEvent, falseEvent))  << "False negative";
  EXPECT_FALSE(filter1(falseEvent, falseEvent)) << "False positive";
}


TEST_F(FilterTestSuite, basicSerializationTest) {

  auto filter0 = e0[Time()] > c0;
  auto filter1 = e0[Time()] < c0;
  auto filter2 = e0[Time()] >= c0;
  auto filter3 = e0[Time()] <= c0;
  auto filter4 = e0[Time()] == c0;
  auto filter5 = e0[Time()] != c0;

	uint8_t e0Time = ::id::attribute::Time::value();
	uint8_t gt = 0x80|::id::filterOp::GT::value;
	uint8_t lt = 0x80|::id::filterOp::LT::value;
	uint8_t ge = 0x80|::id::filterOp::GE::value;
	uint8_t le = 0x80|::id::filterOp::LE::value;
	uint8_t eq = 0x80|::id::filterOp::EQ::value;
	uint8_t ne = 0x80|::id::filterOp::NE::value;

  std::vector<uint8_t> buffer;
  auto i = std::back_inserter(buffer);
  Serializer<decltype(i)> s(i);
  FilterEvent<decltype(s)> s0(0, s);

	uint16_t count = 0;

  s << filter0(s0);
	EXPECT_EQ(buffer[0], e0Time) << "Placeholder event 0 time serialized wrongly";
	EXPECT_EQ(buffer[count+1], gt) << "Operation > with constant argument serialized wrongly";

	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

  s << filter1(s0);
	EXPECT_EQ(buffer[count+1], lt) << "Operation < with constant argument serialized wrongly";
  
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter2(s0);
	EXPECT_EQ(buffer[count+1], ge) << "Operation >= with constant argument serialized wrongly";
  
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter3(s0);
	EXPECT_EQ(buffer[count+1], le) << "Operation <= with constant argument serialized wrongly";
	
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter4(s0);
	EXPECT_EQ(buffer[count+1], eq) << "Operation == with constant argument serialized wrongly";
	
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
	
	s << filter5(s0);
	EXPECT_EQ(buffer[count+1], ne) << "Operation != with constant argument serialized wrongly";
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

}

TEST_F(FilterTestSuite, extendedSerializationTest) {
  auto filter0 = e0[Time()] >  e1[Time()];
  auto filter1 = e0[Time()] <  e1[Time()];
  auto filter2 = e0[Time()] >= e1[Time()];
  auto filter3 = e0[Time()] <= e1[Time()];
  auto filter4 = e0[Time()] == e1[Time()];
  auto filter5 = e0[Time()] != e1[Time()];

	uint8_t e0Time = ::id::attribute::Time::value();
	uint8_t e1Time = (0x1<<5) | ::id::attribute::Time::value();
	uint8_t gt = ::id::filterOp::GT::value;
	uint8_t lt = ::id::filterOp::LT::value;
	uint8_t ge = ::id::filterOp::GE::value;
	uint8_t le = ::id::filterOp::LE::value;
	uint8_t eq = ::id::filterOp::EQ::value;
	uint8_t ne = ::id::filterOp::NE::value;

  std::vector<uint8_t> buffer;
  auto i = std::back_inserter(buffer);
  Serializer<decltype(i)> s(i);
  FilterEvent<decltype(s)> s0(0, s);
  FilterEvent<decltype(s)> s1(1);

	uint16_t count = 0;

  s << filter0(s0, s1);
	EXPECT_EQ(buffer[0], e0Time) << "Placeholder event 0 time serialized wrongly";
	EXPECT_EQ(buffer[count+1], gt) << "Operation > with event argument serialized wrongly";
	EXPECT_EQ(buffer[2], e1Time) << "Placeholder event 1 time serialized wrongly";
	EXPECT_EQ(buffer.size(), 3) << "Wrong length of serialized packet";

	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

  s << filter1(s0, s1);
	EXPECT_EQ(buffer[count+1], lt) << "Operation < with event argument serialized wrongly";
  
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter2(s0, s1);
	EXPECT_EQ(buffer[count+1], ge) << "Operation >= with event argument serialized wrongly";
  
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter3(s0, s1);
	EXPECT_EQ(buffer[count+1], le) << "Operation <= with event argument serialized wrongly";
	
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter4(s0, s1);
	EXPECT_EQ(buffer[count+1], eq) << "Operation == with event argument serialized wrongly";
	
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
	
	s << filter5(s0, s1);
	EXPECT_EQ(buffer[count+1], ne) << "Operation != with event argument serialized wrongly";

	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
}

TEST_F(FilterTestSuite, compositeSerializationTest) {<commit_msg>Unit-Test: add todo for clang failing tests<commit_after>#include <BaseEvent.h>
#include <Filter.h>
#include <MetaFilter.h>
#include <MetaEvent.h>

#include <vector>
#include <algorithm>
#include <sstream>

namespace tests {

namespace filterTestSuite {

using namespace ::id::attribute;
using namespace filter;

class FilterTestSuite : public ::testing::Test {
  public:
    using Event = BaseEvent<>;
    Event trueEvent, falseEvent, compEvent;
    using TimeAttr = Event::findAttribute<Time>::type;
    const TimeAttr c0 = {{{ 1024 }}};
    FilterTestSuite() {
      trueEvent.attribute(Time()).value()  = {{{1050}}};
      compEvent.attribute(Time())  = c0;
      falseEvent.attribute(Time()).value() = {{{100}}};
    }
};

TEST_F(FilterTestSuite, basicExpressionTest){
  auto filter0 = e0[Time()] > c0;
  auto filter1 = e0[Time()] < c0;
  auto filter2 = e0[Time()] == c0;
  auto filter3 = e0[Time()] != c0;
  auto filter4 = e0[Time()] >= c0;
  auto filter5 = e0[Time()] <= c0;

  EXPECT_TRUE(filter0(trueEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent)) << "False positive";
  EXPECT_TRUE(filter1(falseEvent))  << "False negative";
  EXPECT_FALSE(filter1(trueEvent)) << "False positive";
  EXPECT_FALSE(filter2(falseEvent))  << "False positive";
  EXPECT_FALSE(filter2(trueEvent)) << "False positive";
  EXPECT_TRUE(filter3(trueEvent))  << "False negative";
  EXPECT_TRUE(filter3(falseEvent)) << "False negative";
  EXPECT_TRUE(filter4(trueEvent))  << "False negative";
  EXPECT_FALSE(filter4(falseEvent)) << "False positive";
  EXPECT_TRUE(filter5(falseEvent))  << "False negative";
  EXPECT_FALSE(filter5(trueEvent)) << "False positive";
}

TEST_F(FilterTestSuite, extendedExpressionTest){
  auto filter0 = e0[Time()] > e1[Time()];
  auto filter1 = e0[Time()] < e1[Time()];
  auto filter2 = e0[Time()] == e1[Time()];
  auto filter3 = e0[Time()] != e1[Time()];
  auto filter4 = e0[Time()] >= e1[Time()];
  auto filter5 = e0[Time()] <= e1[Time()];

  EXPECT_TRUE(filter0(trueEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter1(falseEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter1(trueEvent, compEvent)) << "False positive";
  EXPECT_FALSE(filter2(falseEvent, compEvent))  << "False positive";
  EXPECT_FALSE(filter2(trueEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter3(trueEvent, compEvent))  << "False negative";
  EXPECT_TRUE(filter3(falseEvent, compEvent)) << "False negative";
  EXPECT_TRUE(filter4(trueEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter4(falseEvent, compEvent)) << "False positive";
  EXPECT_TRUE(filter5(falseEvent, compEvent))  << "False negative";
  EXPECT_FALSE(filter5(trueEvent, compEvent)) << "False positive";
}

TEST_F(FilterTestSuite, compositeExpressionTest){
  auto baseFilter = e0[Time()] > c0;
  auto filter0 = baseFilter(e0) && !baseFilter(e1);
  auto filter1 = baseFilter(e0) || baseFilter(e1);

  EXPECT_TRUE(filter0(trueEvent, falseEvent))  << "False negative";
  EXPECT_FALSE(filter0(falseEvent, falseEvent)) << "False positive";
  EXPECT_TRUE(filter1(trueEvent, falseEvent))  << "False negative";
  EXPECT_FALSE(filter1(falseEvent, falseEvent)) << "False positive";
}

/** \todo Fails on clang++ **/
TEST_F(FilterTestSuite, basicSerializationTest) {

  auto filter0 = e0[Time()] > c0;
  auto filter1 = e0[Time()] < c0;
  auto filter2 = e0[Time()] >= c0;
  auto filter3 = e0[Time()] <= c0;
  auto filter4 = e0[Time()] == c0;
  auto filter5 = e0[Time()] != c0;

	uint8_t e0Time = ::id::attribute::Time::value();
	uint8_t gt = 0x80|::id::filterOp::GT::value;
	uint8_t lt = 0x80|::id::filterOp::LT::value;
	uint8_t ge = 0x80|::id::filterOp::GE::value;
	uint8_t le = 0x80|::id::filterOp::LE::value;
	uint8_t eq = 0x80|::id::filterOp::EQ::value;
	uint8_t ne = 0x80|::id::filterOp::NE::value;

  std::vector<uint8_t> buffer;
  auto i = std::back_inserter(buffer);
  Serializer<decltype(i)> s(i);
  FilterEvent<decltype(s)> s0(0, s);

	uint16_t count = 0;

  s << filter0(s0);
	EXPECT_EQ(buffer[0], e0Time) << "Placeholder event 0 time serialized wrongly";
	EXPECT_EQ(buffer[count+1], gt) << "Operation > with constant argument serialized wrongly";

	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

  s << filter1(s0);
	EXPECT_EQ(buffer[count+1], lt) << "Operation < with constant argument serialized wrongly";
  
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter2(s0);
	EXPECT_EQ(buffer[count+1], ge) << "Operation >= with constant argument serialized wrongly";
  
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter3(s0);
	EXPECT_EQ(buffer[count+1], le) << "Operation <= with constant argument serialized wrongly";
	
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter4(s0);
	EXPECT_EQ(buffer[count+1], eq) << "Operation == with constant argument serialized wrongly";
	
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
	
	s << filter5(s0);
	EXPECT_EQ(buffer[count+1], ne) << "Operation != with constant argument serialized wrongly";
	count+=2*sizeof(uint64_t)+2;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

}

/** \todo Fails on clang++ **/
TEST_F(FilterTestSuite, extendedSerializationTest) {
  auto filter0 = e0[Time()] >  e1[Time()];
  auto filter1 = e0[Time()] <  e1[Time()];
  auto filter2 = e0[Time()] >= e1[Time()];
  auto filter3 = e0[Time()] <= e1[Time()];
  auto filter4 = e0[Time()] == e1[Time()];
  auto filter5 = e0[Time()] != e1[Time()];

	uint8_t e0Time = ::id::attribute::Time::value();
	uint8_t e1Time = (0x1<<5) | ::id::attribute::Time::value();
	uint8_t gt = ::id::filterOp::GT::value;
	uint8_t lt = ::id::filterOp::LT::value;
	uint8_t ge = ::id::filterOp::GE::value;
	uint8_t le = ::id::filterOp::LE::value;
	uint8_t eq = ::id::filterOp::EQ::value;
	uint8_t ne = ::id::filterOp::NE::value;

  std::vector<uint8_t> buffer;
  auto i = std::back_inserter(buffer);
  Serializer<decltype(i)> s(i);
  FilterEvent<decltype(s)> s0(0, s);
  FilterEvent<decltype(s)> s1(1);

	uint16_t count = 0;

  s << filter0(s0, s1);
	EXPECT_EQ(buffer[0], e0Time) << "Placeholder event 0 time serialized wrongly";
	EXPECT_EQ(buffer[count+1], gt) << "Operation > with event argument serialized wrongly";
	EXPECT_EQ(buffer[2], e1Time) << "Placeholder event 1 time serialized wrongly";
	EXPECT_EQ(buffer.size(), 3) << "Wrong length of serialized packet";

	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

  s << filter1(s0, s1);
	EXPECT_EQ(buffer[count+1], lt) << "Operation < with event argument serialized wrongly";
  
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter2(s0, s1);
	EXPECT_EQ(buffer[count+1], ge) << "Operation >= with event argument serialized wrongly";
  
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter3(s0, s1);
	EXPECT_EQ(buffer[count+1], le) << "Operation <= with event argument serialized wrongly";
	
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";

	s << filter4(s0, s1);
	EXPECT_EQ(buffer[count+1], eq) << "Operation == with event argument serialized wrongly";
	
	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
	
	s << filter5(s0, s1);
	EXPECT_EQ(buffer[count+1], ne) << "Operation != with event argument serialized wrongly";

	count+=3;
	EXPECT_EQ(buffer.size(), count) << "Wrong length of serialized packet";
}

/** \todo Fails on clang++ **/
TEST_F(FilterTestSuite, compositeSerializationTest) {
{'fraction_non_alphanumeric': 0.1748777977874968, 'fraction_numerical': 0.03293028042191922, 'mean_word_length': 5.849779735682819, 'pattern_counts': {'":': 0, '<': 335, '<?xml version=': 0, '>': 61, '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': '5239945', 'n_tokens_mistral': 5571, 'n_tokens_neox': 5555, 'n_words': 1212}