Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool InvesmentBrokerExample() {
- cout << "STARTING" << endl;
- InvestmentBroker broker;
- broker.addShare("THIS", 54, 95);
- broker.addShare("TEST", 888, 95);
- broker.addShare("NAT", 553, 84);
- broker.addShare("VAL", 336, 58);
- broker.addBond("THIS", 448, 54);
- broker.addBond("TEST", 550, 31);
- broker.addBond("OKOK", 662, 66);
- broker.addShare("I", 448, 54);
- const string customer1 = "111111111";
- const string customer2 = "111111112";
- const string customer4 = "111111114";
- const string customer9 = "123123219";
- ASSERT_THROW(CustomerNotExistException, broker.changePreference(customer1, LOW_RISK, 14839));
- broker.addCustomer(customer1, 25000, HIGH_RISK);
- broker.addCustomer(customer2, 44125, LOW_RISK);
- broker.addCustomer(customer4, 30000, HIGH_RISK);
- broker.addCustomer(customer9, 15222, LOW_RISK);
- broker.nextTradeDay(); //new customers!
- const string customer5 = "111111115";
- const string customer6 = "111111116";
- const string customer7 = "111111117";
- const string customer8 = "432211238";
- broker.addCustomer(customer5, 25000, HIGH_RISK);
- broker.addCustomer(customer6, 44125, LOW_RISK);
- broker.addCustomer(customer7, 30000, HIGH_RISK);
- broker.addCustomer(customer8, 15222, LOW_RISK);
- broker.nextTradeDay(); //new customers!
- broker.nextTradeDay(); //new customers!
- broker.nextTradeDay(); //new customers!
- broker.addBond("HAVE", 550, 85);
- broker.addBond("LACK", 662, 66);
- broker.addShare("OF", 5.9, 34);
- broker.addBond("SEX", 662, 97);
- broker.addShare("BCUZ", 1, 21);
- broker.addBond("MTM", 662, 13);
- broker.nextTradeDay(); //new customers!
- broker.addBond("IS", 785, 45);
- broker.addBond("VERY", 1124, 11);
- broker.addShare("LONG", 123.45, 95);
- broker.addShare("RAF", 45.45, 88);
- const string customer3 = "111111113";
- broker.addCustomer(customer3, 30000, LOW_RISK);
- broker.nextTradeDay(); //new customers!
- broker.nextTradeDay(); //new customers!
- broker.nextTradeDay(); //new customers!
- broker.printFullReport();
- broker.printCustomerReport(customer1);
- broker.printCustomerReport(customer2);
- broker.printCustomerReport(customer3);
- broker.printCustomerReport(customer4);
- broker.printCustomerReport(customer5);
- broker.printCustomerReport(customer6);
- broker.printCustomerReport(customer7);
- broker.printCustomerReport(customer8);
- broker.printCustomerReport(customer9);
- ASSERT_THROW(IllegalSecurityNameException,broker.addShare("THISNAMEISTOOLONG!", 45.45, 88));
- ASSERT_THROW(IllegalSecurityNameException,broker.addShare("ZzZz", 45.45, 88));
- ASSERT_THROW(InvalidSecurityAmountException,broker.addShare("JSUS", -3, 0));
- ASSERT_THROW(NegetiveSecurityValueException,broker.addShare("JSUS", -3, 5));
- ASSERT_THROW(CustomerAlreadyExistException, broker.addCustomer(customer8, 15222, LOW_RISK));
- ASSERT_THROW(SecurityAlreadyExistException, broker.addBond("VERY", 1124, 11));
- ASSERT_THROW(SecurityAlreadyExistException, broker.addShare("LONG", 123.45, 95));
- //create risks
- int i = 1;
- for (i = 1; i < 14; ++i) {
- if (! i % 10) {
- if (i % 3) {
- broker.sellPortfolio("111111113");
- } else {
- broker.sellPortfolio("111111112");
- }
- }
- if (! i % 9) {
- if (i % 2) {
- broker.changePreference(customer1, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer9, LOW_RISK, i - 1);
- }
- }
- if (! i % 8) {
- if (i % 3) {
- broker.changePreference(customer2, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer8, LOW_RISK, i - 1);
- }
- }
- if (! i % 7) {
- if (i % 2) {
- broker.changePreference(customer3, HIGH_RISK, i);
- } else {
- broker.changePreference(customer7, LOW_RISK, i - 1);
- }
- }
- if (! i % 6) {
- if (i % 5) {
- broker.changePreference(customer4, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer6, LOW_RISK, i - 1);
- }
- }
- if (! i % 5) {
- if (i % 3) {
- broker.changePreference(customer5, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer5, LOW_RISK, i);
- }
- }
- if (! i % 4) {
- if (i % 3) {
- broker.changePreference(customer6, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer4, LOW_RISK, i - 1);
- }
- }
- if (! i % 3) {
- if (i % 3) {
- broker.changePreference(customer7, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer3, LOW_RISK, i - 1);
- }
- }
- if (! i % 2) {
- if (i % 3) {
- broker.changePreference(customer8, HIGH_RISK, i + 10);
- } else {
- broker.changePreference(customer2, LOW_RISK, i - 1);
- }
- }
- if (! i % 11) {
- if (i % 3) {
- broker.changePreference(customer9, HIGH_RISK, i + 3);
- } else {
- broker.changePreference(customer1, LOW_RISK, i - 1);
- }
- }
- if (! i % 12) {
- if (i % 5) {
- ASSERT_THROW(CustomerNotExistException, broker.changePreference("987654321", LOW_RISK, i - 1));
- ASSERT_THROW(CustomerNotExistException, broker.sellPortfolio("988654321"));
- } else {
- broker.changePreference(customer1, LOW_RISK, i - 1);
- }
- }
- if (! i % 13) {
- if (i % 5) {
- broker.sellPortfolio(customer1);
- broker.sellPortfolio(customer3);
- broker.sellPortfolio(customer5);
- broker.sellPortfolio(customer6);
- } else {
- broker.sellPortfolio(customer2);
- broker.sellPortfolio(customer4);
- broker.sellPortfolio(customer6);
- broker.sellPortfolio(customer7);
- broker.sellPortfolio(customer8);
- }
- }
- broker.nextTradeDay();
- cout << "Day " << i+3 << " | i = "<< i << endl;
- broker.printFullReport();
- broker.printCustomerReport(customer1);
- broker.printCustomerReport(customer1, PAPER_BOND);
- broker.printCustomerReport(customer1, PAPER_SHARE);
- broker.printCustomerReport(customer2);
- broker.printCustomerReport(customer2, PAPER_BOND);
- broker.printCustomerReport(customer2, PAPER_SHARE);
- broker.printCustomerReport(customer3);
- broker.printCustomerReport(customer3, PAPER_BOND);
- broker.printCustomerReport(customer3, PAPER_SHARE);
- broker.printCustomerReport(customer4);
- broker.printCustomerReport(customer4, PAPER_BOND);
- broker.printCustomerReport(customer4, PAPER_SHARE);
- broker.printCustomerReport(customer5);
- broker.printCustomerReport(customer5, PAPER_BOND);
- broker.printCustomerReport(customer5, PAPER_SHARE);
- broker.printCustomerReport(customer6);
- broker.printCustomerReport(customer6, PAPER_BOND);
- broker.printCustomerReport(customer6, PAPER_SHARE);
- broker.printCustomerReport(customer7);
- broker.printCustomerReport(customer7, PAPER_BOND);
- broker.printCustomerReport(customer7, PAPER_SHARE);
- broker.printCustomerReport(customer8);
- broker.printCustomerReport(customer8, PAPER_BOND);
- broker.printCustomerReport(customer8, PAPER_SHARE);
- broker.printCustomerReport(customer9);
- broker.printCustomerReport(customer9, PAPER_BOND);
- broker.printCustomerReport(customer9, PAPER_SHARE);
- }
- for(int j = i; j < 10*i ; j++){
- broker.nextTradeDay();
- cout << "Day " << j+3 << " | j = "<< j << endl;
- broker.printFullReport();
- }
- broker.printFullReport();
- cout << "FINISHED!" << endl;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment