Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cassert>
- #include <iomanip>
- #include <fstream>
- #include "input_reader.h"
- #include "stat_reader.h"
- using namespace std;
- void TestAddStop() {
- {
- TransportCatalogue catalogue;
- InputReader reader;
- reader.ParseLine("Stop s1: 1.1, 2.2");
- reader.ParseLine("Stop s2: 0, 0");
- reader.ApplyCommands(catalogue);
- const Stop* stop_ptr = catalogue.GetStopPtr("s1");
- assert(stop_ptr->GetName().compare("s1") == 0); // 0 - sv are equal
- assert(stop_ptr->GetCoordinates().lat == 1.1);
- assert(stop_ptr->GetCoordinates().lng == 2.2);
- //std::cerr << *stop_ptr << std::endl;
- stop_ptr = catalogue.GetStopPtr("s2");
- assert(stop_ptr->GetName().compare("s2") == 0); // 0 - sv are equal
- assert(stop_ptr->GetCoordinates().lat == 0.0);
- assert(stop_ptr->GetCoordinates().lng == 0.0);
- //std::cerr << *stop_ptr << std::endl;
- }
- }
- void TestAddBus() {
- {
- TransportCatalogue catalogue;
- InputReader reader;
- reader.ParseLine("Stop s1: 1.1, 1.2");
- reader.ParseLine("Stop s2: 2.1, 2.2");
- reader.ParseLine("Stop s3: 3.1, 3.2");
- reader.ParseLine("Stop s4: 3.1, 3.2");
- reader.ParseLine("Bus b1: s1 > s2 > s3 > s1");
- reader.ParseLine("Bus b2: s1 - s4 - s3");
- reader.ApplyCommands(catalogue);
- const Bus* bus_ptr = catalogue.GetBusPtr("b1");
- assert(bus_ptr->GetName().compare("b1") == 0);
- assert(bus_ptr->GetStops().size() == 4);
- //std::cerr << *bus_ptr << std::endl;
- bus_ptr = catalogue.GetBusPtr("b2");
- assert(bus_ptr->GetName().compare("b2") == 0);
- assert(bus_ptr->GetStops().size() == 5);
- //std::cerr << *bus_ptr << std::endl;
- }
- }
- void TestRequestBus() {
- {
- TransportCatalogue catalogue;
- InputReader reader;
- reader.ParseLine("Stop Tolstopaltsevo: 55.611087, 37.208290");
- reader.ParseLine("Stop Marushkino: 55.595884, 37.209755");
- reader.ParseLine("Bus 256: Biryulyovo Zapadnoye > Biryusinka > Universam > Biryulyovo Tovarnaya > Biryulyovo Passazhirskaya > Biryulyovo Zapadnoye");
- reader.ParseLine("Bus 750: Tolstopaltsevo - Marushkino - Rasskazovka");
- reader.ParseLine("Stop Rasskazovka: 55.632761, 37.333324");
- reader.ParseLine("Stop Biryulyovo Zapadnoye: 55.574371, 37.651700");
- reader.ParseLine("Stop Biryusinka: 55.581065, 37.648390");
- reader.ParseLine("Stop Universam: 55.587655, 37.645687");
- reader.ParseLine("Stop Biryulyovo Tovarnaya: 55.592028, 37.653656");
- reader.ParseLine("Stop Biryulyovo Passazhirskaya: 55.580999, 37.659164");
- reader.ApplyCommands(catalogue);
- ParseAndPrintStat(catalogue, "Bus 256", std::cout);
- ParseAndPrintStat(catalogue, "Bus 750", std::cout);
- ParseAndPrintStat(catalogue, "Bus 751", std::cout);
- }
- }
- void TestRequestStop() {
- {
- TransportCatalogue catalogue;
- InputReader reader;
- reader.ParseLine("Stop Tolstopaltsevo: 55.611087, 37.208290");
- reader.ParseLine("Stop Marushkino: 55.595884, 37.209755");
- reader.ParseLine("Bus 256: Biryulyovo Zapadnoye > Biryusinka > Universam > Biryulyovo Tovarnaya > Biryulyovo Passazhirskaya > Biryulyovo Zapadnoye");
- reader.ParseLine("Bus 750: Tolstopaltsevo - Marushkino - Rasskazovka");
- reader.ParseLine("Stop Rasskazovka: 55.632761, 37.333324");
- reader.ParseLine("Stop Biryulyovo Zapadnoye: 55.574371, 37.651700");
- reader.ParseLine("Stop Biryusinka: 55.581065, 37.648390");
- reader.ParseLine("Stop Universam: 55.587655, 37.645687");
- reader.ParseLine("Stop Biryulyovo Tovarnaya: 55.592028, 37.653656");
- reader.ParseLine("Stop Biryulyovo Passazhirskaya: 55.580999, 37.659164");
- reader.ParseLine("Bus 828: Biryulyovo Zapadnoye > Universam > Rossoshanskaya ulitsa > Biryulyovo Zapadnoye");
- reader.ParseLine("Stop Rossoshanskaya ulitsa: 55.595579, 37.605757");
- reader.ParseLine("Stop Prazhskaya: 55.611678, 37.603831");
- reader.ApplyCommands(catalogue);
- ParseAndPrintStat(catalogue, "Stop Samara", std::cout);
- ParseAndPrintStat(catalogue, "Stop Prazhskaya", std::cout);
- ParseAndPrintStat(catalogue, "Stop Biryulyovo Zapadnoye", std::cout);
- }
- }
- void TestRequestStop1() {
- {
- TransportCatalogue catalogue;
- InputReader reader;
- reader.ParseLine("Stop s1: 55.611087, 37.208290");
- reader.ParseLine("Stop s2: 55.595884, 37.209755");
- reader.ParseLine("Bus 828: s1 - s2");
- reader.ApplyCommands(catalogue);
- ParseAndPrintStat(catalogue, "Bus 828", std::cout);
- ParseAndPrintStat(catalogue, "Stop s1", std::cout);
- ParseAndPrintStat(catalogue, "Stop s2", std::cout);
- }
- }
- int main() {
- TestAddStop();
- TestAddBus();
- TestRequestBus();
- TestRequestStop();
- TestRequestStop1();
- TransportCatalogue catalogue;
- ifstream fin("tsA_case1_input.txt");
- ofstream fout("result.txt");
- istream& in = fin;
- ostream& out = fout;
- int base_request_count;
- in >> base_request_count >> ws;
- {
- InputReader reader;
- for (int i = 0; i < base_request_count; ++i) {
- string line;
- getline(in, line);
- reader.ParseLine(line);
- }
- reader.ApplyCommands(catalogue);
- }
- int stat_request_count;
- in >> stat_request_count >> ws;
- for (int i = 0; i < stat_request_count; ++i) {
- string line;
- getline(in, line);
- ParseAndPrintStat(catalogue, line, out);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment