示例#1
0
    public bool NegTest1()
    {
        bool retVal = true;

        int[] intList = new int[0];
        MyEnumerator <int> myEnumerator = new MyEnumerator <int>(intList);

        ((IEnumerator <int>)myEnumerator).MoveNext();

        TestLibrary.TestFramework.BeginScenario("NegTest1: Using user-defined type which is empty");

        try
        {
            int i = ((IEnumerator <int>)myEnumerator).Current;
            TestLibrary.TestFramework.LogError("007", "The InvalidOperationException was not thrown as expected");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#2
0
        public void IEnumeratorDisposeTest()
        {
            var enumerator = new MyEnumerator();

            foreach (var item in enumerator)
            {
            }

            Assert.IsTrue(enumerator.Disposed);
        }
示例#3
0
        /** Serializes the cells that are allocated to a certain row range*/
        public int SerializeCellRow(int row, int offset, byte[] data)
        {
            MyEnumerator itr = new MyEnumerator(ref records, row, row);
            int          pos = offset;

            while (itr.MoveNext())
            {
                CellValueRecordInterface cell = (CellValueRecordInterface)itr.Current;
                if (cell.Row != row)
                {
                    break;
                }
                pos += ((RecordBase)cell).Serialize(pos, data);
            }
            return(pos - offset);
        }
示例#4
0
    public override IList <IEnumerator <KeyValuePair <long, T> > > GetOrderablePartitions(int partitionCount)
    {
        var result = new List <IEnumerator <KeyValuePair <long, T> > >();
        //for (int i = 0; i < partitionCount; ++i)
        //{
        //    result.Add(new MyEnumerator<T>(_consumingEnumerable, _ordering));
        //}
        //share the enumerator between partitions in this case to maintain
        //the proper locking on ordering.
        var enumerator = new MyEnumerator <T>(_consumingEnumerable, _ordering);

        for (int i = 0; i < partitionCount; ++i)
        {
            result.Add(enumerator);
        }
        return(result);
    }
示例#5
0
    public bool PosTest2()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest2: Using List<T> which implemented the GetEnumerator method in IComparer<T> and Type is String...";
        const string c_TEST_ID   = "P002";

        String[] strList = new String[2];
        String   x       = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);
        String   y       = TestLibrary.Generator.GetString(-55, false, c_MINI_STRING_LENGTH, c_MAX_STRING_LENGTH);

        strList[0] = x;
        strList[1] = y;

        MyEnumerator <String> myEnumerator = new MyEnumerator <String>(strList);

        ((IEnumerator <String>)myEnumerator).MoveNext();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (((IEnumerator <String>)myEnumerator).Current != x)
            {
                string errorDesc = "Value is not " + x + " as expected: Actual(" + ((IEnumerator <String>)myEnumerator).Current + ")";
                TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }


            ((IEnumerator <String>)myEnumerator).MoveNext();
            if (((IEnumerator <String>)myEnumerator).Current != y)
            {
                string errorDesc = "Value is not " + y + " as expected: Actual(" + ((IEnumerator <String>)myEnumerator).Current + ")";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
示例#6
0
    public bool PosTest1()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest1: Using customer class which implemented the GetEnumerator method in IEnumerator<T> and Type is int...";
        const string c_TEST_ID   = "P001";

        int[] intList = new int[2];
        int   x       = TestLibrary.Generator.GetInt32(-55);
        int   y       = TestLibrary.Generator.GetInt32(-55);

        intList[0] = x;
        intList[1] = y;

        MyEnumerator <int> myEnumerator = new MyEnumerator <int>(intList);

        ((IEnumerator <int>)myEnumerator).MoveNext();

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (((IEnumerator <int>)myEnumerator).Current != x)
            {
                string errorDesc = "Value is not " + x + " as expected: Actual(" + ((IEnumerator <int>)myEnumerator).Current + ")";
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }


            ((IEnumerator <int>)myEnumerator).MoveNext();
            if (((IEnumerator <int>)myEnumerator).Current != y)
            {
                string errorDesc = "Value is not " + y + " as expected: Actual(" + ((IEnumerator <int>)myEnumerator).Current + ")";
                TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest3()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest3: Useing customer class which implemented the GetEnumerator method in IEnumerable<T>... ";
        const string c_TEST_ID   = "P003";

        int[] pArray = new int[2];
        pArray[0] = TestLibrary.Generator.GetInt32(-55);
        pArray[1] = TestLibrary.Generator.GetInt32(-55);

        MyEnumerable <int> myEnumerable = new MyEnumerable <int>(pArray);
        MyEnumerator <int> myEnumerator = new MyEnumerator <int>(pArray);

        ((IEnumerator <int>)myEnumerator).MoveNext();
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            IEnumerator <int> enumerator = ((IEnumerable <int>)myEnumerable).GetEnumerator();
            enumerator.MoveNext();

            if (enumerator.Current != ((IEnumerator <int>)myEnumerator).Current)
            {
                string errorDesc = "Value is not " + myEnumerator.Current + " as expected: Actual(" + enumerator.Current + ")";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
            enumerator.MoveNext();
            ((IEnumerator <int>)myEnumerator).MoveNext();

            if (enumerator.Current != ((IEnumerator <int>)myEnumerator).Current)
            {
                string errorDesc = "Value is not " + myEnumerator.Current + " as expected: Actual(" + enumerator.Current + ")";
                TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("009", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
示例#8
0
        /** Tallies a count of the size of the cell records
         *  that are attached to the rows in the range specified.
         */
        public int GetRowCellBlockSize(int startRow, int endRow)
        {
            MyEnumerator itr  = new MyEnumerator(ref records, startRow, endRow);
            int          size = 0;

            while (itr.MoveNext())
            {
                CellValueRecordInterface cell = (CellValueRecordInterface)itr.Current;
                int row = cell.Row;
                if (row > endRow)
                {
                    break;
                }
                if ((row >= startRow) && (row <= endRow))
                {
                    size += ((RecordBase)cell).RecordSize;
                }
            }
            return(size);
        }
示例#9
0
        public void TestMethod1()
        {
            var source = new int[5, 5];
            var mp     = new MyEnumerator <int>(source);

            bool result;

            for (int i = 0; i < 25; i++)
            {
                result = mp.MoveNext();
                Assert.IsTrue(result);
            }

            result = mp.MoveNext();
            Assert.IsFalse(result);

            mp.Reset();
            result = mp.MoveNext();
            Assert.IsTrue(result);
        }
示例#10
0
        /** Serializes the cells that are allocated to a certain row range*/
        public int SerializeCellRow(int row, int offset, byte[] data)
        {
            MyEnumerator itr = new MyEnumerator(ref records,row, row);
            int pos = offset;

            while (itr.MoveNext())
            {
                CellValueRecordInterface cell = (CellValueRecordInterface)itr.Current;
                if (cell.Row != row)
                    break;
                pos += ((RecordBase)cell).Serialize(pos, data);
            }
            return pos - offset;
        }
示例#11
0
 /** Tallies a count of the size of the cell records
  *  that are attached to the rows in the range specified.
  */
 public int GetRowCellBlockSize(int startRow, int endRow)
 {
     MyEnumerator itr = new MyEnumerator(ref records,startRow, endRow);
     int size = 0;
     while (itr.MoveNext())
     {
         CellValueRecordInterface cell = (CellValueRecordInterface)itr.Current;
         int row = cell.Row;
         if (row > endRow)
             break;
         if ((row >= startRow) && (row <= endRow))
             size += ((RecordBase)cell).RecordSize;
     }
     return size;
 }
示例#12
0
        public IEnumerator GetEnumerator()
        {
            MyEnumerator enumerator = new MyEnumerator(this);

            return(enumerator);
        }
 public MyStructEnumerator(MyEnumerator <T> enumerator)
 {
     _enumerator = enumerator;
 }
示例#14
0
        IEnumerator IEnumerable.GetEnumerator()
        {
            MyEnumerator my = new MyEnumerator();

            return(my);
        }
 void IEnumerator.Reset()
 {
     MyEnumerator.Reset();
 }
 bool IEnumerator.MoveNext()
 {
     return(MyEnumerator.MoveNext());
 }