remove article from sale
This commit is contained in:
parent
2fb72f1701
commit
91357d7c7f
3 changed files with 24 additions and 1 deletions
|
@ -8,6 +8,16 @@ void Sale::addArticle(std::shared_ptr<Article> articlePtr)
|
|||
articles_.push_back(articlePtr);
|
||||
}
|
||||
|
||||
void Sale::removeArticle(const Article* articlePtr)
|
||||
{
|
||||
auto it = std::find_if(articles_.begin(), articles_.end(),
|
||||
[&articlePtr](auto art) { return art.get() == articlePtr; });
|
||||
if (it != articles_.end()) {
|
||||
(*it)->setSale(nullptr);
|
||||
articles_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
int Sale::sumInCents()
|
||||
{
|
||||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
||||
|
|
|
@ -14,6 +14,8 @@ class Sale : public Entity
|
|||
public:
|
||||
int sumInCents();
|
||||
void addArticle(std::shared_ptr<Article> articlePtr);
|
||||
void removeArticle(const Article* articlePtr);
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()};
|
||||
std::vector<std::shared_ptr<Article>> articles_{};
|
||||
|
|
|
@ -31,3 +31,14 @@ BOOST_AUTO_TEST_CASE(articles_sum)
|
|||
BOOST_TEST(sale.sumInCents() == 550);
|
||||
BOOST_TEST(seller.getArticles(true).size() == 10);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(remove_article) {
|
||||
auto art = std::make_shared<Article>();
|
||||
Sale sale{};
|
||||
|
||||
BOOST_TEST(art->isSold() == false);
|
||||
sale.addArticle(art);
|
||||
BOOST_TEST(art->isSold() == true);
|
||||
sale.removeArticle(art.get());
|
||||
BOOST_TEST(art->isSold() == false);
|
||||
}
|
Loading…
Reference in a new issue