Sha256: 5a7c2069ab495245e7f5840bdd1216a18370d34ff3d8c00763507420c319432c

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forsta-0.0.1 test/construct_test.rb