-
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.
Смирнов Павел - Лабораторная работа №3 (#405)
* rework lab_2 * cpplint_fix * code_coverage_fix * fix_2 * feat lab 3 application * fix lint * fix lint * fix ctests * fix ctests * fix lint * fixes * fixe lint * fix text msg in ctest --------- Co-authored-by: STELLSAN <[email protected]>
- Loading branch information
1 parent
2b7269c
commit 9277d49
Showing
6 changed files
with
156 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,69 @@ | ||
############################################# | ||
##### Testing | ||
############################################# | ||
|
||
set(prefix "${MODULE}") | ||
|
||
# Базовый тест: проверка запуска | ||
add_test( | ||
NAME ${prefix}_can_Run | ||
COMMAND ${APPLICATION} 8.0 1 1 1 1 1 | ||
) | ||
set_tests_properties(${prefix}_can_Run PROPERTIES LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_insufficient_arguments | ||
COMMAND ${APPLICATION} 8.0 1 1 1 1 | ||
) | ||
set_tests_properties(${prefix}_insufficient_arguments PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Not enough values. Please provide 6 numbers for the book price, counts" | ||
LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_valid_arguments_one_book | ||
COMMAND ${APPLICATION} 8.0 1 0 0 0 0 | ||
) | ||
set_tests_properties(${prefix}_valid_arguments_one_book PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 8" | ||
LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_valid_arguments_two_books | ||
COMMAND ${APPLICATION} 8.0 1 1 0 0 0 | ||
) | ||
set_tests_properties(${prefix}_valid_arguments_two_books PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 15.2" | ||
LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_valid_arguments_three_books | ||
COMMAND ${APPLICATION} 8.0 1 1 1 0 0 | ||
) | ||
set_tests_properties(${prefix}_valid_arguments_three_books PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 21.6" | ||
LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_valid_arguments_four_books | ||
COMMAND ${APPLICATION} 8.0 1 1 1 1 0 | ||
) | ||
set_tests_properties(${prefix}_valid_arguments_four_books PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 25.6" | ||
LABELS "${MODULE}") | ||
|
||
add_test( | ||
NAME ${prefix}_valid_arguments_five_books | ||
COMMAND ${APPLICATION} 8.0 1 1 1 1 1 | ||
) | ||
set_tests_properties(${prefix}_valid_arguments_five_books PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 30" | ||
LABELS "${MODULE}") | ||
|
||
# Тест для случая, когда количество книг одного вида больше 5 | ||
add_test( | ||
NAME ${prefix}_more_than_five_books_one_type | ||
COMMAND ${APPLICATION} 8.0 6 0 0 0 0 | ||
) | ||
set_tests_properties(${prefix}_more_than_five_books_one_type PROPERTIES | ||
PASS_REGULAR_EXPRESSION "Total price: 48" | ||
LABELS "${MODULE}") |
15 changes: 15 additions & 0 deletions
15
modules/nedelin_d_book_discount_lab2/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) |
14 changes: 14 additions & 0 deletions
14
modules/nedelin_d_book_discount_lab2/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,14 @@ | ||
// Copyright 2024 Смирнов Павел | ||
|
||
#include <iostream> | ||
|
||
#include "include/HarryPotterBooksApp.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
HarryPotterBooksApp app; | ||
auto output = app.run(argc, argv); | ||
|
||
std::cout << output << '\n'; | ||
|
||
return 0; | ||
} |
16 changes: 16 additions & 0 deletions
16
modules/nedelin_d_book_discount_lab2/include/HarryPotterBooksApp.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,16 @@ | ||
// Copyright 2024 Смирнов Павел | ||
#ifndef MODULES_NEDELIN_D_BOOK_DISCOUNT_LAB2_INCLUDE_HARRYPOTTERBOOKSAPP_H_ | ||
#define MODULES_NEDELIN_D_BOOK_DISCOUNT_LAB2_INCLUDE_HARRYPOTTERBOOKSAPP_H_ | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
class HarryPotterBooksApp { | ||
public: | ||
std::string run(int argc, char* argv[]); | ||
|
||
private: | ||
std::string calculatePrice(double price, const std::vector<int>& books); | ||
}; | ||
|
||
#endif // MODULES_NEDELIN_D_BOOK_DISCOUNT_LAB2_INCLUDE_HARRYPOTTERBOOKSAPP_H_ |
34 changes: 34 additions & 0 deletions
34
modules/nedelin_d_book_discount_lab2/src/HarryPotterBooksApp.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,34 @@ | ||
// Copyright 2024 Smirnov Pavel | ||
#include <sstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "include/HarryPotterBooksApp.h" | ||
#include "include/HarryPotterBooks.h" | ||
|
||
|
||
std::string HarryPotterBooksApp::calculatePrice( | ||
double price, const std::vector<int>& books) { | ||
HarryPotterBooks hpBooks(price, books); | ||
double totalPrice = hpBooks.calculateTotalPrice(); | ||
std::stringstream ss; | ||
ss << "Total price: " << totalPrice; | ||
return ss.str(); | ||
} | ||
|
||
std::string HarryPotterBooksApp::run(int argc, char* argv[]) { | ||
std::vector<int> books; | ||
double price; | ||
if (argc < 7) { | ||
return "Not enough values. Please provide 6 numbers for the book price, counts"; | ||
} | ||
for (int i = 1; i < 7; ++i) { | ||
if (i == 1) { | ||
price = std::stoi(argv[i]); | ||
continue; | ||
} | ||
books.push_back(std::stoi(argv[i])); | ||
} | ||
return calculatePrice(price, books); | ||
} |