代码拉取完成,页面将自动刷新
#include <calculator.h>
#include <gtest/gtest.h>
#include <string>
TEST(caculator, interter) {
Value *value = my_calculator("1");
ASSERT_EQ(value->ingeger, 1);
value = my_calculator("-1");
ASSERT_EQ(value->ingeger, -1);
value = my_calculator("1-10");
ASSERT_EQ(value->ingeger, -9);
value = my_calculator("1-10*10");
ASSERT_EQ(value->ingeger, -99);
value = my_calculator("(1+2)*10*11+1");
ASSERT_EQ(value->ingeger, 331);
value = my_calculator("100/10");
ASSERT_EQ(value->ingeger, 10);
value = my_calculator("(1-2)-100/10");
ASSERT_EQ(value->ingeger, -11);
value = my_calculator("abs((1-2)-100/10)");
ASSERT_EQ(value->ingeger, 11);
value = my_calculator("abs((1-2)-100/10) + -abs(1 + abs(-11))");
ASSERT_EQ(value->ingeger, -1);
value = my_calculator(
"max(abs((1-2)-100/10) + -abs(1 + abs(-11)), -100) + 10086");
ASSERT_EQ(value->ingeger, 10085);
}
TEST(caculator, double) {
Value *value = my_calculator("1.1");
ASSERT_EQ(value->number, 1.1);
value = my_calculator("-1.333");
ASSERT_TRUE(-1.4 < value->number && value->number < -1.30);
value = my_calculator("10086-10.1");
ASSERT_EQ(std::to_string(value->number), std::string("10075.900000"));
value = my_calculator("1.234-10*10");
ASSERT_EQ(std::to_string(value->number), std::string("-98.766000"));
value = my_calculator("(1.2+2)*10*11+10000");
ASSERT_EQ(std::to_string(value->number), std::string("10352.000000"));
value = my_calculator("3.14/10");
ASSERT_EQ(std::to_string(value->number), std::string("0.314000"));
value = my_calculator("(1-2)-100/10.1");
ASSERT_EQ(std::to_string(value->number), std::string("-10.900990"));
value = my_calculator("abs((1-2.1)-100/10)");
ASSERT_EQ(std::to_string(value->number), std::string("11.100000"));
value = my_calculator("-abs (max(100, -100.1))");
ASSERT_EQ(std::to_string(value->number), std::string("-100.000000"));
}
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。