-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
mediapipe/tasks/c/components/containers/category_converter_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Copyright 2023 The MediaPipe Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "mediapipe/tasks/c/components/containers/category_converter.h" | ||
|
||
#include <cstdlib> | ||
#include <optional> | ||
#include <string> | ||
|
||
#include "mediapipe/framework/port/gtest.h" | ||
#include "mediapipe/tasks/c/components/containers/category.h" | ||
#include "mediapipe/tasks/cc/components/containers/category.h" | ||
|
||
namespace mediapipe::tasks::c::components::containers { | ||
|
||
TEST(CategoryConverterTest, ConvertsCategoryCustomValues) { | ||
mediapipe::tasks::components::containers::Category cpp_category = { | ||
/* index= */ 1, | ||
/* score= */ 0.1, | ||
/* category_name= */ "category_name", | ||
/* display_name= */ "display_name", | ||
}; | ||
|
||
Category c_category; | ||
CppConvertToCategory(cpp_category, &c_category); | ||
EXPECT_EQ(c_category.index, 1); | ||
EXPECT_FLOAT_EQ(c_category.score, 0.1); | ||
EXPECT_EQ(std::string{c_category.category_name}, "category_name"); | ||
EXPECT_EQ(std::string{c_category.display_name}, "display_name"); | ||
|
||
free(c_category.category_name); | ||
free(c_category.display_name); | ||
} | ||
|
||
TEST(CategoryConverterTest, ConvertsCategoryDefaultValues) { | ||
mediapipe::tasks::components::containers::Category cpp_category = { | ||
/* index= */ 1, | ||
/* score= */ 0.1, | ||
/* category_name= */ std::nullopt, | ||
/* display_name= */ std::nullopt, | ||
}; | ||
|
||
Category c_category; | ||
CppConvertToCategory(cpp_category, &c_category); | ||
EXPECT_EQ(c_category.index, 1); | ||
EXPECT_FLOAT_EQ(c_category.score, 0.1); | ||
EXPECT_EQ(c_category.category_name, nullptr); | ||
EXPECT_EQ(c_category.display_name, nullptr); | ||
} | ||
|
||
} // namespace mediapipe::tasks::c::components::containers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
mediapipe/tasks/c/components/containers/classification_result_converter_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright 2023 The MediaPipe Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "mediapipe/tasks/c/components/containers/classification_result_converter.h" | ||
|
||
#include <cstdlib> | ||
#include <optional> | ||
#include <string> | ||
|
||
#include "mediapipe/framework/port/gtest.h" | ||
#include "mediapipe/tasks/c/components/containers/classification_result.h" | ||
#include "mediapipe/tasks/cc/components/containers/classification_result.h" | ||
|
||
namespace mediapipe::tasks::c::components::containers { | ||
|
||
TEST(ClassificationResultConverterTest, | ||
ConvertsClassificationResulCustomCategory) { | ||
mediapipe::tasks::components::containers::ClassificationResult | ||
cpp_classification_result = { | ||
/* classifications= */ {{/* categories= */ {{ | ||
/* index= */ 1, | ||
/* score= */ 0.1, | ||
/* category_name= */ std::nullopt, | ||
/* display_name= */ std::nullopt, | ||
}}, | ||
/* head_index= */ 0, | ||
/* head_name= */ "foo"}}, | ||
/* timestamp_ms= */ 42, | ||
}; | ||
|
||
ClassificationResult c_classification_result; | ||
CppConvertToClassificationResult(cpp_classification_result, | ||
&c_classification_result); | ||
EXPECT_NE(c_classification_result.classifications, nullptr); | ||
EXPECT_EQ(c_classification_result.classifications_count, 1); | ||
EXPECT_NE(c_classification_result.classifications[0].categories, nullptr); | ||
EXPECT_EQ(c_classification_result.classifications[0].categories_count, 1); | ||
EXPECT_EQ(c_classification_result.classifications[0].head_index, 0); | ||
EXPECT_EQ(std::string(c_classification_result.classifications[0].head_name), | ||
"foo"); | ||
EXPECT_EQ(c_classification_result.timestamp_ms, 42); | ||
EXPECT_EQ(c_classification_result.has_timestamp_ms, true); | ||
|
||
free(c_classification_result.classifications[0].categories); | ||
free(c_classification_result.classifications[0].head_name); | ||
free(c_classification_result.classifications); | ||
} | ||
|
||
TEST(ClassificationResultConverterTest, | ||
ConvertsClassificationResulEmptyCategory) { | ||
mediapipe::tasks::components::containers::ClassificationResult | ||
cpp_classification_result = { | ||
/* classifications= */ {{/* categories= */ {}, /* head_index= */ 0, | ||
/* head_name= */ std::nullopt}}, | ||
/* timestamp_ms= */ std::nullopt, | ||
}; | ||
|
||
ClassificationResult c_classification_result; | ||
CppConvertToClassificationResult(cpp_classification_result, | ||
&c_classification_result); | ||
EXPECT_NE(c_classification_result.classifications, nullptr); | ||
EXPECT_EQ(c_classification_result.classifications_count, 1); | ||
EXPECT_EQ(c_classification_result.classifications[0].categories, nullptr); | ||
EXPECT_EQ(c_classification_result.classifications[0].categories_count, 0); | ||
EXPECT_EQ(c_classification_result.classifications[0].head_index, 0); | ||
EXPECT_EQ(c_classification_result.classifications[0].head_name, nullptr); | ||
EXPECT_EQ(c_classification_result.timestamp_ms, 0); | ||
EXPECT_EQ(c_classification_result.has_timestamp_ms, false); | ||
|
||
free(c_classification_result.classifications); | ||
} | ||
|
||
TEST(ClassificationResultConverterTest, | ||
ConvertsClassificationResultNoCategory) { | ||
mediapipe::tasks::components::containers::ClassificationResult | ||
cpp_classification_result = { | ||
/* classifications= */ {}, | ||
/* timestamp_ms= */ std::nullopt, | ||
}; | ||
|
||
ClassificationResult c_classification_result; | ||
CppConvertToClassificationResult(cpp_classification_result, | ||
&c_classification_result); | ||
EXPECT_EQ(c_classification_result.classifications, nullptr); | ||
EXPECT_EQ(c_classification_result.classifications_count, 0); | ||
EXPECT_EQ(c_classification_result.timestamp_ms, 0); | ||
EXPECT_EQ(c_classification_result.has_timestamp_ms, false); | ||
} | ||
|
||
} // namespace mediapipe::tasks::c::components::containers |