From 9da2f16f4dd70b0a542be89dbb263caa4c1b8c86 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 22 Nov 2009 18:12:29 +0000 Subject: [PATCH] Removed copy/paste in unit tests --- cpp/testBayesTree.cpp | 86 ++++++++++++------------------------------- 1 file changed, 23 insertions(+), 63 deletions(-) diff --git a/cpp/testBayesTree.cpp b/cpp/testBayesTree.cpp index c1ff98dab..70b581664 100644 --- a/cpp/testBayesTree.cpp +++ b/cpp/testBayesTree.cpp @@ -22,11 +22,25 @@ typedef BayesTree SymbolicBayesTree; typedef BayesTree GaussianBayesTree; // Conditionals for ASIA example from the tutorial with A and D evidence -SymbolicConditional::shared_ptr B(new SymbolicConditional("B")), L( - new SymbolicConditional("L", "B")), E( - new SymbolicConditional("E", "L", "B")), S(new SymbolicConditional("S", - "L", "B")), T(new SymbolicConditional("T", "E", "L")), X( - new SymbolicConditional("X", "E")); +SymbolicConditional::shared_ptr + B(new SymbolicConditional("B")), + L(new SymbolicConditional("L", "B")), + E(new SymbolicConditional("E", "B", "L")), + S(new SymbolicConditional("S", "L", "B")), + T(new SymbolicConditional("T", "E", "L")), + X(new SymbolicConditional("X", "E")); + +// Bayes Tree for Asia example +SymbolicBayesTree createAsiaSymbolicBayesTree() { + SymbolicBayesTree bayesTree; + bayesTree.insert(B); + bayesTree.insert(L); + bayesTree.insert(E); + bayesTree.insert(S); + bayesTree.insert(T); + bayesTree.insert(X); + return bayesTree; +} /* ************************************************************************* */ TEST( BayesTree, Front ) @@ -45,13 +59,7 @@ TEST( BayesTree, Front ) TEST( BayesTree, constructor ) { // Create using insert - SymbolicBayesTree bayesTree; - bayesTree.insert(B); - bayesTree.insert(L); - bayesTree.insert(E); - bayesTree.insert(S); - bayesTree.insert(T); - bayesTree.insert(X); + SymbolicBayesTree bayesTree = createAsiaSymbolicBayesTree(); // Check Size LONGS_EQUAL(4,bayesTree.size()); @@ -354,23 +362,7 @@ TEST( BayesTree, removePath ) /* ************************************************************************* */ TEST( BayesTree, removePath2 ) { - // Conditionals for ASIA example from the tutorial with A and D evidence - SymbolicConditional::shared_ptr - B(new SymbolicConditional("B")), - L(new SymbolicConditional("L", "B")), - E(new SymbolicConditional("E", "B", "L")), - S(new SymbolicConditional("S", "L", "B")), - T(new SymbolicConditional("T", "E", "L")), - X(new SymbolicConditional("X", "E")); - - // Create using insert - SymbolicBayesTree bayesTree; - bayesTree.insert(B); - bayesTree.insert(L); - bayesTree.insert(E); - bayesTree.insert(S); - bayesTree.insert(T); - bayesTree.insert(X); + SymbolicBayesTree bayesTree = createAsiaSymbolicBayesTree(); // Call remove-path with clique S FactorGraph factors; @@ -391,23 +383,7 @@ TEST( BayesTree, removePath2 ) /* ************************************************************************* */ TEST( BayesTree, removePath3 ) { - // Conditionals for ASIA example from the tutorial with A and D evidence - SymbolicConditional::shared_ptr - B(new SymbolicConditional("B")), - L(new SymbolicConditional("L", "B")), - E(new SymbolicConditional("E", "B", "L")), - S(new SymbolicConditional("S", "L", "B")), - T(new SymbolicConditional("T", "E", "L")), - X(new SymbolicConditional("X", "E")); - - // Create using insert - SymbolicBayesTree bayesTree; - bayesTree.insert(B); - bayesTree.insert(L); - bayesTree.insert(E); - bayesTree.insert(S); - bayesTree.insert(T); - bayesTree.insert(X); + SymbolicBayesTree bayesTree = createAsiaSymbolicBayesTree(); // Call remove-path with clique S FactorGraph factors; @@ -429,23 +405,7 @@ TEST( BayesTree, removePath3 ) /* ************************************************************************* */ TEST( BayesTree, removeTop ) { - // Conditionals for ASIA example from the tutorial with A and D evidence - SymbolicConditional::shared_ptr - B(new SymbolicConditional("B")), - L(new SymbolicConditional("L", "B")), - E(new SymbolicConditional("E", "B", "L")), - S(new SymbolicConditional("S", "L", "B")), - T(new SymbolicConditional("T", "E", "L")), - X(new SymbolicConditional("X", "E")); - - // Create using insert - SymbolicBayesTree bayesTree; - bayesTree.insert(B); - bayesTree.insert(L); - bayesTree.insert(E); - bayesTree.insert(S); - bayesTree.insert(T); - bayesTree.insert(X); + SymbolicBayesTree bayesTree = createAsiaSymbolicBayesTree(); // create a new factor to be inserted list keys;