-
Notifications
You must be signed in to change notification settings - Fork 52
[task_02] Labwork2 #362
base: main
Are you sure you want to change the base?
[task_02] Labwork2 #362
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| <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); | ||
| } | ||
| ``` | ||
| ## Результаты тестирования ## | ||
|  | ||
| ## Покрытие тестами (OpenCppCoverage) ## | ||
|  | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| cmake_minimum_required(VERSION 3.14) | ||||||
| project(my_project) | ||||||
|
||||||
| project(my_project) | |
| project(task_02_models) |
| 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
|
||
| 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
|
||||||||||||||||||
| 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
AI
Dec 21, 2025
There was a problem hiding this comment.
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.
| 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); |
| 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" | ||||||
|
||||||
| #include "../src/task_01.h" | |
| #include "../src/task_02.h" |
There was a problem hiding this comment.
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.