Unit tests for the 'db' module. Classes tested: [DBHelper, CorpusUtils].  
More...
#include <fstream>
#include <cstdlib>
#include "db_helper.hpp"
#include "corpus_utils.hpp"
#include "catch2/catch.hpp"
 
Go to the source code of this file.
 | 
|   | TEST_CASE ("DBHelper unit tests: Default constructor: DBHelper()","[db]") | 
|   | Testing default constructor and subsequent functions on DBHelper class.  More...
  | 
|   | 
|   | TEST_CASE ("Parameterised constructor: DBHelper(const std::string filename) with 'test.db'","[db]") | 
|   | Testing parameterised constructor and subsequent functions on DBHelper class with given database 'test.db'.  More...
  | 
|   | 
|   | TEST_CASE ("Parameterised constructor: DBHelper(const std::string filename) with 'none.db'","[db]") | 
|   | Testing parameterised constructor and subsequent functions on DBHelper class with non-existant database 'none.db'.  More...
  | 
|   | 
|   | TEST_CASE ("CorpusUtils unit tests: Default constructor: CorpusUtils()","[db]") | 
|   | Testing default constructor and subsequent functions on CorpusUtils class.  More...
  | 
|   | 
|   | TEST_CASE ("CorpusUtils unit tests: Paramaterised constructor: CorpusUtils(test_db.db)","[db]") | 
|   | Testing parameterised constructor and subsequent functions on CorpusUtils class.  More...
  | 
|   | 
Unit tests for the 'db' module. Classes tested: [DBHelper, CorpusUtils]. 
- Author
 - Lee J. O'Riordan (lee.o.nosp@m.rior.nosp@m.dan@i.nosp@m.chec.nosp@m..ie) 
 
- Version
 - 0.1 
 
- Date
 - 2019-05-01
 
- Copyright
 - Copyright (c) 2019 
 
Definition in file test_db.cpp.
 
◆ TEST_CASE() [1/5]
      
        
          | TEST_CASE  | 
          ( | 
          "DBHelper unit tests: Default constructor: DBHelper()"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [db]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Testing default constructor and subsequent functions on DBHelper class. 
Definition at line 28 of file test_db.cpp.
   28                               : Default constructor: 
DBHelper()
","[db]
"){    31     //REQUIRE(db.getFilename() == "qnlp_tagged_corpus.sqlite
");    32     REQUIRE(db.getFilename() == "");    33     REQUIRE(db.getDBRef() == nullptr);    35     SECTION("openDB(
const std::string filename) with 
'test_db.db'"){    36         int ret_code = db.openDB("test_db.db
");    37         REQUIRE(ret_code == 0);    38         REQUIRE(db.getDBRef() != nullptr);    39         REQUIRE(db.getFilename().compare("test_db.db
") == 0);    43             REQUIRE(db.getFilename() == "");    44             REQUIRE(db.getDBRef() == nullptr );    47     SECTION("openDB(
const std::string filename) with 
'none.db'"){    48         REQUIRE(db.openDB("none.db
") != 0);    49         REQUIRE(db.getDBRef() == nullptr);    50         REQUIRE(db.getFilename().compare("") == 0);    54             REQUIRE(db.getFilename() == "");    55             REQUIRE(db.getDBRef() == nullptr ); 
 
References QNLP::DBHelper::closeDB(), QNLP::DBHelper::getDBRef(), QNLP::DBHelper::getFilename(), and QNLP::DBHelper::openDB().
 
 
◆ TEST_CASE() [2/5]
      
        
          | TEST_CASE  | 
          ( | 
          "Parameterised constructor: DBHelper(const std::string filename) with 'test.db'"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [db]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Testing parameterised constructor and subsequent functions on DBHelper class with given database 'test.db'. 
Definition at line 65 of file test_db.cpp.
   65                                     : 
DBHelper(
const std::string filename) with 
'test.db'","[db]
"){    66     DBHelper db("test_db.db
");    68     REQUIRE(db.getFilename() == "test_db.db
");    69     REQUIRE(db.getDBRef() != nullptr);    71     SECTION("openDB(
const std::string filename) with 
'test_db.db'"){    72         REQUIRE(db.openDB("test_db.db
") == 0);    73         REQUIRE(db.getDBRef() != nullptr);    74         REQUIRE(db.getFilename().compare("test_db.db
") == 0);    78         REQUIRE(db.getFilename() == "");    79         REQUIRE(db.getDBRef() == nullptr ); 
 
References QNLP::DBHelper::closeDB(), QNLP::DBHelper::getDBRef(), QNLP::DBHelper::getFilename(), and QNLP::DBHelper::openDB().
 
 
◆ TEST_CASE() [3/5]
      
        
          | TEST_CASE  | 
          ( | 
          "Parameterised constructor: DBHelper(const std::string filename) with 'none.db'"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [db]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Testing parameterised constructor and subsequent functions on DBHelper class with non-existant database 'none.db'. 
Definition at line 88 of file test_db.cpp.
   88                                     : 
DBHelper(
const std::string filename) with 
'none.db'","[db]
"){    89     DBHelper db("none.db
");    91     REQUIRE(db.getFilename() == "");    92     REQUIRE(db.getDBRef() == nullptr);    94     SECTION("openDB(
const std::string filename) with 
'none.db'"){    95         REQUIRE(db.openDB("none.db
") != 0 );    96         REQUIRE(db.getDBRef() == nullptr);    97         REQUIRE(db.getFilename().compare("") == 0);   101         REQUIRE(db.getFilename() == "");   102         REQUIRE(db.getDBRef() == nullptr ); 
 
References QNLP::DBHelper::closeDB(), QNLP::DBHelper::getDBRef(), QNLP::DBHelper::getFilename(), and QNLP::DBHelper::openDB().
 
 
◆ TEST_CASE() [4/5]
      
        
          | TEST_CASE  | 
          ( | 
          "CorpusUtils unit tests: Default constructor: CorpusUtils()"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [db]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Testing default constructor and subsequent functions on CorpusUtils class. 
Definition at line 110 of file test_db.cpp.
  113     REQUIRE(cu.getBinToName().size() == 0);   114     REQUIRE(cu.getNameToBin().size() == 0);   115     REQUIRE(cu.get_database_filename().compare("qnlp_tagged_corpus.sqlite
") == 0);   116     REQUIRE(cu.getDBHelper().getFilename().compare("qnlp_tagged_corpus.sqlite
") == 0);   117     REQUIRE(cu.getDBHelper().getDBRef() != nullptr);   119     SECTION("Load 
data: data_type=noun, table is 
default (
'corpus')
"){   121         std::size_t n_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   122         REQUIRE(n_size[0] != 0);   123         REQUIRE(n_size[1] != 0);   125     SECTION("Load 
data: data_type=verb, table is 
default (
'corpus')
"){   127         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   128         REQUIRE(v_size[0] != 0);   129         REQUIRE(v_size[1] != 0);   131     SECTION("Load 
data: data_type=noun and verb, table is 
default (
'corpus')
"){   133         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   134         REQUIRE(v_size[0] != 0);   135         REQUIRE(v_size[1] != 0);   138         std::size_t vn_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   139         REQUIRE(vn_size[0] != v_size[0]);   140         REQUIRE(vn_size[1] != v_size[1]);   142     SECTION("Load 
data: data_type=noun and verb, table=
'basis'"){   143         cu.loadData("verb
", "basis");   144         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   145         REQUIRE(v_size[0] != 0);   146         REQUIRE(v_size[1] != 0);   148         cu.loadData("noun
", "basis");   149         std::size_t vn_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   150         REQUIRE(vn_size[0] != v_size[0]);   151         REQUIRE(vn_size[1] != v_size[1]); 
 
References QNLP::CorpusUtils::get_database_filename(), QNLP::CorpusUtils::getBinToName(), QNLP::CorpusUtils::getDBHelper(), QNLP::DBHelper::getDBRef(), QNLP::DBHelper::getFilename(), QNLP::CorpusUtils::getNameToBin(), and QNLP::CorpusUtils::loadData().
 
 
◆ TEST_CASE() [5/5]
      
        
          | TEST_CASE  | 
          ( | 
          "CorpusUtils unit tests: Paramaterised constructor: CorpusUtils(test_db.db)"  | 
          ,  | 
        
        
           | 
           | 
          ""  | 
          [db]  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Testing parameterised constructor and subsequent functions on CorpusUtils class. 
Definition at line 159 of file test_db.cpp.
  159                                  : Paramaterised constructor: 
CorpusUtils(test_db.db)
","[db]
"){   160     CorpusUtils cu("test_db.db
");   162     REQUIRE(cu.getBinToName().size() == 0);   163     REQUIRE(cu.getNameToBin().size() == 0);   164     REQUIRE(cu.get_database_filename() == cu.getDBHelper().getFilename());   165     REQUIRE(cu.get_database_filename().compare("test_db.db
") == 0);   166     REQUIRE(cu.getDBHelper().getFilename().compare("test_db.db
") == 0);   167     REQUIRE(cu.getDBHelper().getDBRef() != nullptr);   169     SECTION("Load 
data: data_type=noun, table is 
default (
'corpus')
"){   171         std::size_t n_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   172         REQUIRE(n_size[0] != 0);   173         REQUIRE(n_size[1] != 0);   175     SECTION("Load 
data: data_type=verb, table is 
default (
'corpus')
"){   177         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   178         REQUIRE(v_size[0] != 0);   179         REQUIRE(v_size[1] != 0);   181     SECTION("Load 
data: data_type=noun and verb, table is 
default (
'corpus')
"){   183         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   184         REQUIRE(v_size[0] != 0);   185         REQUIRE(v_size[1] != 0);   188         std::size_t vn_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   189         REQUIRE(vn_size[0] != v_size[0]);   190         REQUIRE(vn_size[1] != v_size[1]);   192     SECTION("Load 
data: data_type=noun and verb, table=
'basis'"){   193         cu.loadData("verb
", "basis");   194         std::size_t v_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   195         REQUIRE(v_size[0] != 0);   196         REQUIRE(v_size[1] != 0);   198         cu.loadData("noun
", "basis");   199         std::size_t vn_size[2] = {cu.getBinToName().size(), cu.getNameToBin().size()};   200         REQUIRE(vn_size[0] != v_size[0]);   201         REQUIRE(vn_size[1] != v_size[1]); 
 
References QNLP::CorpusUtils::get_database_filename(), QNLP::CorpusUtils::getBinToName(), QNLP::CorpusUtils::getDBHelper(), QNLP::DBHelper::getDBRef(), QNLP::DBHelper::getFilename(), QNLP::CorpusUtils::getNameToBin(), and QNLP::CorpusUtils::loadData().