def test_prepare_stage_with_two_typos_should_not_mark_second_as_correct(): stages = prepare_stage("abc", "acb") assert stages == [ t(s="START", e="a", st="CORRECT", t=10), t(s="a", e="c", st="ERROR", t=10), t(s="c", e="b", st="ERROR", t=10), ]
def test_key_stats(ta): stage = [t(e="a", t=50), t(e="x", t=20), t(e="x", t=10), t(e="a", t=100)] assert { "a": [50, 100], "x": [20, 10] }.items() == ta.key_stats(stage).items()
def test_should_limit_to_max_correct_chars_also_taking_errors(): stage = prepare_stage("aaaa", "aab<aa", key_time=0) assert [ t("a", "b", "ERROR"), t("b", "ERASE", "ERASE"), t("ERASE", "a", "CORRECT"), t("a", "a", "CORRECT"), ] == limit(stage, 2)
def test_prepare_stage_with_correction_simple(): stages = prepare_stage("ax", "ab<x") assert stages == [ t(s="START", e="a", st="CORRECT", t=10), t(s="a", e="b", st="ERROR", t=10), t(s="b", e="ERASE", st="ERASE", t=10), t(s="ERASE", e="x", st="CORRECT", t=10), ]
def test_prepare_stage_with_correction(): stages = prepare_stage("abc", "ac<bc") assert stages == [ t(s="START", e="a", st="CORRECT", t=10), t(s="a", e="c", st="ERROR", t=10), t(s="c", e="ERASE", st="ERASE", t=10), t(s="ERASE", e="b", st="CORRECT", t=10), t(s="b", e="c", st="CORRECT", t=10), ]
def test_adjusted_keys_should_not_count_first_element(ta): stage_with_correct = [ t(s="START", e="s", st="CORRECT", t=0), ] stage_with_error = [ t(s="START", e="s", st="ERROR", t=0), ] assert {}.items() == ta.adjusted_key_stats(stage_with_error).items() assert {}.items() == ta.adjusted_key_stats(stage_with_correct).items()
def test_key_stats_should_not_count_first_char_in_stage(ta): stage = [ t("START", e="s", t=0), t(e="a", t=50), t(e="x", t=20), t(e="x", t=10), t(e="a", t=100), ] assert { "a": [50, 100], "x": [20, 10] }.items() == ta.key_stats(stage).items()
def test_prepare_stage_with_consecutive_typos_one_of_them_on_correct_place(): stages = prepare_stage("abc", "acc<<bc") assert stages == [ t(s="START", e="a", st="CORRECT", t=10), t(s="a", e="c", st="ERROR", t=10), t(s="c", e="c", st="ERROR", t=10), t(s="c", e="ERASE", st="ERASE", t=10), t(s="ERASE", e="ERASE", st="ERASE", t=10), t(s="ERASE", e="b", st="CORRECT", t=10), t(s="b", e="c", st="CORRECT", t=10), ]
def test_adjusted_keys_should_not_count_first_error(ta): stage = [ t(s="START", e="s", st="ERROR", t=0), t(e="a", st="ERROR", t=50), t(e="x", st="ERASE", t=20), t(e="x", st="ERASE", t=10), t(e="a", st="CORRECT", t=100), t(e="a", st="CORRECT", t=50), t(e="x", st="CORRECT", t=50), ] # times are in seconds assert { "a": [0.18, 0.05], "x": [0.05] }.items() == ta.adjusted_key_stats(stage).items()
def test_should_limit_to_max_correct_chars(): stage = prepare_stage("aaa", "aaa", key_time=0) assert [t("a", "a", "CORRECT"), t("a", "a", "CORRECT")] == limit(stage, 2)
def state_test_helper(ta, state, fun): one = [t(st=state)] two = [t(st=state), t(st="OTHER"), t(st=state)] assert fun(one) == 1 assert fun(two) == 2
def test_prepare_stage_onechar(): stages = prepare_stage("a", "a") assert stages == [t(s="START", e="a", st="CORRECT", t=10)]
def test_stages(ta): one_stage = [t("START")] two_stages = [t("START"), t("START")] assert ta.stages(one_stage) == 1 assert ta.stages(two_stages) == 2