Files
AVA2/tests/skill_poly_test.cpp

20 lines
923 B
C++

#include "Poly.h"
#include <cmath>
#include <iostream>
#include <stdexcept>
void check(const char* expression,float expected) {
CPoly p;p.SetStr(expression);if(!p.Analyze())throw std::runtime_error("analyze");p.SetVar("k",0.5);p.SetVar("str",20);
if(std::fabs(p.Eval()-expected)>0.0001)throw std::runtime_error(expression);
}
int main() {
try {
check("40+100*k",90);check("(100+str)*k",60);
check("2+3*4",14);check("(2+3)*4",20);
check("min(8,3)+max(2,9)",12);check("floor(2.9)",2);
CPoly p;p.SetRandom(CPoly::RANDOM_TYPE_FORCE_MIN);p.SetStr("number(3,9)");if(!p.Analyze())throw std::runtime_error("random analyze");
if(p.Eval()!=3)throw std::runtime_error("forced minimum");
p.SetRandom(CPoly::RANDOM_TYPE_FORCE_MAX);
if(p.Eval()!=9)throw std::runtime_error("forced maximum");
} catch(const std::exception& e) {std::cerr<<e.what()<<'\n';return 1;}
}