Пример #1
0
        public void Constructor_WhenPassedArray_ReturnsCorrectSize()
        {
            var arr = new int[3, 2];
            var matrix = new CoolMatrix(arr);

            var expectedSize = new Size(width: 3, height: 2);

            Assert.AreEqual(expectedSize, matrix.Size);
        }
Пример #2
0
        public static CoolMatrix operator +(CoolMatrix a, int b)
        {
            var res = new CoolMatrix(new int[a.Size.Width, a.Size.Height]);

            for (int i = 0; i < a.Size.Width; i++)
            {
                for (int j = 0; j < a.Size.Height; j++)
                {
                    res.values[i, j] = a.values[i, j] + b;
                }
            }

            return(res);
        }
Пример #3
0
        public CoolMatrix Transpose()
        {
            var res = new CoolMatrix(new int[Size.Height, Size.Width]);

            for (int i = 0; i < Size.Width; i++)
            {
                for (int j = 0; j < Size.Height; j++)
                {
                    res.values[j, i] = this[i, j];
                }
            }

            return(res);
        }
Пример #4
0
        public static CoolMatrix operator *(CoolMatrix a, CoolMatrix b)
        {
            if (a.Size != b.Size)
            {
                throw new ArgumentException();
            }

            var res = new CoolMatrix(new int[a.Size.Width, a.Size.Height]);

            for (int i = 0; i < a.Size.Width; i++)
            {
                for (int j = 0; j < a.Size.Height; j++)
                {
                    res.values[i, j] = a.values[i, j] * b.values[i, j];
                }
            }

            return res;
        }
Пример #5
0
        public static CoolMatrix operator *(CoolMatrix a, CoolMatrix b)
        {
            if (a.Size != b.Size)
            {
                throw new ArgumentException();
            }

            var res = new CoolMatrix(new int[a.Size.Width, a.Size.Height]);

            for (int i = 0; i < a.Size.Width; i++)
            {
                for (int j = 0; j < a.Size.Height; j++)
                {
                    res.values[i, j] = a.values[i, j] * b.values[i, j];
                }
            }

            return(res);
        }
Пример #6
0
 protected bool Equals(CoolMatrix other)
 {
     if (Size != other.Size) return false;
     for (var i = 0; i < Size.Width; i++)
     {
         for (var j = 0; j < Size.Height; j++)
         {
             if (this[i, j] != other[i, j]) return false;
         }
     }
     return true;
 }
Пример #7
0
        public static CoolMatrix operator +(CoolMatrix left, CoolMatrix right)
        {
            if (left.Size != right.Size) throw new ArgumentException("different sizes");

            CoolMatrix result = new CoolMatrix(new int[left.Size.Width, left.Size.Height]);

            for (var i = 0; i < result.Size.Width; i++)
            {
                for (var j = 0; j < result.Size.Height; j++)
                    result._arrInts[i, j] = left._arrInts[i, j] + right._arrInts[i, j];
            }

            return result;
        }
Пример #8
0
        private bool Equals(CoolMatrix other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (Size != other.Size) return false;

            for(var i=0;i<Size.Width;i++)
                for (var j = 0; j < Size.Height; j++)
                {
                    if (_arrInts[i, j] != other._arrInts[i, j]) return false;
                }
            return true;
        }
Пример #9
0
        public static CoolMatrix operator *(CoolMatrix a, int b)
        {
            var res = new CoolMatrix(new int[a.Size.Width, a.Size.Height]);

            for (int i = 0; i < a.Size.Width; i++)
            {
                for (int j = 0; j < a.Size.Height; j++)
                {
                    res.values[i, j] = a.values[i, j] * b;
                }
            }

            return res;
        }
Пример #10
0
        public CoolMatrix Transpose()
        {
            var res = new CoolMatrix(new int[Size.Height, Size.Width]);

            for (int i = 0; i < Size.Width; i++)
            {
                for (int j = 0; j < Size.Height; j++)
                {
                    res.values[j, i] = this[i, j];
                }
            }

            return res;
        }
Пример #11
0
 protected bool Equals(CoolMatrix other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     if (Equals(_arr, other) && Equals(Size, other.Size)) return true;
     for (int column = 0; column < Size.Height; column++)
     {
         for (int row = 0; row < Size.Width; row++)
         {
             if (this[column, row] != other[column, row])
             {
                 return false;
             }
         }
     }
     return true;
 }
Пример #12
0
        public bool Equals(CoolMatrix coolMatrix)
        {
            if ((object)coolMatrix == null)
            {
                return false;
            }

            if (ReferenceEquals(this, coolMatrix))
                return true;

            if (this.Size != coolMatrix.Size)
                return false;

            for (int i = 0; i < Size.Width; i++)
            {
                for (int j = 0; j < Size.Height; j++)
                {
                    if (this[i, j] != coolMatrix[i, j])
                        return false;
                }
            }
            return true;
        }