Skip to content

Commit

Permalink
add task1
Browse files Browse the repository at this point in the history
  • Loading branch information
Григорий Севергин committed Oct 31, 2024
1 parent 6821b20 commit 244cd7a
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Urfu Testing CI

on:
pull_request:
push:
workflow_dispatch:

jobs:

task1:
runs-on: ubuntu-22.04
container:
image: lifestyle288/urfucpp:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
options: --name main-container
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependecies
run: |
cd task1
cp -R /app/tests/task1 tests
mkdir build
cd build
cmake ..
make -j4
- name: Run tests
run: cd task1/build && ctest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
tests
Dockerfile
test.sh
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Urfu-Advanced-Cpp
# Как работать с репозиторием
- Форкаем реп
- После выполнения задания нужно сделать pull request на преподавателя со всеми пройденными тестами
- Тестирование срабатывает при любом пуше в реп, а так же при создании pull request
15 changes: 15 additions & 0 deletions task1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.25)

project(matrix)

find_package(Boost COMPONENTS unit_test_framework REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif (Boost_FOUND)

add_library(matrix STATIC matrix.cpp)

if (Boost_FOUND)
enable_testing()
add_subdirectory(tests)
endif (Boost_FOUND)
26 changes: 26 additions & 0 deletions task1/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Класс Matrix

#### Требуется реализовать интерфейс:

```c++
class Matrix
{
public:
Matrix() = default;
Matrix(int numRows, int numCols);

void Reset(int numRows, int numCols);
int& At(int row, int col);
const int& At(int row, int col) const;
int GetRows() const;
int GetCols() const;

bool operator==(const Matrix& m2);
bool operator!=(const Matrix& m2);
Matrix operator+(const Matrix& m2);
};
```

- методы At должны выбрасывать исключение std::out_of_range, если ячейка, которая в него передана выходит за границы матрицы
- если в метод Reset передали число колонок или столбцов равное 0, то оставляем объект в консистентном состоянии, зануляя количество столбцов и количество строк
- если мы пытаемся сложить 2 матрицы разных размеров, то должно выбрасываться исключение std::invalid_argument
48 changes: 48 additions & 0 deletions task1/matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "matrix.hpp"

#include <stdexcept>

Matrix::Matrix(int numRows, int numCols)
{
// your implementation here
}

void Matrix::Reset(int numRows, int numCols)
{
// your implementation here
}

int& Matrix::At(int row, int col)
{
// your implementation here
}

const int& Matrix::At(int row, int col) const
{
// your implementation here
}

int Matrix::GetRows() const
{
// your implementation here
}

int Matrix::GetCols() const
{
// your implementation here
}

bool Matrix::operator==(const Matrix& m2)
{
// your implementation here
}

bool Matrix::operator!=(const Matrix& m2)
{
// your implementation here
}

Matrix Matrix::operator+(const Matrix& m2)
{
// your implementation here
}
18 changes: 18 additions & 0 deletions task1/matrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

class Matrix
{
public:
Matrix() = default;
Matrix(int numRows, int numCols);

void Reset(int numRows, int numCols);
int& At(int row, int col);
const int& At(int row, int col) const;
int GetRows() const;
int GetCols() const;

bool operator==(const Matrix& m2);
bool operator!=(const Matrix& m2);
Matrix operator+(const Matrix& m2);
};

0 comments on commit 244cd7a

Please sign in to comment.