2018-02-12 18:48:00 +08:00
|
|
|
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
|
2017-08-09 13:21:12 +08:00
|
|
|
|
2017-12-26 11:08:29 +08:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
2017-08-09 13:21:12 +08:00
|
|
|
|
2017-12-26 11:08:29 +08:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2017-08-09 13:21:12 +08:00
|
|
|
|
2017-12-26 11:08:29 +08:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License. */
|
2017-08-09 13:21:12 +08:00
|
|
|
|
2022-01-25 08:44:31 +08:00
|
|
|
#include "paddle/utils/string/to_string.h"
|
2022-06-05 11:11:31 +08:00
|
|
|
|
2017-08-09 13:21:12 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2023-08-07 16:27:41 +08:00
|
|
|
constexpr char kOutputString[] = "User Defined Output"; // NOLINT
|
2017-08-09 13:21:12 +08:00
|
|
|
class UserDefinedClass {
|
2018-02-11 13:15:40 +08:00
|
|
|
public:
|
2017-08-09 13:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& s, const UserDefinedClass& ins) {
|
2017-08-09 14:29:24 +08:00
|
|
|
s << kOutputString;
|
2017-08-09 13:21:12 +08:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(to_string, normal) {
|
2018-04-05 09:00:59 -07:00
|
|
|
using paddle::string::to_string;
|
2017-08-09 14:14:47 +08:00
|
|
|
ASSERT_EQ("10", to_string(10));
|
2017-08-09 13:21:12 +08:00
|
|
|
ASSERT_EQ("abc", to_string("abc"));
|
2017-08-09 14:14:47 +08:00
|
|
|
ASSERT_EQ("1.2", to_string(1.2));
|
2017-08-09 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(to_string, user_defined) {
|
|
|
|
|
UserDefinedClass instance;
|
2018-04-05 09:00:59 -07:00
|
|
|
ASSERT_EQ(kOutputString, paddle::string::to_string(instance));
|
2017-10-04 14:01:34 -07:00
|
|
|
}
|