diff options
Diffstat (limited to 'tests/remembering.go')
| -rw-r--r-- | tests/remembering.go | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/tests/remembering.go b/tests/remembering.go index 53ca00f..304f971 100644 --- a/tests/remembering.go +++ b/tests/remembering.go @@ -266,7 +266,7 @@ func test_nextProfile() { } lines := []string{"a", "b", "c", "d", "e"} - testing("the pick's count is bumped", func() { + testing("the pick's score is bumped", func() { assertEq(nextProfile(zeroes, lines, "a"), []entryT{ {1, "a"}, {0, "b"}, {0, "c"}, {0, "d"}, {0, "e"}, @@ -290,27 +290,46 @@ func test_nextProfile() { }) }) - testing("entries absent from stdin are retained", func() { + testing("an idle entry fades by the decay factor", func() { + // picking x ages fav: 10 * 0.9 = 9 + given := nextProfile( + []entryT{{10, "fav"}}, []string{"x"}, "x", + ) + assertEq(given, []entryT{{9, "fav"}, {1, "x"}}) + }) + + testing("a faded score snaps to zero", func() { + // 0.001 * 0.9 = 0.0009, below epsilon + given := nextProfile( + []entryT{{0.001, "old"}}, []string{"new"}, "new", + ) + assertEq(given, []entryT{{1, "new"}, {0, "old"}}) + }) + + testing("entries absent from stdin are kept, and fade", func() { profile := []entryT{{0, "a"}, {7, "z"}} given := nextProfile( profile, []string{"a", "b"}, "a", ) + // z is not offered, but a pick still ages it: 7 * 0.9 assertEq(given, []entryT{ - {1, "a"}, {0, "b"}, {7, "z"}, + {1, "a"}, {0, "b"}, {6.3, "z"}, }) }) testing("duplicate texts collapse to the highest", func() { profile := []entryT{{2, "x"}, {5, "x"}} given := nextProfile(profile, []string{}, "x") - assertEq(given, []entryT{{6, "x"}}) + // max is 5; aged 5*0.9=4.5, then the pick adds 1 + assertEq(given, []entryT{{5.5, "x"}}) }) - testing("picking twice accumulates", func() { + testing("picking twice accumulates, minus decay", func() { once := nextProfile([]entryT{}, lines, "c") twice := nextProfile(once, lines, "c") + // c: 1, then 1*0.9 + 1 = 1.9 assertEq(twice, []entryT{ - {0, "a"}, {0, "b"}, {2, "c"}, + {0, "a"}, {0, "b"}, {1.9, "c"}, {0, "d"}, {0, "e"}, }) }) @@ -417,7 +436,8 @@ func test_run_flow() { ) }) - testing("a second pick ranks above", func() { + testing("a second pick accumulates, minus decay", func() { + // a was 1; re-picking ages it then adds 1: 1*0.9+1 rc, out, _ := runWith( "b\na\n", "-p", "t1", "--", "head", "-n1", @@ -426,7 +446,7 @@ func test_run_flow() { assertEq(out, "a\n") assertEq( profileContent("t1"), - "2 profile a\n0 profile b\n", + "1.9 profile a\n0 profile b\n", ) }) |
