<commit_before>/**
 *  @copyright Copyright 2016 The J-PET Framework Authors. All rights reserved.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may find a copy of the License in the LICENCE file.
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  @file JPetOptionsGeneratorTest.cpp
 */

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE JPetOptionsGeneratorTest
#include <boost/test/unit_test.hpp>
#include <cstdlib>
#include "../JPetCmdParser/JPetCmdParser.h"
#include "../JPetCommonTools/JPetCommonTools.h"
#include "../JPetOptionsGenerator/JPetOptionsGenerator.h"
#include "../JPetOptionsGenerator/JPetOptionsGeneratorTools.h"
#include <iostream>
using boost::any_cast;
using namespace std;
using namespace jpet_options_tools;
using namespace jpet_options_generator_tools;

po::variables_map getCmdLineArgs(const char* cmdLine)
{
  auto args_char = JPetCommonTools::createArgs(cmdLine);
  auto argc = args_char.size();
  auto argv = args_char.data();
  JPetCmdParser parser;
  return parser.parseCmdLineArgs(argc, const_cast<const char**>(argv));
}

BOOST_AUTO_TEST_SUITE(FirstSuite)

BOOST_AUTO_TEST_CASE(generateOptions_emptyOptions)
{
  JPetOptionsGenerator gener;
  po::variables_map inArgs;
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, -2);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, 0);
  BOOST_REQUIRE(result.empty());
}

/// @todo add infile.root and infile2.root files to sphinx
BOOST_AUTO_TEST_CASE(generateOptions_oneFileOneTask)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root -t root");
  auto opt = gener.generateAndValidateOptions(inArgs);

/// bad second arg
  auto result = gener.generateOptionsForTasks(opt, -2);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, 0);
  BOOST_REQUIRE(result.empty());

/// one in file one task
  result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 1); //one file
  auto it = result.begin();
  BOOST_REQUIRE_EQUAL(it->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
  auto opts = it->second;
  BOOST_REQUIRE_EQUAL(getRunNumber(opts),  231);
  BOOST_REQUIRE_EQUAL(getInputFile(opts), "unitTestData/JPetOptionsGeneratorTest/infile.root");
  BOOST_REQUIRE_EQUAL(FileTypeChecker::getInputFileType(opts), FileTypeChecker::kRoot);
}

BOOST_AUTO_TEST_CASE(generateOptions_oneFileTwoTasks)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root -t root");

/// one in file two task
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 2);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 1); //one file
  BOOST_REQUIRE_EQUAL(result.begin()->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
  BOOST_REQUIRE_EQUAL(result.begin()->second.size(), 2u); // two tasks
}

BOOST_AUTO_TEST_CASE(generateOptions_TwoFilesOneTasks)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root unitTestData/JPetOptionsGeneratorTest/infile2.root -t root");
/// one in file two tasks
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 2u); //two files

  auto it = result.begin(); //first file
  BOOST_REQUIRE_EQUAL(it->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
  auto opts = it->second;
  BOOST_REQUIRE_EQUAL(getRunNumber(opts),  231);
  BOOST_REQUIRE_EQUAL(getInputFile(opts), "unitTestData/JPetOptionsGeneratorTest/infile.root");
  BOOST_REQUIRE_EQUAL(FileTypeChecker::getInputFileType(opts), FileTypeChecker::kRoot);
  BOOST_REQUIRE_EQUAL(getFirstEvent(opts),  -1);<commit_msg>Remove UT check which is no longer relevant<commit_after>/**
 *  @copyright Copyright 2016 The J-PET Framework Authors. All rights reserved.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may find a copy of the License in the LICENCE file.
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  @file JPetOptionsGeneratorTest.cpp
 */

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE JPetOptionsGeneratorTest
#include <boost/test/unit_test.hpp>
#include <cstdlib>
#include "../JPetCmdParser/JPetCmdParser.h"
#include "../JPetCommonTools/JPetCommonTools.h"
#include "../JPetOptionsGenerator/JPetOptionsGenerator.h"
#include "../JPetOptionsGenerator/JPetOptionsGeneratorTools.h"
#include <iostream>
using boost::any_cast;
using namespace std;
using namespace jpet_options_tools;
using namespace jpet_options_generator_tools;

po::variables_map getCmdLineArgs(const char* cmdLine)
{
  auto args_char = JPetCommonTools::createArgs(cmdLine);
  auto argc = args_char.size();
  auto argv = args_char.data();
  JPetCmdParser parser;
  return parser.parseCmdLineArgs(argc, const_cast<const char**>(argv));
}

BOOST_AUTO_TEST_SUITE(FirstSuite)

BOOST_AUTO_TEST_CASE(generateOptions_emptyOptions)
{
  JPetOptionsGenerator gener;
  po::variables_map inArgs;
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, -2);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, 0);
  BOOST_REQUIRE(result.empty());
}

/// @todo add infile.root and infile2.root files to sphinx
BOOST_AUTO_TEST_CASE(generateOptions_oneFileOneTask)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root -t root");
  auto opt = gener.generateAndValidateOptions(inArgs);

/// bad second arg
  auto result = gener.generateOptionsForTasks(opt, -2);
  BOOST_REQUIRE(result.empty());
  result = gener.generateOptionsForTasks(opt, 0);
  BOOST_REQUIRE(result.empty());

/// one in file one task
  result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 1); //one file
  auto it = result.begin();
  BOOST_REQUIRE_EQUAL(it->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
  auto opts = it->second;
  BOOST_REQUIRE_EQUAL(getRunNumber(opts),  231);
  BOOST_REQUIRE_EQUAL(getInputFile(opts), "unitTestData/JPetOptionsGeneratorTest/infile.root");
  BOOST_REQUIRE_EQUAL(FileTypeChecker::getInputFileType(opts), FileTypeChecker::kRoot);
}

BOOST_AUTO_TEST_CASE(generateOptions_oneFileTwoTasks)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root -t root");

/// one in file two task
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 2);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 1); //one file
  BOOST_REQUIRE_EQUAL(result.begin()->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
}

BOOST_AUTO_TEST_CASE(generateOptions_TwoFilesOneTasks)
{
  JPetOptionsGenerator gener;
  auto inArgs =  getCmdLineArgs("main.x -i 231 -f unitTestData/JPetOptionsGeneratorTest/infile.root unitTestData/JPetOptionsGeneratorTest/infile2.root -t root");
/// one in file two tasks
  auto opt = gener.generateAndValidateOptions(inArgs);
  auto result = gener.generateOptionsForTasks(opt, 1);
  BOOST_REQUIRE(!result.empty());
  BOOST_REQUIRE_EQUAL(result.size(), 2u); //two files

  auto it = result.begin(); //first file
  BOOST_REQUIRE_EQUAL(it->first, "unitTestData/JPetOptionsGeneratorTest/infile.root");
  auto opts = it->second;
  BOOST_REQUIRE_EQUAL(getRunNumber(opts),  231);
  BOOST_REQUIRE_EQUAL(getInputFile(opts), "unitTestData/JPetOptionsGeneratorTest/infile.root");
  BOOST_REQUIRE_EQUAL(FileTypeChecker::getInputFileType(opts), FileTypeChecker::kRoot);
  BOOST_REQUIRE_EQUAL(getFirstEvent(opts),  -1);
{'fraction_non_alphanumeric': 0.10936971473672343, 'fraction_numerical': 0.00800541210959522, 'mean_word_length': 5.95141065830721, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, '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': '5929439', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2813, 'n_words': 620}