Added more recognize tests to iOS Gesture Recognizer Objective C tests
This commit is contained in:
parent
1e77468eec
commit
84560f3e7d
|
@ -284,4 +284,128 @@ static const float kLandmarksErrorTolerance = 0.03f;
|
|||
thumbUpGestureRecognizerResult]];
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithEmptyResultsSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
|
||||
MPPGestureRecognizerResult *gestureRecognizerResult =
|
||||
[self recognizeImageWithFileInfo:kNoHandsImage usingGestureRecognizer:gestureRecognizer];
|
||||
AssertGestureRecognizerResultIsEmpty(gestureRecognizerResult);
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithScoreThresholdSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions = [[MPPClassifierOptions alloc] init];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions.scoreThreshold = 0.5f;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
|
||||
MPPGestureRecognizerResult *gestureRecognizerResult =
|
||||
[self recognizeImageWithFileInfo:kThumbUpImage usingGestureRecognizer:gestureRecognizer];
|
||||
|
||||
MPPGestureRecognizerResult *expectedGestureRecognizerResult =
|
||||
[MPPGestureRecognizerTests thumbUpGestureRecognizerResult];
|
||||
|
||||
XCTAssertTrue(gestureRecognizerResult.gestures.count == 1);
|
||||
AssertEqualGestures(gestureRecognizerResult.gestures[0][0],
|
||||
expectedGestureRecognizerResult.gestures[0][0], 0, 0);
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithNumHandsSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
|
||||
const NSInteger numberOfHands = 2;
|
||||
gestureRecognizerOptions.numberOfHands = numberOfHands;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
|
||||
MPPGestureRecognizerResult *gestureRecognizerResult =
|
||||
[self recognizeImageWithFileInfo:kTwoHandsImage usingGestureRecognizer:gestureRecognizer];
|
||||
|
||||
XCTAssertTrue(gestureRecognizerResult.handedness.count == numberOfHands);
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithRotationSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
|
||||
const NSInteger numberOfHands = 2;
|
||||
gestureRecognizerOptions.numberOfHands = numberOfHands;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
MPPImage *mppImage = [self imageWithFileInfo:kPointingUpRotatedImage
|
||||
orientation:UIImageOrientationRight];
|
||||
|
||||
MPPGestureRecognizerResult *gestureRecognizerResult = [gestureRecognizer recognizeImage:mppImage
|
||||
error:nil];
|
||||
|
||||
XCTAssertNotNil(gestureRecognizerResult);
|
||||
|
||||
const NSInteger expectedGesturesCount = 1;
|
||||
|
||||
XCTAssertEqual(gestureRecognizerResult.gestures.count, expectedGesturesCount);
|
||||
XCTAssertEqualObjects(gestureRecognizerResult.gestures[0][0].categoryName,
|
||||
kExpectedPointingUpLabel);
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithCannedGestureFistSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
|
||||
const NSInteger numberOfHands = 1;
|
||||
gestureRecognizerOptions.numberOfHands = numberOfHands;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
|
||||
[self assertResultsOfRecognizeImageWithFileInfo:kFistImage
|
||||
usingGestureRecognizer:gestureRecognizer
|
||||
approximatelyEqualsGestureRecognizerResult:
|
||||
[MPPGestureRecognizerTests fistGestureRecognizerResultWithLabel:kFistLabel]];
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithAllowGestureFistSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions = [[MPPClassifierOptions alloc] init];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions.scoreThreshold = 0.5f;
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions.categoryAllowlist = @[ kFistLabel ];
|
||||
|
||||
const NSInteger numberOfHands = 1;
|
||||
gestureRecognizerOptions.numberOfHands = numberOfHands;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
|
||||
[self assertResultsOfRecognizeImageWithFileInfo:kFistImage
|
||||
usingGestureRecognizer:gestureRecognizer
|
||||
approximatelyEqualsGestureRecognizerResult:
|
||||
[MPPGestureRecognizerTests fistGestureRecognizerResultWithLabel:kFistLabel]];
|
||||
}
|
||||
|
||||
- (void)testRecognizeWithDenyGestureFistSucceeds {
|
||||
MPPGestureRecognizerOptions *gestureRecognizerOptions =
|
||||
[self gestureRecognizerOptionsWithModelFileInfo:kGestureRecognizerBundleAssetFile];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions = [[MPPClassifierOptions alloc] init];
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions.scoreThreshold = 0.5f;
|
||||
gestureRecognizerOptions.cannedGesturesClassifierOptions.categoryDenylist = @[ kFistLabel ];
|
||||
|
||||
const NSInteger numberOfHands = 1;
|
||||
gestureRecognizerOptions.numberOfHands = numberOfHands;
|
||||
|
||||
MPPGestureRecognizer *gestureRecognizer =
|
||||
[self createGestureRecognizerWithOptionsSucceeds:gestureRecognizerOptions];
|
||||
MPPGestureRecognizerResult *gestureRecognizerResult =
|
||||
[self recognizeImageWithFileInfo:kFistImage usingGestureRecognizer:gestureRecognizer];
|
||||
AssertGestureRecognizerResultIsEmpty(gestureRecognizerResult);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue
Block a user