Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New unit tests #284

Merged
merged 10 commits into from
Nov 6, 2023
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CMake

on:
xendalm marked this conversation as resolved.
Show resolved Hide resolved
push:
branches: [ "main" ]
branches: [ "*" ]
pull_request:
branches: [ "main" ]
branches: [ "*" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ add_subdirectory(libs/Interpreter)
add_subdirectory(libs/InputGenerator)
add_subdirectory(apps/InterpreterApp)
add_subdirectory(apps/InputGeneratorApp)
add_subdirectory(apps/TestsApp)
add_subdirectory(apps/TestsApp)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
6 changes: 4 additions & 2 deletions apps/TestsApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ project(TestsApp)
# Create a sources variable with a link to all cpp files to compile
set(SOURCES
src/Example.cpp
src/main.cpp)
src/main.cpp
src/UnitTests.cpp)


# Add a library with the above sources
add_executable(${PROJECT_NAME} ${SOURCES})
Expand All @@ -18,9 +20,9 @@ target_link_libraries(${PROJECT_NAME}
Interpreter
Tester
Objects
gtest
)

enable_testing()

add_test(NAME UnitTests
COMMAND ${PROJECT_NAME})
104 changes: 104 additions & 0 deletions apps/TestsApp/src/UnitTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "AutomatonToImage/AutomatonToImage.h"

Check notice on line 1 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on apps/TestsApp/src/UnitTests.cpp

File apps/TestsApp/src/UnitTests.cpp does not conform to Custom style guidelines. (lines 1, 27, 40, 95, 97)

Check failure on line 1 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:1:10 [clang-diagnostic-error]

'AutomatonToImage/AutomatonToImage.h' file not found
#include "InputGenerator/RegexGenerator.h"
#include "InputGenerator/TasksGenerator.h"
#include "Interpreter/Interpreter.h"
#include "Objects/FiniteAutomaton.h"
#include "Objects/Grammar.h"
#include "Objects/Language.h"
#include "Objects/Regex.h"
#include "Objects/TransformationMonoid.h"
#include "Objects/iLogTemplate.h"
#include "Tester/Tester.h"
#include <cassert>
#include <functional>
#include <iostream>
#include "gtest/gtest.h"

TEST(TestCaseName, GlaisterShallit) {

Check warning on line 17 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:17:1 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 17 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:17:18 [readability-named-parameter]

all parameters should be named in a function
auto check_classes_number = [](string rgx_str) {
return (Regex(rgx_str).to_glushkov().get_classes_number_GlaisterShallit());
};
EXPECT_EQ(1, 1);
EXPECT_EQ(check_classes_number("abs"), 4);
EXPECT_EQ(check_classes_number("a*b*c*"), 3);
EXPECT_EQ(check_classes_number("aa*bb*cc*"), 4);
EXPECT_EQ(check_classes_number("ab|abc"), 4);
EXPECT_EQ(check_classes_number("a(b|c)(a|b)(b|c)"), 5);

Check warning on line 26 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:26:54 [cppcoreguidelines-avoid-magic-numbers

5 is a magic number; consider replacing it with a named constant
}



TEST(TestCaseName, Test_random_regex_parsing) {

Check warning on line 31 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:31:1 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 31 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:31:18 [readability-named-parameter]

all parameters should be named in a function
RegexGenerator rg(15, 10, 5, 3);

Check warning on line 32 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:32:17 [cppcoreguidelines-init-variables]

variable 'rg' is not initialized
for (int i = 0; i < 30; i++) {

Check warning on line 33 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:33:22 [cppcoreguidelines-avoid-magic-numbers

30 is a magic number; consider replacing it with a named constant
string str = rg.generate_regex();

Check warning on line 34 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:34:10 [cppcoreguidelines-init-variables]

variable 'str' is not initialized
Regex r1(str);

Check warning on line 35 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:35:9 [cppcoreguidelines-init-variables]

variable 'r1' is not initialized
string r1_str = r1.to_txt();

Check warning on line 36 in apps/TestsApp/src/UnitTests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/UnitTests.cpp:36:10 [cppcoreguidelines-init-variables]

variable 'r1_str' is not initialized
Regex r2(r1_str);
EXPECT_EQ(true, Regex::equivalent(r1, r2));
}
}


TEST(TestCaseName, Test_test_fa_equal) {
vector<State> states1;
for (int i = 0; i < 6; i++) {
State s = {i, {i}, to_string(i), false, map<alphabet_symbol, set<int>>()};
states1.push_back(s);
}
states1[0].set_transition(1, "b");
states1[0].set_transition(2, "b");
states1[0].set_transition(5, "c");
states1[1].set_transition(3, "a");
states1[1].set_transition(4, "c");
states1[2].set_transition(4, "a");
states1[5].set_transition(4, "a");
states1[3].is_terminal = true;
states1[4].is_terminal = true;
FiniteAutomaton fa1(0, states1, {"a", "b", "c"});

vector<State> states2;
for (int i = 0; i < 6; i++) {
State s = {i, {i}, to_string(i), false, map<alphabet_symbol, set<int>>()};
states2.push_back(s);
}
states2[0].set_transition(1, "b");
states2[0].set_transition(2, "b");
states2[0].set_transition(5, "c");
states2[1].set_transition(3, "a");
states2[1].set_transition(3, "c");
states2[2].set_transition(4, "a");
states2[5].set_transition(4, "a");
states2[3].is_terminal = true;
states2[4].is_terminal = true;
FiniteAutomaton fa2(0, states2, {"a", "b", "c"});

vector<State> states3;
for (int i = 0; i < 6; i++) {
State s = {i, {i}, to_string(i), false, map<alphabet_symbol, set<int>>()};
states3.push_back(s);
}
states3[5].set_transition(4, "b");
states3[5].set_transition(3, "b");
states3[5].set_transition(0, "c");
states3[4].set_transition(2, "a");
states3[4].set_transition(1, "c");
states3[3].set_transition(1, "a");
states3[0].set_transition(1, "a");
states3[2].is_terminal = true;
states3[1].is_terminal = true;
FiniteAutomaton fa3(5, states3, {"a", "b", "c"});

EXPECT_TRUE(FiniteAutomaton::equal(fa1, fa1));
EXPECT_TRUE(!FiniteAutomaton::equal(fa1, fa2));
EXPECT_TRUE(FiniteAutomaton::equal(fa1, fa3));
EXPECT_TRUE(FiniteAutomaton::equal(Regex("(aab|aab)*").to_thompson().remove_eps(),
Regex("(aab|aab)*").to_glushkov()));
EXPECT_TRUE(FiniteAutomaton::equal(Regex("a(a)*ab(bb)*baa").to_thompson().remove_eps(),
Regex("a(a)*ab(bb)*baa").to_glushkov()));
EXPECT_TRUE(FiniteAutomaton::equal(
Regex("a(bbb*aaa*)*bb*|aaa*(bbb*aaa*)*|b(aaa*bbb*)*aa*|bbb*(aaa*bbb*)*")
.to_thompson()
.remove_eps(),
Regex("a(bbb*aaa*)*bb*|aaa*(bbb*aaa*)*|b(aaa*bbb*)*aa*|bbb*(aaa*bbb*)*").to_glushkov()));
}
16 changes: 11 additions & 5 deletions apps/TestsApp/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include "TestsApp/Example.h"

Check notice on line 1 in apps/TestsApp/src/main.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on apps/TestsApp/src/main.cpp

File apps/TestsApp/src/main.cpp does not conform to Custom style guidelines. (lines 7, 15)

Check failure on line 1 in apps/TestsApp/src/main.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/apps/TestsApp/src/main.cpp:1:10 [clang-diagnostic-error]

'TestsApp/Example.h' file not found
// #include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <iostream>
using namespace std;

int main() {
int main(int argc, char **argv) {
cout << "Test\n";
// Тестирование
Example::test_all();
xendalm marked this conversation as resolved.
Show resolved Hide resolved
Example::all_examples();
Example::logger_test();
}
// Example::test_all();
// Example::all_examples();
// Example::logger_test();
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}