Counter expressions (#3534)

* Add peglib

* - Add expression engine
- Take an expression when setting a counter

* Shift + Click = Middleclick for counters

* minor cleanup for clangify

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>

* Added tip entry
This commit is contained in:
Rob Blanckaert 2019-02-02 10:56:49 -08:00 committed by Zach H
parent 6e1b0a7590
commit c9c0fb28ee
13 changed files with 3508 additions and 26 deletions

View file

@ -1,9 +1,11 @@
enable_testing()
add_test(NAME dummy_test COMMAND dummy_test)
add_test(NAME expression_test COMMAND expression_test)
# Find GTest
add_executable(dummy_test dummy_test.cpp)
add_executable(expression_test expression_test.cpp)
find_package(GTest)
@ -32,10 +34,16 @@ if(NOT GTEST_FOUND)
SET(GTEST_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/gtest-src/include")
SET(GTEST_BOTH_LIBRARIES gtest)
add_dependencies(dummy_test gtest)
add_dependencies(expression_test gtest)
endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(TEST_QT_MODULES Qt5::Widgets)
include_directories(${GTEST_INCLUDE_DIRS})
target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES})
target_link_libraries(expression_test cockatrice_common ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
add_subdirectory(carddatabase)
add_subdirectory(loading_from_clipboard)

30
tests/expression_test.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "gtest/gtest.h"
#include "../common/expression.h"
#include <cmath>
#define TEST_EXPR(name,a,b) TEST(name, Works) { \
Expression exp(8); \
ASSERT_EQ(exp.parse(a), b) << a; \
}
namespace
{
TEST_EXPR(Number, "1", 1)
TEST_EXPR(Multiply, "2*2", 4)
TEST_EXPR(Whitespace, "3 * 3", 9)
TEST_EXPR(Powers, "2^8", 256)
TEST_EXPR(OrderOfOperations, "2+2*2", 6)
TEST_EXPR(Fn, "2*cos(1)", 2*cos(1))
TEST_EXPR(Variable, "x / 2", 4)
TEST_EXPR(Negative, "-2 * 2", -4)
TEST_EXPR(UnknownFnReturnsZero, "blah(22)", 0)
} // namespace
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}