nickxdd23
nickxdd23

Reputation: 11

Problem with UnitTest(Method doesn`t work properly)

I have a matrix calculator

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace ConsoleApp11
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Введите размерность первой матрицы: ");
            int[,] A = new int[Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine())];
            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < A.GetLength(1); j++)
                {
                    Console.Write("A[{0},{1}] = ", i, j);
                    A[i, j] = Convert.ToInt32(Console.ReadLine());
                }
            }
            Console.WriteLine("Введите размерность второй матрицы: ");
            int[,] B = new int[Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine())];
            for (int i = 0; i < B.GetLength(0); i++)
            {
                for (int j = 0; j < B.GetLength(1); j++)
                {
                    Console.Write("B[{0},{1}] = ", i, j);
                    B[i, j] = Convert.ToInt32(Console.ReadLine());
                }
            }

            Console.WriteLine("\nМатрица A:");
            Print(A);
            Console.WriteLine("\nМатрица B:");
            Print(B);
            Console.WriteLine("\nМатрица C = A * B:");
            int[,] C = Multiplication(A, B);
            Print(C);
            
        }
        static int[,] Multiplication(int[,] a, int[,] b)
        {
            if (a.GetLength(1) != b.GetLength(0)) throw new Exception("Матрицы нельзя перемножить");
            int[,] r = new int[a.GetLength(0), b.GetLength(1)];
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < b.GetLength(1); j++)
                {
                    for (int k = 0; k < b.GetLength(0); k++)
                    {
                        r[i, j] += a[i, k] * b[k, j];
                    }
                }
            }
            return r;
        }
        static void Print(int[,] a)
        {
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    Console.Write("{0} ", a[i, j]);
                }
                Console.WriteLine();
            }


        }
        static int[,] Multiplication_test(int[,] a_test, int[,] b_test) // типо забыл поменять что-то
        {
            int[,] r = new int[a_test.GetLength(0), b_test.GetLength(1)];
            for (int i = 0; i < a_test.GetLength(0); i++)
            {
                for (int j = 0; j < b_test.GetLength(1); j++)
                {
                    for (int k = 0; k < b_test.GetLength(0); k++)
                    {
                        r[i, j] -= a_test[i, k] * b_test[k, j];
                    }
                }
            }
            return r;
        }

       

    }
}

And I have a UnitTest Program

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ConsoleApp11;
using System.Threading.Tasks;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            int[,] A = { { 1, 2, 3 }, { 3, 4, 5 } };
            int[,] B = { { 3, 4 }, { 1, 2 }, { 3, 5 } };
            int[,] expected = { { 14, 23 }, { 28, 45 } };
           
            int [,] actual = Multiplication_test(A, B);
            
            Assert.AreEqual(expected, actual, "Multiplication_test1 isn`t correct ");
        }
    }
}

All in all is fine , but i have a problem Severity Code Description Project File Line Suppression State Error CS0103 The name 'Multiplication_test' does not exist in the current context UnitTestProject

I did more things but nothing changed...

I tried change static method to public but nothing changed. Please help me !!!

Upvotes: 1

Views: 28

Answers (1)

D Stanley
D Stanley

Reputation: 152556

Multiplication_test is a static method on Program, so it should be Program.Multiplication_test(...)

Upvotes: 1

Related Questions