-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* impl lab3 app * format
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
############################################# | ||
##### Testing | ||
############################################# | ||
|
||
set(prefix "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_run | ||
COMMAND ${APPLICATION} | ||
) | ||
set_tests_properties (${prefix}_run PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Usage:" | ||
LABELS "${MODULE}" | ||
) | ||
|
||
add_test( | ||
NAME ${prefix}_run_empty | ||
COMMAND ${APPLICATION} | ||
) | ||
set_tests_properties (${prefix}_run_empty PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Usage:" | ||
LABELS "${MODULE}" | ||
) | ||
|
||
add_test( | ||
NAME ${prefix}_run_invalid_vertices | ||
COMMAND ${APPLICATION} 0 0 1 0 1000 | ||
) | ||
set_tests_properties(${prefix}_run_invalid_vertices PROPERTIES | ||
PASS_REGULAR_EXPRESSION "invalid arguments number" | ||
LABELS "${MODULE}" | ||
) | ||
|
||
add_test( | ||
NAME ${prefix}_run_invalid_arguments | ||
COMMAND ${APPLICATION} 0 0 2 e 1 1 2 0 0 2 1000 | ||
) | ||
set_tests_properties(${prefix}_run_invalid_arguments PROPERTIES | ||
PASS_REGULAR_EXPRESSION "invalid_argument" | ||
LABELS "${MODULE}" | ||
) | ||
|
||
add_test( | ||
NAME ${prefix}_run_valid | ||
COMMAND ${APPLICATION} 0 0 1 0 1 1 0 1 1000 | ||
) | ||
set_tests_properties(${prefix}_run_valid PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Area: 1.000000 square meters" | ||
PASS_REGULAR_EXPRESSION "Cost: 1000.000000 currency units" | ||
LABELS "${MODULE}" | ||
) |
15 changes: 15 additions & 0 deletions
15
modules/kachalov_m_calc_polygon/application/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set(target ${APPLICATION}) | ||
|
||
file(GLOB srcs "*.cpp") | ||
set_source_files_properties(${srcs} PROPERTIES | ||
LABELS "${MODULE};Application") | ||
|
||
add_executable(${target} ${srcs}) | ||
set_target_properties(${target} PROPERTIES | ||
OUTPUT_NAME ${MODULE} | ||
LABELS "${MODULE};Application") | ||
|
||
target_link_libraries(${target} ${LIBRARY}) | ||
if (UNIX) | ||
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) | ||
endif (UNIX) |
11 changes: 11 additions & 0 deletions
11
modules/kachalov_m_calc_polygon/application/application.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024 Mironov Ilya | ||
|
||
#include <iostream> | ||
|
||
#include "include/polygon_price_app.h" | ||
|
||
int main(int argc, char** argv) { | ||
PolygonPriceApp ppapp; | ||
std::cout << ppapp(argc, argv) << '\n'; | ||
return 0; | ||
} |
22 changes: 22 additions & 0 deletions
22
modules/kachalov_m_calc_polygon/include/polygon_price_app.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 Mironov Ilya | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "include/polygon_area_calculator.h" | ||
|
||
class PolygonPriceApp { | ||
private: | ||
PolygonAreaCalculator areaCalculator{}; | ||
std::string sMessage{}; | ||
double pricePerSquareMeter{}; | ||
|
||
public: | ||
PolygonPriceApp() = default; | ||
std::string operator()(int argc, char** argv); | ||
|
||
private: | ||
void help(const char* appname, const char* message = ""); | ||
void parseArgs(int argc, char** argv); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Mironov Ilya | ||
|
||
#include "include/polygon_price_app.h" | ||
|
||
#include <stdexcept> | ||
|
||
std::string PolygonPriceApp::operator()(int argc, char** argv) { | ||
if (!(argc >= 6 + 2 && argc % 2 == 0)) { | ||
help(argv[0], "invalid arguments number"); | ||
return sMessage; | ||
} | ||
|
||
try { | ||
parseArgs(argc, argv); | ||
} catch (const std::invalid_argument& e) { | ||
help(argv[0], "invalid_argument"); | ||
return sMessage; | ||
} catch (const std::out_of_range& e) { | ||
help(argv[0], "numbers are to large"); | ||
return sMessage; | ||
} | ||
|
||
double area = areaCalculator.calculateArea(); | ||
double cost = area * pricePerSquareMeter; | ||
|
||
sMessage = "Area: " + std::to_string(area) + " square meters\n" + | ||
"Cost: " + std::to_string(cost) + " currency units\n"; | ||
|
||
return sMessage; | ||
} | ||
|
||
void PolygonPriceApp::help(const char* appname, const char* message) { | ||
sMessage = "Usage: " + std::string(appname) + | ||
" <x1> <y1> <x2> <y2> <x3> <y3> ... <price_per_square_meter>\n" + | ||
std::string(message) + "\n"; | ||
} | ||
|
||
void PolygonPriceApp::parseArgs(int argc, char** argv) { | ||
areaCalculator.clearVertices(); | ||
|
||
for (int i = 1; i < argc - 1; i += 2) { | ||
double x = std::stod(argv[i]); | ||
double y = std::stod(argv[i + 1]); | ||
areaCalculator.addVertex(x, y); | ||
} | ||
|
||
pricePerSquareMeter = std::stod(argv[argc - 1]); | ||
} |