Fix bug in Markov.Chain where reply_chance would get reset, add regression tests for this

* Markov.Chain.add_weight/4 would return a fresh new markov chain,
  instead of using all of the previous values of the chain that was
  being modified. This would result in resetting the reply_chance value
  to the default of 0.01.
* Add tests to make sure this doesn't happen to add_weights in the
  future.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-07-21 14:58:10 -07:00
parent ec1dd42ca1
commit b1461e24db
2 changed files with 22 additions and 5 deletions

View File

@@ -68,6 +68,23 @@ defmodule MarkovChainTest do
}
end
test "chain add_weight does not reset reply_chance" do
chain = %Chain {order: 2, reply_chance: 0.0}
|> Chain.add_weight(["foo", "bar"], "baz")
chain = chain |> Chain.add_weight(["foo", "bar"], "baz", 2)
assert chain.reply_chance == 0.0
chain = chain |> Chain.add_weight(["foo", "bar"], "qux")
assert chain.reply_chance == 0.0
chain = chain |> Chain.add_weight(["bar", "baz"], "qux")
assert chain.reply_chance == 0.0
chain = chain |> Chain.add_weight(["bar", "baz"], nil)
assert chain.reply_chance == 0.0
end
test "chain merge works correctly" do
chain1 = %Chain {order: 2}
|> Chain.add_weight(["foo", "bar"], "baz")