Calculator Step 3

- Main Page
- Classes
- Files

- File List
- File Members

Functions
test_node.cpp File Reference
`#include <iostream>`
`#include <istream>`
`#include <ostream>`
`#include <sstream>`
`#include <string>`
`#include <boost/test/unit_test.hpp>`
`#include "node.hpp"`
`#include "variables.hpp"`

Go to the source code of this file.

## Functions
| BOOST_AUTO_TEST_SUITE (node_test)
| 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_basics |  | ) |

Definition at line 14 of file test_node.cpp.

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

15 {
16 node n(1.0);
17 BOOST_CHECK_EQUAL(1.0, n.evaluate());
18 BOOST_CHECK_EQUAL("1", n.to_string());
19 node s("ident");
20 BOOST_CHECK_EQUAL("ident", s.to_string());
21 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_negate |  | ) |

Definition at line 23 of file test_node.cpp.

References node::evaluate().

24 {
25 node n(1.0);
26 node neg('-', n);
27 BOOST_CHECK_EQUAL(-1.0, neg.evaluate());
28 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_add |  | ) |

Definition at line 30 of file test_node.cpp.

31 {
32 node a(1.0), b(2.0), c(3.0);
33 BOOST_CHECK_EQUAL(3.0, node(a, '+', b).evaluate());
34 BOOST_CHECK_EQUAL(6.0, node(node(a, '+', b), '+', c).evaluate());
35 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_subtract |  | ) |

Definition at line 37 of file test_node.cpp.

38 {
39 node a(1.0), b(2.0), c(3.0);
40 BOOST_CHECK_EQUAL(1.0, node(c, '-', b).evaluate());
41 BOOST_CHECK_EQUAL(-4.0, node(node(a, '-', b), '-', c).evaluate());
42 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_multiply |  | ) |

Definition at line 44 of file test_node.cpp.

45 {
46 node a(1.0), b(2.0), c(3.0);
47 BOOST_CHECK_EQUAL(3.0, node(a, '*', c).evaluate());
48 BOOST_CHECK_EQUAL(6.0, node(node(a, '*', b), '*', c).evaluate());
49 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_divide |  | ) |

Definition at line 51 of file test_node.cpp.

52 {
53 node a(1.0), b(2.0), c(6.0);
54 BOOST_CHECK_EQUAL(0.5, node(a, '/', b).evaluate());
55 BOOST_CHECK_EQUAL(3.0, node(node(c, '/', a), '/', b).evaluate());
56 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_mix |  | ) |

Definition at line 58 of file test_node.cpp.

References node::evaluate().

59 {
60 node a(node(1.5), '*', node(2.0));
61 BOOST_CHECK_EQUAL(3.0, a.evaluate());
62
63 node b(node(3.0), '/', node(1.5));
64 BOOST_CHECK_EQUAL(2.0, b.evaluate());
65
66 node c(a, '+', b);
67 BOOST_CHECK_EQUAL(5.0, c.evaluate());
68
69 node d(node(10), '-', node(3));
70 BOOST_CHECK_EQUAL(7.0, d.evaluate());
71
72 node e('-', node(1.0));
73 BOOST_CHECK_EQUAL(-1.0, e.evaluate());
74
75 node f(node(2), '*', e);
76 BOOST_CHECK_EQUAL(-2.0, f.evaluate());
77
78 node g(d, '+', f);
79 BOOST_CHECK_EQUAL(5.0, g.evaluate());
80
81 node h(c, '-', g);
82 BOOST_CHECK_EQUAL(0.0, h.evaluate());
83 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_CASE | ( | test_var |  | ) |

Definition at line 85 of file test_node.cpp.

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

86 {
87 node n(node(node("half"), node(node(1), '/', node(2))));
88 BOOST_CHECK_EQUAL(0.5, n.evaluate());
89 BOOST_CHECK_EQUAL(0.5, get_variable("half"));
90 }
node
Definition: node.hpp:16
get_variable
double get_variable(std::string const &name)
Definition: variables.cpp:18

BOOST_AUTO_TEST_CASE | ( | test_copy |  | ) |

Definition at line 92 of file test_node.cpp.

References node::evaluate().

93 {
94 node n(node(node(1), '+', node(2)));
95 {
96 node m(n);
97 n = node('-', m);
98 BOOST_CHECK_EQUAL(3.0, m.evaluate());
99 }
100 BOOST_CHECK_EQUAL(-3.0, n.evaluate());
101 }
node
Definition: node.hpp:16

BOOST_AUTO_TEST_SUITE | ( | node_test |  | ) |

BOOST_AUTO_TEST_SUITE_END | ( |  | ) |