Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
io_graph_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
37#include <gtest/gtest.h>
38#include <sstream>
39#include <cstdio>
40#include <algorithm>
41#include <filesystem>
42#include <limits>
43#include <string>
44#include <io_graph.H>
45#include <tpl_graph.H>
46#if defined(_WIN32)
47# include <process.h>
48#else
49# include <unistd.h>
50#endif
51
52using namespace Aleph;
53
54namespace
55{
64long long process_id() noexcept
65{
66#if defined(_WIN32)
67 return static_cast<long long>(_getpid());
68#else
69 return static_cast<long long>(getpid());
70#endif
71}
72} // namespace
73
74//============================================================================
75// Test Fixtures
76//============================================================================
77
78class IOGraphTest : public ::testing::Test
79{
80protected:
83 using Arc = Graph::Arc;
84
85 void SetUp() override
86 {
87 // Create a simple graph:
88 // 0 --1.5--> 1 --2.5--> 2
89 // |
90 // 3.5
91 // v
92 // 3
93
94 n0 = g.insert_node(100);
95 n1 = g.insert_node(200);
96 n2 = g.insert_node(300);
97 n3 = g.insert_node(400);
98
99 g.insert_arc(n0, n1, 1.5);
100 g.insert_arc(n1, n2, 2.5);
101 g.insert_arc(n1, n3, 3.5);
102
103 // Unique per test case and process (see the `process_id()` comment
104 // above for why a plain rand() is not enough).
105 const auto *test_info = ::testing::UnitTest::GetInstance()->current_test_info();
106 std::string base = std::string("aleph_io_graph_test_") + test_info->name() + "_" +
107 std::to_string(process_id());
108 for (auto &ch : base)
109 if (ch == '/' or ch == '\\' or ch == ' ')
110 ch = '_';
111
112 binary_file = (std::filesystem::temp_directory_path() / (base + ".bin")).string();
113 text_file = (std::filesystem::temp_directory_path() / (base + ".txt")).string();
114 }
115
116 void TearDown() override
117 {
118 std::remove(binary_file.c_str());
119 std::remove(text_file.c_str());
120 }
121
122 // Helper to collect node values
123 std::vector<int> get_node_values(Graph & graph)
124 {
125 std::vector<int> values;
126 for (typename Graph::Node_Iterator it(graph); it.has_curr(); it.next())
127 values.push_back(it.get_curr()->get_info());
128 std::sort(values.begin(), values.end());
129 return values;
130 }
131
132 // Helper to collect arc values
133 std::vector<double> get_arc_values(Graph & graph)
134 {
135 std::vector<double> values;
136 for (typename Graph::Arc_Iterator it(graph); it.has_curr(); it.next())
137 values.push_back(it.get_curr()->get_info());
138 std::sort(values.begin(), values.end());
139 return values;
140 }
141
143 Node *n0, *n1, *n2, *n3;
144 std::string binary_file;
145 std::string text_file;
146};
147
148//============================================================================
149// Constructor Tests
150//============================================================================
151
152TEST_F(IOGraphTest, ConstructFromReference)
153{
154 IO_Graph<Graph> io(g);
155 EXPECT_FALSE(io.is_verbose());
156}
157
158TEST_F(IOGraphTest, ConstructFromPointer)
159{
160 IO_Graph<Graph> io(&g);
161 EXPECT_FALSE(io.is_verbose());
162}
163
164TEST_F(IOGraphTest, VerboseMode)
165{
166 IO_Graph<Graph> io(g);
167
168 EXPECT_FALSE(io.is_verbose());
169
170 io.set_verbose(true);
171 EXPECT_TRUE(io.is_verbose());
172
173 io.set_verbose(false);
174 EXPECT_FALSE(io.is_verbose());
175}
176
177//============================================================================
178// Binary Mode Tests
179//============================================================================
180
181TEST_F(IOGraphTest, SaveAndLoadBinary)
182{
183 IO_Graph<Graph> io(g);
184
185 // Save
186 {
187 std::ofstream out(binary_file, std::ios::binary);
188 ASSERT_TRUE(out.is_open());
189 io.save(out);
190 }
191
192 // Load into new graph
193 Graph g2;
194 IO_Graph<Graph> io2(g2);
195
196 {
197 std::ifstream in(binary_file, std::ios::binary);
198 ASSERT_TRUE(in.is_open());
199 io2.load(in);
200 }
201
202 // Verify
203 EXPECT_EQ(g2.get_num_nodes(), 4u);
204 EXPECT_EQ(g2.get_num_arcs(), 3u);
205}
206
207TEST_F(IOGraphTest, BinaryPreservesNodeData)
208{
209 IO_Graph<Graph> io(g);
210
211 // Save
212 {
213 std::ofstream out(binary_file, std::ios::binary);
214 io.save(out);
215 }
216
217 // Load
218 Graph g2;
219 IO_Graph<Graph> io2(g2);
220
221 {
222 std::ifstream in(binary_file, std::ios::binary);
223 io2.load(in);
224 }
225
226 EXPECT_EQ(get_node_values(g), get_node_values(g2));
227}
228
229TEST_F(IOGraphTest, BinaryPreservesArcData)
230{
231 IO_Graph<Graph> io(g);
232
233 // Save
234 {
235 std::ofstream out(binary_file, std::ios::binary);
236 io.save(out);
237 }
238
239 // Load
240 Graph g2;
241 IO_Graph<Graph> io2(g2);
242
243 {
244 std::ifstream in(binary_file, std::ios::binary);
245 io2.load(in);
246 }
247
248 EXPECT_EQ(get_arc_values(g), get_arc_values(g2));
249}
250
251//============================================================================
252// Text Mode Tests
253//============================================================================
254
255TEST_F(IOGraphTest, SaveAndLoadText)
256{
257 IO_Graph<Graph> io(g);
258
259 // Save
260 {
261 std::ofstream out(text_file);
262 ASSERT_TRUE(out.is_open());
264 }
265
266 // Load into new graph
267 Graph g2;
268 IO_Graph<Graph> io2(g2);
269
270 {
271 std::ifstream in(text_file);
272 ASSERT_TRUE(in.is_open());
273 io2.load_in_text_mode(in);
274 }
275
276 // Verify
277 EXPECT_EQ(g2.get_num_nodes(), 4u);
278 EXPECT_EQ(g2.get_num_arcs(), 3u);
279}
280
281TEST_F(IOGraphTest, TextPreservesNodeData)
282{
283 IO_Graph<Graph> io(g);
284
285 // Save
286 {
287 std::ofstream out(text_file);
289 }
290
291 // Load
292 Graph g2;
293 IO_Graph<Graph> io2(g2);
294
295 {
296 std::ifstream in(text_file);
297 io2.load_in_text_mode(in);
298 }
299
300 EXPECT_EQ(get_node_values(g), get_node_values(g2));
301}
302
303TEST_F(IOGraphTest, TextModeToStringStream)
304{
305 IO_Graph<Graph> io(g);
306
307 std::ostringstream out;
309
310 std::string content = out.str();
311
312 // Should start with node count and arc count
313 EXPECT_TRUE(content.find("4") != std::string::npos); // 4 nodes
314 EXPECT_TRUE(content.find("3") != std::string::npos); // 3 arcs
315}
316
317//============================================================================
318// Empty Graph Tests
319//============================================================================
320
321TEST_F(IOGraphTest, SaveAndLoadEmptyGraphBinary)
322{
323 Graph empty_g;
324 IO_Graph<Graph> io(empty_g);
325
326 // Save
327 {
328 std::ofstream out(binary_file, std::ios::binary);
329 io.save(out);
330 }
331
332 // Load
333 Graph g2;
334 IO_Graph<Graph> io2(g2);
335
336 {
337 std::ifstream in(binary_file, std::ios::binary);
338 io2.load(in);
339 }
340
341 EXPECT_EQ(g2.get_num_nodes(), 0u);
342 EXPECT_EQ(g2.get_num_arcs(), 0u);
343}
344
345TEST_F(IOGraphTest, SaveAndLoadEmptyGraphText)
346{
347 Graph empty_g;
348 IO_Graph<Graph> io(empty_g);
349
350 // Save
351 {
352 std::ofstream out(text_file);
354 }
355
356 // Load
357 Graph g2;
358 IO_Graph<Graph> io2(g2);
359
360 {
361 std::ifstream in(text_file);
362 io2.load_in_text_mode(in);
363 }
364
365 EXPECT_EQ(g2.get_num_nodes(), 0u);
366 EXPECT_EQ(g2.get_num_arcs(), 0u);
367}
368
369//============================================================================
370// Single Node Graph Tests
371//============================================================================
372
373TEST_F(IOGraphTest, SaveAndLoadSingleNodeBinary)
374{
375 Graph single_g;
376 single_g.insert_node(42);
377
378 IO_Graph<Graph> io(single_g);
379
380 // Save
381 {
382 std::ofstream out(binary_file, std::ios::binary);
383 io.save(out);
384 }
385
386 // Load
387 Graph g2;
388 IO_Graph<Graph> io2(g2);
389
390 {
391 std::ifstream in(binary_file, std::ios::binary);
392 io2.load(in);
393 }
394
395 EXPECT_EQ(g2.get_num_nodes(), 1u);
396 EXPECT_EQ(g2.get_num_arcs(), 0u);
397
398 typename Graph::Node_Iterator it(g2);
399 EXPECT_EQ(it.get_curr()->get_info(), 42);
400}
401
402//============================================================================
403// Digraph Tests
404//============================================================================
405
406class IODigraphTest : public ::testing::Test
407{
408protected:
412
413 void SetUp() override
414 {
415 n0 = dg.insert_node(10);
416 n1 = dg.insert_node(20);
417 n2 = dg.insert_node(30);
418
419 dg.insert_arc(n0, n1, 1);
420 dg.insert_arc(n1, n2, 2);
421 dg.insert_arc(n2, n0, 3); // Cycle
422
423 // Unique per test case and process (see the `process_id()` comment
424 // near the top of the file for why a plain rand() is not enough).
425 const auto *test_info = ::testing::UnitTest::GetInstance()->current_test_info();
426 std::string base = std::string("aleph_io_digraph_test_") + test_info->name() + "_" +
427 std::to_string(process_id());
428 for (auto &ch : base)
429 if (ch == '/' or ch == '\\' or ch == ' ')
430 ch = '_';
431
432 binary_file = (std::filesystem::temp_directory_path() / (base + ".bin")).string();
433 text_file = (std::filesystem::temp_directory_path() / (base + ".txt")).string();
434 }
435
436 void TearDown() override
437 {
438 std::remove(binary_file.c_str());
439 std::remove(text_file.c_str());
440 }
441
443 Node *n0, *n1, *n2;
444 std::string binary_file;
445 std::string text_file;
446};
447
448TEST_F(IODigraphTest, SaveAndLoadBinary)
449{
450 IO_Graph<Digraph> io(dg);
451
452 // Save
453 {
454 std::ofstream out(binary_file, std::ios::binary);
455 io.save(out);
456 }
457
458 // Load
459 Digraph dg2;
460 IO_Graph<Digraph> io2(dg2);
461
462 {
463 std::ifstream in(binary_file, std::ios::binary);
464 io2.load(in);
465 }
466
467 EXPECT_EQ(dg2.get_num_nodes(), 3u);
468 EXPECT_EQ(dg2.get_num_arcs(), 3u);
469}
470
471TEST_F(IODigraphTest, SaveAndLoadText)
472{
473 IO_Graph<Digraph> io(dg);
474
475 // Save
476 {
477 std::ofstream out(text_file);
479 }
480
481 // Load
482 Digraph dg2;
483 IO_Graph<Digraph> io2(dg2);
484
485 {
486 std::ifstream in(text_file);
487 io2.load_in_text_mode(in);
488 }
489
490 EXPECT_EQ(dg2.get_num_nodes(), 3u);
491 EXPECT_EQ(dg2.get_num_arcs(), 3u);
492}
493
494//============================================================================
495// Default Functor Tests
496//============================================================================
497
498TEST(DftStoreNodeTest, TextMode)
499{
501 Graph g;
502 auto n = g.insert_node(12345);
503
505
506 std::ostringstream ss;
507 store(ss, g, n);
508
509 EXPECT_TRUE(ss.str().find("12345") != std::string::npos);
510}
511
512TEST(DftStoreArcTest, TextMode)
513{
515 Graph g;
516 auto n1 = g.insert_node(1);
517 auto n2 = g.insert_node(2);
518 auto a = g.insert_arc(n1, n2, 3.14159);
519
521
522 std::ostringstream ss;
523 store(ss, g, a);
524
525 EXPECT_TRUE(ss.str().find("3.14") != std::string::npos);
526}
527
528TEST(DftLoadNodeTest, TextMode)
529{
531 Graph g;
532 auto n = g.insert_node(0);
533
535
536 std::istringstream ss("999");
537 load(ss, g, n);
538
539 EXPECT_EQ(n->get_info(), 999);
540}
541
542TEST(DftLoadArcTest, TextMode)
543{
545 Graph g;
546 auto n1 = g.insert_node(1);
547 auto n2 = g.insert_node(2);
548 auto a = g.insert_arc(n1, n2, 0.0);
549
551
552 std::istringstream ss("2.718");
553 load(ss, g, a);
554
555 EXPECT_NEAR(a->get_info(), 2.718, 0.001);
556}
557
558//============================================================================
559// Setter Tests
560//============================================================================
561
562TEST_F(IOGraphTest, SetLoadNode)
563{
564 IO_Graph<Graph> io(g);
566 io.set_load_node(ln); // Should not throw
567 SUCCEED();
568}
569
570TEST_F(IOGraphTest, SetStoreNode)
571{
572 IO_Graph<Graph> io(g);
574 io.set_store_node(sn); // Should not throw
575 SUCCEED();
576}
577
578TEST_F(IOGraphTest, SetLoadArc)
579{
580 IO_Graph<Graph> io(g);
582 io.set_load_arc(la); // Should not throw
583 SUCCEED();
584}
585
586TEST_F(IOGraphTest, SetStoreArc)
587{
588 IO_Graph<Graph> io(g);
590 io.set_store_arc(sa); // Should not throw
591 SUCCEED();
592}
593
594//============================================================================
595// Error Handling Tests
596//============================================================================
597
598TEST_F(IOGraphTest, LoadFromBadFile)
599{
600 Graph g2;
601 IO_Graph<Graph> io(g2);
602
603 std::ifstream bad_file("/nonexistent_file_12345.bin", std::ios::binary);
604
605 // Loading from a bad stream should throw
606 EXPECT_THROW(io.load(bad_file), std::runtime_error);
607}
608
609TEST_F(IOGraphTest, LoadTextFromBadFile)
610{
611 Graph g2;
612 IO_Graph<Graph> io(g2);
613
614 std::ifstream bad_file("/nonexistent_file_12345.txt");
615
616 EXPECT_THROW(io.load_in_text_mode(bad_file), std::runtime_error);
617}
618
619//============================================================================
620// Round-Trip Tests
621//============================================================================
622
623TEST_F(IOGraphTest, MultipleRoundTripsBinary)
624{
625 // First save
626 {
627 IO_Graph<Graph> io(g);
628 std::ofstream out(binary_file, std::ios::binary);
629 io.save(out);
630 }
631
632 // First load
633 Graph g2;
634 {
635 IO_Graph<Graph> io(g2);
636 std::ifstream in(binary_file, std::ios::binary);
637 io.load(in);
638 }
639
640 EXPECT_EQ(g2.get_num_nodes(), 4u);
641
642 // Second save (from loaded graph)
643 std::string second_file = binary_file + ".2";
644 {
645 IO_Graph<Graph> io(g2);
646 std::ofstream out(second_file, std::ios::binary);
647 io.save(out);
648 }
649
650 // Second load
651 Graph g3;
652 {
653 IO_Graph<Graph> io(g3);
654 std::ifstream in(second_file, std::ios::binary);
655 io.load(in);
656 }
657
658 EXPECT_EQ(g3.get_num_nodes(), 4u);
659 EXPECT_EQ(g3.get_num_arcs(), 3u);
660
661 std::remove(second_file.c_str());
662}
663
664TEST_F(IOGraphTest, MultipleRoundTripsText)
665{
666 // First save
667 {
668 IO_Graph<Graph> io(g);
669 std::ofstream out(text_file);
671 }
672
673 // First load
674 Graph g2;
675 {
676 IO_Graph<Graph> io(g2);
677 std::ifstream in(text_file);
678 io.load_in_text_mode(in);
679 }
680
681 EXPECT_EQ(g2.get_num_nodes(), 4u);
682 EXPECT_EQ(g2.get_num_arcs(), 3u);
683}
684
685//============================================================================
686// Main
687//============================================================================
688
689//============================================================================
690// Corrupted streams: the load validates the indices and undoes itself
691//============================================================================
692
693namespace
694{
695 // A binary stream of the nodes `infos` and of one arc from `src` to `tgt`
696 void write_binary_graph(const std::string & file, const std::vector<int> & infos,
697 int src, int tgt, bool with_arc_info = true)
698 {
699 std::ofstream out(file, std::ios::binary);
700 const size_t num_nodes = infos.size();
701 out.write(reinterpret_cast<const char *>(&num_nodes), sizeof(num_nodes));
702 for (int info : infos)
703 out.write(reinterpret_cast<const char *>(&info), sizeof(info));
704 const size_t num_arcs = 1;
705 out.write(reinterpret_cast<const char *>(&num_arcs), sizeof(num_arcs));
706 out.write(reinterpret_cast<const char *>(&src), sizeof(src));
707 out.write(reinterpret_cast<const char *>(&tgt), sizeof(tgt));
708 if (with_arc_info)
709 {
710 const double w = 2.5;
711 out.write(reinterpret_cast<const char *>(&w), sizeof(w));
712 }
713 }
714}
715
716TEST_F(IOGraphTest, LoadRejectsAnArcToANodeThatIsNotThere)
717{
718 // The indices of the arcs were not validated: an index beyond the nodes
719 // of the stream read an entry of the table that holds no node
720 for (int tgt : {7, 3, -1})
721 {
722 write_binary_graph(binary_file, {10, 20, 30}, 0, tgt);
723 Graph g2;
724 g2.insert_node(99);
725 IO_Graph<Graph> io(g2);
726 std::ifstream in(binary_file, std::ios::binary);
727 EXPECT_THROW(io.load(in), std::runtime_error) << tgt;
728 // The load undid itself: the graph is as it was
729 EXPECT_EQ(g2.vsize(), 1u) << tgt;
730 EXPECT_EQ(g2.esize(), 0u) << tgt;
731 EXPECT_EQ(g2.get_first_node()->get_info(), 99) << tgt;
732 }
733}
734
735TEST_F(IOGraphTest, LoadInTextModeRejectsAnArcToANodeThatIsNotThere)
736{
737 for (const char * text : {"3\n1\n10\n20\n30\n0 5 2.5\n", "2\n1\n10\n20\n-1 0 1.0\n"})
738 {
739 std::istringstream in(text);
740 Graph g2;
741 g2.insert_node(99);
742 IO_Graph<Graph> io(g2);
743 EXPECT_THROW(io.load_in_text_mode(in), std::runtime_error) << text;
744 EXPECT_EQ(g2.vsize(), 1u) << text;
745 EXPECT_EQ(g2.esize(), 0u) << text;
746 }
747}
748
749TEST_F(IOGraphTest, AFailedLoadLeavesTheGraphAsItWas)
750{
751 // The nodes and arcs read before the failure stayed in the graph
752 write_binary_graph(binary_file, {10, 20, 30}, 0, 2, false); // no arc info
753 Graph g2;
754 g2.insert_node(99);
755 IO_Graph<Graph> io(g2);
756 std::ifstream in(binary_file, std::ios::binary);
757 EXPECT_THROW(io.load(in), std::runtime_error);
758 EXPECT_EQ(g2.vsize(), 1u);
759 EXPECT_EQ(g2.esize(), 0u);
760
761 std::istringstream text("3\n2\n10\n20\n30\n0 1 1.0\n1 2\n"); // the second arc has no info
762 EXPECT_THROW(io.load_in_text_mode(text), std::runtime_error);
763 EXPECT_EQ(g2.vsize(), 1u);
764 EXPECT_EQ(g2.esize(), 0u);
765}
766
767TEST_F(IOGraphTest, ALoadAddsToTheGraph)
768{
769 // The documentation said that the load cleared the graph, which it does not
770 {
771 std::ofstream out(binary_file, std::ios::binary);
773 }
774 Graph g2;
775 g2.insert_node(99);
776 IO_Graph<Graph> io(g2);
777 std::ifstream in(binary_file, std::ios::binary);
778 io.load(in);
779 EXPECT_EQ(g2.vsize(), 5u);
780 EXPECT_EQ(g2.esize(), 3u);
781}
782
783TEST_F(IOGraphTest, ALoadDoesNotTrustTheCountOfTheStream)
784{
785 // The count of nodes of the stream reserved the table of the load: a
786 // corrupted one, huge, asked for more memory than there is
787 const size_t huge = std::numeric_limits<size_t>::max();
788 {
789 std::ofstream out(binary_file, std::ios::binary);
790 out.write(reinterpret_cast<const char *>(&huge), sizeof(huge));
791 }
792 Graph g2;
793 g2.insert_node(99);
794 IO_Graph<Graph> io(g2);
795 std::ifstream in(binary_file, std::ios::binary);
796 EXPECT_THROW(io.load(in), std::runtime_error);
797 EXPECT_EQ(g2.vsize(), 1u);
798 EXPECT_EQ(g2.esize(), 0u);
799
800 std::istringstream text(std::to_string(huge) + "\n0\n");
801 EXPECT_THROW(io.load_in_text_mode(text), std::runtime_error);
802 EXPECT_EQ(g2.vsize(), 1u);
803 EXPECT_EQ(g2.esize(), 0u);
804}
805
806TEST_F(IOGraphTest, ALoadGrowsBeyondWhatItReserves)
807{
808 // A load reserves for 2^20 nodes at most, and grows as it reads more:
809 // an arc from a node beyond that limit
810 const size_t n = (size_t(1) << 20) + 2;
811 {
812 std::ofstream out(binary_file, std::ios::binary);
813 out.write(reinterpret_cast<const char *>(&n), sizeof(n));
814 for (size_t i = 0; i < n; ++i)
815 {
816 const int info = static_cast<int>(i);
817 out.write(reinterpret_cast<const char *>(&info), sizeof(info));
818 }
819 const size_t num_arcs = 1;
820 out.write(reinterpret_cast<const char *>(&num_arcs), sizeof(num_arcs));
821 const int src = static_cast<int>(n - 1), tgt = 0;
822 out.write(reinterpret_cast<const char *>(&src), sizeof(src));
823 out.write(reinterpret_cast<const char *>(&tgt), sizeof(tgt));
824 const double w = 2.5;
825 out.write(reinterpret_cast<const char *>(&w), sizeof(w));
826 }
827 Graph g2;
828 IO_Graph<Graph> io(g2);
829 std::ifstream in(binary_file, std::ios::binary);
830 io.load(in);
831 EXPECT_EQ(g2.vsize(), n);
832 ASSERT_EQ(g2.esize(), 1u);
833 auto * a = g2.get_first_arc();
834 EXPECT_EQ(g2.get_src_node(a)->get_info(), static_cast<int>(n - 1));
835 EXPECT_EQ(g2.get_tgt_node(a)->get_info(), 0);
836 EXPECT_DOUBLE_EQ(a->get_info(), 2.5);
837}
838
839int main(int argc, char **argv)
840{
841 ::testing::InitGoogleTest(&argc, argv);
842 return RUN_ALL_TESTS();
843}
int main()
long double w
Definition btreepic.C:153
int num_nodes
Definition btreepic.C:410
size_t size_t int32_t * out
Definition ca-c-api.h:120
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
typename BaseGraph::Arc Arc
Definition graph-dry.H:4381
typename BaseGraph::Node Node
Definition graph-dry.H:4380
Graph serialization and deserialization class.
Definition io_graph.H:344
void save(std::ofstream &output)
Save graph to binary stream.
Definition io_graph.H:482
void set_store_arc(const Store_Arc &sa)
Set the arc storage functor.
Definition io_graph.H:391
void save_in_text_mode(std::ostream &output)
Save graph to text stream.
Definition io_graph.H:644
void load_in_text_mode(std::istream &input)
Load graph from text stream.
Definition io_graph.H:712
void load(std::ifstream &input)
Load graph from binary stream.
Definition io_graph.H:552
bool is_verbose() const noexcept
Check if verbose mode is enabled.
Definition io_graph.H:371
void set_store_node(const Store_Node &sn)
Set the node storage functor.
Definition io_graph.H:381
void set_load_arc(const Load_Arc &la)
Set the arc loading functor.
Definition io_graph.H:386
void set_verbose(bool v) noexcept
Enable or disable verbose mode.
Definition io_graph.H:366
void set_load_node(const Load_Node &ln)
Set the node loading functor.
Definition io_graph.H:376
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
Definition tpl_graph.H:609
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
Graph_Arc< double > Arc
The node class type.
Definition tpl_graph.H:444
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:975
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Definition graph-dry.H:1064
constexpr size_t vsize() const noexcept
See get_num_nodes().
Definition graph-dry.H:984
size_t esize() const noexcept
Return the total of arcs of graph.
Definition graph-dry.H:1078
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:1023
std::string text_file
void SetUp() override
Digraph::Arc Arc
Digraph::Node Node
void TearDown() override
std::string binary_file
void SetUp() override
void TearDown() override
std::vector< int > get_node_values(Graph &graph)
std::string binary_file
std::string text_file
std::vector< double > get_arc_values(Graph &graph)
#define TEST(name)
Graph serialization and deserialization utilities.
TEST_F(IOGraphTest, ConstructFromReference)
Main namespace for Aleph-w library functions.
Default arc loading functor for binary and text modes.
Definition io_graph.H:279
Default node loading functor for binary and text modes.
Definition io_graph.H:241
Default arc storage functor for binary and text modes.
Definition io_graph.H:203
Default node storage functor for binary and text modes.
Definition io_graph.H:165
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:231
Generic graph and digraph implementations.
ofstream file
Definition writeRb.C:51