diff --git a/mediapipe/tasks/ios/test/text/text_classifier/MPPTextClassifierTests.m b/mediapipe/tasks/ios/test/text/text_classifier/MPPTextClassifierTests.m index 5c0964e68..ebeaf863f 100644 --- a/mediapipe/tasks/ios/test/text/text_classifier/MPPTextClassifierTests.m +++ b/mediapipe/tasks/ios/test/text/text_classifier/MPPTextClassifierTests.m @@ -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) \ diff --git a/mediapipe/tasks/ios/test/text/text_classifier/TextClassifierTests.swift b/mediapipe/tasks/ios/test/text/text_classifier/TextClassifierTests.swift index 01b5748cf..186887778 100644 --- a/mediapipe/tasks/ios/test/text/text_classifier/TextClassifierTests.swift +++ b/mediapipe/tasks/ios/test/text/text_classifier/TextClassifierTests.swift @@ -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) } }