[Ofer Meshi] Added a script to convert from FastInf fileformat to libDAI fileformat
[libdai.git] / tests / unit / var_test.cpp
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
6 *
7 * Copyright (C) 2010 Joris Mooij [joris dot mooij at libdai dot org]
8 */
9
10
11 #include <dai/var.h>
12 #include <strstream>
13
14
15 using namespace dai;
16
17
18 #define BOOST_TEST_MODULE VarTest
19
20
21 #include <boost/test/unit_test.hpp>
22
23
24 BOOST_AUTO_TEST_CASE( ConstructorsTest ) {
25 // check constructors
26 Var x;
27 BOOST_CHECK_EQUAL( x.label(), 0 );
28 BOOST_CHECK_EQUAL( x.states(), 0 );
29
30 x = Var( 0, 2 );
31 BOOST_CHECK_EQUAL( x.label(), 0 );
32 BOOST_CHECK_EQUAL( x.states(), 2 );
33 }
34
35 BOOST_AUTO_TEST_CASE( AccMutTest ) {
36 // check states and labels mutators
37 Var x;
38 x.states() = 3;
39 BOOST_CHECK_EQUAL( x.states(), 3 );
40
41 x.label() = 5;
42 BOOST_CHECK_EQUAL( x.label(), 5 );
43 }
44
45 BOOST_AUTO_TEST_CASE( ComparisonTest ) {
46 // check comparison operators
47 Var x( 5, 3 );
48 Var y( 6, 3 );
49 Var z( 5, 3 );
50 BOOST_CHECK( x < y );
51 BOOST_CHECK( !(x < z) );
52 BOOST_CHECK( y > x );
53 BOOST_CHECK( !(z > x) );
54 BOOST_CHECK( x <= y );
55 BOOST_CHECK( x <= z );
56 BOOST_CHECK( !(x >= y) );
57 BOOST_CHECK( x >= z );
58 BOOST_CHECK( !(x == y) );
59 BOOST_CHECK( x == z );
60 BOOST_CHECK( x != y );
61 BOOST_CHECK( !(x != z) );
62 }
63
64 BOOST_AUTO_TEST_CASE( StreamTest ) {
65 // check stream output
66 Var x( 5, 3 );
67 std::stringstream ss;
68 ss << x;
69 std::string s;
70 ss >> s;
71 BOOST_CHECK_EQUAL( s, "x5" );
72 }