Debian Codegraph @

unit_test/general/batch_statistics.cpp

raw symbols SCIP
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 #include <regex>
28 #include <sstream>
29
30 #include "g2o/core/batch_stats.h"
31 #include "gtest/gtest.h"
32
33 namespace {
34 std::string extractValue(const std::string& input, const std::string& field) {
35 const std::regex field_regex("(" + field + ")= ([^\t]*)");
36 std::smatch match;
37 if (!std::regex_search(input, match, field_regex)) {
38 return "";
39 }
40 if (match.size() != 3) {
41 return "";
42 }
43 return match[2].str();
44 }
45 } // namespace
46
47 TEST(General, BatchStatisticsOutput) {
48 g2o::G2OBatchStatistics stats;
49
50 std::ostringstream output_stream;
51 stats.iteration = 42;
52 stats.choleskyNNZ = 1001;
53 stats.timeMarginals = 12.1;
54 stats.levenbergIterations = 4;
55 output_stream << stats;
56
57 EXPECT_EQ("42", extractValue(output_stream.str(), "iteration"));
58 EXPECT_EQ("1001", extractValue(output_stream.str(), "choleskyNNZ"));
59 EXPECT_EQ("12.1", extractValue(output_stream.str(), "timeMarginals"));
60 EXPECT_EQ("4", extractValue(output_stream.str(), "levenbergIterations"));
61 }