Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added trunk/ii02824/task_02/doc/images/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trunk/ii02824/task_02/doc/images/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions trunk/ii02824/task_02/doc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<p align="center"> Министерство образования Республики Беларусь</p>
<p align="center">Учреждение образования</p>
<p align="center">“Брестский Государственный технический университет”</p>
<p align="center">Кафедра ИИТ</p>
<br><br><br><br><br><br><br>
<p align="center">Лабораторная работа №2</p>
<p align="center">по дисциплине “Общая теория интеллектуальных систем”</p>
<p align="center">Тема: “Модульное тестирование. Покрытие исходного кода тестами”</p>
<br><br><br><br><br>
<p align="right">Выполнил:</p>
<p align="right">Студент 2 курса</p>
<p align="right">Группы ИИ-28</p>
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation refers to "Группы ИИ-28" (Group II-28) but the directory path indicates ii02824. While the student may be from group II-28, this inconsistency should be verified to ensure the documentation matches the actual student identifier.

Suggested change
<p align="right">Группы ИИ-28</p>
<p align="right">Группы ИИ-28 (ii02824)</p>

Copilot uses AI. Check for mistakes.
<p align="right">Сыч А.Д.</p>
<p align="right">Проверил:</p>
<p align="right">Дворанинович Д.А.</p>
<br><br><br><br><br>
<p align="center">Брест 2025</p>

<hr>


# Общее задание #
Написать модульные тесты для программы, разработанной в лабораторной работе №1.

1. Использовать следующий фреймворк для модульного тестирования - [Google Test](https://google.github.io/googletest/).
2. Написать модульные тесты для основных функций программы. Разместить тесты в каталоге: **trunk\ii0xxyy\task_02\test**.
3. Исходный код модифицированной программы разместить в каталоге: **trunk\ii0xxyy\task_02\src**.
4. В файле `readme.md` отразить количество написанных тестов и процент покрытия кода тестами (использовать любой инструмент для анализа покрытия, например, [gcovr](https://gcovr.com/en/stable/)).
5. Также необходимо отразить выполнение работы в общем файле [`readme.md`](https://github.com/brstu/OTIS-2025/blob/main/README.md) в соответствующей строке (например, для студента под порядковым номером 1 - https://github.com/brstu/OTIS-2025/blob/b2d60c2765b369aed21af76af8fa4461da2c8da6/README.md?plain=1#L13).
## Код модульных тестов ##
```
#define _USE_MATH_DEFINES
#include <gtest/gtest.h>
#include "../src/task_01.h"
#include <cmath>

TEST(LinearModelTest, BasicCase) {
double y1 = 2.0;
double u1 = 3.0;
double a1 = 1.5;
double b1 = -0.5;
double expected1 = a1 * y1 + b1 * u1;
EXPECT_DOUBLE_EQ(linear(y1, u1, a1, b1), expected1);
}

TEST(LinearModelTest, ZeroCoefficients) {
EXPECT_DOUBLE_EQ(linear(5.0, 4.0, 0.0, 0.0), 0.0);
}

TEST(LinearModelTest, NegativeInputs) {
EXPECT_DOUBLE_EQ(linear(-2.0, -3.0, 1.0, 2.0), -2.0 + (-3.0 * 2.0));
}

TEST(NonLinearModelTest, BasicCase) {
double y2 = 1.0;
double y2_p2 = 0.0;
double u2 = 0.5;
double a2 = 2.0;
double b2 = 1.0;
double c2 = 0.5;
double d2 = 1.0;

double expected2 = a2 * y2 - b1 * y2 * y2 + c2 * u2 + d2 * std::sin(u2);
double result2 = non_linear(y2, y2_p2, u2, a2, b2, c2, d2);

EXPECT_DOUBLE_EQ(result2, expected2);
EXPECT_DOUBLE_EQ(y2_p2, y2);
}

TEST(NonLinearModelTest, ZeroCoefficients) {
double y3 = 2.0;
double y3_p3 = 0.0;
double u3 = 1.0;
double result3 = non_linear(y3, y3_p3, u3, 0.0, 0.0, 0.0, 0.0);
EXPECT_DOUBLE_EQ(result3, 0.0);
}

TEST(NonLinearModelTest, SinusoidalEffect) {
double y4 = 0.0;
double y4_p4 = 0.0;
double u4 = M_PI / 2;
double result4 = non_linear(y4, y4_p4, u4, 0.0, 0.0, 0.0, 2.0);
EXPECT_DOUBLE_EQ(result4, 2.0);
}
```
## Результаты тестирования ##
![Результаты тестирования:](images/img1.png)
## Покрытие тестами (OpenCppCoverage) ##
![Покрытие тестами:](images/img2.png)
35 changes: 35 additions & 0 deletions trunk/ii02824/task_02/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.14)
project(my_project)
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project name 'my_project' is generic and non-descriptive. Consider using a more meaningful name like 'task_02_models' or 'labwork2' that reflects the actual purpose of the project.

Suggested change
project(my_project)
project(task_02_models)

Copilot uses AI. Check for mistakes.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

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)

enable_testing()

add_executable(
my_tests1
${CMAKE_CURRENT_SOURCE_DIR}/task_01.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../test/test.cpp
)

target_include_directories(my_tests1 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../src
${CMAKE_CURRENT_SOURCE_DIR}/../test
)

target_link_libraries(
my_tests1
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(my_tests1)
12 changes: 12 additions & 0 deletions trunk/ii02824/task_02/src/task_01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cmath>

double linear(double y1, double u1, double a1, double b1)
{
return a1 * y1 + b1 * u1;
}

double non_linear(double y1, double& y1_p1, double u1, double a1, double b1, double c1, double d1)
{
y1_p1 = y1;
return a1 * y1 - b1 * y1_p1 * y1_p1 + c1 * u1 + d1 * std::sin(u1);
}
Comment on lines +1 to +12
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is named "task_01.cpp" but is located in the task_02 directory. This naming inconsistency could cause confusion. Consider renaming to "task_02.cpp" to match the task directory.

Copilot uses AI. Check for mistakes.
4 changes: 4 additions & 0 deletions trunk/ii02824/task_02/src/task_01.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

double linear(double y1, double u1, double a1, double b1);
double non_linear(double y1, double& y1_p1, double u1, double a1, double b1, double c1, double d1);
Comment on lines +3 to +4
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter names use a '1' suffix (e.g., y1, u1, a1) which is unnecessary and reduces readability. Consider renaming to more conventional names like y, u, a, b, etc., which would match the test code and improve clarity.

Suggested change
double linear(double y1, double u1, double a1, double b1);
double non_linear(double y1, double& y1_p1, double u1, double a1, double b1, double c1, double d1);
double linear(double y, double u, double a, double b);
double non_linear(double y, double& y_p1, double u, double a, double b, double c, double d);

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +4
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable names in the header file use inconsistent suffixes. The parameters are named y1, y1_p1, u1, a1, b1, c1, d1, but based on the context and usage in tests, these should represent generic parameters, not specifically "1"-indexed values. Consider using more descriptive names like 'y', 'y_prev', 'u', 'a', 'b', 'c', 'd' to avoid confusion with the test variable naming convention.

Suggested change
double linear(double y1, double u1, double a1, double b1);
double non_linear(double y1, double& y1_p1, double u1, double a1, double b1, double c1, double d1);
double linear(double y, double u, double a, double b);
double non_linear(double y, double& y_prev, double u, double a, double b, double c, double d);

Copilot uses AI. Check for mistakes.
53 changes: 53 additions & 0 deletions trunk/ii02824/task_02/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#define _USE_MATH_DEFINES
#include <gtest/gtest.h>
#include "../src/task_01.h"
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include path references "task_01.h" but the directory is named "task_02". While this works because the file is in the src directory, this creates confusion. Consider renaming the header and source files to match the task number (task_02) for consistency.

Suggested change
#include "../src/task_01.h"
#include "../src/task_02.h"

Copilot uses AI. Check for mistakes.
#include <cmath>

TEST(LinearModelTest, BasicCase) {
double y1 = 2.0;
double u1 = 3.0;
double a1 = 1.5;
double b1 = -0.5;
double expected1 = a1 * y1 + b1 * u1;
EXPECT_DOUBLE_EQ(linear(y1, u1, a1, b1), expected1);
}

TEST(LinearModelTest, ZeroCoefficients) {
EXPECT_DOUBLE_EQ(linear(5.0, 4.0, 0.0, 0.0), 0.0);
}

TEST(LinearModelTest, NegativeInputs) {
EXPECT_DOUBLE_EQ(linear(-2.0, -3.0, 1.0, 2.0), -2.0 + (-3.0 * 2.0));
}

TEST(NonLinearModelTest, BasicCase) {
double y2 = 1.0;
double y2_p2 = 0.0;
double u2 = 0.5;
double a2 = 2.0;
double b2 = 1.0;
double c2 = 0.5;
double d2 = 1.0;

double expected2 = a2 * y2 - b2 * y2 * y2 + c2 * u2 + d2 * std::sin(u2);
double result2 = non_linear(y2, y2_p2, u2, a2, b2, c2, d2);

EXPECT_DOUBLE_EQ(result2, expected2);
EXPECT_DOUBLE_EQ(y2_p2, y2);
}

TEST(NonLinearModelTest, ZeroCoefficients) {
double y3 = 2.0;
double y3_p3 = 0.0;
double u3 = 1.0;
double result3 = non_linear(y3, y3_p3, u3, 0.0, 0.0, 0.0, 0.0);
EXPECT_DOUBLE_EQ(result3, 0.0);
}

TEST(NonLinearModelTest, SinusoidalEffect) {
double y4 = 0.0;
double y4_p4 = 0.0;
double u4 = M_PI / 2;
double result4 = non_linear(y4, y4_p4, u4, 0.0, 0.0, 0.0, 2.0);
EXPECT_DOUBLE_EQ(result4, 2.0);
}
Loading