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