context: // This test tests all the methods in the C# collection wrapper
  
  using System;
  using li_std_vectorNamespace;
  
  public class li_std_vector_runme {
  
    private static readonly int collectionSize = 20;
    private static readonly int midCollection = collectionSize/2;
  
    public static DoubleVector myDoubleVector;
    public static RealVector myRealVector;
  
    public static void Main() {
      // Setup collection
      DoubleVector vect = new DoubleVector();
      for (int i=0; i<collectionSize; i++) {
        double num = i*10.1;
        vect.Add(num);
      }
  
      // Count property test
      if (vect.Count != collectionSize)
        throw new Exception("Count test failed");
  
      // IsFixedSize property test
      if (vect.IsFixedSize)
        throw new Exception("IsFixedSize test failed");
  
      // IsReadOnly property test
      if (vect.IsReadOnly)
        throw new Exception("IsReadOnly test failed");
  
      // Item indexing
      vect[0] = 200.1;
      if (vect[0] != 200.1)
        throw new Exception("Item property test failed");
      vect[0] = 0*10.1;
      try {
        vect[-1] = 777.1;
        throw new Exception("Item out of range (1) test failed");
      } catch (ArgumentOutOfRangeException) {
      }
      try {
        vect[vect.Count] = 777.1;
        throw new Exception("Item out of range (2) test failed");
      } catch (ArgumentOutOfRangeException) {
      }
  
      // CopyTo() test
      {
        double[] outputarray = new double[collectionSize];
        vect.CopyTo(outputarray);
        int index = 0;
        foreach(double val in outputarray) {
          if (vect[index] != val)
            throw new Exception("CopyTo (1) test failed, index:" + index);
          index++;
        }
      }
      {
        double[] outputarray = new double[midCollection+collectionSize];
        vect.CopyTo(outputarray, midCollection);
        int index = midCollection;
        foreach(double val in vect) {
          if (outputarray[index] != val)
            throw new Exception("CopyTo (2) test failed, index:" + index);
          index++;
        }
      }
      {
        double[] outputarray = new double[3];
        vect.CopyTo(10, outputarray, 1, 2);
          if (outputarray[0] != 0.0 || outputarray[1] != vect[10] || outputarray[2] != vect[11])
            throw new Exception("CopyTo (3) test failed");
      }
      {
        double[] outputarray = new double[collectionSize-1];
        try {
          vect.CopyTo(outputarray);
          throw new Exception("CopyTo (4) test failed");
        } catch (ArgumentException) {
        }
      }
      {
        StructVector inputvector = new StructVector();
        int arrayLen = 10;
        for (int i=0; i<arrayLen; i++) {
          inputvector.Add(new Struct(i/10.0));
        }
        Struct[] outputarray = new Struct[arrayLen];
        inputvector.CopyTo(outputarray);
        for(int i=0; i<arrayLen; i++) {
          if (outputarray[i].num != inputvector[i].num)
            throw new Exception("CopyTo (6) test failed, i:" + i);
        }
        foreach (Struct s in inputvector) {
          s.num += 20.0;
        }
        for(int i=0; i<arrayLen; i++) {
          if (outputarray[i].num + 20.0 != inputvector[i].num )
            throw new Exception("CopyTo (7) test failed (only a shallow copy was made), i:" + i);
        }
      }
      {
        try {
          vect.CopyTo(null);
          throw new Exception("CopyTo (8) test failed");
        } catch (ArgumentNullException) {
        }
      }
  
      // Contains() test
      if (!vect.Contains(0*10.1))
        throw new Exception("Contains test 1 failed");
      if (!vect.Contains(10*10.1))
        throw new Exception("Contains test 2 failed");
      if (!vect.Contains(19*10.1))
        throw new Exception("Contains test 3 failed");
      if (vect.Contains(20*10.1))
        throw new Exception("Contains test 4 failed");
  
      {
        // ICollection constructor
        double[] doubleArray = new double[] { 0.0, 11.1, 22.2, 33.3, 44.4, 55.5, 33.3 };
        DoubleVector dv = new DoubleVector(doubleArray);
        if (doubleArray.Length != dv.Count)
          throw new Exception("ICollection constructor length check failed: " + doubleArray.Length + "-" + dv.Count);
        for (int i=0; i<doubleArray.Length; i++) {
          if (doubleArray[i] != dv[i])
            throw new Exception("ICollection constructor failed, index:" + i);
        }
        {
          Struct[] structArray = new Struct[] { new Struct(0.0), new Struct(11.1), new Struct(22.2), new Struct(33.3) };
          StructVector sv = new StructVector(structArray);
          for (int i=0; i<structArray.Length; i++) {
            structArray[i].num += 200.0;
          }
          for (int i=0; i<structArray.Length; i++) {
            if (structArray[i].num != sv[i].num + 200.0)
              throw new Exception("ICollection constructor not a deep copy, index:" + i);
          }
        }
        try {
          new DoubleVector((System.Collections.ICollection)null);
          throw new Exception("ICollection constructor null test failed");
        } catch (ArgumentNullException) {
        }
        {
          // Collection initializer test, requires C# 3.0
  //        myDoubleVector = new DoubleVector() { 123.4, 567.8, 901.2 };
        }
  
        // IndexOf() test
        for (int i=0; i<collectionSize; i++) {
          if (vect.IndexOf(i*10.1) != i)
            throw new Exception("IndexOf test " + i + " failed");
        }
        if (vect.IndexOf(200.1) != -1)
          throw new Exception("IndexOf non-existent test failed");
        if (dv.IndexOf(33.3) != 3)
          throw new Exception("IndexOf position test failed");
  
        // LastIndexOf() test
        for (int i=0; i<collectionSize; i++) {
          if (vect.LastIndexOf(i*10.1) != i)
            throw new Exception("LastIndexOf test " + i + " failed");
        }
        if (vect.LastIndexOf(200.1) != -1)
          throw new Exception("LastIndexOf non-existent test failed");
        if (dv.LastIndexOf(33.3) != 6)
          throw new Exception("LastIndexOf position test failed");
  
        // Copy constructor test
        DoubleVector dvCopy = new DoubleVector(dv);
        for (int i=0; i<doubleArray.Length; i++) {
          if (doubleArray[i] != dvCopy[i])
            throw new Exception("Copy constructor failed, index:" + i);
        }
      }
      {
        // Repeat() test
        try {
          myDoubleVector = DoubleVector.Repeat(77.7, -1);
          throw new Exception("Repeat negative count test failed");
        } catch (ArgumentOutOfRangeException) {
        }
        DoubleVector dv = DoubleVector.Repeat(77.7, 5);
        if (dv.Count != 5)
          throw new Exception("Repeat count test failed");
        
        // Also tests enumerator
        {
          System.Collections.IEnumerator myEnumerator = dv.GetEnumerator();
          while ( myEnumerator.MoveNext() ) {
             if ((double)myEnumerator.Current != 77.7)
               throw new Exception("Repeat (1) test failed");
          }
        }
        {
          System.Collections.Generic.IEnumerator<double> myEnumerator = dv.GetEnumerator();
          while ( myEnumerator.MoveNext() ) {
             if (myEnumerator.Current != 77.7)
               throw new Exception("Repeat (2) test failed");
          }
        }
      }
  
      {
        // InsertRange() test
        DoubleVector dvect = new DoubleVector();
        for (int i=0; i<5; i++) {
          dvect.Add(1000.0*i);
        }
        vect.InsertRange(midCollection, dvect);
        if (vect.Count != collectionSize+dvect.Count)
          throw new Exception("InsertRange test size failed");
  
        for (int i=0; i<midCollection; i++) {
          if (vect.IndexOf(i*10.1) != i)
            throw new Exception("InsertRange (1) test " + i + " failed");
        }
        for (int i=0; i<dvect.Count; i++) {
          if (vect[i+midCollection] != dvect[i])
            throw new Exception("InsertRange (2) test " + i + " failed");
        }
        for (int i=midCollection; i<collectionSize; i++) {
          if (vect.IndexOf(i*10.1) != i+dvect.Count)
            throw new Exception("InsertRange (3) test " + i + " failed");
        }
        try {
          vect.InsertRange(0, null);
          throw new Exception("InsertRange (4) test failed");
        } catch (ArgumentNullException) {
        }
  
        // RemoveRange() test
        vect.RemoveRange(0, 0);
        vect.RemoveRange(midCollection, dvect.Count);
        if (vect.Count != collectionSize)
          throw new Exception("RemoveRange test size failed");
        for (int i=0; i<collectionSize; i++) {
          if (vect.IndexOf(i*10.1) != i)
            throw new Exception("RemoveRange test " + i + " failed");
        }
        try {
          vect.RemoveRange(-1, 0);
          throw new Exception("RemoveRange index out of range (1) test failed");
        } catch (ArgumentOutOfRangeException) {
        }
        try {
          vect.RemoveRange(0, -1);
          throw new Exception("RemoveRange count out of range (2) test failed");
        } catch (ArgumentOutOfRangeException) {
        }
        try {
          vect.RemoveRange(collectionSize+1, 0);
          throw new Exception("RemoveRange index and count out of range (1) test failed");
        } catch (ArgumentException) {
        }
        try {
          vect.RemoveRange(0, collectionSize+1);
          throw new Exception("RemoveRange index and count out of range (2) test failed");
        } catch (ArgumentException) {
        }
  
        // AddRange() test
        vect.AddRange(dvect);
        if (vect.Count != collectionSize+dvect.Count)
          throw new Exception("AddRange test size failed");
        for (int i=0; i<collectionSize; i++) {
          if (vect.IndexOf(i*10.1) != i)
            throw new Exception("AddRange (1) test " + i + " failed");
        }
        for (int i=0; i<dvect.Count; i++) {
          if (vect[i+collectionSize] != dvect[i])
            throw new Exception("AddRange (2) test " + i + " failed");
        }
        try {
          vect.AddRange(null);
          throw new Exception("AddRange (3) test failed");
        } catch (ArgumentNullException) {
        }
        vect.RemoveRange(collectionSize, dvect.Count);
  
        // GetRange() test
        int rangeSize = 5;
        DoubleVector returnedVec = vect.GetRange(0, 0);
        returnedVec = vect.GetRange(midCollection, rangeSize);
        if (returnedVec.Count != rangeSize)
          throw new Exception("GetRange test size failed");
        for (int i=0; i<rangeSize; i++) {
          if (returnedVec.IndexOf((i+midCollection)*10.1) != i)
            throw new Exception("GetRange test " + i + " failed");
        }
        try {
          vect.GetRange(-1, 0);
          throw new Exception("GetRange index out of range (1) test failed");
        } catch (ArgumentOutOfRangeException) {
        }
        try {
          vect.GetRange(0, -1);
          throw new Exception("GetRange count out of range (2) test failed");
        } catch (ArgumentOutOfRangeException) {
        }
        try {
          vect.GetRange(collectionSize+1, 0);
          throw new Exception("GetRange index and count out of range (1) test failed");
        } catch (ArgumentException) {
        }
        try {
          vect.GetRange(0, collectionSize+1);
          throw new Exception("GetRange index and count out of range (2) test failed");
        } catch (ArgumentException) {
        }
        {
  
gt:         StructVector inputvector = new StructVector();