Added category indices in iOS failure description

This commit is contained in:
Prianka Liz Kariat 2023-01-16 14:01:10 +05:30
parent cf945d3aeb
commit 67735a6fd3
2 changed files with 41 additions and 16 deletions

View File

@ -32,13 +32,16 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
NSNotFound)
#define AssertEqualCategoryArrays(categories, expectedCategories) \
XCTAssertEqual(categories.count, expectedCategories.count); \
for (int i = 0; i < categories.count; i++) { \
XCTAssertEqual(categories[i].index, expectedCategories[i].index); \
XCTAssertEqualWithAccuracy(categories[i].score, expectedCategories[i].score, 1e-6); \
XCTAssertEqualObjects(categories[i].categoryName, expectedCategories[i].categoryName); \
XCTAssertEqualObjects(categories[i].displayName, expectedCategories[i].displayName); \
#define AssertEqualCategoryArrays(categories, expectedCategories) \
XCTAssertEqual(categories.count, expectedCategories.count); \
for (int i = 0; i < categories.count; i++) { \
XCTAssertEqual(categories[i].index, expectedCategories[i].index, @"index i = %d", i); \
XCTAssertEqualWithAccuracy(categories[i].score, expectedCategories[i].score, 1e-6, \
@"index i = %d", i); \
XCTAssertEqualObjects(categories[i].categoryName, expectedCategories[i].categoryName, \
@"index i = %d", i); \
XCTAssertEqualObjects(categories[i].displayName, expectedCategories[i].displayName, \
@"index i = %d", i); \
}
#define AssertTextClassifierResultHasOneHead(textClassifierResult) \

View File

@ -60,33 +60,55 @@ class TextClassifierTests: XCTestCase {
func assertCategoriesAreEqual(
category: ResultCategory,
expectedCategory: ResultCategory) {
expectedCategory: ResultCategory,
indexInCategoryList: Int) {
XCTAssertEqual(
category.index,
expectedCategory.index)
expectedCategory.index,
String(
format: """
category[%d].index and expectedCategory[%d].index are not equal.
""", indexInCategoryList))
XCTAssertEqual(
category.score,
expectedCategory.score,
accuracy:1e-6)
accuracy:1e-6,
String(
format: """
category[%d].score and expectedCategory[%d].score are not equal.
""", indexInCategoryList))
XCTAssertEqual(
category.categoryName,
expectedCategory.categoryName)
expectedCategory.categoryName,
String(
format: """
category[%d].categoryName and expectedCategory[%d].categoryName are \
not equal.
""", indexInCategoryList))
XCTAssertEqual(
category.displayName,
expectedCategory.displayName)
expectedCategory.displayName,
String(
format: """
category[%d].displayName and expectedCategory[%d].displayName are \
not equal.
""", indexInCategoryList))
}
func assertEqualCategoryArrays(
categoryArray: [ResultCategory],
expectedCategoryArray:[ResultCategory]) {
XCTAssertEqual(categoryArray.count, expectedCategoryArray.count)
XCTAssertEqual(
categoryArray.count,
expectedCategoryArray.count)
for (category, expectedCategory) in
zip(categoryArray, expectedCategoryArray) {
for (index, (category, expectedCategory)) in
zip(categoryArray, expectedCategoryArray).enumerated() {
assertCategoriesAreEqual(
category:category,
expectedCategory:expectedCategory)
expectedCategory:expectedCategory,
indexInCategoryList:index)
}
}