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

Смирнов Павел. Лабораторная №2 #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions include/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
#ifndef INCLUDE_CIRCLE_H_
#define INCLUDE_CIRCLE_H_
#include <cstdint>
#include <vector>

class Circle {
private:
double radius;
double ference;
double area;
public:
explicit Circle(double _radius);
void setRadius(double _radius);
void setFerence(double _ference);
void setArea(double _area);
double getRadius();
double getFerence();
double getArea();
};

#endif // INCLUDE_CIRCLE_H_
14 changes: 14 additions & 0 deletions include/tasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 Smirnov Pavel
#ifndef INCLUDE_TASKS_H_
#define INCLUDE_TASKS_H_

#include <vector>
#include "circle.h"


double calculateDeltaRadius(Circle circle, double length);
std::vector<double> calculatePoolPrice(
Circle pool, double path_price, double fance_price, double path_width);


#endif // INCLUDE_TASKS_H_
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(header_path "${${PROJECT_NAME}_SOURCE_DIR}/include")
set(header ${header_path}/circle.h)
set(src circle.cpp)
set(header ${header_path}/circle.h ${header_path}/tasks.h)
set(src circle.cpp tasks.cpp)

add_library(${PROJECT_NAME} SHARED
${header}
Expand Down
42 changes: 41 additions & 1 deletion src/circle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
// Copyright 2022 UNN-CS
// Copyright 2024 Smirnov Pavel
#include <cstdint>
#include <cmath>
#include <vector>
#include "circle.h"

Circle::Circle(double _radius) {
this->area = M_PI*_radius*_radius;
this->ference = 2*M_PI*_radius;
this->radius = _radius;
}

void Circle::setRadius(double _radius) {
this->area = M_PI*_radius*_radius;
this->ference = 2*M_PI*_radius;
this->radius = _radius;
}

void Circle::setArea(double _area) {
double new_radius = sqrt(_area / M_PI);
this->area = _area;
this->radius = new_radius;
this->ference = 2 * M_PI * new_radius;
}

void Circle::setFerence(double _ference) {
double new_radius = _ference / 2 * M_PI;
this->area = M_PI * new_radius * new_radius;
this->radius = new_radius;
this->ference = _ference;
}

double Circle::getRadius() {
return this->radius;
}
double Circle::getFerence() {
return this->ference;
}

double Circle::getArea() {
return this->area;
}


27 changes: 27 additions & 0 deletions src/tasks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Smirnov Pavel
#include <cmath>
#include <vector>

#include "circle.h"
#include "tasks.h"

double calculateDeltaRadius(Circle circle, double length) {
double new_ference = circle.getFerence() + length;
double new_radius = new_ference / 2 * M_PI;
double result = new_radius - circle.getRadius();
return result;
}

std::vector<double> calculatePoolPrice(
Circle pool,
double path_price,
double fence_price,
double path_width
) {
double fence_radius = pool.getRadius() + path_width;
Circle fence(fence_radius);
double result_fence_price = fence.getFerence() * fence_price;
double result_path_price = (fence.getArea() - pool.getArea()) * path_price;
std::vector<double> result = { result_fence_price, result_path_price };
return result;
}
79 changes: 78 additions & 1 deletion test/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,83 @@

// Copyright 2024 Smirnov Pavel
#include <gtest/gtest.h>
#include <cstdint>
#include <cmath>
#include <vector>

#include "circle.h"
#include "tasks.h"

TEST(CirlceTest, CheckArea1) {
double radius = 3;
Circle circle(radius);
double expected_area = radius * radius * M_PI;
EXPECT_EQ(circle.getArea(), expected_area);
}

TEST(CirlceTest, CheckArea2) {
double radius = 4;
Circle circle(radius);
double expected_area = radius * radius * M_PI;
EXPECT_EQ(circle.getArea(), expected_area);
}

TEST(CircleTest, CheckFerence1) {
double radius = 3;
Circle circle(radius);

double expected_ference = 2 * radius * M_PI;

EXPECT_EQ(circle.getFerence(), expected_ference);
}

TEST(CircleTest, CheckFerence2) {
double radius = 5;
Circle circle(radius);

double expected_ference = 2 * radius * M_PI;

EXPECT_EQ(circle.getFerence(), expected_ference);
}


TEST(TaskTest, CheckEarth1) {
double earth_radius = 6378.1 * pow(10, 3);
Circle earth(earth_radius);
double delta = calculateDeltaRadius(earth, 1.0);

double expected_delta = 56571225.401384361;
EXPECT_EQ(delta, expected_delta);
}

TEST(TaskTest, CheckEarth2) {
double earth_radius = 6378.1 * pow(10, 3);
Circle earth(earth_radius);
double delta = calculateDeltaRadius(earth, 2.0);

double expected_delta = 56571226.972180687;
EXPECT_EQ(delta, expected_delta);
}

TEST(TaskTest, CheckPool1) {
double pool_radius = 3;
Circle pool(pool_radius);
std::vector<double> result = calculatePoolPrice(pool, 1000, 2000, 1);

std::vector<double> expected_result = {
50265.482457436687,
21991.148575128551
};
EXPECT_EQ(result, expected_result);
}

TEST(TaskTest, CheckPool2) {
double pool_radius = 3;
Circle pool(pool_radius);
std::vector<double> result = calculatePoolPrice(pool, 1000, 2000, 1);

std::vector<double> expected_result = {
10,
20
};
EXPECT_TRUE(result > expected_result);
}
Loading