/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
*
* MAUS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MAUS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MAUS. If not, see .
*/
#include "gtest/gtest.h"
#include "src/common_cpp/DataStructure/Cuts.hh"
int nCuts = 12;
namespace MAUS {
class CutsTestDS: public ::testing::Test {
protected:
CutsTestDS() {}
virtual ~CutsTestDS() {}
virtual void SetUp() {}
virtual void TearDown() {}
};
/* Test default constructor. Initialised cuts expected to be set to false. */
TEST_F(CutsTestDS, test_default_constructor) {
Cuts* mycut = new Cuts();
EXPECT_TRUE(mycut->GetCutStore().empty());
delete mycut;
}
/* Test copy constructor */
TEST_F(CutsTestDS, test_copy_constructor) {
Cuts* mycut_1 = new Cuts();
Cuts* mycut_2 = new Cuts(*mycut_1);
delete mycut_1;
// Check if default settings (all cuts false) are copied
EXPECT_TRUE(mycut_2->GetCutStore().empty());
delete mycut_2;
}
/* Test assignment operator */
TEST_F(CutsTestDS, test_assignment_operator) {
// Set up a vector of cuts with non-default values
std::vector myvec(nCuts);
myvec[0]=myvec[4]= true;
Cuts* mycut_1 = new Cuts();
mycut_1->SetCutStore(myvec);
Cuts* mycut_2 = new Cuts(*mycut_1);
delete mycut_1;
EXPECT_EQ(mycut_2->GetWillCut(0), myvec[0]);
EXPECT_EQ(mycut_2->GetWillCut(1), myvec[1]);
EXPECT_EQ(mycut_2->GetWillCut(4), myvec[4]);
delete mycut_2;
}
/* Test Get and Set functions */
TEST_F(CutsTestDS, test_setters_getters) {
int cut_index = 2;
std::string cut_name = "cut_TimeOfFlight";
int cut_index_1 = 1;
std::string cut_name_1 = "cut_allPassed";
bool pass = true;
bool notpass = false;
std::vector myvec(nCuts);
Cuts * mycut = new Cuts();
mycut->SetCutStore(myvec);
EXPECT_EQ(mycut->GetCutStore(), myvec);
mycut->SetWillCut(cut_index, pass);
mycut->SetWillCut(cut_name, pass);
mycut->SetWillCut(cut_index_1, notpass);
mycut->SetWillCut(cut_name_1, notpass);
EXPECT_EQ(mycut->GetWillCut(cut_index), pass);
EXPECT_EQ(mycut->GetWillCut(cut_name), pass);
EXPECT_EQ(mycut->GetWillCut(cut_index_1), notpass);
EXPECT_EQ(mycut->GetWillCut(cut_name_1), notpass);
delete mycut;
}
/* Test functions that return a string/int by passing an int/string respectively */
TEST_F(CutsTestDS, test_return_func) {
// test single
int cut_index = 4;
int exp_index = 6;
int cut_index_1 = 13;
std::string cut_name = "cut_momentumLoss";
std::string exp_name = "cut_TKU_hitAllStations";
std::string cut_name_1 = "errorname";
Cuts * mycut = new Cuts();
EXPECT_EQ(mycut->VariableName(cut_index), exp_name);
EXPECT_EQ(mycut->VariableIndex(cut_name), exp_index);
// test double
EXPECT_EQ(mycut->VariableName(mycut->VariableIndex(cut_name)), cut_name);
EXPECT_EQ(mycut->VariableIndex(mycut->VariableName(cut_index)), cut_index);
delete mycut;
}
} // ~ namespace MAUS