rubysolo/dentaku

Issue when using Dentaku::Calculator#solve! with IF statement

acuster77 opened this issue · 0 comments

Hi,

I ran into a surprising/incorrect behavior while using Dentaku::Calculator#solve! with multiple expressions, one containing an IF statement.

require 'dentaku'

calculator = Dentaku::Calculator.new

calculator.store(
  likes_apples: true,
  fruits_per_case: 10,
  apple_cases: 5,
  orange_cases: 3
)

calculator.memory
# => {"likes_apples"=>true, "fruits_per_case"=>10, "apple_cases"=>5, "orange_cases"=>3}

calculator.solve!(
  fruit_given: "IF(likes_apples, apples, oranges)",
  apples: "fruits_per_case * apple_cases",
  oranges: "fruits_per_case * orange_cases",
)
# => Traceback (most recent call last):
# .../lib/dentaku/calculator.rb:64:in `block in evaluate!': no value provided for variables: oranges (Dentaku::UnboundVariableError)

I was expecting #solve! to return:

{:fruit_given=>50, :apples=>50, :oranges=>30}

** Using Ruby 2.7.1 on Ubuntu 20.04 with dentaku@3.4.1