123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #include "gtest/gtest.h"
- #include "galaxy.h"
- #include <array>
- #include <map>
- #include <string>
- #include <vector>
- #define GTEST_COUT std::cerr << "[ ] [ INFO ]"
- namespace {
- std::map<int, const char *> port_classes = {{1, "BBS"}, {2, "BSB"}, {3, "SBB"},
- {4, "SSB"}, {5, "SBS"}, {6, "BSS"},
- {7, "SSS"}, {8, "BBB"}, {9, "BBB"}};
- TEST(ports, get_buysell) {
- for (int type = 1; type < 10; ++type) {
- buysell expected;
- const char *flags;
- flags = port_classes[type];
- for (int x = 0; x < 3; ++x)
- expected.foe[x] = flags[x] == 'B';
- buysell result = get_buysell(type);
- for (int x = 0; x < 3; ++x)
- EXPECT_EQ(result.foe[x], expected.foe[x])
- << "type: " << type << " pos: " << x;
- }
- }
- TEST(ports, text_from_type) {
- for (int type = 1; type < 10; ++type) {
- buysell_text expected;
- const char *flags;
- flags = port_classes[type];
- for (int x = 0; x < 3; ++x)
- expected.txt[x] = flags[x];
- buysell_text result = text_from_type(type);
- EXPECT_EQ(result, expected) << "type: " << type;
- }
- }
- TEST(ports, text_from_buysell) {
- for (int type = 1; type < 10; ++type) {
- buysell source = get_buysell(type);
- buysell_text expected;
- const char *flags;
- flags = port_classes[type];
- for (int x = 0; x < 3; ++x)
- expected.txt[x] = flags[x];
- buysell_text result = text_from_buysell(source);
- EXPECT_EQ(result, expected) << "type: " << type;
- }
- }
- TEST(ports, type_from_buysell) {
- for (int type = 1; type < 9; ++type) {
- buysell source = get_buysell(type);
- int result = type_from_buysell(source);
- EXPECT_EQ(result, type) << "type: " << type;
- }
- }
- TEST(ports, parse_portcim) {
-
-
- std::map<std::string, port> data = {
- {" 2 - 2420 100% 612 35% - 2020 100% ",
- {2, 2, {2420, 612, 2020}, {100, 35, 100}}},
- {" 4 - 2880 100% - 275 23% 61 6% ",
- {4, 1, {2880, 275, 61}, {100, 23, 6}}},
- {" 6 - 820 100% 1952 89% - 2680 100% ",
- {6, 2, {820, 1952, 2680}, {100, 89, 100}}},
- {" 8 - 1000 100% - 855 85% - 1000 100% ",
- {8, 8, {1000, 855, 1000}, {100, 85, 100}}},
- {" 20 - 1708 97% - 710 56% 287 15% ",
- {20, 1, {1708, 710, 287}, {97, 56, 15}}},
- {" 23 - 2120 100% - 709 40% 1902 69% ",
- {23, 1, {2120, 709, 1902}, {100, 40, 69}}},
- {" 28 1511 98% - 478 29% 589 35% ",
- {28, 5, {1511, 478, 589}, {98, 29, 35}}},
- {" 29 913 56% - 970 100% - 1990 100% ",
- {29, 3, {913, 970, 1990}, {56, 100, 100}}}};
-
- for (auto testdata : data) {
- port parse = parse_portcim(testdata.first);
- EXPECT_EQ((int)parse.sector, (int)testdata.second.sector)
- << "Text: [" << testdata.first << "]";
- if (parse.sector != 0) {
- EXPECT_EQ(parse.type, testdata.second.type);
- for (int x = 0; x < 3; ++x) {
- EXPECT_EQ(parse.amount[x], testdata.second.amount[x])
- << "Sector:" << parse.sector;
- EXPECT_EQ(parse.percent[x], testdata.second.percent[x])
- << "Sector:" << parse.sector;
- }
- }
- }
-
-
-
-
- }
- }
|