-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest7.cpp
73 lines (60 loc) · 1.93 KB
/
test7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>
#include <utility>
// Base trading bot class
struct trading_bot
{
virtual void execute() = 0;
virtual ~trading_bot() {}
};
// Template smart trading bot class
template <typename Strategy, void (Strategy::*action)(const std::string&, double)>
struct smart_trading_bot : trading_bot
{
smart_trading_bot(Strategy* strategy, std::pair<std::string, double> args)
: strat(strategy), args(args) {}
void execute() override
{
(strat->*action)(args.first, args.second);
}
private:
Strategy* strat;
std::pair<std::string, double> args;
};
// Trading strategies
struct trading_strategy
{
void buy(const std::string& symbol, double amount)
{
std::cout << "Buying " << amount << " of " << symbol << std::endl;
}
void sell(const std::string& symbol, double amount)
{
std::cout << "Selling " << amount << " of " << symbol << std::endl;
}
void hold(const std::string& symbol, double amount)
{
std::cout << "Holding " << amount << " of " << symbol << std::endl;
}
};
// Test cases
void test_smart_trading_bot()
{
trading_strategy strat;
std::string symbol = "AAPL";
double amount = 50.0;
smart_trading_bot<trading_strategy, &trading_strategy::buy> buy_bot(&strat, std::make_pair(symbol, amount));
smart_trading_bot<trading_strategy, &trading_strategy::sell> sell_bot(&strat, std::make_pair(symbol, amount));
smart_trading_bot<trading_strategy, &trading_strategy::hold> hold_bot(&strat, std::make_pair(symbol, amount));
std::cout << "Testing buy bot..." << std::endl;
buy_bot.execute(); // Expected: Implement buy logic
std::cout << "Testing sell bot..." << std::endl;
sell_bot.execute(); // Expected: Implement sell logic
std::cout << "Testing hold bot..." << std::endl;
hold_bot.execute(); // Expected: Implement hold logic
}
int main()
{
test_smart_trading_bot();
return 0;
}