Skip to content

Commit

Permalink
collab_fix_1
Browse files Browse the repository at this point in the history
  • Loading branch information
STELLSAN committed Nov 11, 2024
1 parent 028b194 commit 719208c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

class HarryPotterBooks {
std::vector<int> books;
double bookPrice;

public:
const double bookPrice = 8.0;

explicit HarryPotterBooks(const std::vector<int>& book_counts);
explicit HarryPotterBooks(double price, const std::vector<int>& book_counts);

std::vector<int> getBooks() const;
void setBooks(const std::vector<int>& book_counts);
Expand Down
4 changes: 2 additions & 2 deletions modules/nedelin_d_book_discount_lab2/src/HarryPotterBooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "include/HarryPotterBooks.h"

HarryPotterBooks::HarryPotterBooks(const std::vector<int>& book_counts)
: books(book_counts) {
HarryPotterBooks::HarryPotterBooks(double price, const std::vector<int>& book_counts)
: bookPrice(price), books(book_counts) {
if (books.empty()) {
throw std::invalid_argument("Empty vector provided in constructor");
}
Expand Down
42 changes: 28 additions & 14 deletions modules/nedelin_d_book_discount_lab2/test/test_HarryPotterBooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,101 @@

TEST(Nedelin_HarryPotterBooksTest, ConstructEmptyVector) {
std::vector<int> 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<int> start_books = { 0, 0, 0, 0, 0 };
HarryPotterBooks hpBooks(start_books);
double price_book = 8.0;
HarryPotterBooks hpBooks(price_book, start_books);
std::vector<int> empty_books;
EXPECT_THROW(hpBooks.setBooks(empty_books), std::invalid_argument);
}

TEST(Nedelin_HarryPotterBooksTest, ConstructValidVector) {
std::vector<int> 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<int> books = { 1, 2, 3, 4, 5 };
HarryPotterBooks hpBooks(books);
double price_book = 8.0;
HarryPotterBooks hpBooks(price_book, books);
std::vector<int> empty_books;
EXPECT_THROW(hpBooks.setBooks(empty_books), std::invalid_argument);
}

TEST(Nedelin_HarryPotterBooksTest, SetBooksWithValidVector) {
std::vector<int> books = { 1, 2, 3, 4, 5 };
HarryPotterBooks hpBooks(books);
double price_book = 8.0;
HarryPotterBooks hpBooks(price_book, books);
std::vector<int> books_2 = { 1, 1, 1, 1, 1 };
hpBooks.setBooks(books_2);
EXPECT_EQ(hpBooks.getBooks(), books_2);
}

TEST(Nedelin_HarryPotterBooksTest, GetBooksTest) {
std::vector<int> 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<int> 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<int> 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<int> 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<int> 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<int> 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<int> 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<int> 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<int> 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);
}

0 comments on commit 719208c

Please sign in to comment.