class TestCase::Operator::ArrayAccess {
  use TestCase::Minimal;
  use Fn;
  use Array;
  use Point;
  use TestCase::Point_3b;
  use TestCase::Point_3s;
  use TestCase::Point_3i;
  use TestCase::Point_3l;
  use TestCase::Point_3f;
  use TestCase::Point_3d;
  
  static method array_store_undef : int () {
    my $minimals = new TestCase::Minimal[3];
    $minimals->[0] = TestCase::Minimal->new;
    $minimals->[0] = undef;
    
    if ($minimals->[0] == undef) {
      return 1;
    }
    return 0;
  }
  
  static method array_set_and_get_array_element_first : int () {
    
    my $nums = new int[3];
    $nums->[0] = 345;
    
    return $nums->[0];
  }
  
  static method array_set_and_get_array_element_last : int () {
    
    my $nums = new int[3];
    $nums->[2] = 298;
    
    return $nums->[2];
  }
  
  static method array_culcurate_sum_by_for : int () {
    
    my $nums = new int[3];
    $nums->[0] = 1;
    $nums->[1] = 2;
    $nums->[2] = 3;
    
    my $total = 0;
    for (my $i = 0; $i < @$nums; $i++) {
      $total = $total + $nums->[$i];
    }
    
    return $total;
  }
  
  static method set_cannot_assign : int () {
    
    my $values = (object[])new Int[][1];
    
    eval { $values->[0] = [Long->new(1)]; }
    
    unless (Fn->contains($@, "An array element set failed. Long[] type cannot be assigned to Int[] type.")) {
      return 0;
    }
    
    return 1;
  }
  
  static method array : int () {
    
    {
      my $array = new byte[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new short[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new int[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new long[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new float[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new double[1];
      
      $array->[-1] = 1;
      
      unless ($array->[0] == 1) {
        return 0;
      }
      
      unless ($array->[-1] == 1) {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new string[1];
      
      $array->[-1] = "1";
      
      unless ($array->[0] eq "1") {
        return 0;
      }
      
      unless ($array->[-1] eq "1") {
        return 0;
      }
      
      $array->[-1] = undef;
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = "1"; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = "1"; }
      unless ($@) {
        return 0;
      }
      
      unless ($array->[0] == undef) {
        return 0;
      }
      
      unless ($array->[-1] == undef) {
        return 0;
      }
      
      eval { $array->[-2] = undef; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = undef; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new object[1];
      
      $array->[-1] = "1";
      
      unless ($array->[0]->(string) eq "1") {
        return 0;
      }
      
      unless ($array->[-1]->(string) eq "1") {
        return 0;
      }
      
      eval { $array->[-2]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2] = "1"; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1] = "1"; }
      unless ($@) {
        return 0;
      }
      
    }
    
    return 1;
  }
  
  static method mulnum_array : int () {
    
    {
      my $array = new TestCase::Point_3b[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new TestCase::Point_3s[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new TestCase::Point_3i[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new TestCase::Point_3l[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new TestCase::Point_3f[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    {
      my $array = new TestCase::Point_3d[1];
      
      $array->[-1]{x} = 1;
      
      unless ($array->[0]{x} == 1) {
        return 0;
      }
      
      unless ($array->[-1]{x} == 1) {
        return 0;
      }
      
      eval { $array->[-2]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[-2]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x}; }
      unless ($@) {
        return 0;
      }
      
      eval { $array->[1]{x} = 1; }
      unless ($@) {
        return 0;
      }
      
    }
    
    return 1;
  }
  
}
