Skip to content

Commit

Permalink
Add test for mathimatical expression operator order
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Mar 1, 2024
1 parent ecceb9c commit 5332c0d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BasedOnStyle: LLVM
IndentWidth: 4
AccessModifierOffset: -4
AlwaysBreakTemplateDeclarations: true
PointerAlignment: Left
ColumnLimit: 120
1 change: 1 addition & 0 deletions libskrypt/tests/TestExpBracketless.skrypt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(x+4)^2-x^2=24
34 changes: 34 additions & 0 deletions libskrypt/tests/TestExpOrder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#define BOOST_TEST_MODULE skryptExpOrder test
#include <boost/test/unit_test.hpp>
#include "skrypt.h"

using namespace ::skrypt;
using namespace std::string_literals;
using namespace std::string_view_literals;

BOOST_AUTO_TEST_CASE(skryptExpOrdertest){
Skrypt skryptWithBrackets;
skryptWithBrackets.Load(TEST_SRC_DIR "TestExpOrderWithBrackets.skrypt");

// get the variable
auto variableName = "x"s;
auto varhost = skryptWithBrackets.GetVarHost();
auto& v = varhost->Host(variableName);

// check that the variable is already solved
auto solutions = skryptWithBrackets.Known(v);
BOOST_TEST(solutions.size() == 1);
for (auto& solution : solutions) {
BOOST_TEST(solution == 1);
}


Skrypt skryptWithExpNoBrackets;
skryptWithExpNoBrackets.Load(TEST_SRC_DIR "TestExpBracketless.skrypt");
auto solutionsWithExpNoBrackets = skryptWithExpNoBrackets.Known(skryptWithExpNoBrackets.GetVarHost()->Host(variableName));
BOOST_TEST(solutionsWithExpNoBrackets.size() == 1);
for (auto& solution : solutionsWithExpNoBrackets) {
BOOST_TEST(solution == 1);
}
BOOST_TEST(solutionsWithExpNoBrackets == solutions);
}
1 change: 1 addition & 0 deletions libskrypt/tests/TestExpOrderWithBrackets.skrypt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(x+4)^2-(x^2)=24

0 comments on commit 5332c0d

Please sign in to comment.