-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
131c291
commit cf0b421
Showing
13 changed files
with
415 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# OS generated files # | ||
###################### | ||
._* | ||
tests | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.6) | ||
project(tests) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fopenmp") | ||
|
||
set(SOURCE_FILES main.cpp TestMarketMatrixWriter.cpp ../output/MarketMatrixWriter.cpp) | ||
add_executable(tests ${SOURCE_FILES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "TestMarketMatrixWriter.h" | ||
|
||
|
||
void TestMarketMatrixWriter::buildUp(std::string fileName) | ||
{ | ||
testOutputFileName = fileName; | ||
testMatrix = {1.1,0,0,0,0,2.2,3.3,0,0,0,0,0,4.4,0,0,5.21,0,0,0,0,0,0,0}; | ||
objectToBeTested = new MatrixMarketWriter(fileName,&testMatrix[0],testMatrix.size()); | ||
} | ||
|
||
void TestMarketMatrixWriter::buildUp(std::string fileName, double cutoff) | ||
{ | ||
testMatrix = {1.1,0,0,0,0,2.2,3.3,0,0,0,0,0,4.4,0,0,5.21,0,0,0,0,0,0,0}; | ||
objectToBeTested = new MatrixMarketWriter(fileName,cutoff,&testMatrix[0],testMatrix.size()); | ||
} | ||
|
||
void TestMarketMatrixWriter::writeSuccessFileNotempty() | ||
{ | ||
fileChecker.open(testOutputFileName); | ||
assert(fileChecker.peek() != std::ifstream::traits_type::eof()); | ||
} | ||
|
||
void TestMarketMatrixWriter::tearDown(std::string fileName) | ||
{ | ||
fileChecker.close(); | ||
remove(fileName.c_str()); | ||
delete objectToBeTested; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef OUTPUT_TESTMARKETMATRIXWRITER_H | ||
#define OUTPUT_TESTMARKETMATRIXWRITER_H | ||
|
||
#include <vector> | ||
#include "../output/MarketMatrixWriter.h" | ||
#include "assert.h" | ||
|
||
class TestMarketMatrixWriter { | ||
private: | ||
MatrixMarketWriter* objectToBeTested; | ||
std::vector<double> testMatrix; | ||
std::string testOutputFileName; | ||
std::ifstream fileChecker; | ||
public: | ||
void buildUp(std::string fileName); | ||
void buildUp(std::string fileName, double cutoff); | ||
|
||
void tearDown(std::string fileName); | ||
void writeSuccessFileNotempty(); | ||
|
||
void createBinaryFile() {objectToBeTested->createBinaryFile();} | ||
void createDumpFile() {objectToBeTested->createDumpFile();} | ||
}; | ||
|
||
|
||
#endif //OUTPUT_TESTMARKETMATRIXWRITER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <unordered_map> | ||
#include <cstdio> | ||
#include <omp.h> | ||
|
||
#include <iostream> | ||
#include <assert.h> | ||
#include "TestMarketMatrixWriter.h" | ||
|
||
int main() | ||
{ | ||
std::string sampleOutputFileName = "someoutput.bin"; | ||
|
||
//Testing MarketMatrixWriter class without using cutoff value | ||
TestMarketMatrixWriter testObject; | ||
testObject.buildUp(sampleOutputFileName); | ||
|
||
//Creating output binary file and checking if the file was not left empty | ||
testObject.createBinaryFile(); | ||
testObject.writeSuccessFileNotempty(); | ||
|
||
testObject.tearDown(sampleOutputFileName); | ||
|
||
//New test for dump function | ||
testObject.buildUp(sampleOutputFileName); | ||
|
||
//Creating dump file and checking if the file was not left empty | ||
testObject.createDumpFile(); | ||
testObject.writeSuccessFileNotempty(); | ||
|
||
testObject.tearDown(sampleOutputFileName); | ||
|
||
//Repeating previous tests for MarketMatrixWriter class with cutoff value | ||
|
||
testObject.buildUp(sampleOutputFileName,0.5); | ||
|
||
testObject.createBinaryFile(); | ||
testObject.writeSuccessFileNotempty(); | ||
testObject.tearDown(sampleOutputFileName); | ||
|
||
testObject.buildUp(sampleOutputFileName,0.5); | ||
|
||
testObject.createDumpFile(); | ||
testObject.writeSuccessFileNotempty(); | ||
|
||
testObject.tearDown(sampleOutputFileName); | ||
return 0; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.6) | ||
project(tests) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
include_directories(../include) | ||
|
||
set(SOURCE_FILES main.cpp TestOpenBabelUtils.cpp TestOpenBabelUtils.h TestPdbParser.cpp TestPdbParser.h TestSettingsParser.cpp TestSettingsParser.h) | ||
add_executable(tests ${SOURCE_FILES} ../PdbParser.cpp ../PdbParser.h ../SettingsParser.cpp ../SettingsParser.h | ||
../OpenBabelUtils.cpp ../OpenBabelUtils.h ../ErrorHandler.h ../ErrorHandler.cpp) | ||
|
||
target_link_libraries(tests /home/toncsi/openbabel/lib/libopenbabel.so) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "TestOpenBabelUtils.h" | ||
|
||
|
||
void TestOpenBabelUtils::buildUp(std::string filename) | ||
{ | ||
objectToBeTested = new OpenBabelUtils(filename); | ||
|
||
//Open PDB mock input file that is going to be used for the test | ||
std::ofstream tempOutFile(filename); | ||
tempOutFile.close(); | ||
} | ||
|
||
void TestOpenBabelUtils::tearDown(std::string fileName) | ||
{ | ||
//Delete previously created file | ||
remove(fileName.c_str()); | ||
objectToBeTested->closeInputFile(); | ||
objectToBeTested->closeOutputFile(); | ||
delete objectToBeTested; | ||
} | ||
|
||
void TestOpenBabelUtils::obtainInputFileFormatSuccessFileName() | ||
{ | ||
//Getting first part of InputFileName, cutting ".<format>" | ||
std::string unformattedFileName1 = | ||
objectToBeTested->getInputFileName().substr(0, objectToBeTested->getInputFileName().length()- | ||
objectToBeTested->getInputFileName().find_last_of(".")); | ||
|
||
//Getting first part of PdbFileName, cutting ".pdb" | ||
std::string unformattedFileName2 = | ||
objectToBeTested->getPdbFileName().substr(0, objectToBeTested->getPdbFileName().length()- | ||
objectToBeTested->getPdbFileName().find_last_of(".")); | ||
|
||
assert(unformattedFileName1==unformattedFileName2); | ||
} | ||
|
||
void TestOpenBabelUtils::obtainInputFileFormatSuccessFormat() | ||
{ | ||
assert(objectToBeTested->getPdbFileName().substr(objectToBeTested->getPdbFileName().find_last_of("."),4)==".pdb"); | ||
} | ||
|
||
void TestOpenBabelUtils::openBabelConversionSuccessInputClosed() | ||
{ | ||
assert(!objectToBeTested->getIsInputOpen()); | ||
} | ||
|
||
void TestOpenBabelUtils::openBabelConversionSuccessOutputClosed() | ||
{ | ||
assert(!objectToBeTested->getIsOutputOpen()); | ||
} | ||
|
||
void TestOpenBabelUtils::initInPutFileSuccessFileOpen(std::string filename) | ||
{ | ||
objectToBeTested->initInputFile(filename); | ||
assert(objectToBeTested->getIsInputOpen()); | ||
} | ||
|
||
void TestOpenBabelUtils::initOutPutFileSuccessFileOpen(std::string filename) | ||
{ | ||
objectToBeTested->initOutPutFile(filename); | ||
assert(objectToBeTested->getIsOutputOpen()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef INPUT_PDB_TESTOPENBABELUTILS_H | ||
#define INPUT_PDB_TESTOPENBABELUTILS_H | ||
|
||
#include "../OpenBabelUtils.h" | ||
|
||
class TestOpenBabelUtils | ||
{ | ||
private: | ||
OpenBabelUtils* objectToBeTested; | ||
public: | ||
|
||
void buildUp(std::string filename); | ||
void tearDown(std::string fileName); | ||
|
||
//Redefining private member's functions due to inaccessibility | ||
void obtainInputFileFormat() { objectToBeTested->obtainInputFileFormat(); } | ||
void openBabelConversion() { objectToBeTested->OpenBabelConversion(); } | ||
|
||
//Check if convert function failed in execution | ||
void convert() { assert(!objectToBeTested->convert()); } | ||
|
||
//Redefining I/O functions for accessibility and testing purposes | ||
void initInPutFileSuccessFileOpen(std::string filename); | ||
void initOutPutFileSuccessFileOpen(std::string filename); | ||
|
||
//Testing OpenBabelUtils obtainInputFileFormat function | ||
void obtainInputFileFormatSuccessFileName(); | ||
void obtainInputFileFormatSuccessFormat(); | ||
|
||
//Testing OpenBabelUtils openBabelConversion function (most of it consists of OpenBabel API calls) | ||
void openBabelConversionSuccessInputClosed(); | ||
void openBabelConversionSuccessOutputClosed(); | ||
}; | ||
|
||
|
||
#endif //INPUT_PDB_TESTOPENBABELUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "TestPdbParser.h" | ||
|
||
|
||
void TestPdbParser::buildUp(std::string filename, std::string molecule) | ||
{ | ||
objectToBeTested = new PdbParser(filename, molecule); | ||
|
||
std::ofstream tempOutFile(filename); | ||
|
||
//placing sample molecule's details into a PDB file | ||
tempOutFile << "TITLE " << molecule << std::endl; | ||
tempOutFile << "ATOM 1 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile << "ATOM 2 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile << "ATOM 3 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile << "ATOM 4 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile << "ATOM 5 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile << "ATOM 6 CAY MET P 1 11.479 -16.234 64.191 1.00 0.00 PRO" << std::endl; | ||
tempOutFile.close(); | ||
} | ||
|
||
void TestPdbParser::readSuccessFileExists() | ||
{ | ||
fileChecker.open(objectToBeTested->getOutputFileName()); | ||
assert(fileChecker.is_open()); | ||
} | ||
|
||
void TestPdbParser::readSuccessFileNotempty() | ||
{ | ||
assert(fileChecker.peek() != std::ifstream::traits_type::eof()); | ||
} | ||
|
||
void TestPdbParser::tearDown(std::string fileName) | ||
{ | ||
|
||
auto const pos = fileName.find_last_of('.'); | ||
std::string tempFileName = fileName.substr(0,pos); | ||
tempFileName.append(".yah"); | ||
|
||
remove(tempFileName.c_str()); | ||
remove(fileName.c_str()); | ||
fileChecker.close(); | ||
delete objectToBeTested; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef INPUT_PDB_TESTPDBPARSER_H | ||
#define INPUT_PDB_TESTPDBPARSER_H | ||
|
||
#include "../PdbParser.h" | ||
|
||
class TestPdbParser { | ||
private: | ||
PdbParser* objectToBeTested; | ||
std::ifstream fileChecker; | ||
public: | ||
|
||
//Creating test PDB file | ||
void buildUp(std::string filename, std::string molecule); | ||
|
||
//Destroying test PDB file | ||
void tearDown(std::string filename); | ||
void convert() {objectToBeTested->convert();} | ||
|
||
//Check if the output file was written after read() was invoked | ||
void readSuccessFileExists(); | ||
void readSuccessFileNotempty(); | ||
}; | ||
|
||
|
||
#endif //INPUT_PDB_TESTPDBPARSER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "TestSettingsParser.h" | ||
|
||
void TestSettingsParser::buildUp(std::string fileName) | ||
{ | ||
objectToBeTested = new SettingsParser(fileName, testProps); | ||
std::ofstream tempOutFile(fileName); | ||
|
||
tempOutFile << "something1=true " << std::endl; | ||
tempOutFile << "something2=true " << std::endl; | ||
tempOutFile << "something3=false " << std::endl; | ||
tempOutFile << "something4=true " << std::endl; | ||
tempOutFile << "something5=false " << std::endl; | ||
|
||
tempOutFile.close(); | ||
} | ||
|
||
void TestSettingsParser::readSettingsSuccessPropsNotEmpty() | ||
{ | ||
assert(!objectToBeTested->getIsPropsEmpty()); | ||
} | ||
|
||
void TestSettingsParser::writeSettingsSuccessFileNotempty() | ||
{ | ||
fileChecker.open(objectToBeTested->getConfigFileName()); | ||
assert(fileChecker.peek() != std::ifstream::traits_type::eof()); | ||
} | ||
|
||
void TestSettingsParser::tearDown(std::string fileName1,std::string fileName2) | ||
{ | ||
remove(fileName1.c_str()); | ||
remove(fileName2.c_str()); | ||
delete objectToBeTested; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef INPUT_PDB_TESTSETTINGSPARSER_H | ||
#define INPUT_PDB_TESTSETTINGSPARSER_H | ||
|
||
#include "../SettingsParser.h" | ||
#include "assert.h" | ||
|
||
class TestSettingsParser { | ||
private: | ||
std::map<std::string, std::string>& testProps; | ||
SettingsParser* objectToBeTested; | ||
std::ifstream fileChecker; | ||
public: | ||
TestSettingsParser(std::map<std::string, std::string>& props) : testProps(props) {} | ||
void buildUp(std::string fileName); | ||
void tearDown(std::string fileName1,std::string fileName2); | ||
|
||
void readSettings() {objectToBeTested->readSettings();} | ||
void writeSettings(std::string outputFileName) {objectToBeTested->writeSettings(outputFileName);} | ||
|
||
void readSettingsSuccessPropsNotEmpty(); | ||
void writeSettingsSuccessFileNotempty(); | ||
}; | ||
|
||
|
||
#endif //INPUT_PDB_TESTSETTINGSPARSER_H |
Oops, something went wrong.