require_relative './test_helper' class TestConstruct < Minitest::Test def setup @child = Construct.new('child', :nil) @parent = Construct.new('parent', @child) end def test_initialize assert_instance_of Construct, @child assert_instance_of Construct, @parent end def test_car assert_equal 'child', @child.car assert_equal 'parent', @parent.car end def test_cdr assert_equal :nil, @child.cdr assert_instance_of Construct, @parent.cdr assert_equal @child, @parent.cdr assert_equal @child.car, @parent.cdr.car assert_equal @child.cdr, @parent.cdr.cdr end def test_construct_list? assert @child.construct_list? assert @parent.construct_list? end def test_to_array assert_instance_of Array, @parent.to_array assert_equal ['parent', 'child'], @parent.to_array flat_construct = Construct.new(1, 2) assert_equal flat_construct, flat_construct.to_array end def test_lisp_eval construct = Construct.new(:+, Construct.new(1, Construct.new(2, :nil))) environment = Environment.new(nil, { :+ => lambda { |x, y| x + y } }) assert_equal 3, construct.lisp_eval(environment, Environment.new) end end