Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelLSmirnov committed Nov 11, 2024
1 parent 5921ee8 commit 907d6bf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 58 deletions.
89 changes: 38 additions & 51 deletions modules/nedelin_d_book_discount_lab2/CTestTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,64 @@ set(prefix "${MODULE}")

# Базовый тест: проверка запуска
add_test(
NAME ${prefix}_can_Run
COMMAND ${APPLICATION} 1 1 1 1 1
NAME ${prefix}_can_Run
COMMAND ${APPLICATION} 8.0 1 1 1 1 1
)
set_tests_properties (${prefix}_can_Run PROPERTIES
LABELS "${MODULE}")
set_tests_properties(${prefix}_can_Run PROPERTIES LABELS "${MODULE}")

# Тесты для неверного количества аргументов
add_test(
NAME ${prefix}_insufficient_arguments
COMMAND ${APPLICATION} 1 1 1 1
NAME ${prefix}_insufficient_arguments
COMMAND ${APPLICATION} 8.0 1 1 1 1
)
set_tests_properties(${prefix}_insufficient_arguments PROPERTIES
PASS_REGULAR_EXPRESSION "Not enough arguments. Please provide 6 numbers for the book price and counts."
LABELS "${MODULE}")

set_tests_properties (${prefix}_insufficient_arguments PROPERTIES
PASS_REGULAR_EXPRESSION "Not enough arguments. Please provide 5 numbers for the book counts."
LABELS "${MODULE}")

# Тесты для корректных аргументов
add_test(
NAME ${prefix}_valid_arguments_one_book
COMMAND ${APPLICATION} 1 0 0 0 0
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}")
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} 1 1 0 0 0
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}")
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} 1 1 1 0 0
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}")
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} 1 1 1 1 0
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}")
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} 1 1 1 1 1
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}")
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} 6 0 0 0 0
)
set_tests_properties (${prefix}_more_than_five_books_one_type PROPERTIES
PASS_REGULAR_EXPRESSION "Total price: 48"
LABELS "${MODULE}")

# Тесты для отрицательных аргументов
add_test(
NAME ${prefix}_negative_argument
COMMAND ${APPLICATION} -1 1 1 1 1
NAME ${prefix}_more_than_five_books_one_type
COMMAND ${APPLICATION} 8.0 6 0 0 0 0
)
set_tests_properties (${prefix}_negative_argument PROPERTIES
PASS_REGULAR_EXPRESSION "Total price: 25.6"
LABELS "${MODULE}")
set_tests_properties(${prefix}_more_than_five_books_one_type PROPERTIES
PASS_REGULAR_EXPRESSION "Total price: 48"
LABELS "${MODULE}")
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class HarryPotterBooksApp {
std::string run(int argc, char* argv[]);

private:
std::string calculatePrice(const std::vector<int>& books);
std::string calculatePrice(double price, const std::vector<int>& books);
};

#endif // MODULES_NEDELIN_D_BOOK_DISCOUNT_LAB2_INCLUDE_HARRYPOTTERBOOKSAPP_H_
17 changes: 11 additions & 6 deletions modules/nedelin_d_book_discount_lab2/src/HarryPotterBooksApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "include/HarryPotterBooks.h"


std::string HarryPotterBooksApp::calculatePrice(const std::vector<int>& books) {
HarryPotterBooks hpBooks(books);
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;
Expand All @@ -18,11 +18,16 @@ std::string HarryPotterBooksApp::calculatePrice(const std::vector<int>& books) {

std::string HarryPotterBooksApp::run(int argc, char* argv[]) {
std::vector<int> books;
if (argc < 6) {
return "Not enough arguments. Please provide 5 numbers for the book counts.";
double price;
if (argc < 7) {
return "Not enough arguments. Please provide 6 numbers for the book price and counts.";
}
for (int i = 1; i < 6; ++i) {
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(books);
return calculatePrice(price, books);
}

0 comments on commit 907d6bf

Please sign in to comment.