diff --git a/src/qtapp/CMakeLists.txt b/src/qtapp/CMakeLists.txt index 61157a2..07427ae 100644 --- a/src/qtapp/CMakeLists.txt +++ b/src/qtapp/CMakeLists.txt @@ -23,12 +23,12 @@ add_library( mdemList.cpp trainWindow.cpp settings.cpp - ${RESOURCES} ) add_executable( MdemoryApp main.cpp + ${RESOURCES} ) target_link_libraries(gui Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api) diff --git a/src/qtapp/mdemList.cpp b/src/qtapp/mdemList.cpp index 1ecde9c..4ca8807 100644 --- a/src/qtapp/mdemList.cpp +++ b/src/qtapp/mdemList.cpp @@ -273,7 +273,7 @@ void switchPage(int pageIdx); std::string getFilename(std::string path) { static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)"); std::smatch matches; - auto filenameMatched = std::regex_search(path, matches, lastPathElementExp); + std::regex_search(path, matches, lastPathElementExp); return matches[2].str(); } @@ -385,7 +385,6 @@ Mdem* makeMdem() { mdem->hFront.addWidget(&mdem->toggleVisibility); // Back - QVBoxLayout *hBack = new QVBoxLayout(); mdem->wBack.setLayout(&mdem->hBack); mdem->vMdem.addWidget(&mdem->wBack); @@ -563,7 +562,6 @@ void reloadMdem(std::string path) { MdemBuffer *buffer; auto filename = getFilename(path); if (currentMdem.compare(path) == 0) { - buffer = currentMdemBuffer; currentMdem = path; if (buffers.contains(path)) { buffers.erase(path); diff --git a/src/test/transpilerNonFunctional.cpp b/src/test/transpilerNonFunctional.cpp index cb20962..8569398 100644 --- a/src/test/transpilerNonFunctional.cpp +++ b/src/test/transpilerNonFunctional.cpp @@ -1,17 +1,22 @@ #include "api.h" #include "mdemList.h" -#include "settings.h" + #include #include #include #include +typedef std::chrono::nanoseconds duration; +typedef duration::rep rep; +typedef duration::period period; +typedef std::chrono::time_point time_point; + 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; + std::cerr << "Nevar atvert failu!" << std::endl; return ""; } std::ostringstream ss; @@ -19,54 +24,45 @@ std::string readFileContents(const std::string& filePath) { return ss.str(); } -TEST(PerformanceTest, DISABLED_Measure100_000SimpleQuestions) { +double timePerformance(time_point start, time_point end, int numIterations) { + std::chrono::duration duration = end - start; + double averageTime = duration.count() / numIterations; + std::cout << "Vidējais laiks (" << numIterations << " iterācijas): " + << averageTime + << " sekundes iterācijā\n"; + auto averagePerSecond = (100000 / averageTime); + std::cout << "Jautājumi sekundē(" << numIterations << " iterācijas): " + << averagePerSecond << std::endl; + return averagePerSecond; +}; + +TEST(PerformanceTest, Measure100000SimpleQuestions) { 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 questions = transpile(contents); } auto end = std::chrono::high_resolution_clock::now(); - std::chrono::duration 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); + + ASSERT_GE(timePerformance(start, end, numIterations), 24999); } -TEST(PerformanceTest, MeasureOutput100_000SimpleQuestions) { +TEST(PerformanceTest, MeasureOutput100000SimpleQuestions) { 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 info = transpile(contents).value; 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 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); + ASSERT_GE(timePerformance(start, end, numIterations), 100000); } int main(int argc, char **argv) { @@ -80,4 +76,3 @@ int main(int argc, char **argv) { } return RUN_ALL_TESTS(); } - diff --git a/src/transpiler/lexer.cpp b/src/transpiler/lexer.cpp index d798181..f1f19db 100644 --- a/src/transpiler/lexer.cpp +++ b/src/transpiler/lexer.cpp @@ -231,6 +231,8 @@ Result> tokenizeMdem(const std::string& content) { previousRow = row; previousColumn = column; textStarted = false; + } break; + default:{ } break; } diff --git a/src/transpiler/parser.cpp b/src/transpiler/parser.cpp index 136e49f..8be8f92 100644 --- a/src/transpiler/parser.cpp +++ b/src/transpiler/parser.cpp @@ -88,7 +88,7 @@ Result ValidateGrammar(const std::vector& tokens) { auto capitalize = [](const std::string& str) { if (str.empty()) return str; std::string result = str; - result[0] = std::towupper(result[0]); + result[0] = std::toupper(result[0]); return result; }; return {