Sei sulla pagina 1di 3

ADEEL HASSAN (01-131162-003) BSE-6A

Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnitTestProject2
{
class myCalc
{
public int op1 = 0;
public int op2 = 0;
string calculator;
public int result;
public myCalc()
{
op1 = 1;
op2 = 1;
Console.WriteLine("constructor called\n");
}
public myCalc(int o1, int o2)
{
op1 = o1; op2 = o2;
calculator = "simple calculator";
Console.WriteLine("constructor called\n");
}
public int myMult(int op1, int op2, string type)
{
if (type == "simple calculator")
return op1 + op2;
return 0;
}
public myCalc myDiv(ref myCalc calc)
{
calc.result = calc.op1 * calc.op2;
return calc;
}

}
}

Test Cases:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject2
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
myCalc ob = new myCalc();
var x = ob.myMult(3, 4, "simple calculator");
Assert.AreEqual(x, 3);
ADEEL HASSAN (01-131162-003) BSE-6A

[TestMethod]
public void TestMethod2()
{
myCalc ob = new myCalc();
var x = ob.myMult(2, -2, "simple calculator");
Assert.AreEqual(x,-4);

[TestMethod]
public void TestMethod3()
{
myCalc ob = new myCalc();
var x = ob.myMult(2, 0, "simple calculator");
Assert.AreEqual(x, 5);

[TestMethod]
public void TestMethod4()
{
myCalc ob = new myCalc(1,2);
var x = ob.myDiv(ref ob);
Assert.AreEqual(x.result, 2);
}
[TestMethod]
public void TestMethod5()
{
myCalc ob = new myCalc(1, 1);
var x = ob.myDiv(ref ob);
Assert.AreEqual(x.result, 0);
}
[TestMethod]
public void TestMethod6()
{
myCalc ob = new myCalc(-1, 0);
var x = ob.myDiv(ref ob);
Assert.AreEqual(x.result, 2);
}
[TestMethod]
public void TestMethod7()
{
myCalc ob = new myCalc(0, 2);
var x = ob.myDiv(ref ob);
Assert.AreEqual(x.result, 0);
}

}
}
ADEEL HASSAN (01-131162-003) BSE-6A

Output:

Potrebbero piacerti anche