require 'test/unit'
require 'criteria/array'
include Criteria

class Person
  attr_accessor :name, :age, :eyecolor
  def initialize(name, age, eyecolor)
    @name      = name
    @age       = age
    @eyecolor  = eyecolor
  end
end

class TestArray < Test::Unit::TestCase
  def setup
    @a = []
    @a << Person.new("Bob",  25, :brown)
    @a << Person.new("Mary", 30, :brown)
    @a << Person.new("George", 19, :green)
    @a << Person.new("Phil", 16, :green)
    @a << Person.new("John", 27, :purple)
    @a << Person.new("Lenna", 15, :purple)
    @a << Person.new("Jak", 12, :grey)
    @a << Person.new("Spike", 53, :grey)
    @a << Person.new("Terra", 23, :blue)

    @idx = ArrayTable.new(@a)
  end

  def test_select
    q = nil

    assert_nothing_raised {
      q = (@idx.age >= 20) & (@idx.eyecolor == :purple)
    }

    assert_equal(q.select(:name, :age), [["John", 27]])
  end


  def test_ints
    q = table = nil

    assert_nothing_raised {
      table = ArrayTable.new([1, 2, 3, 4, 5])
      q     = (table.to_i > 1) & (table.to_i < 5)
    }

    assert_equal(q.select, [2,3,4])
  end
end
    
