2012-07-10 01:47:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* 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
|
2012-07-10 01:47:44 +00:00
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-07-10 01:47:44 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-02-12 07:15:47 +00:00
|
|
|
* 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.
|
2012-07-10 01:47:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
|
|
|
import android.test.AndroidTestCase;
|
2013-02-04 23:25:24 +00:00
|
|
|
import android.test.suitebuilder.annotation.SmallTest;
|
2012-07-10 01:47:44 +00:00
|
|
|
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ResizableIntArray;
|
|
|
|
|
2012-08-23 08:47:13 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2013-02-04 23:25:24 +00:00
|
|
|
@SmallTest
|
2012-07-10 01:47:44 +00:00
|
|
|
public class InputPointersTests extends AndroidTestCase {
|
2012-07-18 11:31:09 +00:00
|
|
|
private static final int DEFAULT_CAPACITY = 48;
|
|
|
|
|
2012-07-10 01:47:44 +00:00
|
|
|
public void testNewInstance() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("new instance size", 0, src.getPointerSize());
|
2012-07-10 01:47:44 +00:00
|
|
|
assertNotNull("new instance xCoordinates", src.getXCoordinates());
|
|
|
|
assertNotNull("new instance yCoordinates", src.getYCoordinates());
|
|
|
|
assertNotNull("new instance pointerIds", src.getPointerIds());
|
|
|
|
assertNotNull("new instance times", src.getTimes());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testReset() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
final int[] xCoordinates = src.getXCoordinates();
|
|
|
|
final int[] yCoordinates = src.getXCoordinates();
|
|
|
|
final int[] pointerIds = src.getXCoordinates();
|
|
|
|
final int[] times = src.getXCoordinates();
|
|
|
|
|
|
|
|
src.reset();
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("size after reset", 0, src.getPointerSize());
|
|
|
|
assertNotSame("xCoordinates after reset", xCoordinates, src.getXCoordinates());
|
|
|
|
assertNotSame("yCoordinates after reset", yCoordinates, src.getYCoordinates());
|
|
|
|
assertNotSame("pointerIds after reset", pointerIds, src.getPointerIds());
|
|
|
|
assertNotSame("times after reset", times, src.getTimes());
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAdd() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
final int limit = src.getXCoordinates().length * 2 + 10;
|
|
|
|
for (int i = 0; i < limit; i++) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
src.addPointer(x, y, pointerId, time);
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("size after add " + i, i + 1, src.getPointerSize());
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < limit; i++) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]);
|
|
|
|
assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]);
|
|
|
|
assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]);
|
|
|
|
assertEquals("times at " + i, time, src.getTimes()[i]);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testAddAt() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
final int limit = 1000, step = 100;
|
|
|
|
for (int i = 0; i < limit; i += step) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
2014-01-08 05:11:56 +00:00
|
|
|
src.addPointerAt(i, x, y, pointerId, time);
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("size after add at " + i, i + 1, src.getPointerSize());
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < limit; i += step) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]);
|
|
|
|
assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]);
|
|
|
|
assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]);
|
|
|
|
assertEquals("times at " + i, time, src.getTimes()[i]);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSet() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
final int limit = src.getXCoordinates().length * 2 + 10;
|
|
|
|
for (int i = 0; i < limit; i++) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
src.addPointer(x, y, pointerId, time);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.set(src);
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("size after set", dst.getPointerSize(), src.getPointerSize());
|
|
|
|
assertSame("xCoordinates after set", dst.getXCoordinates(), src.getXCoordinates());
|
|
|
|
assertSame("yCoordinates after set", dst.getYCoordinates(), src.getYCoordinates());
|
|
|
|
assertSame("pointerIds after set", dst.getPointerIds(), src.getPointerIds());
|
|
|
|
assertSame("times after set", dst.getTimes(), src.getTimes());
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCopy() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
final int limit = 100;
|
|
|
|
for (int i = 0; i < limit; i++) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
src.addPointer(x, y, pointerId, time);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.copy(src);
|
2012-07-19 10:44:54 +00:00
|
|
|
assertEquals("size after copy", dst.getPointerSize(), src.getPointerSize());
|
|
|
|
assertNotSame("xCoordinates after copy", dst.getXCoordinates(), src.getXCoordinates());
|
|
|
|
assertNotSame("yCoordinates after copy", dst.getYCoordinates(), src.getYCoordinates());
|
|
|
|
assertNotSame("pointerIds after copy", dst.getPointerIds(), src.getPointerIds());
|
|
|
|
assertNotSame("times after copy", dst.getTimes(), src.getTimes());
|
2012-07-10 01:47:44 +00:00
|
|
|
final int size = dst.getPointerSize();
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("xCoordinates values after copy",
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.getXCoordinates(), 0, src.getXCoordinates(), 0, size);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("yCoordinates values after copy",
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.getYCoordinates(), 0, src.getYCoordinates(), 0, size);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("pointerIds values after copy",
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.getPointerIds(), 0, src.getPointerIds(), 0, size);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("times values after copy",
|
2012-07-10 01:47:44 +00:00
|
|
|
dst.getTimes(), 0, src.getTimes(), 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testAppend() {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int dstLength = 50;
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
|
2014-01-07 08:43:44 +00:00
|
|
|
for (int i = 0; i < dstLength; i++) {
|
|
|
|
final int x = i * 4;
|
|
|
|
final int y = i * 3;
|
|
|
|
final int pointerId = i * 2;
|
|
|
|
final int time = i;
|
|
|
|
dst.addPointer(x, y, pointerId, time);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
2012-07-18 11:31:09 +00:00
|
|
|
final InputPointers dstCopy = new InputPointers(DEFAULT_CAPACITY);
|
2012-07-10 01:47:44 +00:00
|
|
|
dstCopy.copy(dst);
|
|
|
|
|
2014-01-07 08:43:44 +00:00
|
|
|
final ResizableIntArray srcXCoords = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final ResizableIntArray srcYCoords = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final ResizableIntArray srcPointerIds = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final ResizableIntArray srcTimes = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final int srcLength = 100;
|
|
|
|
final int srcPointerId = 10;
|
|
|
|
for (int i = 0; i < srcLength; i++) {
|
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
// The time value must be larger than <code>dst</code>.
|
|
|
|
final int time = i * 4 + dstLength;
|
|
|
|
srcXCoords.add(x);
|
|
|
|
srcYCoords.add(y);
|
|
|
|
srcPointerIds.add(srcPointerId);
|
|
|
|
srcTimes.add(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
final int startPos = 0;
|
|
|
|
dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords,
|
|
|
|
startPos, 0 /* length */);
|
|
|
|
assertEquals("size after append zero", dstLength, dst.getPointerSize());
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("xCoordinates after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getXCoordinates(), startPos, dst.getXCoordinates(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("yCoordinates after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getYCoordinates(), startPos, dst.getYCoordinates(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("pointerIds after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getPointerIds(), startPos, dst.getPointerIds(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("times after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getTimes(), startPos, dst.getTimes(), startPos, dstLength);
|
2012-07-10 01:47:44 +00:00
|
|
|
|
2014-01-07 08:43:44 +00:00
|
|
|
dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords,
|
|
|
|
startPos, srcLength);
|
|
|
|
assertEquals("size after append", dstLength + srcLength, dst.getPointerSize());
|
2012-07-19 10:44:54 +00:00
|
|
|
assertTrue("primitive length after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dst.getPointerIds().length >= dstLength + srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original xCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getXCoordinates(), startPos, dst.getXCoordinates(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original yCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getYCoordinates(), startPos, dst.getYCoordinates(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original pointerIds values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getPointerIds(), startPos, dst.getPointerIds(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original times values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getTimes(), startPos, dst.getTimes(), startPos, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended xCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcXCoords.getPrimitiveArray(), startPos, dst.getXCoordinates(),
|
|
|
|
dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended yCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcYCoords.getPrimitiveArray(), startPos, dst.getYCoordinates(),
|
|
|
|
dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended pointerIds values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcPointerIds.getPrimitiveArray(), startPos, dst.getPointerIds(),
|
|
|
|
dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended times values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength);
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 08:47:13 +00:00
|
|
|
public void testAppendResizableIntArray() {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int dstLength = 50;
|
|
|
|
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
|
|
|
|
for (int i = 0; i < dstLength; i++) {
|
|
|
|
final int x = i * 4;
|
|
|
|
final int y = i * 3;
|
|
|
|
final int pointerId = i * 2;
|
|
|
|
final int time = i;
|
|
|
|
dst.addPointer(x, y, pointerId, time);
|
|
|
|
}
|
|
|
|
final InputPointers dstCopy = new InputPointers(DEFAULT_CAPACITY);
|
|
|
|
dstCopy.copy(dst);
|
|
|
|
|
|
|
|
final int srcLength = 100;
|
2012-08-23 08:47:13 +00:00
|
|
|
final int srcPointerId = 1;
|
2014-01-07 08:43:44 +00:00
|
|
|
final int[] srcPointerIds = new int[srcLength];
|
2012-08-23 08:47:13 +00:00
|
|
|
Arrays.fill(srcPointerIds, srcPointerId);
|
|
|
|
final ResizableIntArray srcTimes = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final ResizableIntArray srcXCoords = new ResizableIntArray(DEFAULT_CAPACITY);
|
|
|
|
final ResizableIntArray srcYCoords= new ResizableIntArray(DEFAULT_CAPACITY);
|
2014-01-07 08:43:44 +00:00
|
|
|
for (int i = 0; i < srcLength; i++) {
|
|
|
|
// The time value must be larger than <code>dst</code>.
|
|
|
|
final int time = i * 2 + dstLength;
|
|
|
|
final int x = i * 3;
|
|
|
|
final int y = i * 4;
|
|
|
|
srcTimes.add(time);
|
|
|
|
srcXCoords.add(x);
|
|
|
|
srcYCoords.add(y);
|
2012-08-23 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, 0, 0);
|
2014-01-07 08:43:44 +00:00
|
|
|
assertEquals("size after append zero", dstLength, dst.getPointerSize());
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("xCoordinates after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getXCoordinates(), 0, dst.getXCoordinates(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("yCoordinates after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getYCoordinates(), 0, dst.getYCoordinates(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("pointerIds after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getPointerIds(), 0, dst.getPointerIds(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("times after append zero",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getTimes(), 0, dst.getTimes(), 0, dstLength);
|
2012-08-23 08:47:13 +00:00
|
|
|
|
2014-01-07 08:43:44 +00:00
|
|
|
dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, 0, srcLength);
|
|
|
|
assertEquals("size after append", dstLength + srcLength, dst.getPointerSize());
|
2012-08-23 08:47:13 +00:00
|
|
|
assertTrue("primitive length after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dst.getPointerIds().length >= dstLength + srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original xCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getXCoordinates(), 0, dst.getXCoordinates(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original yCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getYCoordinates(), 0, dst.getYCoordinates(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original pointerIds values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getPointerIds(), 0, dst.getPointerIds(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("original times values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
dstCopy.getTimes(), 0, dst.getTimes(), 0, dstLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended xCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcXCoords.getPrimitiveArray(), 0, dst.getXCoordinates(), dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended yCoordinates values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcYCoords.getPrimitiveArray(), 0, dst.getYCoordinates(), dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended pointerIds values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcPointerIds, 0, dst.getPointerIds(), dstLength, srcLength);
|
2013-05-23 09:06:56 +00:00
|
|
|
assertIntArrayEquals("appended times values after append",
|
2014-01-07 08:43:44 +00:00
|
|
|
srcTimes.getPrimitiveArray(), 0, dst.getTimes(), dstLength, srcLength);
|
2012-08-23 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 09:06:56 +00:00
|
|
|
// TODO: Consolidate this method with
|
|
|
|
// {@link ResizableIntArrayTests#assertIntArrayEquals(String,int[],int,int[],int,int)}.
|
|
|
|
private static void assertIntArrayEquals(final String message, final int[] expecteds,
|
|
|
|
final int expectedPos, final int[] actuals, final int actualPos, final int length) {
|
|
|
|
if (expecteds == actuals) {
|
2012-07-10 01:47:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (expecteds == null || actuals == null) {
|
2013-05-23 09:06:56 +00:00
|
|
|
assertEquals(message, Arrays.toString(expecteds), Arrays.toString(actuals));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (expecteds.length < expectedPos + length || actuals.length < actualPos + length) {
|
|
|
|
fail(message + ": insufficient length: expecteds=" + Arrays.toString(expecteds)
|
|
|
|
+ " actuals=" + Arrays.toString(actuals));
|
|
|
|
return;
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < length; i++) {
|
2013-05-23 09:06:56 +00:00
|
|
|
assertEquals(message + " [" + i + "]",
|
2012-07-10 01:47:44 +00:00
|
|
|
expecteds[i + expectedPos], actuals[i + actualPos]);
|
|
|
|
}
|
|
|
|
}
|
2013-09-10 08:48:00 +00:00
|
|
|
|
|
|
|
public void testShift() {
|
|
|
|
final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
|
|
|
|
final int limit = 100;
|
|
|
|
final int shiftAmount = 20;
|
|
|
|
for (int i = 0; i < limit; i++) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int x = i;
|
|
|
|
final int y = i * 2;
|
|
|
|
final int pointerId = i * 3;
|
|
|
|
final int time = i * 4;
|
|
|
|
src.addPointer(x, y, pointerId, time);
|
2013-09-10 08:48:00 +00:00
|
|
|
}
|
|
|
|
src.shift(shiftAmount);
|
2014-01-07 08:43:44 +00:00
|
|
|
assertEquals("length after shift", src.getPointerSize(), limit - shiftAmount);
|
2013-09-10 08:48:00 +00:00
|
|
|
for (int i = 0; i < limit - shiftAmount; ++i) {
|
2014-01-07 08:43:44 +00:00
|
|
|
final int oldIndex = i + shiftAmount;
|
|
|
|
final int x = oldIndex;
|
|
|
|
final int y = oldIndex * 2;
|
|
|
|
final int pointerId = oldIndex * 3;
|
|
|
|
final int time = oldIndex * 4;
|
|
|
|
assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]);
|
|
|
|
assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]);
|
|
|
|
assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]);
|
|
|
|
assertEquals("times at " + i, time, src.getTimes()[i]);
|
2013-09-10 08:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-10 01:47:44 +00:00
|
|
|
}
|