vendredi 22 avril 2016

c# tests Class1' does not contain a definition for 'Function'

I have problem with mz test ..Class1' does not contain a definition for 'Function' and no extension method 'Function' accepting a first argument of type 'Class1' could be found (are you missing a using directive or an assembly reference?) ClassTestProject2

and i have add reference to my class Class1 to the test library and objects are fine too here is my code i am new to c# so i probably didnt do something that i should do sobebodz has some ideas ? thank you :)

tests:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ClassLibrary1;

namespace ClassTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethodPlus()
        {
            double number1 = 9.0;
            double number2 = 1.0;
            string op = "plus";
            double expected = 9.0;
            Class1 count = new Class1();
            double actual = count.Function(number1, number2, op);
            Assert.AreEqual(expected, actual);
        }
   }
}

here is my class:

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

namespace ClassLibrary1
{
    public class Class1
    {
        public static double Function(double num1, double num2, string op)
        {
        double finRes = 0;
        if (op == "plus")
        {
            finRes = num1 + num2;
        }
        else if (op == "minus")
        {
            finRes = num1 - num2;
        }
        else if (op == "multiple")
        {
            finRes = num1 * num2;
        }
        else if (op == "divide")
        {
            finRes = num1 / num2;
        }
        else if (op == "exp")
        {
            finRes = Math.Pow(num1, num2);
        }
        else if (op == "fac")
        {
            double result = num1;
            for (double i = (num1) - 1; i > 0; i--)
            {
                result = result * i;
                finRes = result;
            }
        }
        else if (op == "sqrt")
        {
            finRes = Math.Sqrt(num1);
        }
        return finRes;
    }
}
}

Aucun commentaire:

Enregistrer un commentaire