@@ -8,16 +8,89 @@ using Itinerary = dsf::Itinerary;
88
99TEST_CASE (" Itinerary" ) {
1010 SUBCASE (" Constructors" ) {
11- GIVEN (" Some parameters" ) {
12- dsf::Id itineraryId{0 };
13- dsf::Id destinationId{2 };
14- WHEN (" The Itinerary is constructed" ) {
15- Itinerary itinerary{itineraryId, destinationId};
16- THEN (" The source and destination are set correctly" ) {
17- CHECK_EQ (itinerary.id (), itineraryId);
18- CHECK_EQ (itinerary.destination (), destinationId);
19- }
20- }
11+ dsf::Id itineraryId{0 };
12+ dsf::Id destinationId{2 };
13+ Itinerary itinerary{itineraryId, destinationId};
14+ CHECK_EQ (itinerary.id (), itineraryId);
15+ CHECK_EQ (itinerary.destination (), destinationId);
16+ }
17+
18+ SUBCASE (" Set and get path" ) {
19+ Itinerary itinerary{1 , 42 };
20+ std::unordered_map<dsf::Id, std::vector<dsf::Id>> path = {
21+ {1 , {2 , 3 }}, {2 , {4 }}, {3 , {5 , 6 , 7 }}};
22+ itinerary.setPath (path);
23+ auto const & result = itinerary.path ();
24+ CHECK_EQ (result.size (), path.size ());
25+ for (const auto & [k, v] : path) {
26+ CHECK (result.count (k) == 1 );
27+ CHECK (result.at (k) == v);
28+ }
29+ }
30+
31+ SUBCASE (" Save and load itinerary" ) {
32+ Itinerary itinerary{7 , 99 };
33+ std::unordered_map<dsf::Id, std::vector<dsf::Id>> path = {
34+ {7 , {8 , 9 }}, {8 , {10 }}, {9 , {11 , 12 }}};
35+ itinerary.setPath (path);
36+ const std::string filename = " test_itinerary.bin" ;
37+ itinerary.save (filename);
38+
39+ Itinerary loaded{7 , 0 }; // destination will be overwritten by load
40+ loaded.load (filename);
41+ CHECK_EQ (loaded.destination (), 99 );
42+ auto const & loadedPath = loaded.path ();
43+ CHECK_EQ (loadedPath.size (), path.size ());
44+ for (const auto & [k, v] : path) {
45+ CHECK (loadedPath.count (k) == 1 );
46+ CHECK (loadedPath.at (k) == v);
47+ }
48+ // Clean up
49+ std::remove (filename.c_str ());
50+ }
51+
52+ SUBCASE (" Load from non-existent file throws" ) {
53+ Itinerary itinerary{1 , 2 };
54+ CHECK_THROWS_AS (itinerary.load (" nonexistent_file.bin" ), std::runtime_error);
55+ }
56+
57+ SUBCASE (" Empty path" ) {
58+ Itinerary itinerary{123 , 456 };
59+ itinerary.setPath ({});
60+ CHECK (itinerary.path ().empty ());
61+ const std::string filename = " test_empty_path.bin" ;
62+ itinerary.save (filename);
63+ Itinerary loaded{123 , 0 };
64+ loaded.load (filename);
65+ CHECK (loaded.path ().empty ());
66+ std::remove (filename.c_str ());
67+ }
68+
69+ SUBCASE (" Large path" ) {
70+ Itinerary itinerary{100 , 200 };
71+ std::unordered_map<dsf::Id, std::vector<dsf::Id>> path;
72+ for (dsf::Id i = 0 ; i < 100 ; ++i) {
73+ std::vector<dsf::Id> v;
74+ for (dsf::Id j = 0 ; j < 10 ; ++j)
75+ v.push_back (i * 10 + j);
76+ path[i] = v;
77+ }
78+ itinerary.setPath (path);
79+ CHECK_EQ (itinerary.path ().size (), 100 );
80+ for (dsf::Id i = 0 ; i < 100 ; ++i) {
81+ CHECK (itinerary.path ().count (i) == 1 );
82+ CHECK (itinerary.path ().at (i).size () == 10 );
83+ }
84+ const std::string filename = " test_large_path.bin" ;
85+ itinerary.save (filename);
86+ Itinerary loaded{100 , 0 };
87+ loaded.load (filename);
88+ CHECK_EQ (loaded.path ().size (), 100 );
89+ for (dsf::Id i = 0 ; i < 100 ; ++i) {
90+ CHECK (loaded.path ().count (i) == 1 );
91+ CHECK (loaded.path ().at (i).size () == 10 );
92+ CHECK (loaded.path ().at (i) == path[i]);
2193 }
94+ std::remove (filename.c_str ());
2295 }
2396}
0 commit comments