Ejemplo n.º 1
0
        public void Test_singleElementAccess() {
            int errorCode = 0; 
            try {
                ILArray<int> A = new ILArray<int>(new int[]{1,2,3,4,5,6,7,8,9,10,11,12},3,4); 
                if (!A[0].Equals(1)) throw new Exception("A[0] failed");
                if (!A[1].Equals(2)) throw new Exception("A[1] failed");
                if (!A[2].Equals(3)) throw new Exception("A[2] failed");
                if (!A[3].Equals(4)) throw new Exception("A[3] failed");
                if (!A[4].Equals(5)) throw new Exception("A[4] failed");
                if (!A[5].Equals(6)) throw new Exception("A[5] failed");
                if (!A[6].Equals(7)) throw new Exception("A[6] failed");
                if (!A[7].Equals(8)) throw new Exception("A[7] failed");
                if (!A[8].Equals(9)) throw new Exception("A[8] failed");
                if (!A[9].Equals(10)) throw new Exception("A[9] failed");
                if (!A[10].Equals(11)) throw new Exception("A[10] failed");
                if (!A[11].Equals(12)) throw new Exception("A[11] failed");
                errorCode = 1; 
                try {
                    ILArray<int> B = A[12]; 
                } catch (Exception) {
                    Info ("Out of range signaled ok");
                } 
                errorCode = 2; 
                if (!A[0,0].Equals(1)) throw new Exception("A[0,0] failed");
                if (!A[0,1].Equals(4)) throw new Exception("A[0,1] failed");
                if (!A[0,2].Equals(7)) throw new Exception("A[0,2] failed");
                if (!A[0,3].Equals(10)) throw new Exception("A[0,3] failed");
                if (!A[1,0].Equals(2)) throw new Exception("A[1,0] failed");
                if (!A[1,1].Equals(5)) throw new Exception("A[1,1] failed");
                if (!A[1,2].Equals(8)) throw new Exception("A[1,2] failed");
                if (!A[1,3].Equals(11)) throw new Exception("A[1,3] failed");
                if (!A[2,0].Equals(3)) throw new Exception("A[2,0] failed");
                if (!A[2,1].Equals(6)) throw new Exception("A[2,1] failed");
                if (!A[2,2].Equals(9)) throw new Exception("A[2,2] failed");
                if (!A[2,3].Equals(12)) throw new Exception("A[2,3] failed");
                errorCode = 3; 
                try { 
                    ILArray<int> B = A[3,3]; 
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                try { ILArray<int> B = A[2,4]; 
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                try { ILArray<int> B = A[4,3];  
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                // test reshaping index in last dimension
                errorCode = 4; 
                A = ILMath.toint32(ILMath.vector(1,24));
                A = ILMath.reshape(A,4,3,2); 
                if (!A[1,5].Equals(22)) throw new Exception("A[1,5] failed");
                if (!A[3,5].Equals(24)) throw new Exception("A[1,5] failed");
                errorCode = 5;
                ///////////////  REFERENCE ARRAY /////////////////////////////

                A = new ILArray<int>(new int[]{1,2,3,4,5,6,7,8,9,10,11,12},3,4);
                A.MinimumRefDimensions = 2; 
                A = (ILArray<int>)A.CreateReference(); 
                if (!A[0].Equals(1)) throw new Exception("A[0] failed");
                if (!A[1].Equals(2)) throw new Exception("A[1] failed");
                if (!A[2].Equals(3)) throw new Exception("A[2] failed");
                if (!A[3].Equals(4)) throw new Exception("A[3] failed");
                if (!A[4].Equals(5)) throw new Exception("A[4] failed");
                if (!A[5].Equals(6)) throw new Exception("A[5] failed");
                if (!A[6].Equals(7)) throw new Exception("A[6] failed");
                if (!A[7].Equals(8)) throw new Exception("A[7] failed");
                if (!A[8].Equals(9)) throw new Exception("A[8] failed");
                if (!A[9].Equals(10)) throw new Exception("A[9] failed");
                if (!A[10].Equals(11)) throw new Exception("A[10] failed");
                if (!A[11].Equals(12)) throw new Exception("A[11] failed");
                errorCode = 1; 
                try {
                    ILArray<int> B = A[12]; 
                } catch (Exception) {
                    Info ("Out of range signaled ok");
                } 
                errorCode = 2; 
                if (!A[0,0].Equals(1)) throw new Exception("A[0,0] failed");
                if (!A[0,1].Equals(4)) throw new Exception("A[0,1] failed");
                if (!A[0,2].Equals(7)) throw new Exception("A[0,2] failed");
                if (!A[0,3].Equals(10)) throw new Exception("A[0,3] failed");
                if (!A[1,0].Equals(2)) throw new Exception("A[1,0] failed");
                if (!A[1,1].Equals(5)) throw new Exception("A[1,1] failed");
                if (!A[1,2].Equals(8)) throw new Exception("A[1,2] failed");
                if (!A[1,3].Equals(11)) throw new Exception("A[1,3] failed");
                if (!A[2,0].Equals(3)) throw new Exception("A[2,0] failed");
                if (!A[2,1].Equals(6)) throw new Exception("A[2,1] failed");
                if (!A[2,2].Equals(9)) throw new Exception("A[2,2] failed");
                if (!A[2,3].Equals(12)) throw new Exception("A[2,3] failed");
                errorCode = 3; 
                try { 
                    ILArray<int> B = A[3,3]; 
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                try { ILArray<int> B = A[2,4]; 
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                try { ILArray<int> B = A[4,3];  
                    throw new Exception("out of range should throw exception");
                } catch (Exception e) {
                    if (e.Message == "out of range should throw exception")
                        throw e; 
                }
                // test reshaping index in last dimension
                errorCode = 4; 
                A = ILMath.toint32(ILMath.vector(1,24));
                A = ILMath.reshape(A,4,3,2); 
                if (!A[1,5].Equals(22)) throw new Exception("A[1,5] failed");
                if (!A[3,5].Equals(24)) throw new Exception("A[3,5] failed");
                Success();
            } catch (Exception e) {
                Error(errorCode, e.Message ); 
            }
        }