You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Results from solve can sometimes be incorrect (depend on expression ordering) when one of the named expressions were already in calculator memory.
Incorrect behavior
require"dentaku"calculator=Dentaku::Calculator.new# Notice :discount is already present in calculator memorycalculator.store(discount: 20,foo: 20)do# Correct result# => {:discount=>50, :discount_not_applicable=>true}pcalculator.solve(discount: "foo + 30",discount_not_applicable: "IF(discount > 30, true, false)",# discount is 50 here (correct))endcalculator.store(discount: 20,foo: 20)do# BUG discount_not_applicable should be true# => {:discount_not_applicable=>false, :discount=>50}# Apparently :discount_not_applicable is evaluated first (uses discount: 20 value from memory)# Then :discount is evaluated and becomes 50 from that moment.pcalculator.solve(discount_not_applicable: "IF(discount > 30, true, false)",# discount is 20 here (BUG)discount: "foo + 30",)end
Correct behavior
# Notice :discount is not present in calculator memory# Solver sorts expressions properly before evaluation, so results are correctcalculator.store(foo: 20)do# Correct result# => {:discount=>50, :discount_not_applicable=>true}pcalculator.solve(discount: "foo + 30",discount_not_applicable: "IF(discount > 30, true, false)",# discount is 50 here (correct))endcalculator.store(foo: 20)do# Correct result# => {:discount_not_applicable=>true, :discount=>50}pcalculator.solve(discount_not_applicable: "IF(discount > 30, true, false)",# discount is 50 here (correct)discount: "foo + 30",)end
The text was updated successfully, but these errors were encountered:
Results from
solve
can sometimes be incorrect (depend on expression ordering) when one of the named expressions were already in calculator memory.The text was updated successfully, but these errors were encountered: