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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user