msime-engine 0.2.0

Input method engine for Chinese and other languages: quanpin, shuangpin, nine-key, wubi, zhuyin, Cantonese, Japanese, Korean and more, ranked over a word lattice with typo correction and learning from what the user picks. The engine of 水杉输入法 (Metasequoia IME).
Documentation
use std::sync::Arc;

use super::super::ngram::tests::pair_table;
use super::*;

#[test]
fn a_memo_miss_hashes_the_key_once() {
    let directory = tempfile::tempdir().unwrap();
    let table = Arc::new(pair_table(
        directory.path(),
        "memo.bin",
        &[("前", "后", 1.0)],
    ));
    let mut memo = BigramMemo::default();
    BIGRAM_MEMO_HASH_CALLS.with(|calls| calls.set(0));

    assert_eq!(memo.score(&table, "前", "后"), 1.0);
    BIGRAM_MEMO_HASH_CALLS.with(|calls| calls.set(0));
    assert_eq!(memo.score(&table, "新前", "新后"), 0.0);

    let hash_calls = BIGRAM_MEMO_HASH_CALLS.with(|calls| calls.get());
    assert_eq!(
        hash_calls, 1,
        "一次新的二元分键不应在缓存查询和插入时重复哈希"
    );
}