Commit Graph

8 Commits

Author SHA1 Message Date
Arkaprabha Chakraborty
cb2a43df69 Add AST Node Unit Tests and Refactor Expression Evaluation
Commit details:
- Add unit tests for AST nodes, including Constant, Identifier, UnaryPlus, UnaryMinus, Add, Subtract, Multiply, Divide, and Power.
- Include test cases for evaluating expressions with various node types and operations.
- Introduce a test harness to ensure that each node's `evaluate` method produces the expected results.
- Update the `main` function to use the new `runTests` function when the `--run-tests` option is provided.
- Refactor the existing test function (`runTest`) into individual test functions for better organization and readability.
- Improve the help message to reflect the correct option name (`--run-tests`).
2024-01-22 09:29:50 +05:30
Arkaprabha Chakraborty
0da96101a0 Update README.md with Dependencies and Running Tests section
Commit details:
- Added a 'Dependencies' section listing GNU Make and Clang.
- Introduced a 'Running Tests' section with a test expression and corresponding C++ code.
- Demonstrated a complex expression and its expected result.
2024-01-22 07:14:34 +05:30
Arkaprabha Chakraborty
08c5f9712a Update Makefile for build improvements and testing
Commit details:
- Set optimization level to O3 and include pedantic warnings in CXXFLAGS.
- Introduce separate build and source directories for better project organization.
- Add a target to run tests with the ENABLE_TESTS macro.
- Improve the 'all' target to create the build directory before building the executable.
- Introduce a 'rebuild' target for cleaning and rebuilding the project.

Changes made in Makefile:
- Update CXXFLAGS with -O3 and -pedantic.
- Introduce BUILD_DIR and SRC_DIR variables for better organization.
- Modifie SOURCE to point to the source file within the source directory.
- Update EXECUTABLE to exclude the file extension.
- Update 'all' target to create the build directory.
- Add 'test' target to run tests with the ENABLE_TESTS macro.
- Add 'rebuild' target for cleaning and rebuilding the project.
2024-01-22 07:11:49 +05:30
Arkaprabha Chakraborty
dee7372ae4 Add build directory to .gitignore
Changes made in .gitignore:
- Add 'build/' to exclude generated build files.
2024-01-22 07:09:30 +05:30
Arkaprabha Chakraborty
69bc5b4aa1 Create ast.cxx for AST implementation and tests
Commit details:
- Add new file ast.cxx with ASTNode, Identifier, Divide, Multiply, Subtract, Power classes.
- Include necessary headers and static initialization of variableTable in Identifier class.
- Add a test function runTest() for evaluating a complex expression.
- Add printHelpMessage() function for displaying program usage.
- Update main function to handle "--run-test" argument.
2024-01-22 07:07:30 +05:30
Arkaprabha Chakraborty
7b5eb1e26d Rename main.cxx to ast.hxx
Commit details:
- Rename main.cxx to src/ast.hxx to better reflect its content.
- Update include statements in the renamed file.
- Remove unnecessary include <cstring> statement from ast.hxx.
- Remove redundant implementation of Power::evaluate() in ast.hxx.
2024-01-22 07:06:48 +05:30
Arkaprabha Chakraborty
6c313ae3dd Refactor AST Node Hierarchy and Enable Test Execution
Commit details:
- Refactor the Abstract Syntax Tree (AST) node hierarchy in `main.cxx` for improved memory management and ownership semantics.
- Introduce smart pointers (`std::unique_ptr`) for managing ownership of AST nodes, eliminating manual memory management.
- Add getter functions to access operands in Unary and Binary nodes.
- Implemente functions to release ownership of operands in Unary and Binary nodes.
- Replace manual deletion of operands in the destructor with default virtual destructors for Unary and Binary nodes.
- Add a conditional compilation block (`#ifdef ENABLE_TESTS`) to enable testing functionality.
- Create a test expression in the `runTest` function to evaluate a complex mathematical expression.
- Enable test execution using the `--run-test` command-line option.
- Provide a help message for the main program, outlining available options.
2024-01-22 07:00:48 +05:30
Arkaprabha Chakraborty
49617b7822 Initial commit 2024-01-20 07:34:29 +05:30