提交 858e9032 编写于 作者: M minqiyang

Add unittest for operator

test=develop
上级 6a5f6046
...@@ -70,7 +70,7 @@ inline std::string GradVarName(const std::string& var_name) { ...@@ -70,7 +70,7 @@ inline std::string GradVarName(const std::string& var_name) {
} }
inline std::string OriginVarName(const std::string& grad_var_name) { inline std::string OriginVarName(const std::string& grad_var_name) {
std::size_t pos = grad_var_name.find_last_of(kGradVarSuffix); std::size_t pos = grad_var_name.rfind(kGradVarSuffix);
if (pos == std::string::npos) { if (pos == std::string::npos) {
return grad_var_name; return grad_var_name;
} else { } else {
......
...@@ -289,11 +289,29 @@ TEST(OpKernel, multi_inputs) { ...@@ -289,11 +289,29 @@ TEST(OpKernel, multi_inputs) {
op->Run(scope, cpu_place); op->Run(scope, cpu_place);
} }
TEST(Functions, all) { TEST(VarNameTest, all) {
std::string var_name("X"); std::string var_name("X");
std::string grad_var_name = paddle::framework::GradVarName(var_name); std::string grad_var_name = paddle::framework::GradVarName(var_name);
ASSERT_EQ(grad_var_name.c_str(), "X@GRAD"); ASSERT_EQ(grad_var_name, "X@GRAD");
std::string original_var_name = std::string original_var_name =
paddle::framework::OriginVarName(grad_var_name); paddle::framework::OriginVarName(grad_var_name);
ASSERT_EQ(original_var_name.c_str(), "X"); ASSERT_EQ(original_var_name, "X");
original_var_name = paddle::framework::OriginVarName(original_var_name);
ASSERT_EQ(original_var_name, "X");
std::string var_name_2("XYZ");
grad_var_name = paddle::framework::GradVarName(var_name_2);
ASSERT_EQ(grad_var_name, "XYZ@GRAD");
original_var_name = paddle::framework::OriginVarName(grad_var_name);
ASSERT_EQ(original_var_name, "XYZ");
original_var_name = paddle::framework::OriginVarName(original_var_name);
ASSERT_EQ(original_var_name, "XYZ");
std::string var_name_3("");
grad_var_name = paddle::framework::GradVarName(var_name_3);
ASSERT_EQ(grad_var_name, "@GRAD");
original_var_name = paddle::framework::OriginVarName(grad_var_name);
ASSERT_EQ(original_var_name, "");
original_var_name = paddle::framework::OriginVarName(original_var_name);
ASSERT_EQ(original_var_name, "");
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册