test_parse.cpp File Reference

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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (test_number)
 BOOST_AUTO_TEST_CASE (test_negative)
 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_error1)
 BOOST_AUTO_TEST_CASE (test_error2)
 BOOST_AUTO_TEST_CASE (test_error3)
 BOOST_AUTO_TEST_CASE (test_error4)
 BOOST_AUTO_TEST_SUITE_END ()


Function Documentation

BOOST_AUTO_TEST_CASE ( test_error4   ) 

Definition at line 91 of file test_parse.cpp.

References parse_loop().

00092 {
00093   std::istringstream in("(1 + 2");
00094   std::ostringstream out;
00095   parse_loop(in, out);
00096   BOOST_CHECK_EQUAL("> syntax error: EOF when expecting ')'\n> ", out.str());
00097 }

BOOST_AUTO_TEST_CASE ( test_error3   ) 

Definition at line 83 of file test_parse.cpp.

References parse_loop().

00084 {
00085   std::istringstream in("1 @ 2");
00086   std::ostringstream out;
00087   parse_loop(in, out);
00088   BOOST_CHECK_EQUAL("> 1\nsyntax error: expected digit, got '@'\n> ", out.str());
00089 }

BOOST_AUTO_TEST_CASE ( test_error2   ) 

Definition at line 75 of file test_parse.cpp.

References parse_loop().

00076 {
00077   std::istringstream in("1..2");
00078   std::ostringstream out;
00079   parse_loop(in, out);
00080   BOOST_CHECK_EQUAL("> syntax error: expected digit after decimal point, got '.'\n> ", out.str());
00081 }

BOOST_AUTO_TEST_CASE ( test_error1   ) 

Definition at line 67 of file test_parse.cpp.

References parse_loop().

00068 {
00069   std::istringstream in("1+++2");
00070   std::ostringstream out;
00071   parse_loop(in, out);
00072   BOOST_CHECK_EQUAL("> syntax error: expected digit, got '+'\n> ", out.str());
00073 }

BOOST_AUTO_TEST_CASE ( test_mix   ) 

Definition at line 59 of file test_parse.cpp.

References parse_loop().

00060 {
00061   std::istringstream in(" 1.5 * 2 + 3 / 1.5 - (10 - 3) + 2 * -1");
00062   std::ostringstream out;
00063   parse_loop(in, out);
00064   BOOST_CHECK_EQUAL("> -4\n> ", out.str());
00065 }

BOOST_AUTO_TEST_CASE ( test_divide   ) 

Definition at line 51 of file test_parse.cpp.

References parse_loop().

00052 {
00053   std::istringstream in("1 / 2\n10 / 2 / 2");
00054   std::ostringstream out;
00055   parse_loop(in, out);
00056   BOOST_CHECK_EQUAL("> 0.5\n> 2.5\n> ", out.str());
00057 }

BOOST_AUTO_TEST_CASE ( test_multiply   ) 

Definition at line 43 of file test_parse.cpp.

References parse_loop().

00044 {
00045   std::istringstream in("1 * 2\n5 * 2 * 1.5");
00046   std::ostringstream out;
00047   parse_loop(in, out);
00048   BOOST_CHECK_EQUAL("> 2\n> 15\n> ", out.str());
00049 }

BOOST_AUTO_TEST_CASE ( test_subtract   ) 

Definition at line 35 of file test_parse.cpp.

References parse_loop().

00036 {
00037   std::istringstream in("1 - 2\n5 - 1 - 2");
00038   std::ostringstream out;
00039   parse_loop(in, out);
00040   BOOST_CHECK_EQUAL("> -1\n> 2\n> ", out.str());
00041 }

BOOST_AUTO_TEST_CASE ( test_add   ) 

Definition at line 27 of file test_parse.cpp.

References parse_loop().

00028 {
00029   std::istringstream in("1 + 2\n1 + 2 + 3");
00030   std::ostringstream out;
00031   parse_loop(in, out);
00032   BOOST_CHECK_EQUAL("> 3\n> 6\n> ", out.str());
00033 }

BOOST_AUTO_TEST_CASE ( test_negative   ) 

Definition at line 19 of file test_parse.cpp.

References parse_loop().

00020 {
00021   std::istringstream in("-1\n-3.14159\n-1.23e-45\n-34.56e-7\n");
00022   std::ostringstream out;
00023   parse_loop(in, out);
00024   BOOST_CHECK_EQUAL("> -1\n> -3.14159\n> -1.23e-45\n> -3.456e-06\n> ", out.str());
00025 }

BOOST_AUTO_TEST_CASE ( test_number   ) 

Definition at line 11 of file test_parse.cpp.

References parse_loop().

00012 {
00013   std::istringstream in("1\n3.14159\n1.23e45\n45.67e+8\n");
00014   std::ostringstream out;
00015   parse_loop(in, out);
00016   BOOST_CHECK_EQUAL("> 1\n> 3.14159\n> 1.23e+45\n> 4.567e+09\n> ", out.str());
00017 }

BOOST_AUTO_TEST_SUITE_END (  ) 


Generated on Sun Nov 30 10:04:19 2008 for Calculator by  doxygen 1.5.3