Sha256: 0dd720f9d4e3ad253f108d5e48349d9d0cc0596ed0908f1c9a0080af9962cafb

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

require 'helper'

class TestList < Test::Unit::TestCase
  def test_construction
    list = Dasht::List.new
    ptr1 = list.append(1)
    ptr2 = list.append(2)
    ptr3 = list.append(3)
    assert_equal 6, list.enum(ptr1).to_a.inject(:+)
  end

  def test_trim_to
    list = Dasht::List.new
    ptr1 = list.append(1)
    ptr2 = list.append(2)
    ptr3 = list.append(3)

    list.trim_to(ptr1)
    assert_equal 6, list.enum(ptr1).to_a.inject(:+)

    list.trim_to(ptr2)
    assert_equal 5, list.enum(ptr1).to_a.inject(:+)

    list.trim_to(ptr3)
    assert_equal 3, list.enum(ptr1).to_a.inject(:+)

    ptr4 = list.append(4)
    assert_equal 7, list.enum(ptr1).to_a.inject(:+)

    list.trim_to(ptr4)
    assert_equal 4, list.enum(ptr1).to_a.inject(:+)

    list.trim_to(list.tail_pointer)
    assert_equal nil, list.enum(ptr1).to_a.inject(:+)
  end

  def test_trim_while
    list = Dasht::List.new
    ptr1 = list.append(1)
    ptr2 = list.append(2)
    ptr3 = list.append(3)
    list.trim_while do |data|
      data < 2
    end
    assert_equal 5, list.enum(ptr1).to_a.inject(:+)

    list.trim_while do |data|
      data < 3
    end
    assert_equal 3, list.enum(ptr1).to_a.inject(:+)

    ptr4 = list.append(4)
    assert_equal 7, list.enum(ptr1).to_a.inject(:+)

    list.trim_while do |data|
      data < 4
    end
    assert_equal 4, list.enum(ptr1).to_a.inject(:+)

    list.trim_while do |data|
      data < 5
    end
    assert_equal nil, list.enum(ptr1).to_a.inject(:+)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dasht-0.1.9 test/test_list.rb
dasht-0.1.8 test/test_list.rb
dasht-0.1.7 test/test_list.rb
dasht-0.1.6 test/test_list.rb
dasht-0.1.5 test/test_list.rb
dasht-0.1.4 test/test_list.rb
dasht-0.1.3 test/test_list.rb
dasht-0.1.2 test/test_list.rb
dasht-0.1.1 test/test_list.rb
dasht-0.1.0 test/test_list.rb