class IniSection {
public:
+ IniSection(const std::string &name) : section_name(name) {}
+
IniSection(const std::string §ion_name, const std::string &entry_str) :
- section_name(section_name) {
+ IniSection(section_name) {
setEntry(entry_str);
}
}
};
-namespace initest {
-typedef enum {
- LOAD = 1 << 0, /**< should fail at load */
- INIT = 1 << 1, /**< should fail at init */
-} IniFailAt;
-};
-
-class nntrainerIniTest
- : public ::testing::TestWithParam<
- std::tuple<const char *, const std::vector<IniSection>, int>> {
-protected:
- virtual void SetUp() {
- name = std::string(std::get<0>(GetParam()));
- std::cout << "starting test case : " << name << std::endl << std::endl;
-
- sections = std::get<1>(GetParam());
- failAt = std::get<2>(GetParam());
- save_ini();
- }
-
- virtual void TearDown() { erase_ini(); }
+/**
+ * @brief IniTestWrapper using IniSection
+ *
+ */
+class IniTestWrapper {
+public:
+ using Sections = std::vector<IniSection>;
- bool failAtLoad() { return failAt & initest::IniFailAt::LOAD; }
+ /**
+ * @brief Construct a new Ini Test Wrapper object
+ *
+ */
+ IniTestWrapper(){};
- bool failAtInit() { return failAt & initest::IniFailAt::INIT; }
+ /**
+ * @brief Construct a new Ini Test Wrapper object
+ *
+ * @param name_ name of the ini without `.ini` extension
+ * @param sections_ sections that should go into ini
+ */
+ IniTestWrapper(const std::string &name_, const Sections §ions_) :
+ name(name_),
+ sections(sections_){};
+ /**
+ * @brief Get the Ini Name object
+ *
+ * @return std::string ini name with extension appended
+ */
std::string getIniName() { return name + ".ini"; }
+ /**
+ * @brief Get the Ini object
+ *
+ * @return std::ofstream ini file stream
+ */
std::ofstream getIni() {
std::ofstream out(getIniName().c_str());
if (!out.good()) {
return out;
}
- virtual void save_ini() {
+ /**
+ * @brief save ini to a file
+ *
+ */
+ void save_ini() {
std::ofstream out = getIni();
for (auto &it : sections) {
it.print(std::cout);
out.close();
}
- nntrainer::NeuralNetwork NN;
+ /**
+ * @brief erase ini
+ *
+ */
+ void erase_ini() { remove(getIniName().c_str()); }
private:
- void erase_ini() { name.clear(); }
- int failAt;
std::string name;
- std::vector<IniSection> sections;
+ Sections sections;
};
-/**
- * @brief make ini test case from given parameter
- */
-std::tuple<const char *, const std::vector<IniSection>, int>
-mkIniTc(const char *name, const std::vector<IniSection> vec, int flag);
-
/// @todo: migrate this to datafile unittest
const std::string config_str = "[Model]"
"\n"
* @bug No known bugs except for NYI items
*/
-#include "nntrainer_test_util.h"
#include <gtest/gtest.h>
#include <neuralnet.h>
+#include "nntrainer_test_util.h"
+
+namespace initest {
+typedef enum {
+ LOAD = 1 << 0, /**< should fail at load */
+ INIT = 1 << 1, /**< should fail at init */
+} IniFailAt;
+};
+
+class nntrainerIniTest
+ : public ::testing::TestWithParam<
+ std::tuple<const char *, const IniTestWrapper::Sections, int>> {
+
+protected:
+ virtual void SetUp() {
+ name = std::string(std::get<0>(GetParam()));
+ std::cout << "starting test case : " << name << std::endl << std::endl;
+
+ auto sections = std::get<1>(GetParam());
+
+ ini = IniTestWrapper(name, sections);
+
+ failAt = std::get<2>(GetParam());
+ ini.save_ini();
+ }
+
+ virtual void TearDown() { ini.erase_ini(); }
+
+ std::string getIniName() { return ini.getIniName(); }
+
+ bool failAtLoad() { return failAt & initest::IniFailAt::LOAD; }
+
+ bool failAtInit() { return failAt & initest::IniFailAt::INIT; }
+
+ nntrainer::NeuralNetwork NN;
+
+private:
+ int failAt;
+ std::string name;
+ IniTestWrapper ini;
+};
+
/**
* @brief check given ini is failing/suceeding at load
*/
using I = IniSection;
+/**
+ * @brief make ini test case from given parameter
+ */
+std::tuple<const char *, const IniTestWrapper::Sections, int>
+mkIniTc(const char *name, const IniTestWrapper::Sections vec, int flag) {
+ return std::make_tuple(name, vec, flag);
+}
+
/// @note each line contains 2 (positive or negative test) + 3 negative test.
/// if, there are 6 positive tests and 9 negative tests
/// which sums up to 6 * 2 = 12 positive tests and 9 * 2 + (6 + 9) * 3 = 63