1 /* 2 * Copyright (C) 2013 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 com.android.inputmethod.keyboard.internal; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 22 import androidx.test.filters.SmallTest; 23 import androidx.test.runner.AndroidJUnit4; 24 25 import com.android.inputmethod.keyboard.internal.MatrixUtils.MatrixOperationFailedException; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 @SmallTest 31 @RunWith(AndroidJUnit4.class) 32 public class SmoothingUtilsTests { 33 // "run tests" -c com.android.inputmethod.keyboard.internal.SmoothingUtilsTests 34 private static final boolean DEBUG = false; 35 36 @Test testGet3DParamaters()37 public void testGet3DParamaters() { 38 final float[] xs = new float[] {0, 1, 2, 3, 4}; 39 final float[] ys = new float[] {1, 4, 15, 40, 85}; // y = x^3 + x^2 + x + 1 40 final float[][] retval = new float[4][1]; 41 try { 42 SmoothingUtils.get3DParameters(xs, ys, retval); 43 if (DEBUG) { 44 MatrixUtils.dump("3d", retval); 45 } 46 for (int i = 0; i < 4; ++i) { 47 assertEquals(retval[i][0], 1.0f, 0.001f); 48 } 49 } catch (MatrixOperationFailedException e) { 50 assertTrue(false); 51 } 52 } 53 } 54