- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
First encounters w ith unit testing in C#
First encounters w ith unit testing Creating QR In C# Using Barcode printer for .NET framework Control to generate, create QR image in Visual Studio .NET applications. www.OnBarcode.comScan QR Code JIS X 0510 In Visual C#.NET Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comIn chapter 1, we introduced a small application that ll stay with you through your journey with CI. It s your friend the leasing/credit calculator. It can calculate the credit rate according to several input variables such as contract duration and interest. But before we dive into some mathematical details of finance, let s change the calculator a little by flattening the structure. For better clarity, you ll keep all the projects in your solution at one level. If you like the structure with external SVN references, feel free to keep the project that way; but here you ll modify it. From now on, you ll have one solution named CiDotNet with some projects inside, including the calculation core in a project named CiDotNet.Calc (it contains basically what the Framework external SVN reference repository had). The Windows calculator is in the project CiDotNet.WinCalc, the web calculator is in CiDotNet.WebCalc, and the Silverlight calculator is in CiDotNet.SilverlightCalc. The sources provided with this book include a ready-to-use project. Let s start with the calculation core and its mathematical details. This information isn t necessary from the CI point of view, but it s important to fully understand the unit tests that will follow. If you re a unit testing specialist, please feel free to skip the next section. GS1 - 12 Maker In C#.NET Using Barcode generation for VS .NET Control to generate, create UPC Symbol image in .NET framework applications. www.OnBarcode.comDrawing Code 3 Of 9 In C# Using Barcode printer for VS .NET Control to generate, create Code 3/9 image in VS .NET applications. www.OnBarcode.comFirst encounters w ith unit testing
EAN13 Generation In C# Using Barcode creation for Visual Studio .NET Control to generate, create EAN13 image in Visual Studio .NET applications. www.OnBarcode.comBarcode Generation In C#.NET Using Barcode drawer for .NET framework Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comThe search for perfect unit test m aterial
PDF-417 2d Barcode Drawer In Visual C#.NET Using Barcode creator for VS .NET Control to generate, create PDF-417 2d barcode image in .NET applications. www.OnBarcode.comI-2/5 Maker In C# Using Barcode encoder for .NET framework Control to generate, create 2 of 5 Interleaved image in Visual Studio .NET applications. www.OnBarcode.comIt s time to add code to the project so you have something to unit test. Open the class library project CiDotNet.Calc and add a new class named FinanceHelper, as shown next. Listing 6.1 QR Code Printer In None Using Barcode printer for Excel Control to generate, create QR Code 2d barcode image in Office Excel applications. www.OnBarcode.comCreating QR-Code In Visual Studio .NET Using Barcode encoder for ASP.NET Control to generate, create QR Code image in ASP.NET applications. www.OnBarcode.comusing System; namespace Core.Math { public class Finance { public enum Mode { BeginMode = 1, EndMode = 0 } private static double CalculateSPPV(double compoundPeriods, double periodicInterestRate) { return System.Math.Pow(1.0 + (periodicInterestRate / 100), -compoundPeriods); } private double CalculateSPFV(double compoundPeriods, double periodicInterestRate) { return System.Math.Pow(1 + (periodicInterestRate / 100), compoundPeriods); } private double CalculateUSPV(double compoundPeriods, double periodicInterestRate) { double uspv = (1 - CalculateSPPV(compoundPeriods, periodicInterestRate)) / (periodicInterestRate / 100); return uspv; } private double CalculateUSFV(double compoundPeriods, double periodicInterestRate) { double usfv = (CalculateSPFV(compoundPeriods, periodicInterestRate) - 1) / (periodicInterestRate / 100); return usfv; } private static double GetCompoundPeriods(int periods, int ppy) { return (double)((ppy * periods) / 12); } private static double GetPeriodicInterestRate( double interestRate, int ppy) { 2D Barcode Maker In VS .NET Using Barcode generation for ASP.NET Control to generate, create Matrix Barcode image in ASP.NET applications. www.OnBarcode.comPrinting Code39 In Objective-C Using Barcode generation for iPad Control to generate, create Code 39 Full ASCII image in iPad applications. www.OnBarcode.comA simple finance mathematical library
QR Code JIS X 0510 Decoder In .NET Framework Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comRead Barcode In C# Using Barcode Control SDK for .NET Control to generate, create, read, scan barcode image in Visual Studio .NET applications. www.OnBarcode.comUnit testing continuously integrated code
Drawing Barcode In .NET Using Barcode generator for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comCode 39 Generation In None Using Barcode generation for Online Control to generate, create Code 39 Extended image in Online applications. www.OnBarcode.comreturn (interestRate / ((double)ppy)); } public static double CalculateRate(int periods, int ppy, double interest, double presentValue, double finalValue, Mode mode) { int m = (int)mode; double compoundPeriods = GetCompoundPeriods(periods, ppy); double periodicInterestRate = GetPeriodicInterestRate(interest, ppy); return -((finalValue * CalculateSPPV(compoundPeriods, periodicInterestRate) - presentValue) / ((1.0 + ((periodicInterestRate * m) / 100)) * CalculateUSPV(compoundPeriods, periodicInterestRate))); } } } Encoding GS1 - 12 In None Using Barcode generator for Microsoft Word Control to generate, create UPC-A Supplement 5 image in Microsoft Word applications. www.OnBarcode.comMake Barcode In .NET Framework Using Barcode encoder for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comCalculates monthly payment
Linear Generator In Visual Basic .NET Using Barcode generation for Visual Studio .NET Control to generate, create Linear 1D Barcode image in .NET framework applications. www.OnBarcode.comCode 3 Of 9 Encoder In Java Using Barcode drawer for Eclipse BIRT Control to generate, create Code 3 of 9 image in Eclipse BIRT applications. www.OnBarcode.comThis code seems to include lots of cryptic methods and values, but it s much easier to understand than you can tell at first glance. Single Payment Present Value (SPPV) is the present value of money received in the future at a given interest rate. Single Payment Future Value (SPFV) is the future value of money paid in the future at a given interest rate. Uniform Series Present Value (USPV) is the payment required each period to achieve the future value. And Uniform Series Future Value (USFV) is the future value of a uniform payment. All of these values are used in the last and most important calculation: the monthly payment, with the public method CalculateRate(). It takes as parameters all the necessary data to make the calculation, as shown in table 6.1. Table 6.1 Parameters to the CalculateRate() method Parameter Description Number of periods you want to carry the burden of the loan Periods per year for example, 12 for monthly payments How much the bank charges you (the interest rate) How much money you need right now How much money you need at the end of the loan Whether the bank calculates interest income at the beginning of the calculation period or at the end
|
|