!35645 [MD] Adding docstrings for minddata UT Cpp Part 2

Merge pull request !35645 from davidanugraha/add_cpp_test_comment_part2
This commit is contained in:
i-robot 2022-06-14 14:37:51 +00:00 committed by Gitee
commit f6f872e600
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
86 changed files with 1174 additions and 271 deletions

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020-2021 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -58,6 +58,9 @@ class MindDataTestCacheOp : public UT::DatasetOpTesting {
}
};
/// Feature: Cache
/// Description: Test basic usage of Cache server
/// Expectation: Runs successfully
TEST_F(MindDataTestCacheOp, DISABLED_TestCacheServer) {
Status rc;
CacheClient::Builder builder;
@ -141,6 +144,9 @@ TEST_F(MindDataTestCacheOp, DISABLED_TestCacheServer) {
ASSERT_TRUE(rc.IsOk());
}
/// Feature: Cache
/// Description: Test Cache with concurrency request
/// Expectation: Runs successfully
TEST_F(MindDataTestCacheOp, DISABLED_TestConcurrencyRequest) {
// Clear the rc of the master thread if any
(void)TaskManager::GetMasterThreadRc();
@ -211,6 +217,9 @@ TEST_F(MindDataTestCacheOp, DISABLED_TestConcurrencyRequest) {
ASSERT_TRUE(rc.IsOk());
}
/// Feature: Cache
/// Description: Test Cache with ImageFolderOp and MergeOp
/// Expectation: Runs successfully
TEST_F(MindDataTestCacheOp, DISABLED_TestImageFolderCacheMerge) {
// Clear the rc of the master thread if any
(void)TaskManager::GetMasterThreadRc();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,12 +26,15 @@ class MindDataTestCenterCropOp : public UT::CVOP::CVOpCommon {
MindDataTestCenterCropOp() : CVOpCommon() {}
};
/// Feature: CenterCrop op
/// Description: Test basic usage of CenterCrop op
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCenterCropOp, TestOp1) {
MS_LOG(INFO) << "Doing MindDataTestCenterCropOp::TestOp1.";
std::shared_ptr<Tensor> output_tensor;
int het = 256;
int wid = 128;
std::unique_ptr<CenterCropOp> op(new CenterCropOp(het, wid));
auto op = std::make_unique<CenterCropOp>(het, wid);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
@ -40,6 +43,9 @@ TEST_F(MindDataTestCenterCropOp, TestOp1) {
std::shared_ptr<CVTensor> p = CVTensor::AsCVTensor(output_tensor);
}
/// Feature: CenterCrop op
/// Description: Test CenterCrop op where cap valid crop size at 10 times the input size
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCenterCropOp, TestOp2) {
MS_LOG(INFO) << "MindDataTestCenterCropOp::TestOp2. Cap valid crop size at 10 times the input size";
std::shared_ptr<Tensor> output_tensor;
@ -47,17 +53,20 @@ TEST_F(MindDataTestCenterCropOp, TestOp2) {
int64_t wid = input_tensor_->shape()[0] * 10 + 1;
int64_t het = input_tensor_->shape()[1] * 10 + 1;
std::unique_ptr<CenterCropOp> op(new CenterCropOp(het, wid));
auto op = std::make_unique<CenterCropOp>(het, wid);
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsError());
ASSERT_TRUE(s.StatusCode() == StatusCode::kMDUnexpectedError);
}
/// Feature: CenterCrop op
/// Description: Test CenterCrop op with single integer input for square crop
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCenterCropOp, TestOp3) {
MS_LOG(INFO) << "Doing MindDataTestCenterCropOp::TestOp3. Test single integer input for square crop.";
std::shared_ptr<Tensor> output_tensor;
int side = 128;
std::unique_ptr<CenterCropOp> op(new CenterCropOp(side));
auto op = std::make_unique<CenterCropOp>(side);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,9 @@ class MindDataTestChannelSwap : public UT::CVOP::CVOpCommon {
MindDataTestChannelSwap() : CVOpCommon() {}
};
/// Feature: HwcToChw op
/// Description: Test channel swap with HwcToChw op
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestChannelSwap, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestChannelSwap.";
// Creating a Tensor
@ -36,7 +39,7 @@ TEST_F(MindDataTestChannelSwap, TestOp) {
std::shared_ptr<Tensor> output_tensor;
// Decoding
std::unique_ptr<HwcToChwOp> op(new HwcToChwOp());
auto op = std::make_unique<HwcToChwOp>();
Status status;
status = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(op->OneToOne());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -65,6 +65,9 @@ Status TestMem(MindDataTestCircularPool *tp, int32_t num_iterations) {
return Status::OK();
}
/// Feature: CircularPool
/// Description: Test CircularPool basic usage
/// Expectation: Runs successfully
TEST_F(MindDataTestCircularPool, TestALLFunction) {
const int32_t iteration = 100;
Services::CreateInstance();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestConcatenateOp : public UT::Common {
MindDataTestConcatenateOp() {}
};
/// Feature: Concatenate op
/// Description: Test Concatenate op with single row input
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestConcatenateOp, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestConcatenate-TestOp-SingleRowinput.";
std::vector<uint64_t> labels = {1, 1, 2};
@ -35,7 +38,7 @@ TEST_F(MindDataTestConcatenateOp, TestOp) {
Tensor::CreateFromVector(append_labels, &append);
std::shared_ptr<Tensor> output;
std::unique_ptr<ConcatenateOp> op(new ConcatenateOp(0, nullptr, append));
auto op = std::make_unique<ConcatenateOp>(0, nullptr, append);
TensorRow in;
in.push_back(input);
TensorRow out_row;
@ -54,6 +57,9 @@ TEST_F(MindDataTestConcatenateOp, TestOp) {
ASSERT_TRUE(*output == *expected);
}
/// Feature: Concatenate op
/// Description: Test Concatenate op with multiple inputs
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestConcatenateOp, TestOp2) {
MS_LOG(INFO) << "Doing MindDataTestConcatenate-TestOp2-MultiInput.";
std::vector<uint64_t> labels = {1, 12, 2};
@ -72,7 +78,7 @@ TEST_F(MindDataTestConcatenateOp, TestOp2) {
tensor_list.push_back(row_2);
std::shared_ptr<Tensor> output;
std::unique_ptr<ConcatenateOp> op(new ConcatenateOp(0, nullptr, append));
auto op = std::make_unique<ConcatenateOp>(0, nullptr, append);
TensorRow out_row;
Status s = op->Compute(tensor_list, &out_row);
@ -90,6 +96,9 @@ TEST_F(MindDataTestConcatenateOp, TestOp2) {
ASSERT_TRUE(*output == *expected);
}
/// Feature: Concatenate op
/// Description: Test Concatenate op with string input
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestConcatenateOp, TestOp3) {
MS_LOG(INFO) << "Doing MindDataTestConcatenate-TestOp3-Strings.";
std::vector<std::string> labels = {"hello", "bye"};
@ -104,7 +113,7 @@ TEST_F(MindDataTestConcatenateOp, TestOp3) {
tensor_list.push_back(row_1);
std::shared_ptr<Tensor> output;
std::unique_ptr<ConcatenateOp> op(new ConcatenateOp(0, nullptr, append));
auto op = std::make_unique<ConcatenateOp>(0, nullptr, append);
TensorRow out_row;
Status s = op->Compute(tensor_list, &out_row);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -86,8 +86,10 @@ private:
void GoToSleep(int max_dur);
};
// Test0 : single producer, single consumer which means there is only one queue in the connector
/// Feature: Connector
/// Description: Test Connector with single producer and single consumer,
/// which means there is only one queue in the connector
/// Expectation: Runs successfully
TEST_F(MindDataTestConnector, Test0) {
MS_LOG(INFO) << "MindDataTestConnector Test0: single producer, single consumer.";
Status rc = this->Run_test_0();
@ -96,9 +98,10 @@ TEST_F(MindDataTestConnector, Test0) {
ASSERT_TRUE(rc.IsOk());
}
// Test1: multiple producers, multiple consumers without random delay
// A chain of three layer of thread groups connected by two Connectors between
// two layer.
/// Feature: Connector
/// Description: Test Connector with multiple producers and multiple consumers without random delay,
/// a chain of three layers of thread groups connected by two Connectors between two layers.
/// Expectation: Runs successfully
TEST_F(MindDataTestConnector, Test1) {
MS_LOG(INFO) << "MindDataTestConnector Test1.";
Status rc = this->Run_test_1();
@ -107,9 +110,10 @@ TEST_F(MindDataTestConnector, Test1) {
ASSERT_TRUE(rc.IsOk());
}
// Test1: multiple producers, multiple consumers with random delay after push/pop
// A chain of three layer of thread groups connected by two Connectors between
// two layer.
/// Feature: Connector
/// Description: Test Connector with multiple producers and multiple consumers with random delay after push/pop,
/// a chain of three layers of thread groups connected by two Connectors between two layers.
/// Expectation: Runs successfully
TEST_F(MindDataTestConnector, Test2) {
MS_LOG(INFO) << "MindDataTestConnector Test2.";
this->SetSleepMilliSec(30);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,12 +27,15 @@ class MindDataTestCropOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: Crop op
/// Description: Test Crop op basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCropOp, TestOp1) {
MS_LOG(INFO) << "Doing testCrop.";
// Crop params
int crop_height = 18;
int crop_width = 12;
std::unique_ptr<CropOp> op(new CropOp(0, 0, crop_height, crop_width));
auto op = std::make_unique<CropOp>(0, 0, crop_height, crop_width);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
size_t actual = 0;
@ -44,26 +47,32 @@ TEST_F(MindDataTestCropOp, TestOp1) {
EXPECT_EQ(s, Status::OK());
}
/// Feature: Crop op
/// Description: Test Crop op with negative coordinates
/// Expectation: Throw correct error and message
TEST_F(MindDataTestCropOp, TestOp2) {
MS_LOG(INFO) << "Doing testCrop negative coordinates.";
// Crop params
unsigned int crop_height = 10;
unsigned int crop_width = 10;
std::unique_ptr<CropOp> op(new CropOp(-10, -10, crop_height, crop_width));
auto op = std::make_unique<CropOp>(-10, -10, crop_height, crop_width);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
EXPECT_EQ(false, s.IsOk());
MS_LOG(INFO) << "testCrop coordinate exception end.";
}
/// Feature: Crop op
/// Description: Test Crop op where size is too large
/// Expectation: Throw correct error and message
TEST_F(MindDataTestCropOp, TestOp3) {
MS_LOG(INFO) << "Doing testCrop size too large.";
// Crop params
unsigned int crop_height = 1200000;
unsigned int crop_width = 1200000;
std::unique_ptr<CropOp> op(new CropOp(0, 0, crop_height, crop_width));
auto op = std::make_unique<CropOp>(0, 0, crop_height, crop_width);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
EXPECT_EQ(false, s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,9 @@ class MindDataTestCSVOp : public UT::DatasetOpTesting {
};
/// Feature: CountAllFileRows in CsvOp
/// Description: Test CountAllFileRows in CsvOp on CSV files
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCSVOp, TestTotalRows) {
std::string csv_file1 = datasets_root_path_ + "/testCSV/1.csv";
std::string csv_file2 = datasets_root_path_ + "/testCSV/size.csv";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,9 +27,12 @@ class MindDataTestCutOutOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: CutOut op
/// Description: Test CutOut op basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCutOutOp, TestOp) {
MS_LOG(INFO) << "Doing testCutOut.";
std::unique_ptr<CutOutOp> op(new CutOutOp(50, 50, 5, false, 0, 0, 0));
auto op = std::make_unique<CutOutOp>(50, 50, 5, false, 0, 0, 0);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,9 @@ class MindDataTestCutMixBatchOp : public UT::CVOP::CVOpCommon {
MindDataTestCutMixBatchOp() : CVOpCommon() {}
};
/// Feature: CutMixBatch op
/// Description: Test CutMixBatch op with alpha=1.0 and prob=1.0
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCutMixBatchOp, TestSuccess1) {
MS_LOG(INFO) << "Doing MindDataTestCutMixBatchOp success1 case";
std::shared_ptr<Tensor> input_tensor_resized;
@ -54,6 +57,9 @@ TEST_F(MindDataTestCutMixBatchOp, TestSuccess1) {
EXPECT_EQ(in.at(1)->shape()[1], out.at(1)->shape()[1]);
}
/// Feature: CutMixBatch op
/// Description: Test CutMixBatch op with alpha=1.0 and prob=0.5
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCutMixBatchOp, TestSuccess2) {
MS_LOG(INFO) << "Doing MindDataTestCutMixBatchOp success2 case";
std::shared_ptr<Tensor> input_tensor_resized;
@ -85,6 +91,9 @@ TEST_F(MindDataTestCutMixBatchOp, TestSuccess2) {
EXPECT_EQ(in.at(1)->shape()[1], out.at(1)->shape()[1]);
}
/// Feature: CutMixBatch op
/// Description: Test CutMixBatch op where labels are not batched and are 1-dimensional
/// Expectation: Throw correct error and message
TEST_F(MindDataTestCutMixBatchOp, TestFail1) {
// This is a fail case because our labels are not batched and are 1-dimensional
MS_LOG(INFO) << "Doing MindDataTestCutMixBatchOp fail1 case";
@ -98,6 +107,10 @@ TEST_F(MindDataTestCutMixBatchOp, TestFail1) {
ASSERT_FALSE(op->Compute(in, &out).IsOk());
}
/// Feature: CutMixBatch op
/// Description: Test CutMixBatch op where image_batch_format provided
/// is not the same as the actual format of the images
/// Expectation: Throw correct error and message
TEST_F(MindDataTestCutMixBatchOp, TestFail2) {
// This should fail because the image_batch_format provided is not the same as the actual format of the images
MS_LOG(INFO) << "Doing MindDataTestCutMixBatchOp fail2 case";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -29,6 +29,9 @@ class MindDataTestCyclicArray : public UT::Common {
MindDataTestCyclicArray() {}
};
/// Feature: CyclicArray
/// Description: Test CyclicArray attributes and basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCyclicArray, Test1) {
CyclicArray<int> arr(5);
EXPECT_EQ(5, arr.capacity());
@ -89,6 +92,9 @@ TEST_F(MindDataTestCyclicArray, Test1) {
EXPECT_EQ(arr[arr.size() - 1], 26);
}
/// Feature: CyclicArray
/// Description: Test iterating over CyclicArray
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestCyclicArray, TestIterator) {
CyclicArray<int> arr(5);
for (auto i = 0; i < arr.capacity(); i++) {

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,6 +43,9 @@ class MindDataTestDataHelper : public UT::DatasetOpTesting {
protected:
};
/// Feature: DataHelper
/// Description: Test basic usage of UpdateArray in DataHelper by updating label
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestHelper) {
std::string file_path = datasets_root_path_ + "/testAlbum/images/1.json";
DataHelper dh;
@ -54,6 +57,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestHelper) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of CreateAlbum in DataHelper by generating album
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestAlbumGen) {
std::string file_path = datasets_root_path_ + "/testAlbum/original";
std::string out_path = datasets_root_path_ + "/testAlbum/testout";
@ -65,6 +71,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestAlbumGen) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of UpdateArray in DataHelper by updating with an int array
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateArrayInt) {
std::string file_path = datasets_root_path_ + "/testAlbum/testout/2.json";
DataHelper dh;
@ -76,6 +85,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateArrayInt) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of UpdateArray in DataHelper by updating with a string array
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateArrayString) {
std::string file_path = datasets_root_path_ + "/testAlbum/testout/3.json";
DataHelper dh;
@ -87,6 +99,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateArrayString) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of UpdateArray in DataHelper by updating with a single int value
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateValueInt) {
std::string file_path = datasets_root_path_ + "/testAlbum/testout/4.json";
DataHelper dh;
@ -98,6 +113,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateValueInt) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of UpdateArray in DataHelper by updating with a single string value
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateString) {
std::string file_path = datasets_root_path_ + "/testAlbum/testout/5.json";
DataHelper dh;
@ -109,6 +127,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestTemplateUpdateString) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of DeleteKey in DataHelper
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestDeleteKey) {
std::string file_path = datasets_root_path_ + "/testAlbum/testout/5.json";
DataHelper dh;
@ -119,6 +140,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestDeleteKey) {
}
}
/// Feature: DataHelper
/// Description: Test basic usage of WriteBinFile in DataHelper
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestBinWrite) {
std::string file_path = datasets_root_path_ + "/testAlbum/1.bin";
DataHelper dh;
@ -130,6 +154,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestBinWrite) {
}
}
/// Feature: DataHelper
/// Description: Test WriteBinFile in DataHelper by passing a pointer
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestBinWritePointer) {
std::string file_path = datasets_root_path_ + "/testAlbum/2.bin";
DataHelper dh;
@ -142,6 +169,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestBinWritePointer) {
}
}
/// Feature: CreateFromVector
/// Description: Test basic usage of CreateFromVector using vector of floats
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTensorWriteFloat) {
// create tensor
std::vector<float> y = {2.5, 3.0, 3.5, 4.0};
@ -166,6 +196,9 @@ TEST_F(MindDataTestDataHelper, MindDataTestTensorWriteFloat) {
std::free(data);
}
/// Feature: CreateFromVector
/// Description: Test basic usage of CreateFromVector using vector of uint8
/// Expectation: Runs successfully
TEST_F(MindDataTestDataHelper, MindDataTestTensorWriteUInt) {
// create tensor
std::vector<uint8_t> y = {1, 2, 3, 4};
@ -196,5 +229,3 @@ TEST_F(MindDataTestDataHelper, MindDataTestTensorWriteUInt) {
if (array[3] != 4) { EXPECT_TRUE(false); }
std::free(data);
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,7 +28,9 @@ class MindDataTestDatatype : public UT::Common {
MindDataTestDatatype() = default;
};
/// Feature: DataType
/// Description: Test sizes of various data types in bytes
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDatatype, TestSizes) {
uint8_t x = DataType::kTypeInfo[DataType::DE_BOOL].sizeInBytes_;
DataType d = DataType(DataType::DE_BOOL);
@ -85,6 +87,9 @@ void FromDT(DataType d, uint8_t cv_type, std::string str) {
ASSERT_EQ(d.ToString(), str);
}
/// Feature: DataType
/// Description: Test various DataType constructors
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDatatype, TestConstructors) {
// Default constructor
DataType d;
@ -106,6 +111,9 @@ TEST_F(MindDataTestDatatype, TestConstructors) {
ASSERT_EQ(d4, d5);
}
/// Feature: DataType
/// Description: Test DataType with CVType and test DataType's string
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDatatype, TestFromTypes) {
FromDT(DataType(DataType::DE_BOOL), CV_8U, "bool");
FromDT(DataType(DataType::DE_UINT8), CV_8U, "uint8");
@ -121,6 +129,9 @@ TEST_F(MindDataTestDatatype, TestFromTypes) {
FromDT(DataType(DataType::DE_UNKNOWN), CV_8U, "unknown");
}
/// Feature: DataType
/// Description: Test whether a DataType is compatible or loosely compatible
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDatatype, TestCompatible) {
ASSERT_TRUE(DataType(DataType::DE_BOOL).IsCompatible<bool>());
ASSERT_TRUE(DataType(DataType::DE_UINT8).IsCompatible<uint8_t>());
@ -154,6 +165,9 @@ TEST_F(MindDataTestDatatype, TestCompatible) {
}
/// Feature: DataType
/// Description: Test equality of DataType with CVType
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDatatype, TestCVTypes) {
ASSERT_EQ(DataType::DE_UINT8, DataType::FromCVType(CV_8U).value());
ASSERT_EQ(DataType::DE_UINT8, DataType::FromCVType(CV_8UC1).value());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,9 @@ class MindDataTestDecodeOp : public UT::CVOP::CVOpCommon {
MindDataTestDecodeOp() : CVOpCommon() {}
};
/// Feature: Decode op
/// Description: Test Decode op basic usage
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDecodeOp, TestOp) {
MS_LOG(INFO) << "Doing testDecode";
TensorShape s = TensorShape({1});

View File

@ -50,7 +50,10 @@ void compare_dataset(std::shared_ptr<DatasetNode> ds) {
return;
}
// test mnist dataset, and special cases of tensor operations (no input or tensor operation input)
/// Feature: Deserialize
/// Description: Test Deserialize on MNISTDataset and special cases of tensor operations
/// (no input or tensor operation input)
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeMnist) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Minist.";
std::string data_dir = "./data/dataset/testMnistData";
@ -83,7 +86,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeMnist) {
compare_dataset(ds);
}
// test celeba dataset and part of the tensor operation
/// Feature: Deserialize
/// Description: Test Deserialize on CelebADataset and part of the tensor operation
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCelebA) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-CelebA.";
std::string data_dir = "./data/dataset/testCelebAData/";
@ -145,7 +150,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCelebA) {
compare_dataset(ds);
}
// test cifar10 dataset and random tensor operations
/// Feature: Deserialize
/// Description: Test Deserialize on Cifar10Dataset and random tensor operations
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCifar10) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Cifar10.";
std::string data_dir = "./data/dataset/testCifar10Data";
@ -214,6 +221,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCifar10) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on Cifar100Dataset and part of the tensor operations
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCifar100) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Cifar100.";
std::string data_dir = "./data/dataset/testCifar100Data";
@ -249,6 +259,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCifar100) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on CSVDataset
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCSV) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-CSV.";
std::string data_file = "./data/dataset/testCSV/1.csv";
@ -264,6 +277,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCSV) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on ImageFolderDataset and some random tensor operations
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeImageFolder) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-ImageFolder.";
std::string dataset_dir = "./data/dataset/testPK/data";
@ -295,6 +311,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeImageFolder) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on ManifestDataset with some tensor operations
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeManifest) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Manifest.";
std::string data_file = "./data/dataset/testManifestData/cpp.json";
@ -325,6 +344,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeManifest) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on VOCDataset with RandomColorAdjust op
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeVOC) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-VOC.";
std::string dataset_dir = "./data/dataset/testVOC2012";
@ -348,6 +370,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeVOC) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on CLUEDataset with Decode op
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCLUE) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-CLUE.";
std::string train_file = "./data/dataset/testCLUE/afqmc/train.json";
@ -363,6 +388,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCLUE) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on CocoDataset with some random tensor operations
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeCoco) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Coco.";
std::string folder_path = "./data/dataset/testCOCO/train";
@ -395,6 +423,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeCoco) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on TFRecordDataset
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeTFRecord) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-TFRecord.";
int num_samples = 12;
@ -434,6 +465,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeTFRecord) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on TextFileDataset
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeTextfile) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Textfile.";
std::vector<std::string> dataset_files = {"./data/dataset/testTextFileDataset/1.txt"};
@ -446,6 +480,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeTextfile) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize with invalid json path or object
/// Expectation: Throw correct error and message
TEST_F(MindDataTestDeserialize, TestDeserializeInvalidJson) {
std::shared_ptr<DatasetNode> ds;
// check the invalid json path would return error
@ -455,6 +492,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeInvalidJson) {
EXPECT_EQ(ds, nullptr);
}
/// Feature: Deserialize
/// Description: Test Deserialize on TextFileDataset with Fill op
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeFill) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Fill.";
std::vector<std::string> dataset_files = {"./data/dataset/testTextFileDataset/1.txt"};
@ -470,6 +510,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeFill) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on Tensor
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeTensor) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Tensor.";
std::shared_ptr<Tensor> test_tensor;
@ -491,6 +534,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeTensor) {
// Helper function to get the session id from SESSION_ID env variable
Status GetSessionFromEnv(session_id_type *session_id);
/// Feature: Deserialize
/// Description: Test Deserialize on created Dataset Cache
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, DISABLED_TestDeserializeCache) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-Cache.";
std::string data_dir = "./data/dataset/testCache";
@ -504,6 +550,9 @@ TEST_F(MindDataTestDeserialize, DISABLED_TestDeserializeCache) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize on AlbumDataset with Concat and Flickr
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializeConcatAlbumFlickr) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-ConcatAlbumFlickr.";
std::string dataset_dir = "./data/dataset/testAlbum";
@ -528,6 +577,9 @@ TEST_F(MindDataTestDeserialize, TestDeserializeConcatAlbumFlickr) {
compare_dataset(ds);
}
/// Feature: Deserialize
/// Description: Test Deserialize when Python is initialized
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDeserialize, TestDeserializePyFunc) {
MS_LOG(INFO) << "Doing MindDataTestDeserialize-PyFunc.";
if (Py_IsInitialized() != 0) {

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,6 +40,9 @@ class MindDataTestDistributedSampler : public UT::Common {
};
};
/// Feature: DistributedSampler
/// Description: Test DistributedSampler with num_shards=2 and shard_id=0
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDistributedSampler, TestTwoShardsOne) {
// num samples to draw.
uint64_t num_samples = 7;
@ -64,6 +67,9 @@ TEST_F(MindDataTestDistributedSampler, TestTwoShardsOne) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: DistributedSampler
/// Description: Test DistributedSampler with num_shards=2 and shard_id=1
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDistributedSampler, TestTwoShardsTwo) {
// num samples to draw.
uint64_t num_samples = 7;
@ -89,6 +95,9 @@ TEST_F(MindDataTestDistributedSampler, TestTwoShardsTwo) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: DistributedSampler
/// Description: Test DistributedSampler with num_shards=3 and shard_id=2
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDistributedSampler, TestThreeShards) {
// num samples to draw.
uint64_t num_samples = 2;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,9 @@ class MindDataTestDuplicateOp : public UT::Common {
void SetUp() { GlobalInit(); }
};
/// Feature: Duplicate op
/// Description: Test DuplicateOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestDuplicateOp, Basics) {
std::shared_ptr<Tensor> t;
Tensor::CreateFromVector(std::vector<uint32_t>({1, 2, 3, 4, 5, 6}), &t);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,9 +28,12 @@ class MindDataTestDvppDecodeJpeg : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: DvppDecodeJpeg op
/// Description: Test DvppDecodeJpegOp basic usage
/// Expectation: The data is processed successfully
TEST_F(MindDataTestDvppDecodeJpeg, TestOp1) {
MS_LOG(INFO) << "Doing testDvppDecodeJpeg.";
std::unique_ptr<DvppDecodeJpegOp> op(new DvppDecodeJpegOp());
auto op = std::make_unique<DvppDecodeJpegOp>();
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
EXPECT_EQ(s, Status::OK());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,11 +26,14 @@ class MindDataTestEqualizeOp : public UT::CVOP::CVOpCommon {
MindDataTestEqualizeOp() : CVOpCommon() {}
};
/// Feature: Equalize op
/// Description: Test Equalize op basic usage
/// Expectation: The data is processed successfully
TEST_F(MindDataTestEqualizeOp, TestOp1) {
MS_LOG(INFO) << "Doing testEqualizeOp.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<EqualizeOp> op(new EqualizeOp());
auto op = std::make_unique<EqualizeOp>();
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,7 +30,9 @@ class MindDataTestExecutionTree : public UT::DatasetOpTesting {
public:
};
// Construct some tree nodes and play with them
/// Feature: Execution Tree
/// Description: Test execution tree by using ShuffleOp as the nodes
/// Expectation: Runs successfully
TEST_F(MindDataTestExecutionTree, TestExecutionTree1) {
MS_LOG(INFO) << "Doing MindDataTestExecutionTree1.";
@ -76,7 +78,9 @@ TEST_F(MindDataTestExecutionTree, TestExecutionTree1) {
MS_LOG(INFO) << "Done.";
}
// Construct some tree nodes and play with them
/// Feature: Execution Tree
/// Description: Test execution tree by using TFrecordDataset as the root, prepare, then launch the tree
/// Expectation: Runs successfully
TEST_F(MindDataTestExecutionTree, TestExecutionTree2) {
MS_LOG(INFO) << "Doing MindDataTestExecutionTree2.";
Status rc;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestFillOp : public UT::Common {
MindDataTestFillOp() {}
};
/// Feature: Fill op
/// Description: Test Fill op basic usage (fill uint64 tensor with uint64 scalar)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestFillOp, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-TestOp.";
std::vector<uint64_t> labels = {1, 1, 2};
@ -34,7 +37,7 @@ TEST_F(MindDataTestFillOp, TestOp) {
Tensor::CreateScalar<uint64_t>(4, &fill_tensor);
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {4, 4, 4};
@ -51,6 +54,9 @@ TEST_F(MindDataTestFillOp, TestOp) {
MS_LOG(INFO) << "MindDataTestFillOp-TestOp end.";
}
/// Feature: Fill op
/// Description: Test Fill op with casting (fill uint64 tensor with float scalar)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestFillOp, TestCasting) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-TestCasting.";
std::vector<uint64_t> labels = {0, 1, 2};
@ -61,7 +67,7 @@ TEST_F(MindDataTestFillOp, TestCasting) {
Tensor::CreateScalar<float>(2.0, &fill_tensor);
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {2, 2, 2};
@ -79,6 +85,9 @@ TEST_F(MindDataTestFillOp, TestCasting) {
MS_LOG(INFO) << "MindDataTestFillOp-TestCasting end.";
}
/// Feature: Fill op
/// Description: Test Fill op invalid input (fill uint64 tensor with uint64 tensor)
/// Expectation: Throw correct error and message
TEST_F(MindDataTestFillOp, ScalarFill) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-ScalarFill.";
std::vector<uint64_t> labels = {0, 1, 2};
@ -91,7 +100,7 @@ TEST_F(MindDataTestFillOp, ScalarFill) {
Tensor::CreateFromVector(fill_labels, &fill_tensor);
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
EXPECT_TRUE(s.IsError());
@ -100,6 +109,9 @@ TEST_F(MindDataTestFillOp, ScalarFill) {
MS_LOG(INFO) << "MindDataTestFillOp-ScalarFill end.";
}
/// Feature: Fill op
/// Description: Test Fill op (fill string tensor with string scalar)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestFillOp, StringFill) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-StringFill.";
std::vector<std::string> strings = {"xyzzy", "plugh", "abracadabra"};
@ -111,7 +123,7 @@ TEST_F(MindDataTestFillOp, StringFill) {
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
std::vector<std::string> expected_strings = {"hello", "hello", "hello"};
@ -129,6 +141,9 @@ TEST_F(MindDataTestFillOp, StringFill) {
MS_LOG(INFO) << "MindDataTestFillOp-StringFill end.";
}
/// Feature: Fill op
/// Description: Test Fill op mismatch type (fill string tensor with numeric scalar)
/// Expectation: Throw correct error and message
TEST_F(MindDataTestFillOp, NumericToString) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-NumericToString.";
std::vector<std::string> strings = {"xyzzy", "plugh", "abracadabra"};
@ -140,7 +155,7 @@ TEST_F(MindDataTestFillOp, NumericToString) {
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
EXPECT_TRUE(s.IsError());
@ -149,6 +164,9 @@ TEST_F(MindDataTestFillOp, NumericToString) {
MS_LOG(INFO) << "MindDataTestFillOp-NumericToString end.";
}
/// Feature: Fill op
/// Description: Test Fill op mismatch type (fill numeric tensor with string scalar)
/// Expectation: Throw correct error and message
TEST_F(MindDataTestFillOp, StringToNumeric) {
MS_LOG(INFO) << "Doing MindDataTestFillOp-StringToNumeric.";
std::vector<uint64_t> labels = {0, 1, 2};
@ -160,7 +178,7 @@ TEST_F(MindDataTestFillOp, StringToNumeric) {
std::shared_ptr<Tensor> output;
std::unique_ptr<FillOp> op(new FillOp(fill_tensor));
auto op = std::make_unique<FillOp>(fill_tensor);
Status s = op->Compute(input, &output);
EXPECT_TRUE(s.IsError());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestGlobalContext : public UT::Common {
MindDataTestGlobalContext() {}
};
/// Feature: GlobalContext
/// Description: Test GlobalContext::Instance()
/// Expectation: Runs successfully
TEST_F(MindDataTestGlobalContext, TestGCFunction) {
MS_LOG(INFO) << "Doing Test GlobalContext";
MS_LOG(INFO) << "Doing instance";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -95,6 +95,9 @@ class MindDataTestGNNGraph : public UT::Common {
}
};
/// Feature: GNNGraph
/// Description: Test GetEdgesFromNodes from graph basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestGetEdgesFromNodes) {
std::string path = "data/mindrecord/testGraphData/testdata";
GraphDataImpl graph(path, 1);
@ -110,6 +113,9 @@ TEST_F(MindDataTestGNNGraph, TestGetEdgesFromNodes) {
EXPECT_TRUE(edges->ToString() == "Tensor (shape: <6>, Type: int32)\n[1,9,17,19,31,37]");
}
/// Feature: GNNGraph
/// Description: Test GetAllNeighbors from graph basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestGetAllNeighbors) {
std::string path = "data/mindrecord/testGraphData/testdata";
GraphDataImpl graph(path, 1);
@ -151,6 +157,9 @@ TEST_F(MindDataTestGNNGraph, TestGetAllNeighbors) {
EXPECT_TRUE(features[2]->ToString() == "Tensor (shape: <10>, Type: int32)\n[1,2,3,1,4,3,5,3,5,4]");
}
/// Feature: GNNGraph
/// Description: Test GetAllNeighbors from graph with COO and CSR output format
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestGetAllNeighborsSpecialFormat) {
std::string path = "data/mindrecord/testGraphData/testdata";
GraphDataImpl graph(path, 1);
@ -192,6 +201,9 @@ TEST_F(MindDataTestGNNGraph, TestGetAllNeighborsSpecialFormat) {
"[0,3,5,10,10,11,13,16,17,18,201,205,206,201,202,203,205,206,207,208,204,202,203,201,203,207,208,210,201,210]");
}
/// Feature: GNNGraph
/// Description: Test GetSampledNeighbors from graph basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestGetSampledNeighbors) {
std::string path = "data/mindrecord/testGraphData/testdata";
GraphDataImpl graph(path, 1);
@ -314,6 +326,9 @@ TEST_F(MindDataTestGNNGraph, TestGetSampledNeighbors) {
EXPECT_TRUE(s.ToString().find("Invalid node id:301") != std::string::npos);
}
/// Feature: GNNGraph
/// Description: Test GetNegSampledNeighbors from graph basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestGetNegSampledNeighbors) {
std::string path = "data/mindrecord/testGraphData/testdata";
GraphDataImpl graph(path, 1);
@ -357,6 +372,9 @@ TEST_F(MindDataTestGNNGraph, TestGetNegSampledNeighbors) {
EXPECT_TRUE(s.ToString().find("Invalid neighbor type") != std::string::npos);
}
/// Feature: GNNGraph
/// Description: Test RandomWalk from graph basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestRandomWalk) {
std::string path = "data/mindrecord/testGraphData/sns";
GraphDataImpl graph(path, 1);
@ -383,6 +401,9 @@ TEST_F(MindDataTestGNNGraph, TestRandomWalk) {
EXPECT_TRUE(walk_path->shape().ToString() == "<33,60>");
}
/// Feature: GNNGraph
/// Description: Test RandomWalk from graph with default parameters
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestGNNGraph, TestRandomWalkDefaults) {
std::string path = "data/mindrecord/testGraphData/sns";
GraphDataImpl graph(path, 1);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,6 +31,9 @@ class MindDataTestIntrpService : public UT::Common {
TaskGroup vg_;
};
/// Feature: Interrupt
/// Description: Test Interrupt on Queue that's being operated on
/// Expectation: Runs successfully
TEST_F(MindDataTestIntrpService, Test1) {
Status rc;
Queue<int> q(3);
@ -47,6 +50,9 @@ TEST_F(MindDataTestIntrpService, Test1) {
vg_.join_all(Task::WaitFlag::kNonBlocking);
}
/// Feature: Interrupt
/// Description: Test Interrupt on Wait
/// Expectation: Runs successfully
TEST_F(MindDataTestIntrpService, Test2) {
MS_LOG(INFO) << "Test Semaphore";
Status rc;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,10 +25,13 @@ class MindDataTestInvert : public UT::CVOP::CVOpCommon {
MindDataTestInvert() : CVOpCommon() {}
};
/// Feature: Invert op
/// Description: Test Invert op basic usage
/// Expectation: The data is processed successfully
TEST_F(MindDataTestInvert, TestOp) {
MS_LOG(INFO) << "Doing test Invert.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<InvertOp> op(new InvertOp());
auto op = std::make_unique<InvertOp>();
EXPECT_TRUE(op->OneToOne());
Status st = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(st.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,6 +35,9 @@ class MindDataTestIrSampler : public UT::DatasetOpTesting {
protected:
};
/// Feature: MindData IR Sampler Support
/// Description: Test CalculateNumSamples with various SamplerObj
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestIrSampler, TestCalculateNumSamples) {
int64_t num_rows = 30; // dummy variable for number of rows in the dataset
std::shared_ptr<SamplerObj> sampl = std::make_shared<DistributedSamplerObj>(2, 1, false, 6, 1, -1, true);
@ -123,6 +126,9 @@ TEST_F(MindDataTestIrSampler, TestCalculateNumSamples) {
EXPECT_EQ(sampler_rt7->CalculateNumSamples(num_rows), -1);
}
/// Feature: MindData IR Sampler Support
/// Description: Test samplers move parameter with indices (array of int64) and std::move(indices)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestIrSampler, TestSamplersMoveParameters) {
std::vector<int64_t> indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23};
std::shared_ptr<SamplerObj> sampl1 = std::make_shared<SubsetRandomSamplerObj>(indices, 0);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,6 +32,9 @@ class MindDataTestTensorOpFusionPass : public UT::DatasetOpTesting {
MindDataTestTensorOpFusionPass() = default;
};
/// Feature: MindData Tensor Op Fusion Pass Support
/// Description: Test Decode op and RandomResizedCrop op without IR optimization pass
/// Expectation: Runs successfully
TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeDisabled) {
MS_LOG(INFO) << "Doing MindDataTestTensorOpFusionPass-RandomCropDecodeResizeDisabled";
@ -39,8 +42,8 @@ TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeDisabled) {
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, std::make_shared<SequentialSampler>(0, 11));
// Create objects for the tensor ops
std::shared_ptr<TensorTransform> decode(new vision::Decode());
std::shared_ptr<TensorTransform> random_resized_crop(new vision::RandomResizedCrop({5}));
auto decode = std::make_shared<vision::Decode>();
auto random_resized_crop = std::make_shared<vision::RandomResizedCrop>(std::vector<int32_t>{5});
ds = ds->Map({decode, random_resized_crop}, {"image"});
std::shared_ptr<DatasetNode> node = ds->IRNode();
@ -63,6 +66,9 @@ TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeDisabled) {
EXPECT_EQ((*func_it)->Name(), kRandomCropAndResizeOp);
}
/// Feature: MindData Tensor Op Fusion Pass Support
/// Description: Test Decode op and RandomResizedCrop op with IR optimization pass
/// Expectation: Runs successfully
TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeEnabled) {
MS_LOG(INFO) << "Doing MindDataTestTensorOpFusionPass-RandomCropDecodeResizeEnabled";
@ -70,8 +76,8 @@ TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeEnabled) {
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, std::make_shared<SequentialSampler>(0, 11));
// Create objects for the tensor ops
std::shared_ptr<TensorTransform> decode(new vision::Decode());
std::shared_ptr<TensorTransform> random_resized_crop(new vision::RandomResizedCrop({5}));
auto decode = std::make_shared<vision::Decode>();
auto random_resized_crop = std::make_shared<vision::RandomResizedCrop>(std::vector<int32_t>{5});
ds = ds->Map({decode, random_resized_crop}, {"image"});
std::shared_ptr<DatasetNode> node = ds->IRNode();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020-2021 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,6 +31,9 @@ using mindspore::dataset::Tensor;
class MindDataTestTreeAdapter : public UT::DatasetOpTesting {};
// Feature: TreeAdapter
// Description: Test TreeAdapter in simple case without IR optimization
// Expectation: Runs successfully
TEST_F(MindDataTestTreeAdapter, TestSimpleTreeAdapter) {
MS_LOG(INFO) << "Doing MindDataTestTreeAdapter-TestSimpleTreeAdapter.";
@ -69,6 +72,9 @@ TEST_F(MindDataTestTreeAdapter, TestSimpleTreeAdapter) {
EXPECT_TRUE(err_msg.find("EOF buffer encountered.") != err_msg.npos);
}
// Feature: TreeAdapter
// Description: Test TreeAdapter with repeated row_sizes
// Expectation: Runs successfully
TEST_F(MindDataTestTreeAdapter, TestTreeAdapterWithRepeat) {
MS_LOG(INFO) << "Doing MindDataTestTreeAdapter-TestTreeAdapterWithRepeat.";
@ -101,6 +107,9 @@ TEST_F(MindDataTestTreeAdapter, TestTreeAdapterWithRepeat) {
EXPECT_TRUE(err_msg.find("EOF buffer encountered.") != err_msg.npos);
}
// Feature: TreeAdapter
// Description: Test TreeAdapter on dataset that has been projected
// Expectation: Runs successfully
TEST_F(MindDataTestTreeAdapter, TestProjectMapTreeAdapter) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestProjectMap.";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,218 +43,254 @@ class MindDataTestIRVision : public UT::DatasetOpTesting {
MindDataTestIRVision() = default;
};
// Feature: RandomColor IR
// Description: Test RandomColorOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomColorIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomColorIRFail.";
// Testing invalid lower bound > upper bound
std::shared_ptr<TensorOperation> random_color1(new vision::RandomColorOperation(1.0, 0.1));
auto random_color1 = std::make_shared<vision::RandomColorOperation>(1.0, 0.1);
Status rc1 = random_color1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid negative lower bound
std::shared_ptr<TensorOperation> random_color2(new vision::RandomColorOperation(-0.5, 0.5));
auto random_color2 = std::make_shared<vision::RandomColorOperation>(-0.5, 0.5);
Status rc2 = random_color2->ValidateParams();
EXPECT_ERROR(rc2);
}
// Feature: RandomColorAdjust IR
// Description: Test RandomColorAdjustOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomColorAdjustIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomColorAdjustIRFail.";
// Testing invalid brightness out of range
std::shared_ptr<TensorOperation> random_color_adjust1(
new vision::RandomColorAdjustOperation({-1.0}, {0.0}, {0.0}, {0.0}));
auto random_color_adjust1 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{-1.0}, std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{0.0});
Status rc1 = random_color_adjust1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid contrast out of range
std::shared_ptr<TensorOperation> random_color_adjust2(
new vision::RandomColorAdjustOperation({1.0}, {-0.1}, {0.0}, {0.0}));
auto random_color_adjust2 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{1.0}, std::vector<float>{-0.1}, std::vector<float>{0.0}, std::vector<float>{0.0});
Status rc2 = random_color_adjust2->ValidateParams();
EXPECT_ERROR(rc2);
// Testing invalid saturation out of range
std::shared_ptr<TensorOperation> random_color_adjust3(
new vision::RandomColorAdjustOperation({0.0}, {0.0}, {-0.2}, {0.0}));
auto random_color_adjust3 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{-0.2}, std::vector<float>{0.0});
Status rc3 = random_color_adjust3->ValidateParams();
EXPECT_ERROR(rc3);
// Testing invalid hue out of range
std::shared_ptr<TensorOperation> random_color_adjust4(
new vision::RandomColorAdjustOperation({0.0}, {0.0}, {0.0}, {-0.6}));
auto random_color_adjust4 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{-0.6});
Status rc4 = random_color_adjust4->ValidateParams();
EXPECT_ERROR(rc4);
// Testing invalid hue out of range
std::shared_ptr<TensorOperation> random_color_adjust5(
new vision::RandomColorAdjustOperation({0.0}, {0.0}, {0.0}, {-0.5, 0.6}));
auto random_color_adjust5 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{-0.5, 0.6});
Status rc5 = random_color_adjust5->ValidateParams();
EXPECT_ERROR(rc5);
// Testing invalid hue
std::shared_ptr<TensorOperation> random_color_adjust6(
new vision::RandomColorAdjustOperation({0.0}, {0.0}, {0.0}, {0.51}));
auto random_color_adjust6 = std::make_shared<vision::RandomColorAdjustOperation>(
std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{0.0}, std::vector<float>{0.51});
Status rc6 = random_color_adjust4->ValidateParams();
EXPECT_ERROR(rc6);
}
// Feature: RandomHorizontalFlip IR
// Description: Test RandomHorizontalFlipOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomHorizontalFlipIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomHorizontalFlipIRFail.";
// Testing invalid negative input
std::shared_ptr<TensorOperation> random_horizontal_flip1(new vision::RandomHorizontalFlipOperation(-0.5));
auto random_horizontal_flip1 = std::make_shared<vision::RandomHorizontalFlipOperation>(-0.5);
Status rc1 = random_horizontal_flip1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid >1 input
std::shared_ptr<TensorOperation> random_horizontal_flip2(new vision::RandomHorizontalFlipOperation(2));
auto random_horizontal_flip2 = std::make_shared<vision::RandomHorizontalFlipOperation>(2);
Status rc2 = random_horizontal_flip2->ValidateParams();
EXPECT_ERROR(rc2);
}
// Feature: RandomHorizontalFlipWithBBox IR
// Description: Test RandomHorizontalFlipWithBBoxOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomHorizontalFlipWithBBoxIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomHorizontalFlipWithBBoxIRFail.";
// Testing invalid negative input
std::shared_ptr<TensorOperation> random_horizontal_flip_bbox1(
new vision::RandomHorizontalFlipWithBBoxOperation(-1.0));
auto random_horizontal_flip_bbox1 = std::make_shared<vision::RandomHorizontalFlipWithBBoxOperation>(
-1.0);
Status rc1 = random_horizontal_flip_bbox1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid >1 input
std::shared_ptr<TensorOperation> random_horizontal_flip_bbox2(new vision::RandomHorizontalFlipWithBBoxOperation(2.0));
auto random_horizontal_flip_bbox2 = std::make_shared<vision::RandomHorizontalFlipWithBBoxOperation>(2.0);
Status rc2 = random_horizontal_flip_bbox2->ValidateParams();
EXPECT_ERROR(rc2);
}
// Feature: RandomPosterize IR
// Description: Test RandomPosterizeOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomPosterizeIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomPosterizeIRFail.";
// Testing invalid max > 8
std::shared_ptr<TensorOperation> random_posterize1(new vision::RandomPosterizeOperation({1, 9}));
auto random_posterize1 = std::make_shared<vision::RandomPosterizeOperation>(std::vector<uint8_t>{1, 9});
Status rc1 = random_posterize1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid min < 1
std::shared_ptr<TensorOperation> random_posterize2(new vision::RandomPosterizeOperation({0, 8}));
auto random_posterize2 = std::make_shared<vision::RandomPosterizeOperation>(std::vector<uint8_t>{0, 8});
Status rc2 = random_posterize2->ValidateParams();
EXPECT_ERROR(rc2);
// Testing invalid min > max
std::shared_ptr<TensorOperation> random_posterize3(new vision::RandomPosterizeOperation({8, 1}));
auto random_posterize3 = std::make_shared<vision::RandomPosterizeOperation>(std::vector<uint8_t>{8, 1});
Status rc3 = random_posterize3->ValidateParams();
EXPECT_ERROR(rc3);
// Testing invalid empty input
std::shared_ptr<TensorOperation> random_posterize4(new vision::RandomPosterizeOperation({}));
auto random_posterize4 = std::make_shared<vision::RandomPosterizeOperation>(std::vector<uint8_t>{});
Status rc4 = random_posterize4->ValidateParams();
EXPECT_ERROR(rc4);
}
// Feature: RandomResize IR
// Description: Test RandomResizeOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomResizeIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomResizeIRFail.";
// Testing invalid: size must only contain positive integers
std::shared_ptr<TensorOperation> random_resize1(new vision::RandomResizeOperation({-66, 77}));
auto random_resize1 = std::make_shared<vision::RandomResizeOperation>(std::vector<int32_t>{-66, 77});
Status rc1 = random_resize1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid: size must only contain positive integers
std::shared_ptr<TensorOperation> random_resize2(new vision::RandomResizeOperation({0, 77}));
auto random_resize2 = std::make_shared<vision::RandomResizeOperation>(std::vector<int32_t>{0, 77});
Status rc2 = random_resize2->ValidateParams();
EXPECT_ERROR(rc2);
// Testing invalid: size must be a vector of one or two values
std::shared_ptr<TensorOperation> random_resize3(new vision::RandomResizeOperation({1, 2, 3}));
auto random_resize3 = std::make_shared<vision::RandomResizeOperation>(std::vector<int32_t>{1, 2, 3});
Status rc3 = random_resize3->ValidateParams();
EXPECT_ERROR(rc3);
// Testing invalid: size must be a vector of one or two values
std::shared_ptr<TensorOperation> random_resize4(new vision::RandomResizeOperation({}));
auto random_resize4 = std::make_shared<vision::RandomResizeOperation>(std::vector<int32_t>{});
Status rc4 = random_resize4->ValidateParams();
EXPECT_ERROR(rc4);
}
// Feature: RandomResizeWithBBox IR
// Description: Test RandomResizeWithBBoxOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomResizeWithBBoxIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomResizeWithBBoxIRFail.";
// Testing invalid: size must only contain positive integers
std::shared_ptr<TensorOperation> random_resize_with_bbox1(new vision::RandomResizeWithBBoxOperation({-66, 77}));
auto random_resize_with_bbox1 = std::make_shared<vision::RandomResizeWithBBoxOperation>(
std::vector<int32_t>{-66, 77});
Status rc1 = random_resize_with_bbox1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid: size must be a vector of one or two values
std::shared_ptr<TensorOperation> random_resize_with_bbox2(new vision::RandomResizeWithBBoxOperation({1, 2, 3}));
auto random_resize_with_bbox2 = std::make_shared<vision::RandomResizeWithBBoxOperation>(
std::vector<int32_t>{1, 2, 3});
Status rc2 = random_resize_with_bbox2->ValidateParams();
EXPECT_ERROR(rc2);
// Testing invalid: size must be a vector of one or two values
std::shared_ptr<TensorOperation> random_resize_with_bbox3(new vision::RandomResizeWithBBoxOperation({}));
auto random_resize_with_bbox3 = std::make_shared<vision::RandomResizeWithBBoxOperation>(
std::vector<int32_t>{});
Status rc3 = random_resize_with_bbox3->ValidateParams();
EXPECT_ERROR(rc3);
}
// Feature: RandomSharpness IR
// Description: Test RandomSharpnessOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomSharpnessIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomSharpnessIRFail.";
// Testing invalid empty degrees vector
std::shared_ptr<TensorOperation> random_sharpness1(new vision::RandomSharpnessOperation({}));
auto random_sharpness1 = std::make_shared<vision::RandomSharpnessOperation>(std::vector<float>{});
Status rc1 = random_sharpness1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid single degree value
std::shared_ptr<TensorOperation> random_sharpness2(new vision::RandomSharpnessOperation({0.1}));
auto random_sharpness2 = std::make_shared<vision::RandomSharpnessOperation>(std::vector<float>{0.1});
Status rc2 = random_sharpness2->ValidateParams();
EXPECT_ERROR(rc2);
}
// Feature: RandomSolarize IR
// Description: Test RandomSolarizeOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomSolarizeIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomSolarizeIRFail.";
// Testing invalid lower bound > upper bound
std::shared_ptr<TensorOperation> random_solarize1(new vision::RandomSolarizeOperation({13, 1}));
auto random_solarize1 = std::make_shared<vision::RandomSolarizeOperation>(std::vector<uint8_t>{13, 1});
Status rc1 = random_solarize1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid threshold must be a vector of two values
std::shared_ptr<TensorOperation> random_solarize2(new vision::RandomSolarizeOperation({1, 2, 3}));
auto random_solarize2 = std::make_shared<vision::RandomSolarizeOperation>(std::vector<uint8_t>{1, 2, 3});
Status rc2 = random_solarize2->ValidateParams();
EXPECT_ERROR(rc2);
// Testing invalid threshold must be a vector of two values
std::shared_ptr<TensorOperation> random_solarize3(new vision::RandomSolarizeOperation({1}));
auto random_solarize3 = std::make_shared<vision::RandomSolarizeOperation>(std::vector<uint8_t>{1});
Status rc3 = random_solarize3->ValidateParams();
EXPECT_ERROR(rc3);
// Testing invalid empty threshold
std::shared_ptr<TensorOperation> random_solarize4(new vision::RandomSolarizeOperation({}));
auto random_solarize4 = std::make_shared<vision::RandomSolarizeOperation>(std::vector<uint8_t>{});
Status rc4 = random_solarize4->ValidateParams();
EXPECT_ERROR(rc4);
}
// Feature: RandomVerticalFlip IR
// Description: Test RandomVerticalFlipOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomVerticalFlipIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomVerticalFlipIRFail.";
// Testing invalid negative input
std::shared_ptr<TensorOperation> random_vertical_flip1(new vision::RandomVerticalFlipOperation(-0.5));
auto random_vertical_flip1 = std::make_shared<vision::RandomVerticalFlipOperation>(-0.5);
Status rc1 = random_vertical_flip1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid >1 input
std::shared_ptr<TensorOperation> random_vertical_flip2(new vision::RandomVerticalFlipOperation(1.1));
auto random_vertical_flip2 = std::make_shared<vision::RandomVerticalFlipOperation>(1.1);
Status rc2 = random_vertical_flip2->ValidateParams();
EXPECT_ERROR(rc2);
}
// Feature: RandomVerticalFlipWithBBox IR
// Description: Test RandomVerticalFlipWithBBoxOperation with invalid parameters
// Expectation: Throw correct error and message
TEST_F(MindDataTestIRVision, TestRandomVerticalFlipWithBBoxIRFail) {
MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRandomVerticalFlipWithBBoxIRFail.";
// Testing invalid negative input
std::shared_ptr<TensorOperation> random_vertical_flip1(new vision::RandomVerticalFlipWithBBoxOperation(-0.5));
auto random_vertical_flip1 = std::make_shared<vision::RandomVerticalFlipWithBBoxOperation>(-0.5);
Status rc1 = random_vertical_flip1->ValidateParams();
EXPECT_ERROR(rc1);
// Testing invalid >1 input
std::shared_ptr<TensorOperation> random_vertical_flip2(new vision::RandomVerticalFlipWithBBoxOperation(3.0));
auto random_vertical_flip2 = std::make_shared<vision::RandomVerticalFlipWithBBoxOperation>(3.0);
Status rc2 = random_vertical_flip2->ValidateParams();
EXPECT_ERROR(rc2);
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,13 +34,16 @@ class MindDataTestJiebaTokenizerOp : public UT::DatasetOpTesting {
}
};
/// Feature: JiebaTokenizer op
/// Description: Test JiebaTokenizerOp basic Compute
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestJiebaTokenizerOp, TestJieba_opFuntions) {
MS_LOG(INFO) << "Doing MindDataTestJiebaTokenizerOp TestJieba_opFuntions.";
std::string dataset_path = datasets_root_path_ + "/jiebadict";
std::string hmm_path = dataset_path + "/hmm_model.utf8";
std::string mp_path = dataset_path + "/jieba.dict.utf8";
TensorRow input, output;
std::unique_ptr<JiebaTokenizerOp> op(new JiebaTokenizerOp(hmm_path, mp_path));
auto op = std::make_unique<JiebaTokenizerOp>(hmm_path, mp_path);
std::shared_ptr<Tensor> input_tensor;
Tensor::CreateScalar<std::string>("今天天气太好了我们一起去外面玩吧", &input_tensor);
@ -58,13 +61,16 @@ TEST_F(MindDataTestJiebaTokenizerOp, TestJieba_opFuntions) {
CheckEqual(output[0], {6}, "玩吧");
}
/// Feature: JiebaTokenizer op
/// Description: Test JiebaTokenizerOp AddWord
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestJiebaTokenizerOp, TestJieba_opAdd) {
MS_LOG(INFO) << "Doing MindDataTestJiebaTokenizerOp TestJieba_opAdd.";
std::string dataset_path = datasets_root_path_ + "/jiebadict";
std::string hmm_path = dataset_path + "/hmm_model.utf8";
std::string mp_path = dataset_path + "/jieba.dict.utf8";
TensorRow input, output;
std::unique_ptr<JiebaTokenizerOp> op(new JiebaTokenizerOp(hmm_path, mp_path));
auto op = std::make_unique<JiebaTokenizerOp>(hmm_path, mp_path);
op->AddWord("男默女泪");
std::shared_ptr<Tensor> input_tensor;
@ -77,13 +83,16 @@ TEST_F(MindDataTestJiebaTokenizerOp, TestJieba_opAdd) {
CheckEqual(output[0], {0}, "男默女泪");
}
/// Feature: JiebaTokenizer op
/// Description: Test JiebaTokenizerOp with an empty string input tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestJiebaTokenizerOp, TestJieba_opEmpty) {
MS_LOG(INFO) << "Doing MindDataTestJiebaTokenizerOp TestJieba_opEmpty.";
std::string dataset_path = datasets_root_path_ + "/jiebadict";
std::string hmm_path = dataset_path + "/hmm_model.utf8";
std::string mp_path = dataset_path + "/jieba.dict.utf8";
TensorRow input, output;
std::unique_ptr<JiebaTokenizerOp> op(new JiebaTokenizerOp(hmm_path, mp_path));
auto op = std::make_unique<JiebaTokenizerOp>(hmm_path, mp_path);
op->AddWord("男默女泪");
std::shared_ptr<Tensor> input_tensor;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,6 +36,9 @@ class MindDataTestMaskOp : public UT::Common {
void SetUp() { GlobalInit(); }
};
/// Feature: Mask op
/// Description: Test MaskOp basic usages
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestMaskOp, Basics) {
std::shared_ptr<Tensor> t;
Tensor::CreateFromVector(std::vector<uint32_t>({1, 2, 3, 4, 5, 6}), &t);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,10 +33,16 @@ class MindDataTestMemoryPool : public UT::Common {
}
};
/// Feature: MemoryPool
/// Description: Test dump pool info
/// Expectation: Runs successfully
TEST_F(MindDataTestMemoryPool, DumpPoolInfo) {
MS_LOG(DEBUG) << *(std::dynamic_pointer_cast<CircularPool>(mp_)) << std::endl;
}
/// Feature: MemoryPool
/// Description: Test delete operator on heap
/// Expectation: Runs successfully
TEST_F(MindDataTestMemoryPool, TestOperator1) {
Status rc;
int *p = new (&rc, mp_) int;
@ -45,6 +51,9 @@ TEST_F(MindDataTestMemoryPool, TestOperator1) {
::operator delete(p, mp_);
}
/// Feature: MemoryPool
/// Description: Test assignment operator on heap
/// Expectation: Runs successfully
TEST_F(MindDataTestMemoryPool, TestOperator3) {
Status rc;
int *p = new (&rc, mp_) int[100];
@ -57,6 +66,9 @@ TEST_F(MindDataTestMemoryPool, TestOperator3) {
}
}
/// Feature: MemoryPool
/// Description: Test Allocator usage
/// Expectation: Runs successfully
TEST_F(MindDataTestMemoryPool, TestAllocator) {
class A {
public:
@ -73,6 +85,9 @@ TEST_F(MindDataTestMemoryPool, TestAllocator) {
MS_LOG(DEBUG) << *(std::dynamic_pointer_cast<CircularPool>(mp_)) << std::endl;
}
/// Feature: MemoryPool
/// Description: Test MemGuard usage
/// Expectation: Runs successfully
TEST_F(MindDataTestMemoryPool, TestMemGuard) {
MemGuard<uint8_t> mem;
// Try some large value.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019-2021 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -59,6 +59,9 @@ std::shared_ptr<MindRecordOp> CreateMindRecord(int32_t mind_record_workers, bool
return std::move(op);
}
/// Feature: MindRecord op
/// Description: Test MindRecordOp ShardShuffle in ExecutionTree
/// Expectation: Runs successfully
TEST_F(MindDataTestMindRecordOp, TestMindRecordShuffle) {
// single MindRecord op and nothing else
//
@ -124,6 +127,9 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordShuffle) {
}
}
/// Feature: MindRecord op
/// Description: Test MindRecordOp ShardCategory in ExecutionTree
/// Expectation: Runs successfully
TEST_F(MindDataTestMindRecordOp, TestMindRecordCategory) {
// single MindRecord op and nothing else
//

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,9 @@ class MindDataTestMixUpBatchOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: MixUpBatch op
/// Description: Test MixUpBatchOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestMixUpBatchOp, TestSuccess) {
MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp success case";
std::shared_ptr<Tensor> batched_tensor;
@ -52,6 +55,9 @@ TEST_F(MindDataTestMixUpBatchOp, TestSuccess) {
EXPECT_EQ(in.at(1)->shape()[1], out.at(1)->shape()[1]);
}
/// Feature: MixUpBatch op
/// Description: Test MixUpBatchOp with labels that are not batched and 1D
/// Expectation: Throw correct error and message
TEST_F(MindDataTestMixUpBatchOp, TestFail) {
// This is a fail case because our labels are not batched and are 1-dimensional
MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp fail case";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestOneHotOp : public UT::Common {
MindDataTestOneHotOp() {}
};
/// Feature: OneHot op
/// Description: Test OneHotOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestOneHotOp, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestOneHotOp.";
std::vector<uint64_t> labels = {0, 1, 2};

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020-2021 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,6 +36,9 @@ using namespace mindspore::dataset;
class MindDataTestOptimizationPass : public UT::DatasetOpTesting {};
/// Feature: IR Optimization
/// Description: Test AutoWorkerPass on NumWorkers of IRNode ops
/// Expectation: Set num_workers correctly
TEST_F(MindDataTestOptimizationPass, MindDataTestAutoWorkerPass) {
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestAutoWorkerPass.";
@ -68,6 +71,9 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestAutoWorkerPass) {
MS_LOG(DEBUG) << map->IRNode()->Name() << ": num_worker=" << map->IRNode()->NumWorkers();
}
/// Feature: IR Optimization
/// Description: Test TensorOpFusionPass by fusing multiple tensor operations
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPass) {
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestTensorFusionPass.";
std::string folder_path = datasets_root_path_ + "/testPK/data/";
@ -87,13 +93,18 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPass) {
ASSERT_EQ(fused_ops[0]->Name(), vision::kRandomCropDecodeResizeOperation);
}
/// Feature: IR Optimization
/// Description: Test TensorOpFusionPass by prebuilding tensor ops through PreBuiltOperation
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPassPreBuiltTensorOperation) {
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestTensorFusionPassPreBuiltTensorOperation.";
std::string folder_path = datasets_root_path_ + "/testPK/data/";
// make prebuilt tensor operation
auto decode = std::make_shared<transforms::PreBuiltOperation>(vision::DecodeOperation(true).Build());
auto resize = std::make_shared<transforms::PreBuiltOperation>(
vision::RandomResizedCropOperation({100, 100}, {0.5, 1.0}, {0.1, 0.2}, InterpolationMode::kNearestNeighbour, 5).Build());
vision::RandomResizedCropOperation(
std::vector<int32_t>{100, 100}, std::vector<float>{0.5, 1.0}, std::vector<float>{0.1, 0.2},
InterpolationMode::kNearestNeighbour, 5).Build());
std::vector<std::shared_ptr<TensorOperation>> op_list = {decode, resize};
std::vector<std::string> op_name = {"image"};
std::shared_ptr<DatasetNode> root = ImageFolder(folder_path, false)->IRNode();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestPadEndOp : public UT::Common {
MindDataTestPadEndOp() {}
};
/// Feature: PadEnd op
/// Description: Test PadEndOp basic usage with int Tensor and string Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestPadEndOp, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestPadEndOp.";
@ -66,7 +69,7 @@ TEST_F(MindDataTestPadEndOp, TestOp) {
std::shared_ptr<Tensor> pad_value1;
Tensor::CreateFromVector(pad_data1[i], pad_data_shape, &pad_value1);
std::unique_ptr<PadEndOp> op(new PadEndOp(pad_shape1[i], pad_value1));
auto op = std::make_unique<PadEndOp>(pad_shape1[i], pad_value1);
Status s = op->Compute(input1, &output);
EXPECT_TRUE(s.IsOk());
@ -110,7 +113,7 @@ TEST_F(MindDataTestPadEndOp, TestOp) {
std::shared_ptr<Tensor> output;
std::vector<TensorShape> output_shape = {TensorShape({})};
std::unique_ptr<PadEndOp> op(new PadEndOp(pad_shape2[i], pad_value2[i]));
auto op = std::make_unique<PadEndOp>(pad_shape2[i], pad_value2[i]);
Status s = op->Compute(input2, &output);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,9 +27,12 @@ class MindDataTestPadOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: Pad op
/// Description: Test PadOp basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestPadOp, TestOp) {
MS_LOG(INFO) << "Doing testPad.";
std::unique_ptr<PadOp> op(new PadOp(10, 20, 30, 40, BorderType::kConstant));
auto op = std::make_unique<PadOp>(10, 20, 30, 40, BorderType::kConstant);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
size_t actual = 0;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,9 @@ class MindDataTestPath : public UT::Common {
MindDataTestPath() {}
};
/// Feature: Path
/// Description: Test Path on a directory and on jpeg file extension
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestPath, Test1) {
Path f("/tmp");
ASSERT_TRUE(f.Exists());
@ -49,6 +52,10 @@ TEST_F(MindDataTestPath, Test1) {
ASSERT_EQ(g.Extension(), ".jpeg");
}
/// Feature: Path
/// Description: Test Path with various assignments using a Path, on empty string, std::move on Path
/// and with concatenation
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestPath, Test2) {
Path p("/tmp");
Path p2(p);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,9 @@ class MindDataTestPerfData : public UT::Common {
MindDataTestPerfData() {}
};
/// Feature: PerfData
/// Description: Test PerfData int CyclicArray and std::vector<int64_t> with AddSample by comparing them together
/// Expectation: Both CyclicArray and vector should be equal
TEST_F(MindDataTestPerfData, Test1) {
PerfData<std::vector<int64_t>> p1(2, 3);
PerfData<CyclicArray<int>> p2(2, 3);
@ -57,6 +60,9 @@ TEST_F(MindDataTestPerfData, Test1) {
EXPECT_EQ(p2[2][1], 6);
}
/// Feature: PerfData
/// Description: Test PerfData int CyclicArray by using AddSample to add rows to the CyclicArray
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestPerfData, Test2) {
auto pd = PerfData<CyclicArray<int>>(1000000, 3);
auto row = {1, 2, 3};

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -58,6 +58,9 @@ class RefCount {
std::shared_ptr<int> v_;
};
/// Feature: Queue
/// Description: Test Queue by passing shared pointer and destructor of Queue
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test1) {
// Passing shared pointer along the queue
Queue<std::shared_ptr<int>> que(3);
@ -95,6 +98,9 @@ TEST_F(MindDataTestQueue, Test1) {
ASSERT_TRUE(rc.IsOk());
}
/// Feature: Queue
/// Description: Test Queue by passing Status object and destructor of Queue
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test2) {
// Passing status object
Queue<Status> que(3);
@ -113,9 +119,12 @@ TEST_F(MindDataTestQueue, Test2) {
ASSERT_TRUE(rc_recv2 == StatusCode::kMDOutOfMemory);
}
/// Feature: Queue
/// Description: Test Queue by passing unique pointer and destructor of Queue
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test3) {
Queue<std::unique_ptr<int>> que(3);
std::unique_ptr<int> a(new int(3));
auto a = std::make_unique<int>(3);
Status rc = que.Add(std::move(a));
ASSERT_TRUE(rc.IsOk());
ASSERT_EQ(a.get(), nullptr);
@ -134,7 +143,8 @@ void test4() {
gRefCountDestructorCalled = 0;
// Pass a structure along the queue.
Queue<RefCount> que(3);
RefCount a(3);
int num {3};
RefCount a(num);
Status rc = que.Add(a);
ASSERT_TRUE(rc.IsOk());
RefCount b;
@ -147,8 +157,14 @@ void test4() {
ASSERT_TRUE(rc.IsOk());
}
/// Feature: Queue
/// Description: Test Queue by passing a structure and destructor of Queue
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test4) { test4(); }
/// Feature: Queue
/// Description: Test destructor of RefCount after running Test4
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test5) {
test4();
// Assume we have run Test4. The destructor of the RefCount should be called 4 times.
@ -157,6 +173,9 @@ TEST_F(MindDataTestQueue, Test5) {
ASSERT_EQ(gRefCountDestructorCalled, 6);
}
/// Feature: Queue
/// Description: Test list of Queues by inserting a number into a specific queue and pop it
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestQueue, Test6) {
// Create a list of queues
QueueList<std::unique_ptr<int>> my_list_of_queues;
@ -165,7 +184,7 @@ TEST_F(MindDataTestQueue, Test6) {
const int queue_capacity = 3;
my_list_of_queues.Init(num_queues, queue_capacity);
// Now try to insert a number into a specific queue and pop it
std::unique_ptr<int> a(new int(99));
auto a = std::make_unique<int>(99);
Status rc = my_list_of_queues[chosen_queue_index]->Add(std::move(a));
ASSERT_TRUE(rc.IsOk());
std::unique_ptr<int> pepped_value;
@ -175,9 +194,9 @@ TEST_F(MindDataTestQueue, Test6) {
ASSERT_EQ(*pepped_value, 99);
}
// Feature: Test basic check in the resize.
// Description: Check false input for resize function.
// Expectation: Return false when the input is unexpected, and true when the new capacity is the same as original.
/// Feature: Test basic check in the resize.
/// Description: Check false input for resize function.
/// Expectation: Return false when the input is unexpected, and true when the new capacity is the same as original.
TEST_F(MindDataTestQueue, TestResize1) {
// Create a list of queues with capacity = 3
Queue<TensorRow> queue(3);
@ -210,9 +229,9 @@ TEST_F(MindDataTestQueue, TestResize1) {
EXPECT_OK(queue.Resize(3));
}
// Feature: Check resize is finished without changing elements and influencing operations.
// Description: Compare elements in queue before and after resize, and test add/pop/reset.
// Expectation: Elements in queue after resize are the same as the original queue.
/// Feature: Check resize is finished without changing elements and influencing operations.
/// Description: Compare elements in queue before and after resize, and test add/pop/reset.
/// Expectation: Elements in queue after resize are the same as the original queue.
TEST_F(MindDataTestQueue, TestResize2) {
// Create a list of queues with capacity = 3
Queue<TensorRow> queue(3);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,13 +26,18 @@ class MindDataTestRandomAffineOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomAffineOp() : CVOpCommon() {}
};
/// Feature: RandomAffine op
/// Description: Test RandomAffineOp basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomAffineOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomAffineOp.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomAffineOp> op(new RandomAffineOp({30.0, 30.0}, {0.0, 0.0, 0.0, 0.0}, {2.0, 2.0},
{10.0, 10.0, 20.0, 20.0}, InterpolationMode::kNearestNeighbour,
{255, 0, 0}));
auto op = std::make_unique<RandomAffineOp>(std::vector<float>{30.0, 30.0}, std::vector<float>{0.0, 0.0, 0.0, 0.0},
std::vector<float>{2.0, 2.0},
std::vector<float>{10.0, 10.0, 20.0, 20.0},
InterpolationMode::kNearestNeighbour,
std::vector<uint8_t>{255, 0, 0});
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,11 +26,14 @@ class MindDataTestRandomColorAdjustOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomColorAdjustOp() : CVOpCommon() {}
};
/// Feature: RandomColorAdjust op
/// Description: Test RandomColorAdjustOp basic usage and check OneToOne
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestRandomColorAdjustOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomColorAdjustOp.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomColorAdjustOp> op(new RandomColorAdjustOp(0.7, 1.3, 0.8, 1.2, 0.8, 1.2, -0.2, 0.2));
auto op = std::make_unique<RandomColorAdjustOp>(0.7, 1.3, 0.8, 1.2, 0.8, 1.2, -0.2, 0.2);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
@ -38,11 +41,14 @@ TEST_F(MindDataTestRandomColorAdjustOp, TestOp1) {
EXPECT_EQ(input_tensor_->shape()[1], output_tensor->shape()[1]);
}
/// Feature: RandomColorAdjust op
/// Description: Test RandomColorAdjustOp basic usage
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestRandomColorAdjustOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomColorAdjustOp2.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomColorAdjustOp> op(new RandomColorAdjustOp(0.7, 1.3, 0.8, 1.2, 0.8, 1.2, -0.2, 0.2));
auto op = std::make_unique<RandomColorAdjustOp>(0.7, 1.3, 0.8, 1.2, 0.8, 1.2, -0.2, 0.2);
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
@ -50,11 +56,14 @@ TEST_F(MindDataTestRandomColorAdjustOp, TestOp2) {
EXPECT_EQ(input_tensor_->shape()[1], output_tensor->shape()[1]);
}
/// Feature: RandomColorAdjust op
/// Description: Test RandomColorAdjustOp with min max brightness=0.8 and min max hue=0.0
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestRandomColorAdjustOp, TestOp3) {
MS_LOG(INFO) << "Doing testRandomColorAdjustOp Brightness.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomColorAdjustOp> op(new RandomColorAdjustOp(0.8, 0.8, 0, 0, 0, 0, 0, 0));
auto op = std::make_unique<RandomColorAdjustOp>(0.8, 0.8, 0, 0, 0, 0, 0, 0);
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
@ -62,11 +71,14 @@ TEST_F(MindDataTestRandomColorAdjustOp, TestOp3) {
EXPECT_EQ(input_tensor_->shape()[1], output_tensor->shape()[1]);
}
/// Feature: RandomColorAdjust op
/// Description: Test RandomColorAdjustOp with min max brightness=0.8 and min max hue=0.2
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestRandomColorAdjustOp, TestOp4) {
MS_LOG(INFO) << "Doing testRandomColorAdjustOp Brightness.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomColorAdjustOp> op(new RandomColorAdjustOp(0.8, 0.8, 0, 0, 0, 0, 0.2, 0.2));
auto op = std::make_unique<RandomColorAdjustOp>(0.8, 0.8, 0, 0, 0, 0, 0.2, 0.2);
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -69,6 +69,9 @@ int64_t Compare(std::shared_ptr<Tensor> t1, std::shared_ptr<Tensor> t2) {
// these tests are tautological, write better tests when the requirements for the output are determined
// e. g. how do we want to convert to gray and what does it mean to blend with a gray image (pre- post- gamma corrected,
// what weights).
/// Feature: RandomColor op
/// Description: Test RandomColorOp with lower bound equal to upper bound equal to 1
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomColorOp, TestOp1) {
std::shared_ptr<Tensor> output_tensor;
auto op = RandomColorOp(1, 1);
@ -77,6 +80,9 @@ TEST_F(MindDataTestRandomColorOp, TestOp1) {
EXPECT_EQ(0, res);
}
/// Feature: RandomColor op
/// Description: Test RandomColorOp with lower bound equal to upper bound equal to 0
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomColorOp, TestOp2) {
std::shared_ptr<Tensor> output_tensor;
auto op = RandomColorOp(0, 0);
@ -86,6 +92,9 @@ TEST_F(MindDataTestRandomColorOp, TestOp2) {
EXPECT_EQ(res, 0);
}
/// Feature: RandomColor op
/// Description: Test RandomColorOp with lower bound=0.0 and upper bound=1.0
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomColorOp, TestOp3) {
std::shared_ptr<Tensor> output_tensor;
auto op = RandomColorOp(0.0, 1.0);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,10 @@ class MindDataTestRandomCropAndResizeOp : public UT::CVOP::CVOpCommon {
public:
MindDataTestRandomCropAndResizeOp() : CVOpCommon() {}
};
/// Feature: RandomCropAndResize op
/// Description: Test RandomCropAndResizeOp with aspect_lb=2, aspect_ub=2.5, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomCropAndResizeOp, TestOpSimpleTest1) {
MS_LOG(INFO) << " starting RandomCropAndResizeOp simple test";
TensorShape s_in = input_tensor_->shape();
@ -51,6 +55,10 @@ TEST_F(MindDataTestRandomCropAndResizeOp, TestOpSimpleTest1) {
MS_LOG(INFO) << "RandomCropAndResizeOp simple test finished";
}
/// Feature: RandomCropAndResize op
/// Description: Test RandomCropAndResizeOp with aspect_lb=1, aspect_ub=1.5, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomCropAndResizeOp, TestOpSimpleTest2) {
MS_LOG(INFO) << " starting RandomCropAndResizeOp simple test";
TensorShape s_in = input_tensor_->shape();
@ -77,6 +85,10 @@ TEST_F(MindDataTestRandomCropAndResizeOp, TestOpSimpleTest2) {
MS_LOG(INFO) << "RandomCropAndResizeOp simple test finished";
}
/// Feature: RandomCropAndResize op
/// Description: Test RandomCropAndResizeOp with aspect_lb=0.2, aspect_ub=3, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomCropAndResizeOp, TestOpSimpleTest3) {
MS_LOG(INFO) << " starting RandomCropAndResizeOp simple test";
TensorShape s_in = input_tensor_->shape();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020-2021 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,9 @@ class MindDataTestRandomCropAndResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxO
MindDataTestRandomCropAndResizeWithBBoxOp() : BBoxOpCommon() {}
};
/// Feature: RandomCropAndResizeWithBBox op
/// Description: Test RandomCropAndResizeWithBBoxOp with aspect_lb=2, aspect_ub=2.5, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp1.";
// setting seed here
@ -60,6 +63,9 @@ TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp1) {
GlobalContext::config_manager()->set_seed(current_seed);
}
/// Feature: RandomCropAndResizeWithBBox op
/// Description: Test RandomCropAndResizeWithBBoxOp with aspect_lb=1, aspect_ub=1.5, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp2.";
// setting seed here to prevent random core dump
@ -82,6 +88,9 @@ TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp2) {
GlobalContext::config_manager()->set_seed(current_seed);
}
/// Feature: RandomCropAndResizeWithBBox op
/// Description: Test RandomCropAndResizeWithBBoxOp with aspect_lb=0.2, aspect_ub=3, scale_lb=0.2, and scale_ub=2.0
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomCropAndResizeWithBBoxOp, TestOp3) {
MS_LOG(INFO) << "Doing testRandomCropAndResizeWithBBoxOp3.";
TensorRow output_tensor_row_;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,9 @@ class MindDataTestRandomCropDecodeResizeOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomCropDecodeResizeOp() : CVOpCommon() {}
};
/// Feature: RandomCropDecodeResize op
/// Description: Test RandomCropDecodeResizeOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp2) {
MS_LOG(INFO) << "starting RandomCropDecodeResizeOp test 1";
@ -83,6 +86,9 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp2) {
MS_LOG(INFO) << "RandomCropDecodeResizeOp test 1 finished";
}
/// Feature: RandomCropDecodeResize op
/// Description: Test by applying individual ops: Decode op and Crop op, and JpegCropAndDecode op
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp1) {
MS_LOG(INFO) << "starting RandomCropDecodeResizeOp test 2";
constexpr int h = 884;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,12 +27,15 @@ class MindDataTestRandomCropOp : public UT::CVOP::CVOpCommon {
TensorRow output_tensor_row;
};
/// Feature: RandomCrop op
/// Description: Test RandomCropOp with crop size (128, 128) and padding = (0, 0, 0, 0)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomCrop.";
// Crop params
unsigned int crop_height = 128;
unsigned int crop_width = 128;
std::unique_ptr<RandomCropOp> op(new RandomCropOp(crop_height, crop_width, 0, 0, 0, 0, false, BorderType::kConstant));
auto op = std::make_unique<RandomCropOp>(crop_height, crop_width, 0, 0, 0, 0, false, BorderType::kConstant);
TensorRow input_tensor_row;
input_tensor_row.push_back(input_tensor_);
input_tensor_row.push_back(input_tensor_);
@ -47,6 +50,9 @@ TEST_F(MindDataTestRandomCropOp, TestOp1) {
}
}
/// Feature: RandomCrop op
/// Description: Test RandomCropOp with crop size (1280, 1280) and padding = (513, 513, 513, 513)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCrop.";
// Crop params
@ -55,8 +61,8 @@ TEST_F(MindDataTestRandomCropOp, TestOp2) {
TensorRow input_tensor_row;
input_tensor_row.push_back(input_tensor_);
input_tensor_row.push_back(input_tensor_);
std::unique_ptr<RandomCropOp> op(
new RandomCropOp(crop_height, crop_width, 513, 513, 513, 513, false, BorderType::kConstant));
auto op = std::make_unique<RandomCropOp>(
crop_height, crop_width, 513, 513, 513, 513, false, BorderType::kConstant);
Status s = op->Compute(input_tensor_row, &output_tensor_row);
EXPECT_EQ(true, s.IsOk());
MS_LOG(INFO) << "testRandomCrop end.";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020-2021 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,6 +32,9 @@ class MindDataTestRandomCropWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
TensorRow output_tensor_row_;
};
/// Feature: RandomCropWithBBox op
/// Description: Test RandomCropWithBBoxOp with crop size (128, 128) and padding = (0, 0, 0, 0)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomCropWithBBoxOp1.";
TensorTable results;
@ -40,8 +43,8 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp1) {
// setting seed here
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
std::unique_ptr<RandomCropWithBBoxOp> op(
new RandomCropWithBBoxOp(crop_height, crop_width, 0, 0, 0, 0, false, BorderType::kConstant));
auto op = std::make_unique<RandomCropWithBBoxOp>(
crop_height, crop_width, 0, 0, 0, 0, false, BorderType::kConstant);
for (auto tensor_row_ : images_and_annotations_) {
Status s = op->Compute(tensor_row_, &output_tensor_row_);
size_t actual = 0;
@ -66,6 +69,9 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp1) {
MS_LOG(INFO) << "testRandomCropWithBBoxOp1 end.";
}
/// Feature: RandomCropWithBBox op
/// Description: Test RandomCropWithBBoxOp with crop size (1280, 1280) and padding = (513, 513, 513, 513)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
MS_LOG(INFO) << "Doing testRandomCropWithBBoxOp2.";
// Crop params
@ -75,8 +81,8 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
std::unique_ptr<RandomCropWithBBoxOp> op(
new RandomCropWithBBoxOp(crop_height, crop_width, 513, 513, 513, 513, false, BorderType::kConstant));
auto op = std::make_unique<RandomCropWithBBoxOp>(
crop_height, crop_width, 513, 513, 513, 513, false, BorderType::kConstant);
for (auto tensor_row_ : images_and_annotations_) {
Status s = op->Compute(tensor_row_, &output_tensor_row_);
@ -93,6 +99,9 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
GlobalContext::config_manager()->set_seed(current_seed);
}
/// Feature: RandomCropWithBBox op
/// Description: Test RandomCropWithBBoxOp with crop size (1280, 1280) and padding = (3841, 3841, 3841, 3841)
/// Expectation: Throw correct error and message
TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp3) {
MS_LOG(INFO) << "Doing testRandomCropWithBBoxOp3.";
// Crop params
@ -102,9 +111,9 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp3) {
uint32_t current_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(327362);
std::unique_ptr<RandomCropWithBBoxOp> op(new RandomCropWithBBoxOp(crop_height, crop_width, crop_height * 3 + 1,
auto op = std::make_unique<RandomCropWithBBoxOp>(crop_height, crop_width, crop_height * 3 + 1,
crop_height * 3 + 1, crop_width * 3 + 1,
crop_width * 3 + 1, false, BorderType::kConstant));
crop_width * 3 + 1, false, BorderType::kConstant);
for (auto tensor_row_ : images_and_annotations_) {
Status s = op->Compute(tensor_row_, &output_tensor_row_);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,9 @@ class MindDataTestRandomHorizontalFlipOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomHorizontalFlipOp() : CVOpCommon() {}
};
/// Feature: RandomHorizontalFlip op
/// Description: Test RandomHorizontalFlipOp with prob=0.5
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomHorizontalFlipOp, TestOp) {
MS_LOG(INFO) << "Doing testHorizontalFlip.";
// flip
@ -32,7 +35,7 @@ TEST_F(MindDataTestRandomHorizontalFlipOp, TestOp) {
input_tensor_row.push_back(input_tensor_);
input_tensor_row.push_back(input_tensor_);
TensorRow output_tensor_row;
std::unique_ptr<RandomHorizontalFlipOp> op(new RandomHorizontalFlipOp(0.5));
auto op = std::make_unique<RandomHorizontalFlipOp>(0.5);
Status s = op->Compute(input_tensor_row, &output_tensor_row);
EXPECT_TRUE(s.IsOk());
CheckImageShapeAndData(input_tensor_, kFlipHorizontal);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,10 +27,13 @@ class MindDataTestRandomHorizontalFlipWithBBoxOp : public UT::CVOP::BBOXOP::BBox
MindDataTestRandomHorizontalFlipWithBBoxOp() : UT::CVOP::BBOXOP::BBoxOpCommon() {}
};
/// Feature: RandomHorizontalFlipWithBBox op
/// Description: Test RandomHorizontalFlipWithBBoxOp with prob=1
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomHorizontalFlipWithBBoxOp, TestOp) {
MS_LOG(INFO) << "Doing testRandomHorizontalFlipWithBBox.";
TensorTable results;
std::unique_ptr<RandomHorizontalFlipWithBBoxOp> op(new RandomHorizontalFlipWithBBoxOp(1));
auto op = std::make_unique<RandomHorizontalFlipWithBBoxOp>(1);
for (const auto &row: images_and_annotations_) {
TensorRow output_row;
Status s = op->Compute(row, &output_row);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,17 +26,23 @@ using namespace mindspore::dataset;
class MindDataTestRandomPosterizeOp : public UT::CVOP::CVOpCommon {
};
/// Feature: RandomPosterize op
/// Description: Test RandomPosterizeOp basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomPosterizeOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomPosterize.";
std::shared_ptr<Tensor> output_tensor;
std::unique_ptr<RandomPosterizeOp> op(new RandomPosterizeOp({1, 1}));
auto op = std::make_unique<RandomPosterizeOp>(std::vector<uint8_t>{1, 1});
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
CheckImageShapeAndData(output_tensor, kRandomPosterize);
}
/// Feature: RandomPosterize op
/// Description: Test RandomPosterizeOp in eager mode with image with HWC format
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomPosterizeOp, TestOp2) {
// Test Eager RandomPosterize image = (h, w, c)
MS_LOG(INFO) << "Doing VisionRandomPosterizeTest.";
@ -45,7 +51,7 @@ TEST_F(MindDataTestRandomPosterizeOp, TestOp2) {
Tensor::CreateFromFile(dataset_root_path + "/testPK/data/class1/0.jpg", &de_tensor);
auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
std::shared_ptr<TensorTransform> randomposterize_op(new vision::RandomPosterize({3, 5}));
auto randomposterize_op = std::make_shared<vision::RandomPosterize>(std::vector<uint8_t>{3, 5});
auto transform = Execute({decode_op, randomposterize_op});
Status rc = transform(image, &image);
EXPECT_TRUE(rc.IsOk());
@ -53,6 +59,9 @@ TEST_F(MindDataTestRandomPosterizeOp, TestOp2) {
EXPECT_EQ(image.Shape()[2], 3);
}
/// Feature: RandomPosterize op
/// Description: Test RandomPosterizeOp in eager mode with image size {2, 2, 2, 1}
/// Expectation: Throw correct error and message
TEST_F(MindDataTestRandomPosterizeOp, TestOp3) {
// Test Eager RandomSolarize image.size = {2, 2, 2, 1}
MS_LOG(INFO) << "Doing VisionRandomSolarizeTest.";
@ -60,8 +69,8 @@ TEST_F(MindDataTestRandomPosterizeOp, TestOp3) {
std::shared_ptr<Tensor> de_tensor;
Tensor::CreateFromVector(std::vector<uint8_t>({0, 25, 120, 0, 38, 2, 10, 13}), TensorShape({2, 2, 2, 1}), &de_tensor);
auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
std::shared_ptr<TensorTransform> randomsolarize_op(new vision::RandomSolarize({12, 25}));
auto transform = Execute({randomsolarize_op});
auto randomsolarize_op = std::make_shared<vision::RandomSolarize>(std::vector<uint8_t>{12, 25});
auto transform = Execute(std::vector<std::shared_ptr<TensorTransform>>{randomsolarize_op});
Status rc = transform(image, &image);
EXPECT_TRUE(rc.IsError());
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,9 @@ class MindDataTestRandomResize : public UT::CVOP::CVOpCommon {
MindDataTestRandomResize() : CVOpCommon() {}
};
/// Feature: RandomResize op
/// Description: Test RandomResizeOp with a factor of 0.5
/// Expectation: Runs successfully
TEST_F(MindDataTestRandomResize, TestOp) {
MS_LOG(INFO) << "Doing test RandomResize.";
// Resizing with a factor of 0.5
@ -36,7 +39,7 @@ TEST_F(MindDataTestRandomResize, TestOp) {
input_tensor_row.push_back(input_tensor_);
TensorRow output_tensor_row;
// Resizing
std::unique_ptr<RandomResizeOp> op(new RandomResizeOp(output_h, output_w));
auto op = std::make_unique<RandomResizeOp>(output_h, output_w);
Status st = op->Compute(input_tensor_row, &output_tensor_row);
EXPECT_TRUE(st.IsOk());
MS_LOG(INFO) << "testResize end.";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,13 +30,17 @@ class MindDataTestRandomResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon
protected:
MindDataTestRandomResizeWithBBoxOp() : BBoxOpCommon() {}
};
/// Feature: RandomResizeWithBBox op
/// Description: Test RandomResizeWithBBoxOp with single int value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomResizeWithBBoxOp, TestOp) {
MS_LOG(INFO) << "Doing testRandomResizeWithBBox.";
//setting seed here
u_int32_t curr_seed = GlobalContext::config_manager()->seed();
GlobalContext::config_manager()->set_seed(120);
TensorTable results;
std::unique_ptr<RandomResizeWithBBoxOp> op(new RandomResizeWithBBoxOp(500));
auto op = std::make_unique<RandomResizeWithBBoxOp>(500);
for (const auto &tensor_row_ : images_and_annotations_) {
// selected a tensorRow
TensorRow output_row;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,9 @@ class MindDataTestRandomRotationOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomRotationOp() : CVOpCommon() {}
};
/// Feature: RandomRotation op
/// Description: Test RandomRotationOp with basic usage using empty vector for center and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomRotationOp, TestOp) {
MS_LOG(INFO) << "Doing MindDataTestRandomRotationOp::TestOp.";
std::shared_ptr<Tensor> output_tensor;
@ -34,8 +37,8 @@ TEST_F(MindDataTestRandomRotationOp, TestOp) {
// use compute center to use for rotation
std::vector<float> center = {};
bool expand = false;
std::unique_ptr<RandomRotationOp> op(
new RandomRotationOp(sDegree, eDegree, InterpolationMode::kLinear, expand, center));
auto op = std::make_unique<RandomRotationOp>(
sDegree, eDegree, InterpolationMode::kLinear, expand, center);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,6 +28,9 @@ class MindDataTestRandomSharpness : public UT::CVOP::CVOpCommon {
MindDataTestRandomSharpness() : CVOpCommon() {}
};
/// Feature: RandomSharpness op
/// Description: Test RandomSharpnessOp with a factor in range [0.2, 1.8] and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomSharpness, TestOp) {
MS_LOG(INFO) << "Doing test RandomSharpness.";
// setting seed here
@ -38,7 +41,7 @@ TEST_F(MindDataTestRandomSharpness, TestOp) {
float end_degree = 1.8;
std::shared_ptr<Tensor> output_tensor;
// sharpening
std::unique_ptr<RandomSharpnessOp> op(new RandomSharpnessOp(start_degree, end_degree));
auto op = std::make_unique<RandomSharpnessOp>(start_degree, end_degree);
EXPECT_TRUE(op->OneToOne());
Status st = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(st.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -29,6 +29,9 @@ class MindDataTestRandomSolarizeOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: RandomSolarize op
/// Description: Test RandomSolarizeOp with basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomSolarizeOp, TestOp1) {
MS_LOG(INFO) << "Doing testRandomSolarizeOp1.";
// setting seed here
@ -36,7 +39,7 @@ TEST_F(MindDataTestRandomSolarizeOp, TestOp1) {
GlobalContext::config_manager()->set_seed(0);
std::vector<uint8_t> threshold = {100, 100};
std::unique_ptr<RandomSolarizeOp> op(new RandomSolarizeOp(threshold));
auto op = std::make_unique<RandomSolarizeOp>(threshold);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,9 @@ class MindDataTestRandomVerticalFlipOp : public UT::CVOP::CVOpCommon {
MindDataTestRandomVerticalFlipOp() : CVOpCommon() {}
};
/// Feature: RandomVerticalFlip op
/// Description: Test RandomVerticalFlipOp with prob=0.5
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomVerticalFlipOp, TestOp) {
MS_LOG(INFO) << "Doing testVerticalFlip.";
// flip
@ -32,7 +35,7 @@ TEST_F(MindDataTestRandomVerticalFlipOp, TestOp) {
input_tensor_row.push_back(input_tensor_);
input_tensor_row.push_back(input_tensor_);
TensorRow output_tensor_row;
std::unique_ptr<RandomVerticalFlipOp> op(new RandomVerticalFlipOp(0.5));
auto op = std::make_unique<RandomVerticalFlipOp>(0.5);
Status s = op->Compute(input_tensor_row, &output_tensor_row);
EXPECT_TRUE(s.IsOk());
CheckImageShapeAndData(input_tensor_, kFlipVertical);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,10 +27,14 @@ class MindDataTestRandomVerticalFlipWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOp
protected:
MindDataTestRandomVerticalFlipWithBBoxOp() : BBoxOpCommon() {}
};
/// Feature: RandomVerticalFlipWithBBox op
/// Description: Test RandomVerticalFlipWithBBoxOp with prob=1
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRandomVerticalFlipWithBBoxOp, TestOp) {
MS_LOG(INFO) << "Doing testRandomVerticalFlipWithBBoxOp.";
TensorTable results;
std::unique_ptr<RandomVerticalFlipWithBBoxOp> op(new RandomVerticalFlipWithBBoxOp(1));
auto op = std::make_unique<RandomVerticalFlipWithBBoxOp>(1);
for (const auto &tensor_row_ : images_and_annotations_) {
TensorRow output_row;
Status s = op->Compute(tensor_row_, &output_row);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,12 +25,15 @@ class MindDataTestRescaleOp : public UT::CVOP::CVOpCommon {
MindDataTestRescaleOp() : CVOpCommon() {}
};
/// Feature: Rescale op
/// Description: Test RescaleOp with rescale=1.0 / 255 and shift=1.0 and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRescaleOp, TestOp) {
// Rescale Factor
float rescale = 1.0 / 255;
float shift = 1.0;
std::unique_ptr<RescaleOp> op(new RescaleOp(rescale, shift));
auto op = std::make_unique<RescaleOp>(rescale, shift);
std::shared_ptr<Tensor> output_tensor;
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(op->OneToOne());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,9 @@ class MindDataTestResizeOp : public UT::CVOP::CVOpCommon {
MindDataTestResizeOp() : CVOpCommon() {}
};
/// Feature: Resize op
/// Description: Test ResizeOp with a factor of 0.5
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestResizeOp, TestOp) {
MS_LOG(INFO) << "Doing testResize";
// Resizing with a factor of 0.5
@ -33,7 +36,7 @@ TEST_F(MindDataTestResizeOp, TestOp) {
int output_h = (s[0] * output_w) / s[1];
std::shared_ptr<Tensor> output_tensor;
// Resizing
std::unique_ptr<ResizeOp> op(new ResizeOp(output_h, output_w));
auto op = std::make_unique<ResizeOp>(output_h, output_w);
Status st = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(st.IsOk());
CheckImageShapeAndData(output_tensor, kResizeBilinear);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,11 +27,15 @@ class MindDataTestResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
protected:
MindDataTestResizeWithBBoxOp() : BBoxOpCommon() {}
};
/// Feature: ResizeWithBBox op
/// Description: Test ResizeWithBBoxOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestResizeWithBBoxOp, TestOp) {
MS_LOG(INFO) << "Doing testResizeWithBBox.";
// resize
TensorTable results;
std::unique_ptr<ResizeWithBBoxOp> op(new ResizeWithBBoxOp(500));
auto op = std::make_unique<ResizeWithBBoxOp>(500);
for (const auto &tensor_row_ : images_and_annotations_) {
// selected a tensorRow
TensorRow output_row;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,9 +30,12 @@ class MindDataTestRgbaToBgrOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: RgbaToBgr op
/// Description: Test RgbaToBgrOp basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRgbaToBgrOp, TestOp1) {
MS_LOG(INFO) << "Doing testRGBA2BGR.";
std::unique_ptr<RgbaToBgrOp> op(new RgbaToBgrOp());
auto op = std::make_unique<RgbaToBgrOp>();
EXPECT_TRUE(op->OneToOne());
// prepare 4 channel image
cv::Mat rgba_image;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,9 +30,12 @@ class MindDataTestRgbaToRgbOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: RgbaToRgb op
/// Description: Test RgbaToRgbOp basic usage and check OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestRgbaToRgbOp, TestOp1) {
MS_LOG(INFO) << "Doing testRGBA2RGB.";
std::unique_ptr<RgbaToRgbOp> op(new RgbaToRgbOp());
auto op = std::make_unique<RgbaToRgbOp>();
EXPECT_TRUE(op->OneToOne());
// prepare 4 channel image
cv::Mat rgba_image;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,6 +31,9 @@ class MindDataTestSchema : public UT::DatasetOpTesting {
protected:
};
/// Feature: Schema
/// Description: Test DataSchema LoadSchemaFile using an old schema file
/// Expectation: Correct number of columns
TEST_F(MindDataTestSchema, TestOldSchema) {
std::string schema_file = datasets_root_path_ + "/testDataset2/datasetSchema.json";
std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
@ -44,6 +47,9 @@ TEST_F(MindDataTestSchema, TestOldSchema) {
}
}
/// Feature: Schema
/// Description: Test DataSchema LoadSchemaFile using an Album Schema file
/// Expectation: Correct number of columns
TEST_F(MindDataTestSchema, TestAlbumSchema) {
std::string schema_file = datasets_root_path_ + "/testAlbum/fullSchema.json";
std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -57,6 +57,9 @@ std::shared_ptr<TextFileOp> TextFile(std::vector<std::string> text_files_list, i
return text_file_op;
}
/// Feature: SentencePieceVocab
/// Description: Test SentencePieceVocab basic usage
/// Expectation: Runs successfully
TEST_F(MindDataTestSentencePieceVocabOp, TestSentencePieceFromFileFuntions) {
MS_LOG(INFO) << "Doing MindDataTestSentencePieceVocabOp TestSentencePieceFromFileFuntions.";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestSliceOp : public UT::Common {
MindDataTestSliceOp() {}
};
/// Feature: Slice op
/// Description: Test SliceOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpBasic) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpBasic.";
std::vector<uint64_t> labels = {1, 1, 3, 2};
@ -32,7 +35,7 @@ TEST_F(MindDataTestSliceOp, TestOpBasic) {
std::shared_ptr<Tensor> output;
Slice slice = Slice(1, 3);
std::unique_ptr<SliceOp> op(new SliceOp(SliceOption(slice)));
auto op = std::make_unique<SliceOp>(SliceOption(slice));
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 3};
@ -51,6 +54,9 @@ TEST_F(MindDataTestSliceOp, TestOpBasic) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp with negative start, stop, and step
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpNeg) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpNeg.";
std::vector<uint64_t> labels = {1, 1, 3, 6, 4, 2};
@ -59,7 +65,7 @@ TEST_F(MindDataTestSliceOp, TestOpNeg) {
std::shared_ptr<Tensor> output;
Slice slice = Slice(-1, -5, -1);
std::unique_ptr<SliceOp> op(new SliceOp(slice));
auto op = std::make_unique<SliceOp>(slice);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {2, 4, 6, 3};
@ -77,6 +83,9 @@ TEST_F(MindDataTestSliceOp, TestOpNeg) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on 2D Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOp2D) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOp2D.";
std::vector<uint64_t> labels = {1, 1, 3, 2, 3, 2};
@ -88,7 +97,7 @@ TEST_F(MindDataTestSliceOp, TestOp2D) {
Slice slice2_ = Slice(0, 1);
std::vector<SliceOption> slices_ = {SliceOption(slice1_), SliceOption(slice2_)};
std::unique_ptr<SliceOp> op(new SliceOp(slices_));
auto op = std::make_unique<SliceOp>(slices_);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 2};
@ -106,6 +115,9 @@ TEST_F(MindDataTestSliceOp, TestOp2D) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on 3D Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOp3D) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOp3D.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -117,7 +129,7 @@ TEST_F(MindDataTestSliceOp, TestOp3D) {
Slice slice2_ = Slice(0, 2);
Slice slice3_ = Slice(0, 2);
std::vector<SliceOption> slices_ = {SliceOption(slice1_), SliceOption(slice2_), SliceOption(slice3_)};
std::unique_ptr<SliceOp> op(new SliceOp(slices_));
auto op = std::make_unique<SliceOp>(slices_);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 2, 3, 4};
@ -135,6 +147,9 @@ TEST_F(MindDataTestSliceOp, TestOp3D) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp when start > stop (nothing being sliced)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpReturnNothing) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpReturnNothing.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -146,7 +161,7 @@ TEST_F(MindDataTestSliceOp, TestOpReturnNothing) {
Slice slice2_ = Slice(2, 1);
Slice slice3_ = Slice(0, 2);
std::vector<SliceOption> slices_ = {SliceOption(slice1_), SliceOption(slice2_), SliceOption(slice3_)};
std::unique_ptr<SliceOp> op(new SliceOp(slices_));
auto op = std::make_unique<SliceOp>(slices_);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {};
@ -164,6 +179,9 @@ TEST_F(MindDataTestSliceOp, TestOpReturnNothing) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp partial slice
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpPartialSlice) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpPartialSlice.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -172,7 +190,7 @@ TEST_F(MindDataTestSliceOp, TestOpPartialSlice) {
std::shared_ptr<Tensor> output;
Slice slice1_ = Slice(0, 2);
std::unique_ptr<SliceOp> op(new SliceOp(slice1_));
auto op = std::make_unique<SliceOp>(slice1_);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 2, 3, 4};
@ -190,6 +208,9 @@ TEST_F(MindDataTestSliceOp, TestOpPartialSlice) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by passing SliceOption(true) as input
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpBool1) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpBool1.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -197,7 +218,7 @@ TEST_F(MindDataTestSliceOp, TestOpBool1) {
Tensor::CreateFromVector(labels, TensorShape({2, 2, 2}), &input);
std::shared_ptr<Tensor> output;
std::unique_ptr<SliceOp> op(new SliceOp(SliceOption(true)));
auto op = std::make_unique<SliceOp>(SliceOption(true));
Status s = op->Compute(input, &output);
std::shared_ptr<Tensor> expected;
@ -214,6 +235,9 @@ TEST_F(MindDataTestSliceOp, TestOpBool1) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by passing true as input
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpBool2) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpBool2.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -221,7 +245,7 @@ TEST_F(MindDataTestSliceOp, TestOpBool2) {
Tensor::CreateFromVector(labels, TensorShape({2, 2, 2}), &input);
std::shared_ptr<Tensor> output;
std::unique_ptr<SliceOp> op(new SliceOp(true));
auto op = std::make_unique<SliceOp>(true);
Status s = op->Compute(input, &output);
std::shared_ptr<Tensor> expected;
@ -238,7 +262,9 @@ TEST_F(MindDataTestSliceOp, TestOpBool2) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
// testing passing in just indices
/// Feature: Slice op
/// Description: Test SliceOp by passing vector of SliceOption with indices
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpIndices1) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndices1.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8, 9};
@ -251,7 +277,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndices1) {
std::vector<dsize_t> index2 = {0, 1};
indices.emplace_back(SliceOption(index1));
indices.emplace_back(SliceOption(index2));
std::unique_ptr<SliceOp> op(new SliceOp(indices));
auto op = std::make_unique<SliceOp>(indices);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {4, 5, 7, 8};
@ -269,7 +295,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndices1) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
// testing passing in just indices
/// Feature: Slice op
/// Description: Test SliceOp by passing just one index
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpIndices2) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndices2.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -278,7 +306,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndices2) {
std::shared_ptr<Tensor> output;
std::vector<dsize_t> indices = {0};
std::unique_ptr<SliceOp> op(new SliceOp(indices));
auto op = std::make_unique<SliceOp>(indices);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 2, 3, 4};
@ -297,7 +325,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndices2) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
// Test Index Object
/// Feature: Slice op
/// Description: Test SliceOp by passing SliceOption passed with indices and SliceOption passed with Slice
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpSliceAndIndex) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpSliceAndIndex.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -308,7 +338,7 @@ TEST_F(MindDataTestSliceOp, TestOpSliceAndIndex) {
std::vector<dsize_t> indices = {0};
Slice slice = Slice(1);
std::vector<SliceOption> slice_options = {SliceOption(indices), SliceOption(slice)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 2};
@ -326,6 +356,9 @@ TEST_F(MindDataTestSliceOp, TestOpSliceAndIndex) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp with step larger than the vector dimension
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpLargerStep) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpLargerStep.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5};
@ -337,7 +370,7 @@ TEST_F(MindDataTestSliceOp, TestOpLargerStep) {
Slice slice2_ = Slice(0, 4, 2);
std::vector<SliceOption> slice_options = {SliceOption(slice1_), SliceOption(slice2_)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<uint64_t> out = {1, 3};
@ -356,6 +389,9 @@ TEST_F(MindDataTestSliceOp, TestOpLargerStep) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp with empty indices and slices
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesError1) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesError1.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -363,7 +399,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError1) {
Tensor::CreateFromVector(labels, TensorShape({2, 2, 2}), &input);
std::shared_ptr<Tensor> output;
std::unique_ptr<SliceOp> op(new SliceOp(Slice()));
auto op = std::make_unique<SliceOp>(Slice());
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());
@ -372,6 +408,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError1) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by providing indices and slices
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesError2) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesError2.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -382,7 +421,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError2) {
SliceOption slice_option = SliceOption(Slice(2));
std::vector<dsize_t> indices = {0};
slice_option.indices_ = indices;
std::unique_ptr<SliceOp> op(new SliceOp(slice_option));
auto op = std::make_unique<SliceOp>(slice_option);
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());
@ -391,6 +430,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError2) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by providing out of bounds index
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesError3) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesError3.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -400,7 +442,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError3) {
std::shared_ptr<Tensor> output;
std::vector<dsize_t> indices = {8};
std::unique_ptr<SliceOp> op(new SliceOp(SliceOption(indices)));
auto op = std::make_unique<SliceOp>(SliceOption(indices));
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());
@ -409,6 +451,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesError3) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpBasicString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpBasicString.";
std::vector<std::string> labels = {"1", "1", "3", "2d"};
@ -417,7 +462,7 @@ TEST_F(MindDataTestSliceOp, TestOpBasicString) {
std::shared_ptr<Tensor> output;
Slice slice = Slice(1, 3);
std::unique_ptr<SliceOp> op(new SliceOp(slice));
auto op = std::make_unique<SliceOp>(slice);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1", "3"};
@ -435,6 +480,9 @@ TEST_F(MindDataTestSliceOp, TestOpBasicString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on 2D Tensor of strings
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOp2DString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOp2DString.";
std::vector<std::string> labels = {"1a", "1b", "3", "2", "3", "2"};
@ -446,7 +494,7 @@ TEST_F(MindDataTestSliceOp, TestOp2DString) {
Slice slice2_ = Slice(0, 2);
std::vector<SliceOption> slice_option = {SliceOption(slice1_), SliceOption(slice2_)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_option));
auto op = std::make_unique<SliceOp>(slice_option);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1a", "1b", "2", "3"};
@ -464,6 +512,9 @@ TEST_F(MindDataTestSliceOp, TestOp2DString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings partial slice
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpPartialSliceString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpPartialSliceString.";
std::vector<std::string> labels = {"1a", "1b", "3", "2", "3", "2", "4", "66"};
@ -475,7 +526,7 @@ TEST_F(MindDataTestSliceOp, TestOpPartialSliceString) {
Slice slice2 = Slice(0, 1);
std::vector<SliceOption> slice_options = {SliceOption(slice1), SliceOption(slice2)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1a", "1b", "3", "2"};
@ -493,6 +544,9 @@ TEST_F(MindDataTestSliceOp, TestOpPartialSliceString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by passing vector of SliceOption with indices
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpIndicesString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesString.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
@ -504,7 +558,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesString) {
std::vector<dsize_t> index2 = {0, 1};
std::vector<SliceOption> slice_options = {SliceOption(index1), SliceOption(index2)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"4", "5", "7", "8"};
@ -522,6 +576,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings with single index
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpIndicesString2) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesString2.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5", "6", "7", "8"};
@ -530,7 +587,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesString2) {
std::shared_ptr<Tensor> output;
std::vector<dsize_t> indices = {0};
std::unique_ptr<SliceOp> op(new SliceOp(indices));
auto op = std::make_unique<SliceOp>(indices);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1", "2", "3", "4"};
@ -549,6 +606,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesString2) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings with SliceOption with indices and SliceOption with slice
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpSliceAndIndexString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpSliceAndIndexString.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5", "6", "7", "8"};
@ -559,7 +619,7 @@ TEST_F(MindDataTestSliceOp, TestOpSliceAndIndexString) {
std::vector<dsize_t> indices = {0};
Slice slice = Slice(1);
std::vector<SliceOption> slice_options = {SliceOption(indices), SliceOption(slice)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1", "2"};
@ -577,6 +637,9 @@ TEST_F(MindDataTestSliceOp, TestOpSliceAndIndexString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings with step larger than the Tensor dimension
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSliceOp, TestOpLargerStepString) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpLargerStepString.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5"};
@ -588,7 +651,7 @@ TEST_F(MindDataTestSliceOp, TestOpLargerStepString) {
Slice slice2_ = Slice(0, 4, 2);
std::vector<SliceOption> slice_options = {SliceOption(slice1_), SliceOption(slice2_)};
std::unique_ptr<SliceOp> op(new SliceOp(slice_options));
auto op = std::make_unique<SliceOp>(slice_options);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"1", "3"};
@ -607,6 +670,9 @@ TEST_F(MindDataTestSliceOp, TestOpLargerStepString) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings with empty indices and slices
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString1) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesErrorString1.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5", "6", "7", "8"};
@ -614,7 +680,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString1) {
Tensor::CreateFromVector(labels, TensorShape({2, 2, 2}), &input);
std::shared_ptr<Tensor> output;
std::unique_ptr<SliceOp> op(new SliceOp(Slice()));
auto op = std::make_unique<SliceOp>(Slice());
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());
@ -623,6 +689,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString1) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp on Tensor of strings by providing both indices and slices
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString2) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesErrorString2.";
std::vector<std::string> labels = {"1", "2", "3", "4", "5", "6", "7", "8"};
@ -633,7 +702,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString2) {
SliceOption slice_option = SliceOption(Slice(2));
std::vector<dsize_t> indices = {0};
slice_option.indices_ = indices;
std::unique_ptr<SliceOp> op(new SliceOp(slice_option));
auto op = std::make_unique<SliceOp>(slice_option);
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());
@ -642,6 +711,9 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString2) {
MS_LOG(INFO) << "MindDataTestSliceOp-TestOp end.";
}
/// Feature: Slice op
/// Description: Test SliceOp by providing out of bound index
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString3) {
MS_LOG(INFO) << "Doing MindDataTestSliceOp-TestOpIndicesErrorString3.";
std::vector<uint64_t> labels = {1, 2, 3, 4, 5, 6, 7, 8};
@ -651,7 +723,7 @@ TEST_F(MindDataTestSliceOp, TestOpIndicesErrorString3) {
std::shared_ptr<Tensor> output;
std::vector<dsize_t> indices = {2};
std::unique_ptr<SliceOp> op(new SliceOp(SliceOption(indices)));
auto op = std::make_unique<SliceOp>(SliceOption(indices));
Status s = op->Compute(input, &output);
EXPECT_FALSE(s.IsOk());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestSlidingWindowOp : public UT::Common {
MindDataTestSlidingWindowOp() {}
};
/// Feature: SlidingWindow op
/// Description: Test SlidingWindowOp's Compute
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSlidingWindowOp, Compute) {
MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->Compute.";
std::vector<std::string> strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
@ -32,7 +35,7 @@ TEST_F(MindDataTestSlidingWindowOp, Compute) {
Tensor::CreateFromVector(strings, shape, &input);
std::shared_ptr<Tensor> output;
std::unique_ptr<SlidingWindowOp> op(new SlidingWindowOp(3, 0));
auto op = std::make_unique<SlidingWindowOp>(3, 0);
Status s = op->Compute(input, &output);
std::vector<std::string> out = {"one", "two", "three", "two", "three", "four", "three", "four", "five",
@ -49,6 +52,9 @@ TEST_F(MindDataTestSlidingWindowOp, Compute) {
MS_LOG(INFO) << "MindDataTestSlidingWindowOp end.";
}
/// Feature: SlidingWindow op
/// Description: Test SlidingWindowOp's OutputShape
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestSlidingWindowOp, OutputShape) {
MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->OutputShape.";
std::vector<std::string> strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
@ -58,7 +64,7 @@ TEST_F(MindDataTestSlidingWindowOp, OutputShape) {
std::vector<TensorShape> input_shape = {input->shape()};
std::vector<TensorShape> output_shape = {TensorShape({})};
std::unique_ptr<SlidingWindowOp> op(new SlidingWindowOp(3, 0));
auto op = std::make_unique<SlidingWindowOp>(3, 0);
Status s = op->OutputShape(input_shape, output_shape);
MS_LOG(DEBUG) << "input_shape" << input_shape[0];

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,21 +30,27 @@ class MindDataTestSolarizeOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: Solarize op
/// Description: Test SolarizeOp OneToOne
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSolarizeOp, TestOp1) {
MS_LOG(INFO) << "Doing testSolarizeOp1.";
std::unique_ptr<SolarizeOp> op(new SolarizeOp());
auto op = std::make_unique<SolarizeOp>();
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
EXPECT_TRUE(s.IsOk());
}
/// Feature: Solarize op
/// Description: Test SolarizeOp with default values
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSolarizeOp, TestOp2) {
MS_LOG(INFO) << "Doing testSolarizeOp2 - test default values";
// unsigned int threshold = 128;
std::unique_ptr<SolarizeOp> op(new SolarizeOp());
auto op = std::make_unique<SolarizeOp>();
std::vector<uint8_t> test_vector = {3, 4, 59, 210, 255};
std::vector<uint8_t> expected_output_vector = {252, 251, 196, 45, 0};
@ -67,12 +73,15 @@ TEST_F(MindDataTestSolarizeOp, TestOp2) {
ASSERT_TRUE(*test_output_tensor == *expected_output_tensor);
}
/// Feature: Solarize op
/// Description: Test SolarizeOp by passing only threshold_min parameter
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSolarizeOp, TestOp3) {
MS_LOG(INFO) << "Doing testSolarizeOp3 - Pass in only threshold_min parameter";
// unsigned int threshold = 128;
std::vector<uint8_t> threshold ={1, 255};
std::unique_ptr<SolarizeOp> op(new SolarizeOp(threshold));
auto op = std::make_unique<SolarizeOp>(threshold);
std::vector<uint8_t> test_vector = {3, 4, 59, 210, 255};
std::vector<uint8_t> expected_output_vector = {252, 251, 196, 45, 0};
@ -93,11 +102,14 @@ TEST_F(MindDataTestSolarizeOp, TestOp3) {
ASSERT_TRUE(*test_output_tensor == *expected_output_tensor);
}
/// Feature: Solarize op
/// Description: Test SolarizeOp by passing both threshold parameters
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSolarizeOp, TestOp4) {
MS_LOG(INFO) << "Doing testSolarizeOp4 - Pass in both threshold parameters.";
std::vector<uint8_t> threshold ={1, 230};
std::unique_ptr<SolarizeOp> op(new SolarizeOp(threshold));
auto op = std::make_unique<SolarizeOp>(threshold);
std::vector<uint8_t> test_vector = {3, 4, 59, 210, 255};
std::vector<uint8_t> expected_output_vector = {252, 251, 196, 45, 255};
@ -118,11 +130,14 @@ TEST_F(MindDataTestSolarizeOp, TestOp4) {
ASSERT_TRUE(*test_output_tensor == *expected_output_tensor);
}
/// Feature: Solarize op
/// Description: Test SolarizeOp on rank 2 input tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSolarizeOp, TestOp5) {
MS_LOG(INFO) << "Doing testSolarizeOp5 - Rank 2 input tensor.";
std::vector<uint8_t> threshold ={1, 230};
std::unique_ptr<SolarizeOp> op(new SolarizeOp(threshold));
auto op = std::make_unique<SolarizeOp>(threshold);
std::vector<uint8_t> test_vector = {3, 4, 59, 210, 255};
std::vector<uint8_t> expected_output_vector = {252, 251, 196, 45, 255};
@ -144,11 +159,14 @@ TEST_F(MindDataTestSolarizeOp, TestOp5) {
ASSERT_TRUE(*test_output_tensor == *expected_output_tensor);
}
/// Feature: Solarize op
/// Description: Test SolarizeOp with invalid thresholds
/// Expectation: Throw correct error and message
TEST_F(MindDataTestSolarizeOp, TestOp6) {
MS_LOG(INFO) << "Doing testSolarizeOp6 - Bad Input.";
std::vector<uint8_t> threshold ={10, 1};
std::unique_ptr<SolarizeOp> op(new SolarizeOp(threshold));
auto op = std::make_unique<SolarizeOp>(threshold);
std::vector<uint8_t> test_vector = {3, 4, 59, 210, 255};
std::shared_ptr<Tensor> test_input_tensor;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -48,6 +48,9 @@ class MindDataTestStandAloneSampler : public UT::DatasetOpTesting {
};
};
/// Feature: MindData RT DistributedSampler Support
/// Description: Test MindData RT DistributedlSampler HandshakeRandomAccessOp and GetNextSampler
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStandAloneSampler, TestDistributedSampler) {
std::vector<std::shared_ptr<Tensor>> row;
uint64_t res[6][7] = {{0, 3, 6, 9, 12, 15, 18}, {1, 4, 7, 10, 13, 16, 19}, {2, 5, 8, 11, 14, 17, 0},
@ -74,6 +77,9 @@ TEST_F(MindDataTestStandAloneSampler, TestDistributedSampler) {
}
}
/// Feature: MindData RT SequentialSampler Support
/// Description: Test MindData RT SequentialSampler HandshakeRandomAccessOp, GetNextSample, and ResetSampler
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStandAloneSampler, TestStandAoneSequentialSampler) {
std::vector<std::shared_ptr<Tensor>> row;
MockStorageOp mock(5);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,9 @@ Status f3() {
RETURN_STATUS_UNEXPECTED("Testing macro3");
}
/// Feature: Status
/// Description: Test Status default constructor
/// Expectation: Runs successfully
TEST_F(MindDataTestStatus, Test1) {
// Test default constructor which should be OK
Status rc;
@ -49,11 +52,17 @@ TEST_F(MindDataTestStatus, Test1) {
MS_LOG(DEBUG) << err2;
}
/// Feature: Status
/// Description: Test RETURN_IF_NOT_OK with Status with StatusCode::kMDUnexpectedError
/// Expectation: Runs successfully
TEST_F(MindDataTestStatus, Test2) {
Status rc = f1();
MS_LOG(DEBUG) << rc;
}
/// Feature: Status
/// Description: Test RETURN_STATUS_UNEXPECTED
/// Expectation: Runs successfully
TEST_F(MindDataTestStatus, Test3) {
Status rc = f3();
MS_LOG(DEBUG) << rc;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,9 @@ class MindDataTestSubsetRandomSampler : public UT::Common {
};
};
/// Feature: SubsetRandomSampler
/// Description: Test using all input for SubsetRandomSampler at once
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetRandomSampler, TestAllAtOnce) {
std::vector<int64_t> in({0, 1, 2, 3, 4});
std::unordered_set<int64_t> in_set(in.begin(), in.end());
@ -64,6 +67,9 @@ TEST_F(MindDataTestSubsetRandomSampler, TestAllAtOnce) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: SubsetRandomSampler
/// Description: Test SubsetRandomSampler GetNextSample method with samples_per_tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetRandomSampler, TestGetNextSample) {
int64_t total_samples = 100000 - 5;
int64_t samples_per_tensor = 10;
@ -94,6 +100,9 @@ TEST_F(MindDataTestSubsetRandomSampler, TestGetNextSample) {
ASSERT_EQ(input.size(), out.size());
}
/// Feature: SubsetRandomSampler
/// Description: Test SubsetRandomSampler ResetSampler method
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetRandomSampler, TestReset) {
std::vector<int64_t> in({0, 1, 2, 3, 4});
std::unordered_set<int64_t> in_set(in.begin(), in.end());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,9 @@ class MindDataTestSubsetSampler : public UT::Common {
};
};
/// Feature: SubsetSampler
/// Description: Test using all input for SubsetSampler at once
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetSampler, TestAllAtOnce) {
std::vector<int64_t> in({3, 1, 4, 0, 1});
std::unordered_set<int64_t> in_set(in.begin(), in.end());
@ -64,6 +67,9 @@ TEST_F(MindDataTestSubsetSampler, TestAllAtOnce) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: SubsetSampler
/// Description: Test SubsetSampler GetNextSample method with samples_per_tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetSampler, TestGetNextSample) {
int64_t total_samples = 100000 - 5;
int64_t samples_per_tensor = 10;
@ -95,6 +101,9 @@ TEST_F(MindDataTestSubsetSampler, TestGetNextSample) {
ASSERT_EQ(input.size(), out.size());
}
/// Feature: SubsetSampler
/// Description: Test SubsetSampler ResetSampler method
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSubsetSampler, TestReset) {
std::vector<int64_t> in({0, 1, 2, 3, 4});
std::unordered_set<int64_t> in_set(in.begin(), in.end());

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,10 +27,13 @@ class MindDataTestSwapRedBlueOp : public UT::CVOP::CVOpCommon {
std::shared_ptr<Tensor> output_tensor_;
};
/// Feature: SwapRedBlue op
/// Description: Test SwapRedBlueOp with default parameters
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestSwapRedBlueOp, TestOp1) {
MS_LOG(INFO) << "Doing testSwapRedBlue.";
// SwapRedBlue params
std::unique_ptr<SwapRedBlueOp> op(new SwapRedBlueOp());
auto op = std::make_unique<SwapRedBlueOp>();
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor_);
size_t actual = 0;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -29,6 +29,9 @@ class MindDataTestTensorRowDE : public UT::Common {
void SetUp() { GlobalInit(); }
};
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using scalar bool value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowBoolTest) {
Status s;
@ -43,6 +46,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowBoolTest) {
ASSERT_EQ(*(bool_output.at(0)) == *(expected_bool.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using scalar int value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowIntTest) {
Status s;
TensorRow int_output;
@ -56,6 +62,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowIntTest) {
ASSERT_EQ(*(int_output.at(0)) == *(expected_int.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using scalar float value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowFloatTest) {
Status s;
TensorRow expected_bool;
@ -70,6 +79,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowFloatTest) {
ASSERT_EQ(*(float_output.at(0)) == *(expected_float.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using vector of bool
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowBoolVectorTest) {
Status s;
TensorRow bool_output;
@ -83,6 +95,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowBoolVectorTest) {
ASSERT_EQ(*(bool_output.at(0)) == *(expected_bool.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using vector of int
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowIntVectorTest) {
Status s;
TensorRow int_output;
@ -96,6 +111,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowIntVectorTest) {
ASSERT_EQ(*(int_output.at(0)) == *(expected_int.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow using vector of float
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowFloatVectorTest) {
Status s;
TensorRow float_output;
@ -109,6 +127,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowFloatVectorTest) {
ASSERT_EQ(*(float_output.at(0)) == *(expected_float.at(0)), true);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using scalar bool value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowBoolTest) {
Status s;
bool bool_value = true;
@ -122,6 +143,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowBoolTest) {
ASSERT_EQ(bool_value, result);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using scalar int value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowIntTest) {
Status s;
int32_t int_value = 12;
@ -135,6 +159,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowIntTest) {
ASSERT_EQ(int_value, result);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using scalar float value
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowFloatTest) {
Status s;
float float_value = 12.57;
@ -148,6 +175,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowFloatTest) {
ASSERT_EQ(float_value, result);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using vector of bools
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowBoolVectorTest) {
Status s;
std::vector<bool> bool_value = {true, false};
@ -161,6 +191,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowBoolVectorTest) {
ASSERT_EQ(result, bool_value);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using vector of ints
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowIntVectorTest) {
Status s;
std::vector<uint64_t> int_value = {12, 16};
@ -174,6 +207,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowIntVectorTest) {
ASSERT_EQ(result, int_value);
}
/// Feature: TensorRow
/// Description: Test ConvertFromTensorRow using vector of floats
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowFloatVectorTest) {
Status s;
std::vector<double> float_value = {12.57, 0.264};
@ -187,6 +223,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowFloatVectorTest) {
ASSERT_EQ(result, float_value);
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow with invalid data for input
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowInvalidDataTest) {
TensorRow output;
std::string string_input = "Bye";
@ -195,6 +234,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertToTensorRowInvalidDataTest) {
ASSERT_FALSE(TensorRow::ConvertToTensorRow(string_vector_input, &output).IsOk());
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow with mismatched type input
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowTypeMismatchTest) {
TensorRow input_tensor_row;
std::shared_ptr<Tensor> input_tensor1;
@ -206,6 +248,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowTypeMismatchTest) {
ASSERT_FALSE(TensorRow::ConvertFromTensorRow(input_tensor_row, &output_vector).IsOk());
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow with invalid shape input
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowInvalidShapeTest) {
TensorRow input_tensor_row;
std::shared_ptr<Tensor> input_tensor1;
@ -217,6 +262,9 @@ TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowInvalidShapeTest) {
ASSERT_FALSE(TensorRow::ConvertFromTensorRow(input_tensor_row, &output_vector).IsOk());
}
/// Feature: TensorRow
/// Description: Test ConvertToTensorRow with an empty input
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTensorRowDE, ConvertFromTensorRowEmptyInputTest) {
TensorRow input_tensor_row;
double output;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,9 @@ class MindDataTestStringTensorDE : public UT::Common {
void SetUp() override { GlobalInit(); }
};
/// Feature: Tensor
/// Description: Test creating a Tensor from a scalar string and 1D string array
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, Basics) {
std::shared_ptr<Tensor> t;
Tensor::CreateScalar<std::string>("Hi", &t);
@ -65,6 +68,9 @@ TEST_F(MindDataTestStringTensorDE, Basics) {
}
}
/// Feature: Tensor
/// Description: Test memory of Tensor created from a 1D string array
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, Basics2) {
std::shared_ptr<Tensor> t;
Tensor::CreateFromVector(std::vector<std::string>{"abc", "defg", "hi", "klmno", "123", "789"}, TensorShape({2, 3}),
@ -90,6 +96,9 @@ TEST_F(MindDataTestStringTensorDE, Basics2) {
}
}
/// Feature: Tensor
/// Description: Test creating Tensor from array of strings that contain empty strings
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, Empty) {
std::vector<std::string> strings{"abc", "defg", "", "", "123", ""};
std::shared_ptr<Tensor> t;
@ -117,6 +126,9 @@ TEST_F(MindDataTestStringTensorDE, Empty) {
}
}
/// Feature: Tensor
/// Description: Test creating Tensor from empty data
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, EmptyData) {
std::shared_ptr<Tensor> t;
Tensor::CreateScalar<std::string>("", &t);
@ -128,6 +140,9 @@ TEST_F(MindDataTestStringTensorDE, EmptyData) {
ASSERT_TRUE(!t1->HasData());
}
/// Feature: Tensor
/// Description: Test SetItemAt usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, SetItem) {
std::vector<std::string> strings{"abc", "defg", "hi", "klmno", "123", "789"};
std::shared_ptr<Tensor> t3;
@ -154,6 +169,9 @@ TEST_F(MindDataTestStringTensorDE, SetItem) {
}
}
/// Feature: Tensor
/// Description: Test iterating over a Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestStringTensorDE, Iterator) {
std::vector<std::string> strings{"abc", "defg", "hi", "klmno", "123", "789"};
std::shared_ptr<Tensor> t;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,9 @@ class MindDataTestTensorDE : public UT::Common {
void SetUp() { GlobalInit(); }
};
/// Feature: Tensor
/// Description: Test Tensor basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, Basics) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 3}), DataType(DataType::DE_UINT64), &t);
@ -74,6 +77,9 @@ TEST_F(MindDataTestTensorDE, Basics) {
ASSERT_EQ(*t != *t2, false);
}
/// Feature: Tensor
/// Description: Test Fill on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, Fill) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 2}), DataType(DataType::DE_FLOAT32), &t);
@ -84,6 +90,9 @@ TEST_F(MindDataTestTensorDE, Fill) {
ASSERT_EQ(*t == *t2, true);
}
/// Feature: Tensor
/// Description: Test Reshape on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, Reshape) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 2}), DataType(DataType::DE_UINT8), &t);
@ -104,6 +113,9 @@ TEST_F(MindDataTestTensorDE, Reshape) {
ASSERT_TRUE(rc.IsError());
}
/// Feature: Tensor
/// Description: Test copying a Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, CopyTensor) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({}), DataType(DataType::DE_INT16), &t);
@ -128,6 +140,9 @@ TEST_F(MindDataTestTensorDE, CopyTensor) {
ASSERT_TRUE(rc.IsError());
}
/// Feature: Tensor
/// Description: Test InsertTensor on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, InsertTensor) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 3}), DataType(DataType::DE_FLOAT64), &t);
@ -164,7 +179,9 @@ TEST_F(MindDataTestTensorDE, InsertTensor) {
ASSERT_EQ(*t == *t6, true);
}
// Test the bug of Tensor::ToString will exec failed for Tensor which store bool values
/// Feature: Tensor
/// Description: Test the bug of Tensor::ToString will exec failed for Tensor which store bool values
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTensorDE, BoolTensor) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2}), DataType(DataType::DE_BOOL), &t);
@ -174,6 +191,9 @@ TEST_F(MindDataTestTensorDE, BoolTensor) {
ASSERT_TRUE(out.find("Template type and Tensor type are not compatible") == std::string::npos);
}
/// Feature: Tensor
/// Description: Test GetItemAt on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, GetItemAt) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 2}), DataType(DataType::DE_UINT8), &t);
@ -216,6 +236,9 @@ TEST_F(MindDataTestTensorDE, GetItemAt) {
ASSERT_FLOAT_EQ(o10, 1.1);
}
/// Feature: Tensor
/// Description: Test assignment operator on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, OperatorAssign) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({2, 2}), DataType(DataType::DE_UINT8), &t);
@ -234,6 +257,9 @@ TEST_F(MindDataTestTensorDE, OperatorAssign) {
ASSERT_EQ(o, 1);
}
/// Feature: Tensor
/// Description: Test Strides on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, Strides) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({4, 2, 2}), DataType(DataType::DE_UINT8), &t);
@ -281,6 +307,9 @@ void checkCvMat(TensorShape shape, DataType type) {
}
}
/// Feature: CVTensor
/// Description: Test CVTensor basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, CVTensorBasics) {
checkCvMat(TensorShape({4, 5}), DataType(DataType::DE_UINT8));
checkCvMat(TensorShape({4, 5, 3}), DataType(DataType::DE_UINT8));
@ -296,6 +325,9 @@ TEST_F(MindDataTestTensorDE, CVTensorBasics) {
checkCvMat(TensorShape({}), DataType(DataType::DE_INT16));
}
/// Feature: CVTensor
/// Description: Test CVTensor::CreateFromMat
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, CVTensorFromMat) {
cv::Mat m(2, 2, CV_8U);
m.at<uint8_t>(0, 0) = 10;
@ -330,6 +362,9 @@ TEST_F(MindDataTestTensorDE, CVTensorFromMat) {
ASSERT_TRUE(*t2 == *cvt2);
}
/// Feature: CVTensor
/// Description: Test CVTensor::AsCVTensor using Tensor as input
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, CVTensorAs) {
std::shared_ptr<Tensor> t;
Tensor::CreateEmpty(TensorShape({3, 2}), DataType(DataType::DE_FLOAT64), &t);
@ -352,6 +387,9 @@ TEST_F(MindDataTestTensorDE, CVTensorAs) {
ASSERT_TRUE(*t2 == *ctv);
}
/// Feature: CVTensor
/// Description: Test CVTensor MatAtIndex
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, CVTensorMatSlice) {
cv::Mat m(2, 3, CV_32S);
m.at<int32_t>(0, 0) = 10;
@ -383,6 +421,9 @@ TEST_F(MindDataTestTensorDE, CVTensorMatSlice) {
ASSERT_TRUE(*cvt2 == *cvt3);
}
/// Feature: Tensor
/// Description: Test iterating on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, TensorIterator) {
std::vector<uint32_t> values = {1, 2, 3, 4, 5, 6};
std::vector<uint32_t> values2 = {2, 3, 4, 5, 6, 7};
@ -420,6 +461,9 @@ TEST_F(MindDataTestTensorDE, TensorIterator) {
ASSERT_TRUE(ctr == 6);
}
/// Feature: Tensor
/// Description: Test Slice on Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, TensorSlice) {
std::shared_ptr<Tensor> t;
Tensor::CreateFromVector(std::vector<dsize_t>{0, 1, 2, 3, 4}, &t);
@ -432,6 +476,9 @@ TEST_F(MindDataTestTensorDE, TensorSlice) {
ASSERT_EQ(*t2, *expected);
}
/// Feature: Tensor
/// Description: Test partial InsertTensor on Tensor
/// Expectation: Output is equal to the expected output and throw correct error if concatenated vector is too large
TEST_F(MindDataTestTensorDE, TensorPartialInsert) {
std::vector<uint32_t> values1 = {1, 2, 3, 0, 0, 0};
std::vector<uint32_t> values2 = {4, 5, 6};
@ -459,6 +506,9 @@ TEST_F(MindDataTestTensorDE, TensorPartialInsert) {
EXPECT_FALSE(s.IsOk());
}
/// Feature: Tensor
/// Description: Test creating an empty Tensor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorDE, TensorEmpty) {
TensorPtr t;
Status rc = Tensor::CreateEmpty(TensorShape({0}), DataType(DataType::DE_UINT64), &t);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,6 +32,9 @@ class MindDataTestTensorShape : public UT::Common {
MindDataTestTensorShape() = default;
};
/// Feature: TensorShape
/// Description: Test TensorShape functions where input comes from a vector
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorShape, TestBasics) {
std::vector<dsize_t> vec = {4, 5, 6};
TensorShape t(vec);
@ -62,6 +65,9 @@ TEST_F(MindDataTestTensorShape, TestBasics) {
ASSERT_EQ(t3.NumOfElements(), 0);
}
/// Feature: TensorShape
/// Description: Test TensorShape::CreateScalar() basic functions
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorShape, TestScalars) {
TensorShape t = TensorShape::CreateScalar();
ASSERT_EQ(t.Rank(), 0);
@ -72,6 +78,9 @@ TEST_F(MindDataTestTensorShape, TestScalars) {
ASSERT_EQ(t.NumOfElements(), 1);
}
/// Feature: TensorShape
/// Description: Test TensorShape dim functions (Append, Prepend, Insert)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorShape, TestDims) {
TensorShape t = TensorShape::CreateScalar();
t = t.AppendDim(1);
@ -90,6 +99,9 @@ TEST_F(MindDataTestTensorShape, TestDims) {
ASSERT_EQ(t3, TensorShape({1, 4, 2, 5, 3, 6}));
}
/// Feature: TensorShape
/// Description: Test TensorShape::CreateUnknownRankShape and TensorShape::CreateUnknownShapeWithRank
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorShape, TestUnknown) {
TensorShape t1({-1, 5, 6});
ASSERT_EQ(t1.AsVector(), std::vector<dsize_t>({-1, 5, 6}));
@ -104,7 +116,9 @@ TEST_F(MindDataTestTensorShape, TestUnknown) {
ASSERT_EQ(t4, TensorShape({-1, -1, -1}));
}
// Test materializing a TensorShape by calling method on a given column descriptor
/// Feature: TensorShape
/// Description: Test materializing a TensorShape by calling method on a given column descriptor
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTensorShape, TestColDescriptor) {
int32_t rank = 0; // not used
int32_t num_elements = 0;
@ -175,6 +189,9 @@ TEST_F(MindDataTestTensorShape, TestColDescriptor) {
ASSERT_FALSE(rc.IsOk());
}
/// Feature: TensorShape
/// Description: Test TensorShape with invalid parameters
/// Expectation: Same output as TensorShape::CreateUnknownRankeShape()
TEST_F(MindDataTestTensorShape, TestInvalid) {
ASSERT_EQ(TensorShape({kDeMaxDim - 1, kDeMaxDim - 1, kDeMaxDim - 1}), TensorShape::CreateUnknownRankShape());
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019-2021 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,9 @@ using namespace mindspore::dataset;
class MindDataTestTFReaderOp : public UT::DatasetOpTesting {};
/// Feature: TFReader op
/// Description: Test TFReaderOp with large rows per buffer
/// Expectation: Runs successfully and equal row count
TEST_F(MindDataTestTFReaderOp, TestTFReaderLargeRowsPerBuffer) {
// Start with an empty execution tree
auto my_tree = std::make_shared<ExecutionTree>();
@ -87,6 +90,9 @@ TEST_F(MindDataTestTFReaderOp, TestTFReaderLargeRowsPerBuffer) {
ASSERT_EQ(row_count, 12);
}
/// Feature: TFReader op
/// Description: Test TFReaderOp with small rows per buffer
/// Expectation: Runs successfully and equal row count
TEST_F(MindDataTestTFReaderOp, TestTFReaderSmallRowsPerBuffer) {
// Start with an empty execution tree
auto my_tree = std::make_shared<ExecutionTree>();
@ -144,6 +150,9 @@ TEST_F(MindDataTestTFReaderOp, TestTFReaderSmallRowsPerBuffer) {
ASSERT_EQ(row_count, 12);
}
/// Feature: TFReader op
/// Description: Test TFReaderOp with large queue size
/// Expectation: Runs successfully and equal row count
TEST_F(MindDataTestTFReaderOp, TestTFReaderLargeQueueSize) {
// Start with an empty execution tree
auto my_tree = std::make_shared<ExecutionTree>();
@ -201,6 +210,9 @@ TEST_F(MindDataTestTFReaderOp, TestTFReaderLargeQueueSize) {
ASSERT_EQ(row_count, 12);
}
/// Feature: TFReader op
/// Description: Test TFReaderOp with one thread
/// Expectation: Runs successfully and equal row count
TEST_F(MindDataTestTFReaderOp, TestTFReaderOneThread) {
// Start with an empty execution tree
auto my_tree = std::make_shared<ExecutionTree>();
@ -258,6 +270,9 @@ TEST_F(MindDataTestTFReaderOp, TestTFReaderOneThread) {
ASSERT_EQ(row_count, 12);
}
/// Feature: TFReader op
/// Description: Test TFReaderOp that takes 1 buffer
/// Expectation: Runs successfully and equal row count
TEST_F(MindDataTestTFReaderOp, TestTFReaderTake1Buffer) {
// Start with an empty execution tree
auto my_tree = std::make_shared<ExecutionTree>();
@ -321,6 +336,9 @@ TEST_F(MindDataTestTFReaderOp, TestTFReaderTake1Buffer) {
}
/// Feature: TFReader op
/// Description: Test TFReaderOp::CountTotalRows basic cases
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTFReaderOp, TestTotalRowsBasic) {
std::string tf_file = datasets_root_path_ + "/testTFTestAllTypes/test.data";

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,9 @@ class MindDataTestToFloat16Op : public UT::CVOP::CVOpCommon {
MindDataTestToFloat16Op() : CVOpCommon() {}
};
/// Feature: ToFloat16 op
/// Description: Test ToFloat16Op after RandomRotationOp
/// Expectation: Output's shape is equal to the expected output's shape
TEST_F(MindDataTestToFloat16Op, TestOp) {
MS_LOG(INFO) << "Doing TestRandomRotationOp::TestOp.";
std::shared_ptr<Tensor> output_tensor;
@ -35,15 +38,15 @@ TEST_F(MindDataTestToFloat16Op, TestOp) {
// use compute center to use for rotation
std::vector<float> center = {};
bool expand = false;
std::unique_ptr<RandomRotationOp> op(
new RandomRotationOp(s_degree, e_degree, InterpolationMode::kLinear, expand, center));
auto op = std::make_unique<RandomRotationOp>(
s_degree, e_degree, InterpolationMode::kLinear, expand, center);
EXPECT_TRUE(op->OneToOne());
Status s = op->Compute(input_tensor_, &output_tensor);
EXPECT_TRUE(s.IsOk());
EXPECT_EQ(input_tensor_->shape()[0], output_tensor->shape()[0]);
EXPECT_EQ(input_tensor_->shape()[1], output_tensor->shape()[1]);
std::unique_ptr<ToFloat16Op> to_float_op(new ToFloat16Op());
auto to_float_op = std::make_unique<ToFloat16Op>();
std::shared_ptr<Tensor> output_tensor1;
s = op->Compute(output_tensor, &output_tensor1);
EXPECT_EQ(output_tensor->shape()[0], output_tensor1->shape()[0]);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,9 +43,12 @@ class MindDataTestTokenizerOp : public UT::Common {
}
};
/// Feature: UnicodeCharTokenizer op
/// Description: Test UnicodeCharTokenizerOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTokenizerOp, TestUnicodeCharTokenizerOp) {
MS_LOG(INFO) << "Doing TestUnicodeCharTokenizerOp.";
std::unique_ptr<UnicodeCharTokenizerOp> op(new UnicodeCharTokenizerOp(true));
auto op = std::make_unique<UnicodeCharTokenizerOp>(true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Hello World!", &input); TensorRow output;
Status s = op->Compute(TensorRow(0, {input}), &output);
@ -118,9 +121,12 @@ output.clear();
CheckEqual(output[0], {0}, "");
}
/// Feature: WhitespaceTokenizer op
/// Description: Test WhitespaceTokenizerOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTokenizerOp, TestWhitespaceTokenizerOp) {
MS_LOG(INFO) << "Doing TestWhitespaceTokenizerOp.";
std::unique_ptr<WhitespaceTokenizerOp> op(new WhitespaceTokenizerOp(true));
auto op = std::make_unique<WhitespaceTokenizerOp>(true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China.", &input); TensorRow output;
Status s = op->Compute(TensorRow(0, {input}), &output);
@ -169,10 +175,13 @@ output.clear();
CheckEqual(output[0], {0}, "");
}
/// Feature: UnicodeScriptTokenizer op
/// Description: Test UnicodeScriptTokenizerOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTokenizerOp, TestUnicodeScriptTokenizer) {
MS_LOG(INFO) << "Doing TestUnicodeScriptTokenizer.";
std::unique_ptr<UnicodeScriptTokenizerOp> keep_whitespace_op(new UnicodeScriptTokenizerOp(true, true));
std::unique_ptr<UnicodeScriptTokenizerOp> skip_whitespace_op(new UnicodeScriptTokenizerOp(false, true));
auto keep_whitespace_op = std::make_unique<UnicodeScriptTokenizerOp>(true, true);
auto skip_whitespace_op = std::make_unique<UnicodeScriptTokenizerOp>(false, true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China. \n 中国\t北京", &input);
@ -283,9 +292,12 @@ output.clear();
CheckEqual(output[0], {0}, "");
}
/// Feature: CaseFold op
/// Description: Test CaseFoldOp basic usage
/// Expectation: Runs successfully and output is equal to the expected output
TEST_F(MindDataTestTokenizerOp, TestCaseFold) {
MS_LOG(INFO) << "Doing TestCaseFold.";
std::unique_ptr<CaseFoldOp> case_fold_op(new CaseFoldOp());
auto case_fold_op = std::make_unique<CaseFoldOp>();
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China. \n 中国\t北京", &input);
@ -298,12 +310,15 @@ TEST_F(MindDataTestTokenizerOp, TestCaseFold) {
CheckEqual(output, {}, "welcome to china. \n 中国\t北京");
}
/// Feature: NormalizeUTF8 op
/// Description: Test NormalizeUTF8Op with various NormalizeForm
/// Expectation: Runs successfully
TEST_F(MindDataTestTokenizerOp, TestNormalize) {
MS_LOG(INFO) << "Doing TestNormalize.";
std::unique_ptr<NormalizeUTF8Op> nfc_normalize_op(new NormalizeUTF8Op(NormalizeForm::kNfc));
std::unique_ptr<NormalizeUTF8Op> nfkc_normalize_op(new NormalizeUTF8Op(NormalizeForm::kNfkc));
std::unique_ptr<NormalizeUTF8Op> nfd_normalize_op(new NormalizeUTF8Op(NormalizeForm::kNfd));
std::unique_ptr<NormalizeUTF8Op> nfkd_normalize_op(new NormalizeUTF8Op(NormalizeForm::kNfkd));
auto nfc_normalize_op = std::make_unique<NormalizeUTF8Op>(NormalizeForm::kNfc);
auto nfkc_normalize_op = std::make_unique<NormalizeUTF8Op>(NormalizeForm::kNfkc);
auto nfd_normalize_op = std::make_unique<NormalizeUTF8Op>(NormalizeForm::kNfd);
auto nfkd_normalize_op = std::make_unique<NormalizeUTF8Op>(NormalizeForm::kNfkd);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("", &input);
std::shared_ptr<Tensor> output;
@ -324,9 +339,12 @@ TEST_F(MindDataTestTokenizerOp, TestNormalize) {
MS_LOG(INFO) << "NFKD str:" << output->ToString();
}
/// Feature: RegexReplace op
/// Description: Test RegexReplaceOp basic usage
/// Expectation: Runs successfully and output is equal to the expected output
TEST_F(MindDataTestTokenizerOp, TestRegexReplace) {
MS_LOG(INFO) << "Doing TestRegexReplace.";
std::unique_ptr<RegexReplaceOp> regex_replace_op(new RegexReplaceOp("\\s+", "_", true));
auto regex_replace_op = std::make_unique<RegexReplaceOp>("\\s+", "_", true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China. \n 中国\t北京", &input);
std::shared_ptr<Tensor> output;
@ -338,9 +356,12 @@ TEST_F(MindDataTestTokenizerOp, TestRegexReplace) {
CheckEqual(output, {}, "Welcome_to_China._中国_北京");
}
/// Feature: RegexTokenizer op
/// Description: Test RegexTokenizerOp basic usage
/// Expectation: Runs successfully
TEST_F(MindDataTestTokenizerOp, TestRegexTokenizer) {
MS_LOG(INFO) << "Doing TestRegexTokenizerOp.";
std::unique_ptr<RegexTokenizerOp> regex_tokenizer_op(new RegexTokenizerOp("\\p{Cc}|\\p{Cf}|\\s+", "", true));
auto regex_tokenizer_op = std::make_unique<RegexTokenizerOp>("\\p{Cc}|\\p{Cf}|\\s+", "", true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China. \n 中国\t北京", &input);
TensorRow output;
@ -348,11 +369,14 @@ std::shared_ptr<Tensor> input;
EXPECT_TRUE(s.IsOk());
}
/// Feature: BasicTokenizer op
/// Description: Test BasicTokenizerOp basic usage
/// Expectation: Runs successfully
TEST_F(MindDataTestTokenizerOp, TestBasicTokenizer) {
MS_LOG(INFO) << "Doing TestBasicTokenizer.";
// bool lower_case, bool keep_whitespace,
// NormalizeForm normalization_form, bool preserve_unused_token
std::unique_ptr<BasicTokenizerOp> basic_tokenizer(new BasicTokenizerOp(true, true, NormalizeForm::kNone, false,true));
auto basic_tokenizer = std::make_unique<BasicTokenizerOp>(true, true, NormalizeForm::kNone, false,true);
std::shared_ptr<Tensor> input;
Tensor::CreateScalar<std::string>("Welcome to China. 中国\t北京", &input);
TensorRow output;

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,9 @@ class MindDataTestTreap : public UT::Common {
MindDataTestTreap() {}
};
/// Feature: Treap
/// Description: Test all functions of Treap
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreap, TestALLFunction) {
Treap<uint64_t, uint64_t> tree;
srand(time(NULL));

View File

@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,9 @@ class MindDataTestTreeModifying : public UT::DatasetOpTesting {
MindDataTestTreeModifying() = default;
};
/// Feature: TreeAdapter modifying functions
/// Description: Test AppendChild using DatasetNode to a DatasetNode
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, AppendChild) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-AppendChild";
/*
@ -69,6 +72,9 @@ TEST_F(MindDataTestTreeModifying, AppendChild) {
EXPECT_TRUE( ds4_node->Children()[2] == node_to_insert);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test InsertChild at certain valid position using DatasetNode to a DatasetNode
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, InsertChildAt01) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-InsertChildAt01";
/*
@ -152,6 +158,9 @@ TEST_F(MindDataTestTreeModifying, InsertChildAt01) {
EXPECT_TRUE( ds4_node->Children()[2] == ds6_to_insert);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test InsertChild at invalid position using DatasetNode to a DatasetNode
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTreeModifying, InsertChildAt04) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-InsertChildAt04";
@ -203,6 +212,9 @@ TEST_F(MindDataTestTreeModifying, InsertChildAt04) {
EXPECT_TRUE( ds4_node->Children()[1] == ds2_node);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test InsertAbove using DatasetNode to a DatasetNode (in between non-leaf nodes)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, InsertAbove01) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-InsertAbove01";
/*
@ -266,6 +278,9 @@ TEST_F(MindDataTestTreeModifying, InsertAbove01) {
EXPECT_TRUE( ds4_node->Children()[0] == ds5_to_insert);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test InsertAbove using DatasetNode to a DatasetNode (in between internal node and leaf node)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, InsertAbove02) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-InsertAbove02";
@ -291,6 +306,10 @@ TEST_F(MindDataTestTreeModifying, InsertAbove02) {
EXPECT_TRUE( ds4_node->Children()[1] == ds6_to_insert);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test InsertAbove using DatasetNode to a DatasetNode
/// (in between a leaf node and internal node which sibling node is a leaf node)
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, InsertAbove03) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-InsertAbove03";
@ -316,6 +335,9 @@ TEST_F(MindDataTestTreeModifying, InsertAbove03) {
EXPECT_TRUE( ds3_node->Children()[0] == ds7_to_insert);
}
/// Feature: TreeAdapter modifying functions
/// Description: Test Drop on a DatasetNode that is a leaf node or a parent node with one child with no sibling
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, Drop01) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-Drop01";
/*
@ -399,6 +421,9 @@ TEST_F(MindDataTestTreeModifying, Drop01) {
EXPECT_TRUE(ds8_node->Children().empty());
}
/// Feature: TreeAdapter modifying functions
/// Description: Test Drop on a DatasetNode that has more than one child and no sibling
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTreeModifying, Drop03) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-Drop03";
/* Case 3: When the node has more than one child and no sibling, Drop() detaches the node from its tree and the node's
@ -443,6 +468,9 @@ TEST_F(MindDataTestTreeModifying, Drop03) {
EXPECT_NE(rc, Status::OK());
}
/// Feature: TreeAdapter modifying functions
/// Description: Test Drop on a DatasetNode that has no child but has siblings
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, Drop04) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-Drop04";
/* Case 4: When the node has no child but has siblings, Drop() detaches the node from its tree and its siblings will be
@ -499,6 +527,9 @@ TEST_F(MindDataTestTreeModifying, Drop04) {
EXPECT_TRUE(ds5_node->Children().empty());
}
/// Feature: TreeAdapter modifying functions
/// Description: Test Drop on a DatasetNode that has only one child but has siblings
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTreeModifying, Drop05) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-Drop05";
/*
@ -553,6 +584,9 @@ TEST_F(MindDataTestTreeModifying, Drop05) {
EXPECT_TRUE(ds4_node->Children().empty());
}
/// Feature: TreeAdapter modifying functions
/// Description: Test Drop on a DatasetNode that has more than one child and more than one sibling
/// Expectation: Throw correct error and message
TEST_F(MindDataTestTreeModifying, Drop06) {
MS_LOG(INFO) << "Doing MindDataTestTreeModifying-Drop06";
/*

View File

@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,6 +33,9 @@ class MindDataTestTruncatePairOp : public UT::Common {
void SetUp() { GlobalInit(); }
};
/// Feature: TruncateSequencePair op
/// Description: Test TruncateSequencePairOp basic usage
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTruncatePairOp, Basics) {
std::shared_ptr<Tensor> t1;
Tensor::CreateFromVector(std::vector<uint32_t>({1, 2, 3}), &t1);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ void testCast(std::vector<FROM> values, const DataType &from, const DataType &to
std::shared_ptr<Tensor> t;
Tensor::CreateFromVector(values, &t);
std::unique_ptr<TypeCastOp> op(new TypeCastOp(to));
auto op = std::make_unique<TypeCastOp>(to);
EXPECT_TRUE(op->OneToOne());
std::shared_ptr<Tensor> output;
EXPECT_TRUE(op->Compute(t, &output));
@ -60,6 +60,9 @@ void testCast(std::vector<FROM> values, const DataType &from, const DataType &to
}
}
/// Feature: TypeCast op
/// Description: Test TypeCastOp from UINT8
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTypeCast, CastFromUINT8) {
std::vector<uint8_t> input{0, 10, 255};
DataType input_format = DataType(DataType("uint8"));
@ -77,6 +80,9 @@ TEST_F(MindDataTestTypeCast, CastFromUINT8) {
testCast<uint8_t, bool>(input, input_format, DataType("bool"));
}
/// Feature: TypeCast op
/// Description: Test TypeCastOp from UINT64
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTypeCast, CastFromINT64) {
std::vector<int64_t> input{-9223372036854775806, 0, 9223372036854775807};
DataType input_format = DataType("int64");
@ -94,6 +100,9 @@ TEST_F(MindDataTestTypeCast, CastFromINT64) {
testCast<int64_t, bool>(input, input_format, DataType("bool"));
}
/// Feature: TypeCast op
/// Description: Test TypeCastOp from FLOAT64
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTypeCast, CastFromFLOAT64) {
std::vector<double> input{(-1) * MAX_INT_PRECISION, 0, MAX_INT_PRECISION};
DataType input_format = DataType("float64");
@ -111,6 +120,9 @@ TEST_F(MindDataTestTypeCast, CastFromFLOAT64) {
testCast<double, bool>(input, input_format, DataType("bool"));
}
/// Feature: TypeCast op
/// Description: Test TypeCastOp from FLOAT16
/// Expectation: Output is equal to the expected output
TEST_F(MindDataTestTypeCast, CastFromFLOAT16) {
float16 min(0.0005);
float16 zero(0);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,6 +40,9 @@ class MindDataTestWeightedRandomSampler : public UT::Common {
};
};
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=true
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestOneshotReplacement) {
// num samples to draw.
uint64_t num_samples = 100;
@ -69,6 +72,9 @@ TEST_F(MindDataTestWeightedRandomSampler, TestOneshotReplacement) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=false
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestOneshotNoReplacement) {
// num samples to draw.
uint64_t num_samples = 100;
@ -104,6 +110,9 @@ TEST_F(MindDataTestWeightedRandomSampler, TestOneshotNoReplacement) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=true and samples_per_tensor
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestGetNextSampleReplacement) {
// num samples to draw.
uint64_t num_samples = 100;
@ -136,6 +145,9 @@ TEST_F(MindDataTestWeightedRandomSampler, TestGetNextSampleReplacement) {
ASSERT_EQ(num_samples, out.size());
}
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=false and samples_per_tensor
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestGetNextSampleNoReplacement) {
// num samples to draw.
uint64_t num_samples = 100;
@ -179,6 +191,9 @@ TEST_F(MindDataTestWeightedRandomSampler, TestGetNextSampleNoReplacement) {
ASSERT_EQ(num_samples, out.size());
}
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=true followed by ResetSampler
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestResetReplacement) {
// num samples to draw.
uint64_t num_samples = 1000000;
@ -223,6 +238,9 @@ TEST_F(MindDataTestWeightedRandomSampler, TestResetReplacement) {
ASSERT_EQ(row.eoe(), true);
}
/// Feature: WeightedRandomSampler
/// Description: Test WeightedRandomSampler with replacement=false followed by ResetSampler
/// Expectation: Runs successfully
TEST_F(MindDataTestWeightedRandomSampler, TestResetNoReplacement) {
// num samples to draw.
uint64_t num_samples = 1000000;