Пример #1
0
        public void TestMatriceAjout()
        {
            int[,] mat1 = new int[, ] {
                { 1, 2 },
                { 3, 4 },
            };
            int[,] mat2 = new int[, ] {
                { 1, 2 },
                { 3, 4 },
            };
            int[,] matResult = new int[, ] {
                { 2, 4 },
                { 6, 8 },
            };

            Matrice m1 = new Matrice(mat1);
            Matrice m2 = new Matrice(mat2);
            Matrice r  = m1.Ajout(m2);;

            // parcours des lignes
            for (int i = 0; i < matResult.GetLength(0); i++)
            {
                // parcours des colonnes
                for (int j = 0; j < matResult.GetLength(1); j++)
                {
                    Assert.AreEqual(matResult[i, j], r.matrice[i, j],
                                    string.Format("position: {0}, {1}", i, j));
                }
            }
        }
Пример #2
0
        public void TestMatriceAjoutKO()
        {
            Matrice m1 = new Matrice(new int[, ] {
                { 0, 1 },
                { 2, 3 }
            });
            Matrice m2 = new Matrice(new int[, ] {
                { 0, 1, 3, 4 }
            });

            try
            {
                m1.Ajout(m2);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(MatriceException));
            }
        }