Ứng dụng chương trình

Một phần của tài liệu Sử dụng UNIT TEST trong lập trình C .Net (Trang 77)

- Các hàm cộng, trừ, nhân, chia tương ứng với các lớp: MyAdd, MySub, MyMulti, MyDiv như sau:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project5 { //hàm cộng

publicclassMyAdd

{

publicdouble Add(double a, double b) {

return a + b; }

}

//hàm trừ

publicclassMySub

{

publicdouble Sub(double a, double b) {

return a - b; }

}

//hàm nhân

publicclassMyMulti

{

publicdouble Multi(double a, double b) {

return a * b; }

}

//hàm chia

publicclassMyDiv

{

publicdouble Div(double a, double b) {

return (double)(a / b); }

} }

78

- Các hàm mũ như hàm mũ 2, hàm mũ 3, hàm mũ n như sau:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project5 { //hàm mũ 2

publicclassMyHamMu

{

publicdouble Mu2(double a) {

returnMath.Pow(a, 2); }

}

//hàm mũ 3

publicclassMyHamMu3

{

publicdouble Mu3(double a) {

returnMath.Pow(a, 3); }

}

//hàm x mũ y

publicclassMyHamXMuY

{

publicdouble XmuY(double x, double y) {

returnMath.Pow(x, y); }

} }

- Các hàm lượng giác như hàm sin, hàm cos, hàm tan, hàm cotan như sau:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project5 {

publicclassMyHamLuongGiac

{

publicdouble Sin(double a) {

return (double)Math.Sin(Math.PI * a / 180); }

79 }

public classMyCosin

{

publicdouble CoSin(double a) {

returnMath.Cos(Math.PI * a / 180); }

}

public classMyTag

{

publicdouble Tag(double a) {

returnMath.Sin(Math.PI * a / 180) / Math.Cos(Math.PI * a / 180); }

}

publicclassMyCoTag

{

publicdouble CoTag(double a) {

returnMath.Cos(Math.PI * a / 180) / Math.Sin(Math.PI * a / 180); }

} }

- Các hàm căn thức như hàm căn bậc 2, hàm căn bậc n như sau:

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project5 {

publicclassMyHamCanThuc

{

publicdouble CanBac2(double a) {

returnMath.Sqrt(a); }

}

publicclassMyCanBacN

{

publicdouble CanBacN(double a, double b) {

returnMath.Pow(a, (double)(1 / b)); }

} }

80

Một phần của tài liệu Sử dụng UNIT TEST trong lập trình C .Net (Trang 77)