1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.gesture.cts; 18 19 import android.gesture.Gesture; 20 import android.gesture.GestureStroke; 21 22 import java.util.Arrays; 23 24 import junit.framework.Assert; 25 26 /** 27 * Helper class to assert that two Gestures are approximately equal 28 */ 29 class GestureComparator { 30 31 /** 32 * Compare the contents of two (@link Gesture}'s 33 * 34 * @throws {@link junit.framework.AssertionFailedError} if Gesture's are not equal 35 */ 36 void assertGesturesEquals(Gesture expectedGesture, Gesture observedGesture) { 37 Assert.assertEquals(expectedGesture.getID(), observedGesture.getID()); 38 Assert.assertEquals(expectedGesture.getStrokesCount(), observedGesture.getStrokesCount()); 39 40 // now compare gesture strokes. Order is important 41 for (int i=0; i < expectedGesture.getStrokesCount(); i++) { 42 GestureStroke expectedStroke = expectedGesture.getStrokes().get(i); 43 GestureStroke observedStroke = observedGesture.getStrokes().get(i); 44 assertGestureStrokesEqual(expectedStroke, observedStroke); 45 } 46 } 47 48 /** 49 * Compare the contents of two {@link GestureStroke} 50 * 51 * @throws {@link junit.framework.AssertionFailedError} if GestureStroke's are not 52 * equal 53 */ 54 void assertGestureStrokesEqual(GestureStroke expectedStroke, GestureStroke observedStroke) { 55 Assert.assertEquals(expectedStroke.length, observedStroke.length); 56 Assert.assertTrue(Arrays.equals(expectedStroke.points, observedStroke.points)); 57 } 58 } 59