Пример #1
0
        public void TestUnravelRavel(int[] shape, int index)
        {
            Multiarray <int> array = new Multiarray <int>(shape);

            Assert.AreEqual(index, array.RavelIndex(array.UnravelIndex(index)));
            Assert.AreEqual(array[index], array[array.UnravelIndex(index)]);
        }
Пример #2
0
        public void TestRavelUnravel(int[] shape, int[] indices)
        {
            Multiarray <int> array = new Multiarray <int>(shape);

            Assert.AreEqual(indices, array.UnravelIndex(array.RavelIndex(indices)));
            Assert.AreEqual(array[indices], array[array.RavelIndex(indices)]);
        }
Пример #3
0
        public void TestReorder(string arrayKey, int[] order, int[] indices, int element)
        {
            Multiarray <int> array        = TestIntegerArrays[arrayKey];
            Multiarray <int> arrayReorder = array.Reordered(order);

            Assert.AreEqual(array.Size, arrayReorder.Size);
            Assert.AreEqual(order, arrayReorder.Order);
            Assert.AreEqual(element, arrayReorder[indices]);
        }
Пример #4
0
        protected void SetUp()
        {
            TestIntegerArrays =
                new Dictionary <string, Multiarray <int> >()
            {
                { "A", Multiarray <int> .FromArray(new int[] {
                        1, 3, 5, 2, 4, 6, 8
                    }) },
                { "B", Multiarray <int> .FromArray(new int[, ] {
                        { 1, 2, 3 },
                        { 4, 5, 6 }
                    }) },
                { "C", Multiarray <int> .FromArray(new int[, , ] {
                        { { -4, -2, -1 }, { 1, 4, 2 }, { 5, 3, 1 }, { -6, 3, 13 } },
                        { { 0, 0, 1 }, { 1, 2, 3 }, { -4, 0, 5 }, { 7, 6, -1 } }
                    }) },
                { "D", Multiarray <int> .FromArray(new int[, , , ] {
                        { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 0, 1, 2 } } },
                        { { { 3, 4, 5 }, { 6, 7, 8 } }, { { 9, 0, 1 }, { 2, 3, 4 } } },
                        { { { 5, 6, 7 }, { 8, 9, 0 } }, { { 1, 2, 3 }, { 4, 5, 6 } } }
                    }) },
                { "E", Multiarray <int> .FromArray(new int[, ] {
                        { 1, 3, 5, 2, 4, 6, 8 }
                    }) },
                { "F", Multiarray <int> .FromArray(new int[, , ] {
                        { { -4, -2, -1 }, { 1, 4, 2 }, { 5, 3, 1 }, { -6, 3, 13 } },
                        { { 0, 0, 1 }, { 1, 2, 3 }, { -4, 0, 5 }, { 7, 6, -1 } }
                    }) },
                { "G", new Multiarray <int>(new int[] {
                        5, 2, 8
                    }, new int[] { 3 }) },
                { "H", new Multiarray <int>(new int[] {
                        1, 3, 4, 6
                    }, new int[] { 2, 2 }) },
                { "I", new Multiarray <int>(new int[] {
                        0, 0, 1, 2, -4, 0, 7, 6
                    }, new int[] { 1, 4, 2 }) },
                { "J", Multiarray <int> .FromArray(new int[] {
                        1, 3, 5, 3, 4, 6, 8
                    }) },
                { "K", Multiarray <int> .FromArray(new int[] {}) },
            };

            TestIntegerArrays.Add("A'", TestIntegerArrays["A"].Subarray(axis: 0, 2, 3, 6));
            TestIntegerArrays.Add("B'", TestIntegerArrays["B"].Subarray(axis: 1, new int[] { 0, 2 })
                                  .Subarray(axis: 0, new int[] { 0, 1 }));
            TestIntegerArrays.Add("C'", TestIntegerArrays["C"].Subarray(new int[][] {
                new int[] { 1 },
                null,
                new int[] { 0, 1 }
            }));

            TestIntegerArrays.Add("B''", TestIntegerArrays["B'"].Subarray(axis: 0, new int[] { 1, 0, 1 }));
        }
Пример #5
0
        public void TestNullEquality(string arrayKey)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(true, null == null);
            Assert.AreEqual(false, null != null);
            Assert.AreEqual(false, null == array);
            Assert.AreEqual(true, null != array);
            Assert.AreEqual(false, array == null);
            Assert.AreEqual(true, array != null);
        }
Пример #6
0
        public void TestModification(string arrayKey, int index)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            int value = array[index];

            array[index] += 1;
            Assert.AreEqual(value + 1, array[index]);

            array[index] -= 1;
            Assert.AreEqual(value, array[index]);
        }
Пример #7
0
        public void TestEquality(string arrayKeyA, string arrayKeyB, bool equal)
        {
            Multiarray <int> arrayA = TestIntegerArrays[arrayKeyA];
            Multiarray <int> arrayB = TestIntegerArrays[arrayKeyB];

            Assert.AreEqual(equal, arrayA == arrayB);
            Assert.AreEqual(!equal, arrayA != arrayB);
            Assert.AreEqual(!equal, !(arrayA == arrayB));
            Assert.AreEqual(equal, !(arrayA != arrayB));
            Assert.AreEqual(equal, arrayA.Equals(arrayB));
            Assert.AreEqual(equal, arrayB.Equals(arrayA));
            Assert.AreEqual(!equal, !arrayA.Equals(arrayB));
            Assert.AreEqual(!equal, !arrayB.Equals(arrayA));
        }
Пример #8
0
        public void TestSubarrayModification(string arrayKey, string subarrayKey, int[] arrayIndices, int[] subarrayIndices)
        {
            Multiarray <int> array    = TestIntegerArrays[arrayKey];
            Multiarray <int> subarray = TestIntegerArrays[subarrayKey];

            int value = array[arrayIndices];

            array[arrayIndices] += 1;
            Assert.AreEqual(value + 1, array[arrayIndices]);
            Assert.AreEqual(value + 1, subarray[subarrayIndices]);

            subarray[subarrayIndices] -= 1;
            Assert.AreEqual(value, array[arrayIndices]);
            Assert.AreEqual(value, subarray[subarrayIndices]);
        }
Пример #9
0
 public void TestArrayTypeMismatch(object[] data, bool fails)
 {
     if (fails)
     {
         Assert.Throws <ArrayTypeMismatchException>(delegate
         {
             Multiarray <double> array = Multiarray <double> .FromArray(data);
         });
     }
     else
     {
         Assert.DoesNotThrow(delegate
         {
             Multiarray <double> array = Multiarray <double> .FromArray(data);
         });
     }
 }
Пример #10
0
        public void TestIndexOutOfRange(string arrayKey, int index)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                int value = array[index];
            });
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                array[index] = 0;
            });
            Assert.Throws <IndexOutOfRangeException>(delegate
            {
                array.UnravelIndex(index);
            });
        }
Пример #11
0
        public void TestRankMismatch(string arrayKey, int[] indices)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.Throws <RankException>(delegate
            {
                int value = array[indices];
            });
            Assert.Throws <RankException>(delegate
            {
                array[indices] = 0;
            });
            Assert.Throws <RankException>(delegate
            {
                array.RavelIndex(indices);
            });
        }
Пример #12
0
        public void TestArrayEnumerate(string arrayKey, int[] elements)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            int k = 0;

            foreach (int element in array)
            {
                Assert.AreEqual(elements[k++], element);
            }

            k = 0;
            int count = 0;

            foreach (object obj in (IEnumerable)array)
            {
                count++;
                Assert.AreEqual(elements[k++], (int)obj);
            }
            Assert.AreEqual(count, elements.Length);
        }
Пример #13
0
        public void TestSize(string arrayKey, int size)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(size, array.Size);
        }
Пример #14
0
        public void TestIsMatrix(string arrayKey, bool isMatrix)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(isMatrix, array.IsMatrix());
        }
Пример #15
0
        public void TestIsVector(string arrayKey, bool isVector)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(isVector, array.IsVector());
        }
Пример #16
0
        public void TestFilled(double fillValue, int[] arrayShape, int[] arrayIndex)
        {
            Multiarray <double> array = Multiarray <double> .Filled(arrayShape, fillValue);

            Assert.AreEqual(fillValue, array[arrayIndex]);
        }
Пример #17
0
        public void TestOrder(string arrayKey, int[] order)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(order, array.Order);
        }
Пример #18
0
        public void TestDegree(string arrayKey, int degree)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(degree, array.Degree);
        }
Пример #19
0
        public void TestElements(string arrayKey, int index, int element)
        {
            Multiarray <int> array = TestIntegerArrays[arrayKey];

            Assert.AreEqual(element, array[index]);
        }