1 /* 2 * Copyright (C) 2012 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.latin; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 @SmallTest 23 public class ForgettingCurveTests extends AndroidTestCase { 24 public void testFcToFreq() { 25 for (int i = 0; i < Byte.MAX_VALUE; ++i) { 26 final byte fc = (byte)i; 27 final int e = UserHistoryForgettingCurveUtils.fcToElapsedTime(fc); 28 final int c = UserHistoryForgettingCurveUtils.fcToCount(fc); 29 final int l = UserHistoryForgettingCurveUtils.fcToLevel(fc); 30 final byte fc2 = UserHistoryForgettingCurveUtils.calcFc(e, c, l); 31 assertEquals(fc, fc2); 32 } 33 byte fc = 0; 34 int l; 35 for (int i = 0; i < 4; ++i) { 36 for (int j = 0; j < (UserHistoryForgettingCurveUtils.COUNT_MAX + 1); ++j) { 37 fc = UserHistoryForgettingCurveUtils.pushCount(fc, true); 38 } 39 l = UserHistoryForgettingCurveUtils.fcToLevel(fc); 40 assertEquals(l, Math.max(1, Math.min(i + 1, 3))); 41 } 42 fc = 0; 43 for (int i = 0; i < 4; ++i) { 44 for (int j = 0; j < (UserHistoryForgettingCurveUtils.COUNT_MAX + 1); ++j) { 45 fc = UserHistoryForgettingCurveUtils.pushCount(fc, false); 46 } 47 l = UserHistoryForgettingCurveUtils.fcToLevel(fc); 48 assertEquals(l, Math.min(i + 1, 3)); 49 } 50 for (int i = 0; i < 4; ++i) { 51 for (int j = 0; j < (UserHistoryForgettingCurveUtils.ELAPSED_TIME_MAX + 1); ++j) { 52 fc = UserHistoryForgettingCurveUtils.pushElapsedTime(fc); 53 } 54 l = UserHistoryForgettingCurveUtils.fcToLevel(fc); 55 assertEquals(l, Math.max(0, 2 - i)); 56 } 57 } 58 } 59