浏览代码

Added Test for densityline to Master too

  Oops, I don't know how I got the 2 branches confused.
david 3 年之前
父节点
当前提交
ac39380eb4
共有 1 个文件被更改,包括 99 次插入0 次删除
  1. 99 0
      test-director.cpp

+ 99 - 0
test-director.cpp

@@ -69,4 +69,103 @@ TEST(director, director_galaxy_save) {
 
   EXPECT_TRUE(1) << "No exception, this is good!";
 }
+
+TEST(director, director_parsing_density) {
+  Director dir;
+  std::vector<std::string> client;
+  std::vector<std::string> server;
+  dir.to_client = [&client](const std::string line) { client.push_back(line); };
+  dir.to_server = [&server](const std::string line) { server.push_back(line); };
+
+  dir.username = "test";
+  std::string lines[] = {
+      "TradeWars Game Server                                     Copyright (C) "
+      "EIS",
+      "Selection (? for menu): N",
+      "^Command [TL=00:00:00]:[2985] (?=Help)? :",
+      "!s",
+      "Command [TL=00:00:00]:[926] (?=Help)? : S",
+      "",
+      "Long Range Scan",
+      "^Select (H)olo Scan or (D)ensity Scan or (Q)uit? [D] ",
+      "!d",
+      "Select (H)olo Scan or (D)ensity Scan or (Q)uit? [D] D",
+      "",
+      "                          Relative Density Scan",
+      "------------------------------------------------------------------------"
+      "-----",
+      "Sector    70  ==>              0  Warps : 6    NavHaz :     0%    Anom "
+      ": No",
+      "Sector   441  ==>            100  Warps : 2    NavHaz :     0%    Anom "
+      ": No",
+      "Sector ( 575) ==>           1000  Warps : 2    NavHaz :     15%    Anom "
+      ": Yes",
+      "Sector   600  ==>             40  Warps : 6    NavHaz :     0%    Anom "
+      ": No",
+      "Sector   629  ==>              1  Warps : 4    NavHaz :     0%    Anom "
+      ": No",
+      "Sector   711  ==>            101  Warps : 6    NavHaz :     0%    Anom "
+      ": No",
+      ""};
+
+  for (auto line : lines) {
+    if (line[0] == '^') {
+      dir.server_prompt(line.substr(1), line.substr(1));
+    } else if (line[0] == '!') {
+      // client input
+      dir.client_input(line.substr(1));
+    } else {
+      dir.server_line(line, line);
+    }
+  }
+
+  // Check that each sector was correctly processed
+  std::vector<int> sectors = {70, 441, 575, 600, 629, 711};
+  YAML::Node sector_data;
+  sector_data[70]["density"] = 0;
+  sector_data[70]["warps"] = 6;
+  sector_data[70]["navhaz"] = 0;
+  sector_data[70]["anom"] = false;
+  sector_data[70]["known"] = true;
+  sector_data[441]["density"] = 100;
+  sector_data[441]["warps"] = 2;
+  sector_data[441]["navhaz"] = 0;
+  sector_data[441]["anom"] = false;
+  sector_data[441]["known"] = true;
+  sector_data[575]["density"] = 1000;
+  sector_data[575]["warps"] = 2;
+  sector_data[575]["navhaz"] = 15;
+  sector_data[575]["anom"] = true;
+  sector_data[575]["known"] = false;
+  sector_data[600]["density"] = 40;
+  sector_data[600]["warps"] = 6;
+  sector_data[600]["navhaz"] = 0;
+  sector_data[600]["anom"] = false;
+  sector_data[600]["known"] = true;
+  sector_data[629]["density"] = 1;
+  sector_data[629]["warps"] = 4;
+  sector_data[629]["navhaz"] = 0;
+  sector_data[629]["anom"] = false;
+  sector_data[629]["known"] = true;
+  sector_data[711]["density"] = 101;
+  sector_data[711]["warps"] = 6;
+  sector_data[711]["navhaz"] = 0;
+  sector_data[711]["anom"] = false;
+  sector_data[711]["known"] = true;
+
+  for (auto sector : sectors) {
+    // GTEST_COUT << "Testing Sector " << sector << std::endl;
+    EXPECT_EQ(dir.galaxy.meta["density"][sector]["density"].as<int>(),
+              sector_data[sector]["density"].as<int>());
+    EXPECT_EQ(dir.galaxy.meta["density"][sector]["warps"].as<int>(),
+              sector_data[sector]["warps"].as<int>());
+    EXPECT_EQ(dir.galaxy.meta["density"][sector]["navhaz"].as<int>(),
+              sector_data[sector]["navhaz"].as<int>());
+    EXPECT_EQ(dir.galaxy.meta["density"][sector]["anom"].as<bool>(),
+              sector_data[sector]["anom"].as<bool>());
+    EXPECT_EQ(dir.galaxy.meta["density"][sector]["known"].as<bool>(),
+              sector_data[sector]["known"].as<bool>());
+  }
+}
+
 }  // namespace