New git HEAD version
[libdai.git] / tests / unit / var_test.cpp
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 *
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6 */
7
8
9 #include <dai/var.h>
10 #include <strstream>
11
12
13 using namespace dai;
14
15
16 #define BOOST_TEST_MODULE VarTest
17
18
19 #include <boost/test/unit_test.hpp>
20
21
22 BOOST_AUTO_TEST_CASE( ConstructorsTest ) {
23 // check constructors
24 Var x;
25 BOOST_CHECK_EQUAL( x.label(), 0 );
26 BOOST_CHECK_EQUAL( x.states(), 0 );
27
28 x = Var( 0, 2 );
29 BOOST_CHECK_EQUAL( x.label(), 0 );
30 BOOST_CHECK_EQUAL( x.states(), 2 );
31 }
32
33 BOOST_AUTO_TEST_CASE( AccMutTest ) {
34 // check states and labels mutators
35 Var x;
36 x.states() = 3;
37 BOOST_CHECK_EQUAL( x.states(), 3 );
38
39 x.label() = 5;
40 BOOST_CHECK_EQUAL( x.label(), 5 );
41 }
42
43 BOOST_AUTO_TEST_CASE( ComparisonTest ) {
44 // check comparison operators
45 Var x( 5, 3 );
46 Var y( 6, 3 );
47 Var z( 5, 3 );
48 BOOST_CHECK( x < y );
49 BOOST_CHECK( !(x < z) );
50 BOOST_CHECK( y > x );
51 BOOST_CHECK( !(z > x) );
52 BOOST_CHECK( x <= y );
53 BOOST_CHECK( x <= z );
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 }
61
62 BOOST_AUTO_TEST_CASE( StreamTest ) {
63 // check stream output
64 Var x( 5, 3 );
65 std::stringstream ss;
66 ss << x;
67 std::string s;
68 ss >> s;
69 BOOST_CHECK_EQUAL( s, "x5" );
70 BOOST_CHECK_EQUAL( x.toString(), s );
71 }