KartonArmadon

main.cpp

Oct 9th, 2023
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.72 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cassert>
  4. #include <iomanip>
  5. #include <fstream>
  6.  
  7. #include "input_reader.h"
  8. #include "stat_reader.h"
  9.  
  10. using namespace std;
  11.  
  12. void TestAddStop() {
  13.     {
  14.         TransportCatalogue catalogue;
  15.         InputReader reader;
  16.         reader.ParseLine("Stop s1: 1.1, 2.2");
  17.         reader.ParseLine("Stop s2: 0, 0");
  18.         reader.ApplyCommands(catalogue);
  19.  
  20.         const Stop* stop_ptr = catalogue.GetStopPtr("s1");
  21.         assert(stop_ptr->GetName().compare("s1") == 0); // 0 - sv are equal
  22.         assert(stop_ptr->GetCoordinates().lat == 1.1);
  23.         assert(stop_ptr->GetCoordinates().lng == 2.2);
  24.         //std::cerr << *stop_ptr << std::endl;
  25.  
  26.         stop_ptr = catalogue.GetStopPtr("s2");
  27.         assert(stop_ptr->GetName().compare("s2") == 0); // 0 - sv are equal
  28.         assert(stop_ptr->GetCoordinates().lat == 0.0);
  29.         assert(stop_ptr->GetCoordinates().lng == 0.0);
  30.         //std::cerr << *stop_ptr << std::endl;
  31.     }
  32. }
  33.  
  34. void TestAddBus() {
  35.     {
  36.         TransportCatalogue catalogue;
  37.         InputReader reader;
  38.         reader.ParseLine("Stop s1: 1.1, 1.2");
  39.         reader.ParseLine("Stop s2: 2.1, 2.2");
  40.         reader.ParseLine("Stop s3: 3.1, 3.2");
  41.         reader.ParseLine("Stop s4: 3.1, 3.2");
  42.         reader.ParseLine("Bus b1: s1 > s2 > s3 > s1");
  43.         reader.ParseLine("Bus b2: s1 - s4 - s3");
  44.         reader.ApplyCommands(catalogue);
  45.  
  46.         const Bus* bus_ptr = catalogue.GetBusPtr("b1");
  47.         assert(bus_ptr->GetName().compare("b1") == 0);
  48.         assert(bus_ptr->GetStops().size() == 4);
  49.         //std::cerr << *bus_ptr << std::endl;
  50.  
  51.         bus_ptr = catalogue.GetBusPtr("b2");
  52.         assert(bus_ptr->GetName().compare("b2") == 0);
  53.         assert(bus_ptr->GetStops().size() == 5);
  54.         //std::cerr << *bus_ptr << std::endl;
  55.     }
  56. }
  57.  
  58. void TestRequestBus() {
  59.     {
  60.         TransportCatalogue catalogue;
  61.         InputReader reader;
  62.         reader.ParseLine("Stop Tolstopaltsevo: 55.611087, 37.208290");
  63.         reader.ParseLine("Stop Marushkino: 55.595884, 37.209755");
  64.         reader.ParseLine("Bus 256: Biryulyovo Zapadnoye > Biryusinka > Universam > Biryulyovo Tovarnaya > Biryulyovo Passazhirskaya > Biryulyovo Zapadnoye");
  65.         reader.ParseLine("Bus 750: Tolstopaltsevo - Marushkino - Rasskazovka");
  66.         reader.ParseLine("Stop Rasskazovka: 55.632761, 37.333324");
  67.         reader.ParseLine("Stop Biryulyovo Zapadnoye: 55.574371, 37.651700");
  68.         reader.ParseLine("Stop Biryusinka: 55.581065, 37.648390");
  69.         reader.ParseLine("Stop Universam: 55.587655, 37.645687");
  70.         reader.ParseLine("Stop Biryulyovo Tovarnaya: 55.592028, 37.653656");
  71.         reader.ParseLine("Stop Biryulyovo Passazhirskaya: 55.580999, 37.659164");
  72.         reader.ApplyCommands(catalogue);
  73.  
  74.         ParseAndPrintStat(catalogue, "Bus 256", std::cout);
  75.         ParseAndPrintStat(catalogue, "Bus 750", std::cout);
  76.         ParseAndPrintStat(catalogue, "Bus 751", std::cout);
  77.     }
  78. }
  79.  
  80. void TestRequestStop() {
  81.     {
  82.         TransportCatalogue catalogue;
  83.         InputReader reader;
  84.         reader.ParseLine("Stop Tolstopaltsevo: 55.611087, 37.208290");
  85.         reader.ParseLine("Stop Marushkino: 55.595884, 37.209755");
  86.         reader.ParseLine("Bus 256: Biryulyovo Zapadnoye > Biryusinka > Universam > Biryulyovo Tovarnaya > Biryulyovo Passazhirskaya > Biryulyovo Zapadnoye");
  87.         reader.ParseLine("Bus 750: Tolstopaltsevo - Marushkino - Rasskazovka");
  88.         reader.ParseLine("Stop Rasskazovka: 55.632761, 37.333324");
  89.         reader.ParseLine("Stop Biryulyovo Zapadnoye: 55.574371, 37.651700");
  90.         reader.ParseLine("Stop Biryusinka: 55.581065, 37.648390");
  91.         reader.ParseLine("Stop Universam: 55.587655, 37.645687");
  92.         reader.ParseLine("Stop Biryulyovo Tovarnaya: 55.592028, 37.653656");
  93.         reader.ParseLine("Stop Biryulyovo Passazhirskaya: 55.580999, 37.659164");
  94.         reader.ParseLine("Bus 828: Biryulyovo Zapadnoye > Universam > Rossoshanskaya ulitsa > Biryulyovo Zapadnoye");
  95.         reader.ParseLine("Stop Rossoshanskaya ulitsa: 55.595579, 37.605757");
  96.         reader.ParseLine("Stop Prazhskaya: 55.611678, 37.603831");
  97.                    
  98.         reader.ApplyCommands(catalogue);
  99.  
  100.         ParseAndPrintStat(catalogue, "Stop Samara", std::cout);
  101.         ParseAndPrintStat(catalogue, "Stop Prazhskaya", std::cout);
  102.         ParseAndPrintStat(catalogue, "Stop Biryulyovo Zapadnoye", std::cout);
  103.     }
  104. }
  105.  
  106. void TestRequestStop1() {
  107.     {
  108.         TransportCatalogue catalogue;
  109.         InputReader reader;
  110.         reader.ParseLine("Stop s1: 55.611087, 37.208290");
  111.         reader.ParseLine("Stop s2: 55.595884, 37.209755");
  112.         reader.ParseLine("Bus 828: s1 - s2");
  113.         reader.ApplyCommands(catalogue);
  114.  
  115.         ParseAndPrintStat(catalogue, "Bus 828", std::cout);
  116.         ParseAndPrintStat(catalogue, "Stop s1", std::cout);
  117.         ParseAndPrintStat(catalogue, "Stop s2", std::cout);
  118.     }
  119. }
  120.  
  121. int main() {
  122.     TestAddStop();
  123.     TestAddBus();
  124.     TestRequestBus();
  125.     TestRequestStop();
  126.     TestRequestStop1();
  127.  
  128.     TransportCatalogue catalogue;
  129.     ifstream fin("tsA_case1_input.txt");
  130.     ofstream fout("result.txt");
  131.     istream& in = fin;
  132.     ostream& out = fout;
  133.     int base_request_count;
  134.     in >> base_request_count >> ws;
  135.  
  136.     {
  137.         InputReader reader;
  138.         for (int i = 0; i < base_request_count; ++i) {
  139.             string line;
  140.             getline(in, line);
  141.             reader.ParseLine(line);
  142.         }
  143.         reader.ApplyCommands(catalogue);
  144.     }
  145.  
  146.     int stat_request_count;
  147.     in >> stat_request_count >> ws;
  148.     for (int i = 0; i < stat_request_count; ++i) {
  149.         string line;
  150.         getline(in, line);
  151.         ParseAndPrintStat(catalogue, line, out);
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment