package TestCase::Lib::SPVM::IntList {
  use SPVM::IntList;

  sub new_with_array : int () {
    {
      my $list = SPVM::IntList->new_with_array([3, 5, INT32_MAX()]);
      
      unless ($list->get(0) == 3) {
        return 0;
      }

      unless ($list->get(1) == 5) {
        return 0;
      }

      unless ($list->get(2) == INT32_MAX()) {
        return 0;
      }
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
    }
    
    return 1;
  }

  sub to_array : int () {
    {
      my $list = SPVM::IntList->new_with_array([3, 5, INT32_MAX()]);
      
      my $array = $list->to_array;
      
      unless ($array isa int[]) {
        return 0;
      }
      
      unless ($array->[0] == 3) {
        return 0;
      }

      unless ($array->[1] == 5) {
        return 0;
      }

      unless ($array->[2] == INT32_MAX()) {
        return 0;
      }
      
      my $length = @$array;
      unless ($length == 3) {
        return 0;
      }
    }
    
    return 1;
  }

  sub get : int () {
    {
      my $list = SPVM::IntList->new_with_array([3, 5, INT32_MAX()]);
      
      unless ($list->get(0) == 3) {
        return 0;
      }

      unless ($list->get(1) == 5) {
        return 0;
      }

      unless ($list->get(2) == INT32_MAX()) {
        return 0;
      }
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
      
      eval {
        $list->get(-1);
      };
      unless ($@) {
        return 0;
      }
      
      eval {
        $list->get(3);
      };
      unless ($@) {
        return 0;
      }
      
      $@ = undef;
    }
    
    return 1;
  }

  sub set : int () {
    {
      my $list = SPVM::IntList->new_with_array([0, 0, 0]);
      
      $list->set(0 => 3);
      $list->set(1 => 5);
      $list->set(2 => INT32_MAX());
      
      unless ($list->get(0) == 3) {
        return 0;
      }

      unless ($list->get(1) == 5) {
        return 0;
      }

      unless ($list->get(2) == INT32_MAX()) {
        return 0;
      }
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
      
      eval {
        $list->get(-1);
      };
      unless ($@) {
        return 0;
      }
      
      eval {
        $list->get(3);
      };
      unless ($@) {
        return 0;
      }
      
      $@ = undef;
    }
    
    return 1;
  }

  sub push : int () {
    # push
    {
      my $list = SPVM::IntList->new;
      
      $list->push(3);
      $list->push(5);
      $list->push(INT32_MAX());
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
      
      unless ($list->get(0) == 3 && $list->get(1) == 5 && $list->get(2) == INT32_MAX()) {
        return 0;
      }
    }
    
    # internal _extend tests
    {
      my $list = SPVM::IntList->new;
      
      for (my $i = 0; $i < 100; $i++) {
        $list->push(1);
      }
      
      my $length = $list->length;
      unless ($length == 100) {
        return 0;
      }
      
      for (my $i = 0; $i < 100; $i++) {
        unless ($list->get($i) == 1) {
          return 0;
        }
      }
    }
    
    
    return 1;
  }

  sub pop : int () {
    # pop
    {
      my $list = SPVM::IntList->new;
      
      $list->push(3);
      $list->push(5);
      $list->push(INT32_MAX());
      
      unless ($list->pop == INT32_MAX()) {
        return 0;
      }

      unless ($list->pop == 5) {
        return 0;
      }

      unless ($list->pop == 3) {
        return 0;
      }
      
      my $length = $list->length;
      unless ($length == 0) {
        return 0;
      }
      
      eval {
        $list->pop;
      };
      unless ($@) {
        return 0;
      }
      $@ = undef;
    }
    
    return 1;
  }

  sub unshift : int () {
    # unshift
    {
      my $list = SPVM::IntList->new;
      
      $list->unshift(3);
      $list->unshift(5);
      $list->unshift(INT32_MAX());
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
      
      unless ($list->get(0) == INT32_MAX() && $list->get(1) == 5 && $list->get(2) == 3) {
        return 0;
      }
    }
    
    # internal _extend tests
    {
      my $list = SPVM::IntList->new;
      
      for (my $i = 0; $i < 100; $i++) {
        $list->unshift(1);
      }
      
      my $length = $list->length;
      unless ($length == 100) {
        return 0;
      }
      
      for (my $i = 0; $i < 100; $i++) {
        unless ($list->get($i) == 1) {
          return 0;
        }
      }
    }
    
    return 1;
  }

  sub shift : int () {
    # shift
    {
      my $list = SPVM::IntList->new;
      
      $list->unshift(3);
      $list->unshift(5);
      $list->unshift(INT32_MAX());
      
      unless ($list->shift == INT32_MAX()) {
        return 0;
      }

      unless ($list->shift == 5) {
        return 0;
      }

      unless ($list->shift == 3) {
        return 0;
      }
      
      my $length = $list->length;
      unless ($length == 0) {
        return 0;
      }
      
      eval {
        $list->shift;
      };
      unless ($@) {
        return 0;
      }
      $@ = undef;
    }
    
    return 1;
  }

  sub length : int () {
    # length
    {
      my $list = SPVM::IntList->new;
      
      $list->unshift(3);
      $list->unshift(5);
      $list->unshift(INT32_MAX());
      
      my $length = $list->length;
      unless ($length == 3) {
        return 0;
      }
    }
    
    return 1;
  }

}
