Browse Source

trade_type_info tests.

updated sector_warps to handle {} init.
Steve Thielemann 3 years ago
parent
commit
3658e458c9
3 changed files with 27 additions and 4 deletions
  1. 4 0
      galaxy.cpp
  2. 1 0
      galaxy.h
  3. 22 4
      test-galaxy.cpp

+ 4 - 0
galaxy.cpp

@@ -83,6 +83,10 @@ bool operator==(const density lhs, const density rhs) {
 }
 
 sector_warps::sector_warps() { sector = 0; }
+sector_warps::sector_warps(sector_type s, std::set<sector_type> w) {
+  sector = s;
+  warps = w;
+}
 
 void sector_warps::add(sector_type new_sector) {
   warps.insert(new_sector);

+ 1 - 0
galaxy.h

@@ -27,6 +27,7 @@ struct sector_warps {
   // planets
   // ctor that zeros everything out?
   sector_warps();
+  sector_warps(sector_type, std::set<sector_type>);
   void add(sector_type sector);
   // add() that adds warp to end of warps?
   friend std::ostream& operator<<(std::ostream& os, const sector_warps& warps);

+ 22 - 4
test-galaxy.cpp

@@ -4,9 +4,9 @@
 #include <string>
 #include <vector>
 
+#include "director.h"
 #include "galaxy.h"
 #include "gtest/gtest.h"
-#include "director.h"
 
 /*
 
@@ -110,6 +110,7 @@ struct pair {
   };
 };
 
+#ifdef NOT_ANYMORE
 TEST(ports, trade_types) {
   std::map<pair, int> expected;
   for (int x = 0; x < 9; ++x) {
@@ -139,7 +140,6 @@ TEST(ports, trade_types) {
   GTEST_COUT << "Done!" << std::endl;
   */
 
-#ifdef NOT_ANYMORE
   for (int p1 = 1; p1 <= 8; ++p1) {
     for (int p2 = p1; p2 <= 8; ++p2) {
       // GTEST_COUT << "Type " << p1 << " and " << p2 << std::endl;
@@ -157,9 +157,8 @@ TEST(ports, trade_types) {
       }
     }
   }
-#endif
-  
 }
+#endif
 
 TEST(ports, parse_portcim) {
   // This really needs to be checked against real lines from a log file
@@ -242,4 +241,23 @@ TEST(ports, parse_portcim) {
   // EXPECT_EQ(parse.percent, ports[0].percent);
 }
 
+TEST(galaxy, trade_type_info) {
+  // test this code to see that we get the correct trade type results.
+  Galaxy g;
+  g.add_port(port{68, 1, {1290, 557, 561}, {100, 47, 56}});
+  g.add_port(port{706, 4, {2490, 2590, 743}, {100, 100, 94}});
+  trade_type_result ttr = g.trade_type_info(68, 706);
+  EXPECT_EQ(ttr.type, BEST) << "Expect Trade Type BEST";
+  // burn out equipment
+  g.add_port(port{68, 1, {1290, 557, 161}, {100, 47, 16}});
+  ttr = g.trade_type_info(68, 706);
+  EXPECT_EQ(ttr.type, FAIR_O) << "Expect Trade Type FAIR_O";
+  std::vector<port_pair_type> vppt = g.find_trades(68);
+  EXPECT_EQ(vppt.size(), 0) << "Should have no trades, because no warps";
+  g.add_warp(sector_warps{706, {68}});
+  g.add_warp(sector_warps{68, {51, 693, 706, 904}});
+  vppt = g.find_trades(68);
+  EXPECT_EQ(vppt.size(), 1) << "Found a trade";
+}
+
 }  // namespace