From ede0a8c874475028f905e6626ca2ee23ebd9b0a9 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 18 Feb 2010 14:29:40 +0000 Subject: [PATCH] Added unit test --- cpp/testGaussianBayesNet.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/cpp/testGaussianBayesNet.cpp b/cpp/testGaussianBayesNet.cpp index 1beabfec3..ae02cd23b 100644 --- a/cpp/testGaussianBayesNet.cpp +++ b/cpp/testGaussianBayesNet.cpp @@ -88,21 +88,43 @@ TEST( GaussianBayesNet, optimize ) /* ************************************************************************* */ TEST( GaussianBayesNet, backSubstitute ) { + // y=R*x, x=inv(R)*y + // 2 = 1 1 -1 + // 3 1 3 GaussianBayesNet cbn = createSmallGaussianBayesNet(); - VectorConfig y, expected; - y.insert("x",Vector_(1,4.)); - y.insert("y",Vector_(1,2.)); - expected.insert("x",Vector_(1,2.)); - expected.insert("y",Vector_(1,2.)); + VectorConfig y, x; + y.insert("x",Vector_(1,2.)); + y.insert("y",Vector_(1,3.)); + x.insert("x",Vector_(1,-1.)); + x.insert("y",Vector_(1, 3.)); // test functional version VectorConfig actual = backSubstitute(cbn,y); - CHECK(assert_equal(expected,actual)); + CHECK(assert_equal(x,actual)); // test imperative version backSubstituteInPlace(cbn,y); - CHECK(assert_equal(expected,y)); + CHECK(assert_equal(x,y)); +} + +/* ************************************************************************* */ +TEST( GaussianBayesNet, backSubstituteTranspose ) +{ + // x=R'*y, y=inv(R')*x + // 2 = 1 2 + // 5 1 1 3 + GaussianBayesNet cbn = createSmallGaussianBayesNet(); + + VectorConfig x, y; + x.insert("x",Vector_(1,2.)); + x.insert("y",Vector_(1,5.)); + y.insert("x",Vector_(1,2.)); + y.insert("y",Vector_(1,3.)); + + // test functional version + VectorConfig actual = backSubstituteTranspose(cbn,x); + CHECK(assert_equal(y,actual)); } /* ************************************************************************* */