Program: testujący sumę liczb oraz dzielenie (w tym dzielenie przez zero).
Jak w opisie.
Kompilator: Microsoft Visual Studio
Kod programu:
Program główny:
//Program główny
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace matematyka
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
//Klasy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace matematyka
{
public class matma
{
public int suma(int a, int b)
{
int c = a + b;
return c;
}
public double iloraz(int a, int b)
{
if (b == 0) throw new ArgumentOutOfRangeException();
int c = a / b;
return c;
}
}
}
Jednostka testowa:
//Unie testowy
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using matematyka;
namespace UnitTestProjectMatematyka
{
[TestClass]
public class UnitTestMatma
{
matma test = new matma();
[TestMethod]
public void TestMethodSuma()
{
int a = 1;
int b = 2;
int pop = 3;
int od_metody_testowej = test.suma(a, b);
Assert.AreEqual(pop, od_metody_testowej);
}
[TestMethod]
public void TestMethodIloraz()
{
int a = 1;
int b = 2;
double pop = 1/2;
double od_metody_testowej = test.iloraz(a, b);
Assert.AreEqual(pop, od_metody_testowej);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethodIlorazPrzezZero()
{
int a = 2;
int b = 0;
double od_metody_testowej = test.iloraz(a, b);
}
}
}