示例#1
0
 public void GetIndices()
 {
     Assert.AreEqual(new int[] { 0, 0 }, _array.GetIndices(0));
     Assert.AreEqual(new int[] { 0, 1 }, _array.GetIndices(1));
     Assert.AreEqual(new int[] { 1, 0 }, _array.GetIndices(3));
     Assert.AreEqual(new int[] { 1, 2 }, _array.GetIndices(5));
 }
示例#2
0
        public void Constructor()
        {
            var source = new CloneableType[4, 2]
            {
                { "a", "b" }, { "c", "d" }, { "e", "f" }, { "g", "h" }
            };
            StringArray array = new StringArray(source, true);

            Assert.AreEqual(8, array.Length);
            Assert.AreEqual(2, array.Rank);
            Assert.AreEqual(4, array.GetLength(0));
            Assert.AreEqual(2, array.GetLength(1));

            // check equality by multidimensional index
            for (int i = 0; i < array.Length; i++)
            {
                int[] indices = array.GetIndices(i);
                var   value   = source.GetValue(indices);
                Assert.AreEqual(value, array[i]);
                Assert.AreSame(value, array[i]);
            }

            // check equality by enumeration sequence
            int index = 0;

            foreach (CloneableType value in source)
            {
                Assert.AreEqual(value, array[index]);
                Assert.AreSame(value, array[index]);
                index++;
            }
        }
示例#3
0
        public void GetIndices3D()
        {
            StringArray array = new StringArray(2, 3, 4);

            Assert.AreEqual(new int[] { 0, 0, 0 }, array.GetIndices(0));
            Assert.AreEqual(new int[] { 0, 0, 1 }, array.GetIndices(1));
            Assert.AreEqual(new int[] { 0, 1, 0 }, array.GetIndices(4));
            Assert.AreEqual(new int[] { 0, 2, 0 }, array.GetIndices(8));
            Assert.AreEqual(new int[] { 1, 0, 0 }, array.GetIndices(12));
            Assert.AreEqual(new int[] { 1, 2, 3 }, array.GetIndices(23));
        }