mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
some non functional tests
This commit is contained in:
@@ -69,6 +69,12 @@ void update(bool isChanged = false);
|
|||||||
void saveMdem();
|
void saveMdem();
|
||||||
void updateMdemInfo(std::string filename = "", bool isChanged = true);
|
void updateMdemInfo(std::string filename = "", bool isChanged = true);
|
||||||
QMainWindow *initMdemListWindow();
|
QMainWindow *initMdemListWindow();
|
||||||
|
std::string outputMdem(
|
||||||
|
std::vector<Question*> questions,
|
||||||
|
time_t time,
|
||||||
|
const int wrap_width,
|
||||||
|
const int timezoneOffset
|
||||||
|
);
|
||||||
|
|
||||||
#define SETTING_PER_PAGE "perPage"
|
#define SETTING_PER_PAGE "perPage"
|
||||||
#define SETTING_MEMORYBASE "defaultMemorybase"
|
#define SETTING_MEMORYBASE "defaultMemorybase"
|
||||||
|
|||||||
@@ -18,14 +18,19 @@ include_directories(/usr/include/qt/Qsci)
|
|||||||
|
|
||||||
qt5_add_resources(RESOURCES ${CMAKE_SOURCE_DIR}/resources/resources.qrc)
|
qt5_add_resources(RESOURCES ${CMAKE_SOURCE_DIR}/resources/resources.qrc)
|
||||||
|
|
||||||
add_executable(
|
add_library(
|
||||||
MdemoryApp
|
gui
|
||||||
main.cpp
|
|
||||||
mdemList.cpp
|
mdemList.cpp
|
||||||
trainWindow.cpp
|
trainWindow.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
${RESOURCES}
|
${RESOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(MdemoryApp Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api)
|
add_executable(
|
||||||
|
MdemoryApp
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(gui Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api)
|
||||||
|
target_link_libraries(MdemoryApp gui)
|
||||||
target_include_directories(MdemoryApp PRIVATE ${CMAKE_SOURCE_DIR}/src/include)
|
target_include_directories(MdemoryApp PRIVATE ${CMAKE_SOURCE_DIR}/src/include)
|
||||||
|
|||||||
@@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
#include "mdemList.h"
|
#include "mdemList.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int initApp(int argc, char *argv[]) {
|
||||||
auto *app = new QApplication(argc, argv);
|
auto *app = new QApplication(argc, argv);
|
||||||
initMdemListWindow();
|
initMdemListWindow();
|
||||||
app->exec();
|
app->exec();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
return initApp(argc, argv);
|
||||||
|
}
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ Mdem *editMdem;
|
|||||||
QLabel *membaseLabel;
|
QLabel *membaseLabel;
|
||||||
QLabel *mdemLabel;
|
QLabel *mdemLabel;
|
||||||
QLabel *lastPracticeLabel;
|
QLabel *lastPracticeLabel;
|
||||||
|
|
||||||
QMainWindow *trainWindow;
|
QMainWindow *trainWindow;
|
||||||
|
|
||||||
void showBacklabels(Mdem *mdem) {
|
void showBacklabels(Mdem *mdem) {
|
||||||
@@ -115,17 +114,15 @@ void showBacklabels(Mdem *mdem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
std::string outputMdem(
|
||||||
|
std::vector<Question*> questions,
|
||||||
|
time_t time = 0,
|
||||||
|
const int wrap_width = 80,
|
||||||
|
const int timezoneOffset = 0
|
||||||
|
) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
int wrap_width = 80;
|
|
||||||
if (settings->contains(SETTING_CHARACTER_WRAP)) {
|
|
||||||
wrap_width = settings->value(SETTING_CHARACTER_WRAP).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
auto timezoneOffset = settings->value(SETTING_TIMEZONE).toInt();
|
|
||||||
/*time = time + 3600 * timezoneOffset;*/
|
|
||||||
std::tm* tm = std::localtime(&time);
|
std::tm* tm = std::localtime(&time);
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
std::strftime(buffer, sizeof(buffer), "%d.%m.%Y %H\\:%M", tm);
|
std::strftime(buffer, sizeof(buffer), "%d.%m.%Y %H\\:%M", tm);
|
||||||
@@ -342,9 +339,13 @@ Mdem* makeMdem() {
|
|||||||
[mdem]() {
|
[mdem]() {
|
||||||
editMdem = mdem;
|
editMdem = mdem;
|
||||||
if (mdem->question) {
|
if (mdem->question) {
|
||||||
|
int wrap_width = 80;
|
||||||
|
if (settings->contains(SETTING_CHARACTER_WRAP)) {
|
||||||
|
wrap_width = settings->value(SETTING_CHARACTER_WRAP).toInt();
|
||||||
|
}
|
||||||
editor->setText(
|
editor->setText(
|
||||||
QString::fromStdString(
|
QString::fromStdString(
|
||||||
outputMdem(std::vector<Question*>{mdem->question})
|
outputMdem(std::vector<Question*>{mdem->question}, 0, wrap_width)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
editorWindow->show();
|
editorWindow->show();
|
||||||
@@ -771,7 +772,21 @@ void saveMdem() {
|
|||||||
|
|
||||||
auto filename = getFilename(currentMdem);
|
auto filename = getFilename(currentMdem);
|
||||||
std::ofstream out(currentMdem);
|
std::ofstream out(currentMdem);
|
||||||
out << outputMdem(currentMdemBuffer->questions, currentMdemBuffer->trainedAt);
|
|
||||||
|
int wrap_width = 80;
|
||||||
|
if (settings->contains(SETTING_CHARACTER_WRAP)) {
|
||||||
|
wrap_width = settings->value(SETTING_CHARACTER_WRAP).toInt();
|
||||||
|
}
|
||||||
|
int timezoneOffset = 0;
|
||||||
|
if (settings->contains(SETTING_TIMEZONE)) {
|
||||||
|
timezoneOffset = settings->value(SETTING_TIMEZONE).toInt();
|
||||||
|
}
|
||||||
|
out << outputMdem(
|
||||||
|
currentMdemBuffer->questions,
|
||||||
|
currentMdemBuffer->trainedAt,
|
||||||
|
wrap_width,
|
||||||
|
timezoneOffset
|
||||||
|
);
|
||||||
updateMdemInfo(getFilename(currentMdem), false);
|
updateMdemInfo(getFilename(currentMdem), false);
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
|||||||
@@ -8,16 +8,30 @@ find_package(GTest REQUIRED)
|
|||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
testTranspiler
|
transpilerFunctional
|
||||||
testTranspiler.cpp
|
transpilerFunctional.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(
|
||||||
|
transpilerNonFunctional
|
||||||
|
transpilerNonFunctional.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
testTranspiler
|
transpilerFunctional
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
api
|
api
|
||||||
)
|
)
|
||||||
|
|
||||||
include(GoogleTest)
|
target_link_libraries(
|
||||||
gtest_discover_tests(testTranspiler)
|
transpilerNonFunctional
|
||||||
|
GTest::gtest_main
|
||||||
|
api
|
||||||
|
gui
|
||||||
|
)
|
||||||
|
|
||||||
|
if(ENABLE_TESTS)
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(transpilerFunctional)
|
||||||
|
gtest_discover_tests(transpilerNonFunctional)
|
||||||
|
endif()
|
||||||
|
|||||||
100000
src/test/testFiles/100000_simple_questions.mdem
Normal file
100000
src/test/testFiles/100000_simple_questions.mdem
Normal file
File diff suppressed because it is too large
Load Diff
83
src/test/transpilerNonFunctional.cpp
Normal file
83
src/test/transpilerNonFunctional.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "api.h"
|
||||||
|
#include "mdemList.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
std::string testFileDirectory;
|
||||||
|
|
||||||
|
std::string readFileContents(const std::string& filePath) {
|
||||||
|
std::ifstream file(filePath);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
std::cerr << "Could not open the file!" << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << file.rdbuf();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PerformanceTest, DISABLED_Measure100_000SimpleQuestions) {
|
||||||
|
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||||
|
const std::string contents = readFileContents(filePath);
|
||||||
|
const int numIterations = 15;
|
||||||
|
auto parseLargeFile = [contents]() {
|
||||||
|
auto questions = transpile(contents);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
for (int i = 0; i < numIterations; ++i) {
|
||||||
|
parseLargeFile();
|
||||||
|
}
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> duration = end - start;
|
||||||
|
|
||||||
|
double averageTime = duration.count() / numIterations;
|
||||||
|
std::cout << "Average time: "
|
||||||
|
<< averageTime
|
||||||
|
<< " seconds per iteration\n";
|
||||||
|
auto averagePerSecond = (100000 / averageTime);
|
||||||
|
std::cout << "Questions per second (" << numIterations << " iterations): "
|
||||||
|
<< averagePerSecond << std::endl;
|
||||||
|
|
||||||
|
ASSERT_GE(averagePerSecond, 24999);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PerformanceTest, MeasureOutput100_000SimpleQuestions) {
|
||||||
|
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||||
|
const std::string contents = readFileContents(filePath);
|
||||||
|
auto info = transpile(contents).value;
|
||||||
|
const int numIterations = 15;
|
||||||
|
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
for (int i = 0; i < numIterations; ++i) {
|
||||||
|
auto output = outputMdem(info.questions, 0, 80, 0);
|
||||||
|
}
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> duration = end - start;
|
||||||
|
|
||||||
|
double averageTime = duration.count() / numIterations;
|
||||||
|
std::cout << "Average time: "
|
||||||
|
<< averageTime
|
||||||
|
<< " seconds per iteration\n";
|
||||||
|
auto averagePerSecond = (100000 / averageTime);
|
||||||
|
std::cout << "Questions per second (" << numIterations << " iterations): "
|
||||||
|
<< averagePerSecond << std::endl;
|
||||||
|
|
||||||
|
ASSERT_GE(averagePerSecond, 24999);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
if (argc > 1) {
|
||||||
|
testFileDirectory = argv[1];
|
||||||
|
std::cout << "Test file directory set to: " << testFileDirectory << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "No test file directory provided! Using default directory.\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,3 @@
|
|||||||
# Set sources
|
|
||||||
set(
|
|
||||||
SOURCES
|
|
||||||
main.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
api
|
api
|
||||||
lexer.cpp
|
lexer.cpp
|
||||||
@@ -12,7 +6,7 @@ add_library(
|
|||||||
stringUtils.cpp
|
stringUtils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(transpiler ${SOURCES})
|
add_executable(transpiler main.cpp)
|
||||||
target_link_libraries(transpiler api)
|
target_link_libraries(transpiler api)
|
||||||
|
|
||||||
target_compile_options(transpiler PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(transpiler PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
|||||||
Reference in New Issue
Block a user