加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tests.cpp 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
ljy 提交于 2023-11-18 22:46 . init commit
#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();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化