testSignatureParser.cpp
Go to the documentation of this file.
1 
9 
10 using namespace gtsam;
11 
12 /* ************************************************************************* */
13 // Simple test case
15  const SignatureParser::Table& table2) {
16  if (table1.size() != table2.size()) {
17  return false;
18  }
19  for (size_t i = 0; i < table1.size(); ++i) {
20  if (table1[i].size() != table2[i].size()) {
21  return false;
22  }
23  for (size_t j = 0; j < table1[i].size(); ++j) {
24  if (table1[i][j] != table2[i][j]) {
25  return false;
26  }
27  }
28  }
29  return true;
30 }
31 
32 /* ************************************************************************* */
33 // Simple test case
34 TEST(SimpleParser, Simple) {
35  SignatureParser::Table expectedTable{{1, 1}, {2, 3}, {1, 4}};
36  const auto table = SignatureParser::Parse("1/1 2/3 1/4");
37  CHECK(table);
38  // compare the tables
39  EXPECT(compareTables(*table, expectedTable));
40 }
41 
42 /* ************************************************************************* */
43 // Test case with each row having 3 elements
44 TEST(SimpleParser, ThreeElements) {
45  SignatureParser::Table expectedTable{{1, 1, 1}, {2, 3, 2}, {1, 4, 3}};
46  const auto table = SignatureParser::Parse("1/1/1 2/3/2 1/4/3");
47  CHECK(table);
48  // compare the tables
49  EXPECT(compareTables(*table, expectedTable));
50 }
51 
52 /* ************************************************************************* */
53 // A test case to check if we can parse a signature with 'T' and 'F'
54 TEST(SimpleParser, TAndF) {
55  SignatureParser::Table expectedTable{{1, 0}, {1, 0}, {1, 0}, {0, 1}};
56  const auto table = SignatureParser::Parse("F F F T");
57  CHECK(table);
58  // compare the tables
59  EXPECT(compareTables(*table, expectedTable));
60 }
61 
62 /* ************************************************************************* */
63 // A test to parse {F F F 1}
64 TEST(SimpleParser, FFF1) {
65  SignatureParser::Table expectedTable{{1, 0}, {1, 0}, {1, 0}};
66  const auto table = SignatureParser::Parse("F F F");
67  CHECK(table);
68  // compare the tables
69  EXPECT(compareTables(*table, expectedTable));
70 }
71 
72 /* ************************************************************************* */
73 // Expect false if the string is empty
74 TEST(SimpleParser, emptyString) {
75  const auto table = SignatureParser::Parse("");
76  EXPECT(!table);
77 }
78 
79 /* ************************************************************************* */
80 // Expect false if gibberish
81 TEST(SimpleParser, Gibberish) {
82  const auto table = SignatureParser::Parse("sdf 22/3");
83  EXPECT(!table);
84 }
85 
86 // If Gibberish is in the middle, it should not parse.
87 TEST(SimpleParser, GibberishInMiddle) {
88  const auto table = SignatureParser::Parse("1/1 2/3 sdf 1/4");
89  EXPECT(!table);
90 }
91 
92 // A test with slash in the end
93 TEST(SimpleParser, SlashInEnd) {
94  const auto table = SignatureParser::Parse("1/1 2/");
95  EXPECT(!table);
96 }
97 
98 /* ************************************************************************* */
99 
100 int main() {
101  TestResult tr;
102  return TestRegistry::runAllTests(tr);
103 }
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
SignatureParser.h
Parser for conditional distribution signatures.
main
int main()
Definition: testSignatureParser.cpp:100
TestableAssertions.h
Provides additional testing facilities for common data structures.
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
table
ArrayXXf table(10, 4)
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
compareTables
bool compareTables(const SignatureParser::Table &table1, const SignatureParser::Table &table2)
Definition: testSignatureParser.cpp:14
TestResult
Definition: TestResult.h:26
gtsam
traits
Definition: SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
CHECK
#define CHECK(condition)
Definition: Test.h:108
gtsam::SignatureParser::Table
std::vector< Row > Table
Definition: SignatureParser.h:54
gtsam::SignatureParser::Parse
static std::optional< Table > Parse(const std::string &str)
Definition: SignatureParser.cpp:77
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:36