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
http://www.apache.org/licenses/LICENSE-2.0
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.
==============================================================================*/
#include <gtest/gtest.h>
#include "utils/common.h"
TEST(TestVectorToString, Basic)
{
std::vector<int> vec = {1, 2, 3};
EXPECT_EQ(MxRec::VectorToString(vec), "[1, 2, 3]");
}
TEST(TestMapToString, Basic)
{
std::map<int, int> map = {{1, 2}, {3, 4}};
EXPECT_EQ(MxRec::MapToString(map), "{1: 2, 3: 4}");
}
TEST(TestMapToString, AbseilFlatHashMap)
{
absl::flat_hash_map<int, int> map = {{1, 2}, {3, 4}};
std::string result = MxRec::MapToString(map);
EXPECT_TRUE(result.find("1: 2") != std::string::npos);
EXPECT_TRUE(result.find("3: 4") != std::string::npos);
}
TEST(TestVec2TensorI32, Basic)
{
std::vector<int> vec = {1, 2, 3};
tensorflow::Tensor tensor = MxRec::Vec2TensorI32(vec);
auto tensor_data = tensor.flat<tensorflow::int32>();
for (int i = 0; i < vec.size(); ++i) {
EXPECT_EQ(tensor_data(i), vec[i]);
}
}
TEST(TestVec2TensorI64, Basic) {
std::vector<int64_t> vec = {1, 2, 3};
tensorflow::Tensor tensor = MxRec::Vec2TensorI64(vec);
auto tensor_data = tensor.flat<tensorflow::int64>();
for (int i = 0; i < vec.size(); ++i) {
EXPECT_EQ(tensor_data(i), vec[i]);
}
}
TEST(TestGetUBSize, InvalidDeviceID)
{
EXPECT_THROW(MxRec::GetUBSize(999), std::runtime_error);
}
TEST(TestBatch, SizeAndUnParse)
{
MxRec::Batch<int> batch;
batch.sample = {1, 2, 3};
EXPECT_EQ(batch.Size(), 3);
EXPECT_EQ(batch.UnParse(), "1 2 3 ");
}
TEST(TestRankInfo, DefaultConstructor)
{
MxRec::RankInfo rankInfo;
}
TEST(TestThresholdValue, DefaultConstructor)
{
MxRec::ThresholdValue thresholdValue;
}
TEST(TestFeatureItemInfo, Constructors)
{
MxRec::FeatureItemInfo featureItemInfo1;
MxRec::FeatureItemInfo featureItemInfo2(123, 456);
}
TEST(TestAdmitAndEvictData, DefaultConstructor)
{
MxRec::AdmitAndEvictData admitAndEvictData;
}
TEST(TestEmbInfo, DefaultConstructor)
{
MxRec::EmbInfo embInfo;
}
TEST(TestHostEmbTable, DefaultConstructor)
{
MxRec::HostEmbTable hostEmbTable;
}
TEST(TestAll2AllInfo, DefaultConstructor)
{
MxRec::All2AllInfo all2AllInfo;
}
TEST(TestUniqueInfo, DefaultConstructor)
{
MxRec::UniqueInfo uniqueInfo;
}
TEST(TestKeySendInfo, DefaultConstructor)
{
MxRec::KeySendInfo keySendInfo;
}
TEST(TestCkptTransData, DefaultConstructor)
{
MxRec::CkptTransData ckptTransData;
}
TEST(TestCTRLog, DifferentLevel)
{
int invilid = -1;
MxRec::CTRLog(MxRec::CTRLogLevel::DEBUG, "test message");
MxRec::CTRLog(MxRec::CTRLogLevel::INFO, "test message");
MxRec::CTRLog(MxRec::CTRLogLevel::WARN, "test message");
MxRec::CTRLog(MxRec::CTRLogLevel::ERROR, "test message");
EXPECT_NO_THROW(MxRec::CTRLog(invilid, "test message"));
}