From 719208ce8fff4c441cf033f04b1a2d90498d9cc2 Mon Sep 17 00:00:00 2001 From: STELLSAN Date: Mon, 11 Nov 2024 10:11:33 +0300 Subject: [PATCH] collab_fix_1 --- .../include/HarryPotterBooks.h | 4 +- .../src/HarryPotterBooks.cpp | 4 +- .../test/test_HarryPotterBooks.cpp | 42 ++++++++++++------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/modules/nedelin_d_book_discount_lab2/include/HarryPotterBooks.h b/modules/nedelin_d_book_discount_lab2/include/HarryPotterBooks.h index e6685c95a..97c08353d 100644 --- a/modules/nedelin_d_book_discount_lab2/include/HarryPotterBooks.h +++ b/modules/nedelin_d_book_discount_lab2/include/HarryPotterBooks.h @@ -8,11 +8,11 @@ class HarryPotterBooks { std::vector books; + double bookPrice; public: - const double bookPrice = 8.0; - explicit HarryPotterBooks(const std::vector& book_counts); + explicit HarryPotterBooks(double price, const std::vector& book_counts); std::vector getBooks() const; void setBooks(const std::vector& book_counts); diff --git a/modules/nedelin_d_book_discount_lab2/src/HarryPotterBooks.cpp b/modules/nedelin_d_book_discount_lab2/src/HarryPotterBooks.cpp index 144d151e0..2451ce81e 100644 --- a/modules/nedelin_d_book_discount_lab2/src/HarryPotterBooks.cpp +++ b/modules/nedelin_d_book_discount_lab2/src/HarryPotterBooks.cpp @@ -2,8 +2,8 @@ #include "include/HarryPotterBooks.h" -HarryPotterBooks::HarryPotterBooks(const std::vector& book_counts) - : books(book_counts) { +HarryPotterBooks::HarryPotterBooks(double price, const std::vector& book_counts) + : bookPrice(price), books(book_counts) { if (books.empty()) { throw std::invalid_argument("Empty vector provided in constructor"); } diff --git a/modules/nedelin_d_book_discount_lab2/test/test_HarryPotterBooks.cpp b/modules/nedelin_d_book_discount_lab2/test/test_HarryPotterBooks.cpp index 289e93f18..c546e4bbe 100644 --- a/modules/nedelin_d_book_discount_lab2/test/test_HarryPotterBooks.cpp +++ b/modules/nedelin_d_book_discount_lab2/test/test_HarryPotterBooks.cpp @@ -5,32 +5,37 @@ TEST(Nedelin_HarryPotterBooksTest, ConstructEmptyVector) { std::vector empty_books; - EXPECT_THROW(HarryPotterBooks hpBooks(empty_books), std::invalid_argument); + double price_book = 8.0; + EXPECT_THROW(HarryPotterBooks hpBooks(price_book, empty_books), std::invalid_argument); } TEST(Nedelin_HarryPotterBooksTest, SetterEmptyVector) { std::vector start_books = { 0, 0, 0, 0, 0 }; - HarryPotterBooks hpBooks(start_books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, start_books); std::vector empty_books; EXPECT_THROW(hpBooks.setBooks(empty_books), std::invalid_argument); } TEST(Nedelin_HarryPotterBooksTest, ConstructValidVector) { std::vector books = { 1, 2, 3, 4, 5 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_NO_THROW(hpBooks.calculateTotalPrice()); } TEST(Nedelin_HarryPotterBooksTest, SetBooksWithEmptyVector) { std::vector books = { 1, 2, 3, 4, 5 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); std::vector empty_books; EXPECT_THROW(hpBooks.setBooks(empty_books), std::invalid_argument); } TEST(Nedelin_HarryPotterBooksTest, SetBooksWithValidVector) { std::vector books = { 1, 2, 3, 4, 5 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); std::vector books_2 = { 1, 1, 1, 1, 1 }; hpBooks.setBooks(books_2); EXPECT_EQ(hpBooks.getBooks(), books_2); @@ -38,54 +43,63 @@ TEST(Nedelin_HarryPotterBooksTest, SetBooksWithValidVector) { TEST(Nedelin_HarryPotterBooksTest, GetBooksTest) { std::vector books = { 1, 2, 3, 4, 5 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_EQ(hpBooks.getBooks(), books); } TEST(Nedelin_HarryPotterBooksTest, SingleBook) { std::vector books = { 1, 0, 0, 0, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 8.0); } TEST(Nedelin_HarryPotterBooksTest, TwoDifferentBooks) { std::vector books = { 1, 1, 0, 0, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 2 * 8.0 * 0.95); } TEST(Nedelin_HarryPotterBooksTest, ThreeDifferentBooks) { std::vector books = { 1, 1, 1, 0, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 8.0 * 3 * 0.9); } TEST(Nedelin_HarryPotterBooksTest, FourDifferentBooks) { std::vector books = { 1, 1, 1, 1, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 8.0 * 4 * 0.8); } TEST(Nedelin_HarryPotterBooksTest, FullSetOfFiveBooks) { std::vector books = { 1, 1, 1, 1, 1 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 8.0 * 5 * 0.75); } TEST(Nedelin_HarryPotterBooksTest, ComplexBasket) { std::vector books = { 2, 2, 2, 1, 1 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 51.6); } TEST(Nedelin_HarryPotterBooksTest, NoBooks) { std::vector books = { 0, 0, 0, 0, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 0.0); } TEST(Nedelin_HarryPotterBooksTest, MultipleSameBooks) { std::vector books = { 3, 0, 0, 0, 0 }; - HarryPotterBooks hpBooks(books); + double price_book = 8.0; + HarryPotterBooks hpBooks(price_book, books); EXPECT_DOUBLE_EQ(hpBooks.calculateTotalPrice(), 8.0 * 3); }