TEST(CxxCaseQuote, MockBulk) { using namespace case_quote; // Bulk_quote sales which has discount: minimum 5 and 25% discount // 35*6*(1-.25) = 157.5 shared_ptr<MockBulk> q1(new MockBulk("912", 35, 5, .25)); shared_ptr<MockBulk> q2(new MockBulk("912", 35, 5, .25)); shared_ptr<MockBulk> q3(new MockBulk("912", 35, 5, .25)); shared_ptr<MockBulk> q4(new MockBulk("912", 35, 5, .25)); shared_ptr<MockBulk> q5(new MockBulk("912", 35, 5, .25)); EXPECT_CALL(*q1, net_price(_)) .WillOnce(Return(157.5)); Basket sale; sale.add_item(q1); sale.add_item(q2); sale.add_item(q3); sale.add_item(q4); sale.add_item(q5); EXPECT_EQ(sale.total_receipt(cout), 157.5); }
int main() { Basket basket; basket.add_item(Quote("0-201-82470-1", 50)); for (int i = 0; i < 15; ++i) basket.add_item(Bulk_quote("0-201-54848-8", 50, 10, .25)); basket.total_receipt(cout); return 0; }
TEST(CxxCaseQuote, MockQuote) { using namespace case_quote; // Quote sales which has no discount, 45*3 = 135 std::shared_ptr<MockQuote> q1(new MockQuote("123", 45)); std::shared_ptr<MockQuote> q2(new MockQuote("123", 45)); std::shared_ptr<MockQuote> q3(new MockQuote("123", 45)); EXPECT_CALL(*q1, net_price(_)) .WillOnce(Return(135)); // when expects that net_price() gets called on q2 and q3 since net_price() // will be called once. // // .cpp:169: Failure // Actual function call count doesn't match EXPECT_CALL(*q3, net_price(_))... // Expected: to be called once // Actual: never called - unsatisfied and active // t_ex_basket.cpp:166: Failure // Actual function call count doesn't match EXPECT_CALL(*q2, net_price(_))... // Expected: to be called once // Actual: never called - unsatisfied and active // [ FAILED ] BasketTest.checkTotal1 (2 ms) // // EXPECT_CALL(*q2, net_price(_)) // .WillOnce(Return(135)); // // EXPECT_CALL(*q3, net_price(_)) // .WillOnce(Return(135)); // so change "Times" or comment them out // // EXPECT_CALL(*q2, net_price(_)) // .Times(AnyNumber()) // .WillOnce(Return(135)); // // EXPECT_CALL(*q3, net_price(_)) // .Times(AnyNumber()) // .WillOnce(Return(135)); Basket sale; sale.add_item(q1); sale.add_item(q2); sale.add_item(q3); EXPECT_EQ(sale.total_receipt(cout), 135); }
int main() { Basket basket; Sales_item item1(Bulk_item("0-0001-0001-1", 99, 20, 0.5)); Sales_item item2(Bulk_item("0-0001-0001-2", 50)); Sales_item item3(Bulk_item("0-0001-0001-3", 59, 200, 0.3)); Sales_item item4(Bulk_item("0-0001-0001-1", 99, 20, 0.2)); basket.add_item(item1); basket.add_item(item2); basket.add_item(item3); basket.add_item(item4); cout << basket.total() << endl; system("pause"); return 0; }
TEST(CxxCaseQuote, Clone) { using namespace case_quote_clone; Basket sale; // Quote sales which has no discount. 45*3 = 135 sale.add_item(Quote("123", 45)); sale.add_item(Quote("123", 45)); sale.add_item(Quote("123", 45)); // minimum 3 and 15% discount. no discount 45*2 = 90 sale.add_item(Bulk_Quote("345", 45, 3, .15)); sale.add_item(Bulk_Quote("345", 45, 3, .15)); sale.total_receipt(cout); }
int main() { Basket basket; for (unsigned i = 0; i != 10; ++i) basket.add_item(Bulk_quote("Bible",20.6,20,0.3)); for (unsigned i = 0; i != 10; ++i) basket.add_item(Bulk_quote("C++Primer",30.9,5,0.4)); for (unsigned i = 0; i != 10; ++i) basket.add_item(Quote("CLRS",40.1)); std::ofstream log("log.txt",std::ios_base::app|std::ios_base::out); basket.total_receipt(log); return 0; }
int main() { Basket bQuote; for (int i = 0; i != 10; ++i) { bQuote.add_item(Bulk_quote("book", i * 10.1, 10, 0.3)); } std::cout << std::endl << std::endl; std::cout << bQuote.total() << std::endl; return 0; }
int main() { Sales_item item1(Item_base("123", 45)); Sales_item item2(Bulk_item("345", 45, 3, .15)); Sales_item item3(Bulk_item("678", 55, 5, .25)); Sales_item item4(Lim_item("abc", 35, 2, .10)); Sales_item item5(Item_base("def", 35)); Basket sale; sale.add_item(item1); cout << "added first item" << endl; sale.add_item(item1); sale.add_item(item1); sale.add_item(item1); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item2); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item3); sale.add_item(item4); sale.add_item(item4); sale.add_item(item4); sale.add_item(item4); sale.add_item(item4); sale.add_item(item4); sale.add_item(item5); sale.add_item(item5); cout << "added last item" << endl; sale.display(cout); cout << sale.total() << endl; { // arguments are the isbn, price, minimum quantity, and discount Bulk_item bulk("0-201-82470-1", 50, 5, .19); Basket sale; sale.add_item(Bulk_item("0-201-82470-1", 50, 5, .19)); sale.add_item(Bulk_item("0-201-82470-1", 50, 5, .19)); sale.add_item(Bulk_item("0-201-82470-1", 50, 5, .19)); sale.add_item(Bulk_item("0-201-82470-1", 50, 5, .19)); sale.add_item(Bulk_item("0-201-82470-1", 50, 5, .19)); sale.add_item(Lim_item("0-201-54848-8", 35, 2, .10)); sale.add_item(Lim_item("0-201-54848-8", 35, 2, .10)); sale.add_item(Lim_item("0-201-54848-8", 35, 2, .10)); double total = sale.total(); cout << "Total Sale: " << total << endl; } }
int main() { Basket sale; sale.add_item(shared_ptr<Quote>(new Quote("123", 45))); sale.add_item(shared_ptr<Quote>(new Quote("123", 45))); sale.add_item(shared_ptr<Quote>(new Quote("123", 45))); sale.add_item(make_shared<Bulk_quote>("345", 45, 3, .15)); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("345", 45, 3, .15))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Bulk_quote("678", 55, 5, .25))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Lim_quote("abc", 35, 2, .10))); sale.add_item(shared_ptr<Quote>(new Quote("def", 35))); sale.add_item(shared_ptr<Quote>(new Quote("def", 35))); sale.total_receipt(cout); Basket bsk; // arguments are the ISBN, price, minimum quantity, and discount bsk.add_item(shared_ptr<Quote>(new Bulk_quote("0-201-82470-1", 50, 5, .19))); bsk.add_item(shared_ptr<Quote>(new Bulk_quote("0-201-82470-1", 50, 5, .19))); bsk.add_item(shared_ptr<Quote>(new Bulk_quote("0-201-82470-1", 50, 5, .19))); bsk.add_item(shared_ptr<Quote>(new Bulk_quote("0-201-82470-1", 50, 5, .19))); bsk.add_item(shared_ptr<Quote>(new Bulk_quote("0-201-82470-1", 50, 5, .19))); bsk.add_item(shared_ptr<Quote>(new Lim_quote("0-201-54848-8", 35, 2, .10))); bsk.add_item(shared_ptr<Quote>(new Lim_quote("0-201-54848-8", 35, 2, .10))); bsk.add_item(shared_ptr<Quote>(new Lim_quote("0-201-54848-8", 35, 2, .10))); bsk.total_receipt(cout); }