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_var)
 BOOST_AUTO_TEST_CASE (test_predefined_vars)
 BOOST_AUTO_TEST_CASE (test_function)
 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_CASE (test_error5)
 BOOST_AUTO_TEST_CASE (test_error6)
 BOOST_AUTO_TEST_CASE (test_error7)
 BOOST_AUTO_TEST_SUITE_END ()


Function Documentation

BOOST_AUTO_TEST_CASE ( test_error7   ) 

Definition at line 139 of file test_parse.cpp.

References parse_loop().

00140 {
00141   std::istringstream in("def times(a, b) = a * b\ndivide(2, 3)");
00142   std::ostringstream out;
00143   parse_loop(in, out);
00144   BOOST_CHECK_EQUAL("> > unknown function: divide\n> ", out.str());
00145 }

BOOST_AUTO_TEST_CASE ( test_error6   ) 

Definition at line 131 of file test_parse.cpp.

References parse_loop().

00132 {
00133   std::istringstream in("def times(a, b) = a * b\ntimes(2)");
00134   std::ostringstream out;
00135   parse_loop(in, out);
00136   BOOST_CHECK_EQUAL("> > wrong number of arguments in call to times(), expected 2, got 1\n> ", out.str());
00137 }

BOOST_AUTO_TEST_CASE ( test_error5   ) 

Definition at line 123 of file test_parse.cpp.

References parse_loop().

00124 {
00125   std::istringstream in("pi(2)");
00126   std::ostringstream out;
00127   parse_loop(in, out);
00128   BOOST_CHECK_EQUAL("> wrong number of arguments in call to pi(), expected 0, got 1\n> ", out.str());
00129 }

BOOST_AUTO_TEST_CASE ( test_error4   ) 

Definition at line 115 of file test_parse.cpp.

References parse_loop().

00116 {
00117   std::istringstream in("(1 + 2");
00118   std::ostringstream out;
00119   parse_loop(in, out);
00120   BOOST_CHECK_EQUAL("> syntax error: expected ')', got end of line\n> ", out.str());
00121 }

BOOST_AUTO_TEST_CASE ( test_error3   ) 

Definition at line 107 of file test_parse.cpp.

References parse_loop().

00108 {
00109   std::istringstream in("1 @ 2");
00110   std::ostringstream out;
00111   parse_loop(in, out);
00112   BOOST_CHECK_EQUAL("> syntax error: expected digit, got '@'\n> ", out.str());
00113 }

BOOST_AUTO_TEST_CASE ( test_error2   ) 

Definition at line 99 of file test_parse.cpp.

References parse_loop().

00100 {
00101   std::istringstream in("1..2");
00102   std::ostringstream out;
00103   parse_loop(in, out);
00104   BOOST_CHECK_EQUAL("> syntax error: expected digit after decimal point, got '.'\n> ", out.str());
00105 }

BOOST_AUTO_TEST_CASE ( test_error1   ) 

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: expected a primary, got +\n> ", out.str());
00097 }

BOOST_AUTO_TEST_CASE ( test_function   ) 

Definition at line 83 of file test_parse.cpp.

References parse_loop().

00084 {
00085   std::istringstream in("def times(a, b) = a * b\ntimes(2, 3)\n");
00086   std::ostringstream out;
00087   parse_loop(in, out);
00088   BOOST_CHECK_EQUAL("> > 6\n> ", out.str());
00089 }

BOOST_AUTO_TEST_CASE ( test_predefined_vars   ) 

Definition at line 75 of file test_parse.cpp.

References parse_loop().

00076 {
00077   std::istringstream in(" pi - e");
00078   std::ostringstream out;
00079   parse_loop(in, out);
00080   BOOST_CHECK_EQUAL("> 0.423311\n> ", out.str());
00081 }

BOOST_AUTO_TEST_CASE ( test_var   ) 

Definition at line 67 of file test_parse.cpp.

References parse_loop().

00068 {
00069   std::istringstream in(" def half = 1.0 / 2\ndef one=1.0\n one + half");
00070   std::ostringstream out;
00071   parse_loop(in, out);
00072   BOOST_CHECK_EQUAL("> > > 1.5\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.0 / 2\n10.0 / 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:06:52 2008 for Calculator by  doxygen 1.5.3