Click here to Skip to main content
15,886,258 members
Articles / Programming Languages / C#

An extensible math expression parser with plug-ins

Rate me:
Please Sign up or sign in to vote.
4.92/5 (147 votes)
13 Mar 2008CPOL51 min read 1.4M   29K   364  
Design and code for an extensible, maintainable, robust, and easy to use math parser.
#ifndef _TESTCASES_INCLUDED
#define _TESTCASES_INCLUDED

#include "MTParser.h"

// A set of test expressions to do
// regression testing when modifying the code
class MTTestCases
{
public:

	// launch the test
	// return true if all tests passed
	bool test();

private:

	struct TESTCASE
	{
		MTSTRING expr;
		MTDOUBLE expectedResult;
		bool valid;
	};

	std::vector<TESTCASE> m_testCases;

	// add a test case to the test suite
	void addTest(MTSTRING expr, MTDOUBLE result, bool valid);

	// run all registered tests
	bool runTest();

	// helper function: convert a long value to a string value
	MTSTRING longToS(long val);

};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
Software Engineer working at a fun and smart startup company

Comments and Discussions