0% found this document useful (0 votes)
114 views3 pages

SQE Assignment#02

The document defines a myCalc class with methods for multiplication and division. It includes two constructors, one default and one that takes two integer parameters. The myMult method performs multiplication, returning the sum for a "simple calculator" and 0 otherwise. The myDiv method divides the operand values and returns the object. Unit tests are provided to test the myMult and myDiv methods under different input conditions.

Uploaded by

asdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views3 pages

SQE Assignment#02

The document defines a myCalc class with methods for multiplication and division. It includes two constructors, one default and one that takes two integer parameters. The myMult method performs multiplication, returning the sum for a "simple calculator" and 0 otherwise. The myDiv method divides the operand values and returns the object. Unit tests are provided to test the myMult and myDiv methods under different input conditions.

Uploaded by

asdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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:

You might also like