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
40 changes: 40 additions & 0 deletions trunk/ii02704/task_02/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<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">Группы ИИ-27</p>
<p align="right">Гридчин А.В.</p>
<p align="right">Проверил:</p>
<p align="right">Дворанинович Д.А.</p>
<br><br><br><br><br>
<p align="center">Брест 2025</p>

# Общее задание #
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/)).

## Задание 2.##
Comment thread
gr1frykt marked this conversation as resolved.
Comment thread
gr1frykt marked this conversation as resolved.
В ходе выполнения было написано три теста. Было написано три теста для функции linear. Покрытие программы составляет 67%. Замер производился с помощью программы OpenCppCoverage(https://github.com/OpenCppCoverage/OpenCppCoverage/releases).
[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from Test
[ RUN ] Test.linearr
[ OK ] Test.linearr (0 ms)
[ RUN ] Test.linearr2
[ OK ] Test.linearr2 (0 ms)
[ RUN ] Test.linearr3
[ OK ] Test.linearr3 (0 ms)
[----------] 3 tests from Test (2 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (4 ms total)
[ PASSED ] 3 tests.
10 changes: 10 additions & 0 deletions trunk/ii02704/task_02/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required (VERSION 3.5)
project (task_02_ii02704)

add_library(linear_ii02704
linear1.cpp)

add_executable (ii02704_task2
otis2.cpp)

target_link_libraries(ii02704_task2 PRIVATE linear_ii02704)
18 changes: 18 additions & 0 deletions trunk/ii02704/task_02/src/Linear.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef LINE_H
#define LINE_H
Comment thread
gr1frykt marked this conversation as resolved.
#include <iostream>
#include <vector>

struct Params
{
int k;
Comment thread
gr1frykt marked this conversation as resolved.
std::vector<double> y;
std::vector<double> u;
double a;
Comment thread
gr1frykt marked this conversation as resolved.
double b;
};
Comment thread
gr1frykt marked this conversation as resolved.

void input(Params &s);
void linear(Params &s, const int& place);
Comment thread
gr1frykt marked this conversation as resolved.

#endif
31 changes: 31 additions & 0 deletions trunk/ii02704/task_02/src/linear1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Linear.h"
#include <iostream>

using namespace std;

void input(Params &s) {
cout << "Enter amount of iterations: ";
cin >> s.k;
s.u.resize(s.k + 1, 0);
s.y.resize(s.k + 1, 0);
cout << "\nEnter temperature: ";
cin >> s.y.at(0);
for (auto& warm : s.u) {
cout << "\nEnter warm: ";
cin >> warm;
}

cout << "Enter const a: ";

cin >> s.a;

cout << "Enter const b: ";

cin >> s.b;

}
void linear(Params &s, const int& place) {
if(s.k >= 0){
s.y.at(place + 1) = s.a * s.y.at(place) + s.b * s.u.at(place);
}
}
19 changes: 19 additions & 0 deletions trunk/ii02704/task_02/src/otis2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
Comment thread
gr1frykt marked this conversation as resolved.
#include <vector>
#include "Linear.h"

using namespace std;


int main()
{
Params p;
input(p);
for (int i = 0; i < p.k; i++) {
linear(p,i);
}
for (auto n : p.y) {
cout << n << endl;
}
return 0;
}
46 changes: 46 additions & 0 deletions trunk/ii02704/task_02/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.5)
project(task_02_ii02704_test)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")


include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()


add_executable(
${CMAKE_PROJECT_NAME}
test.cpp

../src/linear1.cpp
../src/Linear.h
)
target_link_libraries(
${CMAKE_PROJECT_NAME}
PRIVATE
gtest
gtest_main
gmock
)


target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE --coverage -g -O0)
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE --coverage)


include(GoogleTest)
gtest_discover_tests(${CMAKE_PROJECT_NAME})
45 changes: 45 additions & 0 deletions trunk/ii02704/task_02/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "gtest/gtest.h"
#include "../src/Linear.h"
TEST(Test, linearr) {
Comment thread
gr1frykt marked this conversation as resolved.
double res;
Params p;
p.y.resize(2, 0);
p.u.resize(2, 0);
p.k = 2;
p.y[0] = 13;
p.u[0] = 1.3;
Comment thread
gr1frykt marked this conversation as resolved.
p.a = 2.3;
p.b = 5.6;
linear(p,0);
res = p.y[1];
EXPECT_NEAR(res, 37.18, 0.01);
Comment thread
gr1frykt marked this conversation as resolved.
}
TEST(Test, linearr2) {
Comment thread
gr1frykt marked this conversation as resolved.
double res;
Params p;
p.y.resize(2, 0);
p.u.resize(2, 0);
p.k = 2;
p.y[0] = 2.6;
p.u[0] = 3.5;
p.a = 14.7;
p.b = 5.6;
linear(p,0);
res = p.y[1];
EXPECT_NEAR(res, 57.82, 0.01);
}

TEST(Test, linearr3) {
Comment thread
gr1frykt marked this conversation as resolved.
Comment thread
gr1frykt marked this conversation as resolved.
double res;
Params p;
p.y.resize(2, 0);
p.u.resize(2, 0);
p.k = 2;
p.y[0] = 0.8;
p.u[0] = 9.6;
p.a = 12.3;
p.b = 7.3;
linear(p,0);
res = p.y[1];
EXPECT_NEAR(res, 79.92, 0.01);
Comment thread
gr1frykt marked this conversation as resolved.
}
Comment thread
gr1frykt marked this conversation as resolved.
Loading