- Main Page
- Classes
- Files

# test_node.cpp File Reference

`#include <iostream>`
`#include <istream>`
`#include <ostream>`
`#include <sstream>`
`#include <string>`
`#include <boost/test/auto_unit_test.hpp>`
`#include "node.hpp"`
`#include "variables.hpp"`

Go to the source code of this file.

## Functions
| BOOST_AUTO_TEST_CASE (test_basics)
| BOOST_AUTO_TEST_CASE (test_negate)
| BOOST_AUTO_TEST_CASE (test_add)
| BOOST_AUTO_TEST_CASE (test_subtract)
| BOOST_AUTO_TEST_CASE (test_multiply)
| BOOST_AUTO_TEST_CASE (test_divide)
| BOOST_AUTO_TEST_CASE (test_mix)
| BOOST_AUTO_TEST_CASE (test_var)
| BOOST_AUTO_TEST_CASE (test_copy)
| BOOST_AUTO_TEST_SUITE_END ()

## Function Documentation

BOOST_AUTO_TEST_CASE | ( | test_copy |  | ) |

Definition at line 90 of file test_node.cpp.

References node::evaluate().

    00091 {
    00092   node n(node(node(1), '+', node(2)));
    00093   {
    00094     node m(n);
    00095     n = node('-', m);
    00096     BOOST_CHECK_EQUAL(3.0, m.evaluate());
    00097   }
    00098   BOOST_CHECK_EQUAL(-3.0, n.evaluate());
    00099 }

BOOST_AUTO_TEST_CASE | ( | test_var |  | ) |

Definition at line 83 of file test_node.cpp.

References node::evaluate(), and get_variable().

    00084 {
    00085   node n(node(node("half"), node(node(1), '/', node(2))));
    00086   BOOST_CHECK_EQUAL(0.5, n.evaluate());
    00087   BOOST_CHECK_EQUAL(0.5, get_variable("half"));
    00088 }

BOOST_AUTO_TEST_CASE | ( | test_mix |  | ) |

Definition at line 56 of file test_node.cpp.

References node::evaluate().

    00057 {
    00058   node a(node(1.5), '*', node(2.0));
    00059   BOOST_CHECK_EQUAL(3.0, a.evaluate());
    00060
    00061   node b(node(3.0), '/', node(1.5));
    00062   BOOST_CHECK_EQUAL(2.0, b.evaluate());
    00063
    00064   node c(a, '+', b);
    00065   BOOST_CHECK_EQUAL(5.0, c.evaluate());
    00066
    00067   node d(node(10), '-', node(3));
    00068   BOOST_CHECK_EQUAL(7.0, d.evaluate());
    00069
    00070   node e('-', node(1.0));
    00071   BOOST_CHECK_EQUAL(-1.0, e.evaluate());
    00072
    00073   node f(node(2), '*', e);
    00074   BOOST_CHECK_EQUAL(-2.0, f.evaluate());
    00075
    00076   node g(d, '+', f);
    00077   BOOST_CHECK_EQUAL(5.0, g.evaluate());
    00078
    00079   node h(c, '-', g);
    00080   BOOST_CHECK_EQUAL(0.0, h.evaluate());
    00081 }

BOOST_AUTO_TEST_CASE | ( | test_divide |  | ) |

Definition at line 49 of file test_node.cpp.

    00050 {
    00051   node a(1.0), b(2.0), c(6.0);
    00052   BOOST_CHECK_EQUAL(0.5, node(a, '/', b).evaluate());
    00053   BOOST_CHECK_EQUAL(3.0, node(node(c, '/', a), '/', b).evaluate());
    00054 }

BOOST_AUTO_TEST_CASE | ( | test_multiply |  | ) |

Definition at line 42 of file test_node.cpp.

    00043 {
    00044   node a(1.0), b(2.0), c(3.0);
    00045   BOOST_CHECK_EQUAL(3.0, node(a, '*', c).evaluate());
    00046   BOOST_CHECK_EQUAL(6.0, node(node(a, '*', b), '*', c).evaluate());
    00047 }

BOOST_AUTO_TEST_CASE | ( | test_subtract |  | ) |

Definition at line 35 of file test_node.cpp.

    00036 {
    00037   node a(1.0), b(2.0), c(3.0);
    00038   BOOST_CHECK_EQUAL(1.0, node(c, '-', b).evaluate());
    00039   BOOST_CHECK_EQUAL(-4.0, node(node(a, '-', b), '-', c).evaluate());
    00040 }

BOOST_AUTO_TEST_CASE | ( | test_add |  | ) |

Definition at line 28 of file test_node.cpp.

    00029 {
    00030   node a(1.0), b(2.0), c(3.0);
    00031   BOOST_CHECK_EQUAL(3.0, node(a, '+', b).evaluate());
    00032   BOOST_CHECK_EQUAL(6.0, node(node(a, '+', b), '+', c).evaluate());
    00033 }

BOOST_AUTO_TEST_CASE | ( | test_negate |  | ) |

Definition at line 21 of file test_node.cpp.

References node::evaluate().

    00022 {
    00023   node n(1.0);
    00024   node neg('-', n);
    00025   BOOST_CHECK_EQUAL(-1.0, neg.evaluate());
    00026 }

BOOST_AUTO_TEST_CASE | ( | test_basics |  | ) |

Definition at line 12 of file test_node.cpp.

References node::evaluate(), and node::to_string().

    00013 {
    00014   node n(1.0);
    00015   BOOST_CHECK_EQUAL(1.0, n.evaluate());
    00016   BOOST_CHECK_EQUAL("1", n.to_string());
    00017   node s("ident");
    00018   BOOST_CHECK_EQUAL("ident", s.to_string());
    00019 }

BOOST_AUTO_TEST_SUITE_END | ( |  | ) |