kima2/test/test_sale.cpp

46 lines
1 KiB
C++
Raw Normal View History

2018-07-12 14:39:08 +02:00
#define BOOST_TEST_MODULE sale
#include "../src/core/sale.h"
#include "../src/core/seller.h"
#include "../src/core/article.h"
2018-07-12 14:39:08 +02:00
#include <vector>
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(articles_sum)
{
const int NUM_ARTICLES = 30;
Seller seller("Max", "Mustermann", 1, NUM_ARTICLES);
2018-07-20 11:52:26 +02:00
ArticlesVec articles{};
2018-07-12 14:39:08 +02:00
Sale sale{};
for(int i = 0; i < NUM_ARTICLES; ++i)
{
2018-07-20 11:52:26 +02:00
auto art = std::make_unique<Article>();
2018-07-12 14:39:08 +02:00
art->setPrice((i+1) * 10);
2018-07-20 11:52:26 +02:00
articles.push_back(art.get());
seller.addArticle(std::move(art));
2018-07-12 14:39:08 +02:00
}
for(int i = 0; i < 10; ++i)
{
sale.addArticle(articles.at(i));
}
BOOST_TEST(sale.sumInCents() == 550);
BOOST_TEST(seller.getArticles(true).size() == 10);
2018-07-13 10:12:16 +02:00
}
BOOST_AUTO_TEST_CASE(remove_article) {
auto art = std::make_shared<Article>();
Sale sale{};
BOOST_TEST(art->isSold() == false);
2018-07-20 11:52:26 +02:00
sale.addArticle(art.get());
2018-07-13 10:12:16 +02:00
BOOST_TEST(art->isSold() == true);
sale.removeArticle(art.get());
BOOST_TEST(art->isSold() == false);
2018-07-12 14:39:08 +02:00
}