⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 financialtests.cs

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 CS
📖 第 1 页 / 共 2 页
字号:
// FinancialTest.cs - NUnit Test Cases for Microsoft.VisualBasic.Financial//// Boris Kirzner <borisk@mainsoft.com>//// // Copyright (c) 2002-2006 Mainsoft Corporation.// Copyright (C) 2004 Novell, Inc (http://www.novell.com)//// Permission is hereby granted, free of charge, to any person obtaining// a copy of this software and associated documentation files (the// "Software"), to deal in the Software without restriction, including// without limitation the rights to use, copy, modify, merge, publish,// distribute, sublicense, and/or sell copies of the Software, and to// permit persons to whom the Software is furnished to do so, subject to// the following conditions:// // The above copyright notice and this permission notice shall be// included in all copies or substantial portions of the Software.// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.//using NUnit.Framework;using System;using System.IO;using System.Collections;using Microsoft.VisualBasic;namespace MonoTests.Microsoft_VisualBasic{	[TestFixture]	public class FinancialTests	{		public FinancialTests()		{		}		[SetUp]		public void GetReady() 		{		}		[TearDown]		public void Clean() 		{		}		#region DDB Tests                //[Test]        //[ExpectedException(typeof(ArgumentException))]        //public void DDBArg1()        //{        //    // docs doesn`t say it should throw an exception on 'cost' <= 0         //    Financial.DDB (-1, 1, 1, 1, 1);        //}				[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDBArg2()		{			Financial.DDB (1, -1, 1, 1, 1);		}				[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDBArg3()		{			Financial.DDB (1, 1, 0, 1, 1);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDBArg4()		{			Financial.DDB (1, 1, 1, 1, 0);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDBArg5()		{			// Period has to be <= Life			Financial.DDB (1, 1, 1, 2, 1);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDBArg6()		{			// Period has to be > 0			Financial.DDB (1, 1, 1, 0, 1);		}			[Test]		public void DDB()		{			double ddb = Financial.DDB(1000, 50, 10, 5, 3);			Assert.AreEqual(72.03, ddb, 1E-10);			ddb = Financial.DDB (1000, 50, 10, 5, 2);			Assert.AreEqual(81.92, ddb, 1E-10);			ddb = Financial.DDB (1000, 50, 10, 1, 0.1);			Assert.AreEqual(10, ddb, 1E-10);			ddb = Financial.DDB (1000, 50, 10, 0.3, 0.1);			Assert.AreEqual(10, ddb, 1E-10);		}		[Test]		public void DDB_1()		{			Assert.AreEqual(47.999403820109578, Financial.DDB(1500, 120, 24, 12, 2.0), 1E-10);			Assert.AreEqual(479.9940382010958, Financial.DDB(15000, 1000, 24, 12, 2.0), 1E-10);			Assert.AreEqual(391.34749179845591, Financial.DDB(15000, 1000, 48, 12, 2.0), 1E-10);			Assert.AreEqual(33.646996435384537, Financial.DDB(1500, 120, 24, 12, 4.0), 1E-10);			Assert.AreEqual(43.160836714378092, Financial.DDB(1500, 100, 48, 12, 6.0), 1E-10);			Assert.AreEqual(24.789790003786901, Financial.DDB(1500, 100, 48, 12, 1.0), 1E-10);			Assert.AreEqual(383.10767441791506, Financial.DDB(15000, 1000, 48, 12.5, 2.0), 1E-10);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDB_2()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(1500, 120, 12, 24, 2.0);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDB_3()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(1500, 120, 48, 24, -1);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDB_4()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(1500, -2, 48, 24, 2.0);		}		[Test]		//[ExpectedException(typeof(ArgumentException))]		//LAMESPEC: MSDN claims the exception should be thrown in this case		public void DDB_5()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(-5, 120, 48, 24, 2.0);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDB_6()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(1500, 120, 48, -24, 2.0);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void DDB_7()		{			// Argument 'Factor' is not a valid value.			double d = Financial.DDB(1500, 120, -2, -5, 2.0);		}		#endregion		#region SLN Tests						[Test]		[ExpectedException(typeof(ArgumentException))]		public void TestSLNArgs()		{			Financial.SLN (0, 0, 0);		}						[Test]		public void SLN()		{//			double d = Financial.SLN (0, 0, 1);//			Assert.AreEqual( 0, d, "#SLN01");					Assert.AreEqual(0.037681159420289857, Financial.SLN (45, 32, 345), 0.00002);			Assert.AreEqual(0.657894736842105, Financial.SLN (-54, -4, -76), 0.00002);		}        			[Test]		public void SLN_1()		{			Assert.AreEqual(20.833333333333332, Financial.SLN(1500, 500, 48));			Assert.AreEqual(10.416666666666666, Financial.SLN(1500, 500, 96));			Assert.AreEqual(0, Financial.SLN(500, 500, 96));			Assert.AreEqual(500, Financial.SLN(1500, 500, 2));			Assert.AreEqual(-500, Financial.SLN(1500, 500, -2));		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SLN_2()		{			//Argument 'Life' cannot be zero.			Financial.SLN(1500, 500, 0);		}		#endregion		#region SYD Tests		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYDArgs1()		{			Financial.SYD (1, 1, 1, -1);		}					[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYDArgs2()		{			Financial.SYD (1, -1, 1, 1);		}				[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYDArgs3()		{			Financial.SYD (1, 1, 1, 2);		}				[Test]		public void SYD()		{			double d = Financial.SYD (23, 34, 26, 21);			Assert.AreEqual( -0.188034188034188, d, 0.0001, "#SYD01");			d = Financial.SYD (0, 1, 1, 1);			Assert.AreEqual( -1, d, 0.00001, "#SYD02");		}				[Test]		public void SYD_1()		{			Assert.AreEqual (44.047619047619044, Financial.SYD (1500, 100, 48, 12), 1E-10);						Assert.AreEqual (1.1904761904761905, Financial.SYD (1500, 100, 48, 48), 1E-10);			Assert.AreEqual(0, Financial.SYD(100, 100, 48, 48));		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYD_2()		{			// Argument 'Salvage' must be greater than or equal to zero.			Financial.SYD(1500, -100, 48, 12);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYD_3()		{			// Argument 'Period' must be less than or equal to argument 'Life'.			Financial.SYD(1500, 100, 8, 12);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYD_4()		{			// Argument 'Period' must be greater than zero.			Financial.SYD(1500, 100, 48, 0);		}		[Test]		[ExpectedException(typeof(ArgumentException))]		public void SYD_5()		{			// Argument 'Period' must be greater than zero.			Financial.SYD(1500, 100, 48, -2);		}		#endregion		#region FV Tests		[Test]		public void FV()		{			double d = Financial.FV (10, 5, 3, 7, DueDate.BegOfPeriod);			Assert.AreEqual (-1658822, d, "#FV01");						d = Financial.FV (10, 5, 3, 7, DueDate.EndOfPeriod);			Assert.AreEqual (-1175672, d, "#FV02");						d = Financial.FV (0, 5, 3, 7, DueDate.BegOfPeriod);			Assert.AreEqual (-22, d, "#FV03");						d = Financial.FV(0, 1, 1, 1, DueDate.BegOfPeriod);			Assert.AreEqual (-2, d, "#FV04");						d = Financial.FV (0, 0, 0, 0, DueDate.BegOfPeriod);			Assert.AreEqual (0, d, "#FV05");						d = Financial.FV (-3, -5, -6, -4, DueDate.BegOfPeriod);			Assert.AreEqual (-4.25, d, "#FV06");		}		[Test]		public void FV_1()		{			Assert.AreEqual(-5042.6861628644065, Financial.FV (0.1 / 48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(5042.6861628644065, Financial.FV(0.1/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(6026.9653563801103, Financial.FV(0.45/48, 48, -100, 0, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(30134.826781900552, Financial.FV(0.45/48, 48, -500, 0, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(5053.1917590370413, Financial.FV(0.1/48, 48, -100, 0, DueDate.BegOfPeriod), 1E-8);			Assert.AreEqual(1727.5182776853812, Financial.FV(0.1/48, 48, -100, 3000, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(8357.8540480434312, Financial.FV(0.1/48, 48, -100, -3000, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(1738.023873858016, Financial.FV(0.1/48, 48, -100, 3000, DueDate.BegOfPeriod), 1E-8);			Assert.AreEqual(8368.359644216067, Financial.FV(0.1/48, 48, -100, -3000, DueDate.BegOfPeriod), 1E-8);			Assert.AreEqual(-4572.3341785092407, Financial.FV(-0.1/48, 48, 100, 0, DueDate.EndOfPeriod), 1E-8);			Assert.AreEqual(-4599.4962842992118, Financial.FV(-0.1/48, 48.3, 100, 0, DueDate.EndOfPeriod), 1E-8);		}		#endregion		#region Rate Tests		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void RateArgs1()		{			double d = Financial.Rate (-1, 1, 1, 1, DueDate.BegOfPeriod, 1);		}		[Category ("NotWorking")]//Not Implemented		[Test]		public void Rate()		{						Assert.AreEqual(-1.5000000000001, Financial.Rate (1, 1, 1, 1, DueDate.BegOfPeriod, 0.1), 0.1);			Assert.AreEqual(-1.5000000000001, Financial.Rate (1, -1, -1, -1, DueDate.BegOfPeriod, 0.1), 0.1);			Assert.AreEqual(-1.71428571428571, Financial.Rate (1, 2, 12, 10, DueDate.BegOfPeriod, 0.5), 0.1);		}		[Category ("NotWorking")]//Not Implemented		[Test]		public void Rate_1()		{			Assert.AreEqual(-0.067958335561249847, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.1));			Assert.AreEqual(-0.054284323350630818, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.1));			Assert.AreEqual(-0.03391640485393424, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.1));			Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.1));			Assert.AreEqual(-0.99999999998846933, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.1));			Assert.AreEqual(-0.055871364867281934, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.1));			Assert.AreEqual(-0.065503055347169575, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.1));			Assert.AreEqual(-0.058920469572311909, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.1));		}		[Category ("NotWorking")]//Not Implemented		[Test]		public void Rate_2()		{			Assert.AreEqual(-0.067958335561434935, Financial.Rate(48, -120, 50000, 0, DueDate.EndOfPeriod, 0.3));			Assert.AreEqual(-0.054284323350996831, Financial.Rate(48, -200, 50000, 0, DueDate.EndOfPeriod, 0.3));			Assert.AreEqual(-0.033916404853936467, Financial.Rate(48, -400, 50000, 0, DueDate.EndOfPeriod, 0.3));			Assert.AreEqual(0.19996831303445506, Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.2));			Assert.AreEqual(-0.99999999999999079, Financial.Rate(48, -1000, 5000, 0, DueDate.BegOfPeriod, 0.3));			Assert.AreEqual(-0.055871364867277139, Financial.Rate(48, -200, 50000, 0, DueDate.BegOfPeriod, 0.3));			Assert.AreEqual(-0.065503055348340639, Financial.Rate(48, -200, 50000, 1000, DueDate.EndOfPeriod, 0.3));			Assert.AreEqual(-0.058920469572100169, Financial.Rate(48, -200, 50000, 500, DueDate.EndOfPeriod, 0.3));		}		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void Rate_3()		{			// Argument 'NPer' must be greater than zero.			Financial.Rate(0, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);		}		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void Rate_4()		{			// Argument 'NPer' must be greater than zero.			Financial.Rate(-10, -120, 50000, 0, DueDate.EndOfPeriod, 0.1);		}		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void Rate_5()		{			// Cannot calculate rate using the arguments provided.			Financial.Rate(48, -1000, 5000, 0, DueDate.EndOfPeriod, 0.3);		}		#endregion		#region IRR Tests		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void IRRArgs1()		{			double [] arr = new double [0];			Financial.IRR (ref arr, 0.1);		}		[Category ("NotWorking")]//Not Implemented		[Test]		[ExpectedException(typeof(ArgumentException))]		public void IRRArgs2()		{			double [] arr = new double [] {134};			Financial.IRR (ref arr, 0.1);		}		//		[Test]//		[ExpectedException(typeof(ArgumentException))]//		public void IRRArgs3()//		{//			// -0.99 as Guess throws an exception on MS.NET, -0.98 doesn't//			//double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};//			//double d = Financial.IRR (ref arr, -0.99);//		}		[Category ("NotWorking")]//Not Implemented		[Test]		public void IRR()		{			double [] arr = new double [] {-70000, 22000, 25000, 28000, 31000};			double d = Financial.IRR (ref arr, 0.1);			Assert.AreEqual ( 0.177435884422527, d, 0.00001);		}		#if NET_2_0		[Category ("NotWorking")]//Not Implemented		[Test]		public void IRR_1 ()		{			double [] values = new double [] { -50000, 20000, 20000, 20000, 10000 };			Assert.AreEqual (0.16479098450887533, Financial.IRR (ref values, 0.1));			Assert.AreEqual (0.16479098450893837, Financial.IRR (ref values, 0.3));			Assert.AreEqual (0.16479098450893415, Financial.IRR (ref values, 0.5));			values = new double [] { -100000, 40000, 35000, 30000, 25000 };			Assert.AreEqual (0.12441449540624081, Financial.IRR (ref values, 0.1));			Assert.AreEqual (0.12441449541502105, Financial.IRR (ref values, 0.3));			Assert.AreEqual (0.12441449541025705, Financial.IRR (ref values, 0.5));		}		#else		[Test]		[Category ("NotWorking")]//Not Implemented		public void IRR_1()		{			double[] values = new double[] {-50000, 20000, 20000, 20000, 10000};			Assert.AreEqual(0.164790984508875, Financial.IRR(ref values, 0.1), "A1");			Assert.AreEqual (0.164790984508938, Financial.IRR (ref values, 0.3), "A2");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -