// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using Xunit;
namespace Microsoft.VisualBasic.Tests
{
public class FinancialTests
{
+ private static bool IsNotArmOrAlpine() => !PlatformDetection.IsArmOrArm64Process && !PlatformDetection.IsAlpine;
+
/// <summary>
/// The accuracy of some numeric parsing and formatting has been increased,
/// so this will use correct value if the tests run on Full Framework.
Assert.Equal(expected, actual);
}
- [Theory]
+ [ConditionalTheory(nameof(IsNotArmOrAlpine))] // some tests fail due to precision
[InlineData(0, 1.0, 1.0, 1.0, 1.0, 0, 0)]
[InlineData(2000.0, 500.0, 2.0, 1.0, 2.0, 1500.0, 1500.0)]
[InlineData(10000.0, 4350.0, 84.0, 35.0, 2.0, 57.3268063538875, 57.32680635388748)]
[InlineData(10100.0, 10100.0, 70.0, 20.0, 2.0, 0, 0)] // cost = salvage
public void DDB(double Cost, double Salvage, double Life, double Period, double Factor, double expectedOld, double expectedNew)
{
- if (PlatformDetection.IsAlpine)
- {
- // some tests fail due to precision
- return;
- }
AreEqual(expectedOld, expectedNew, Financial.DDB(Cost, Salvage, Life, Period, Factor));
}
AreEqual(-4182.65729113816, -4182.657291138164, Financial.FV(0.0083, 15, 263.0));
}
- [Theory]
+ [ConditionalTheory(nameof(IsNotArmOrAlpine))] // some tests fail due to precision
[InlineData(0, 1.0, 1.0, 0, 0, DueDate.EndOfPeriod, 0, 0)]
[InlineData(0.1 / 12, 12.0, 48.0, -20000.0, 0, DueDate.BegOfPeriod, 133.00409235109, 133.00409235108953)]
[InlineData(0.008, 4, 12, 3000, 0, 0, -18.2133959841799, -18.21339598417987)]
[InlineData(0.008, 4, 12, 3000, 0, 7, -18.0688452224006, -18.068845222400633)] // type <> 0 and type <> 1
public void IPmt(double Rate, double Per, double NPer, double PV, double FV, DueDate Due, double expectedOld, double expectedNew)
{
- if (PlatformDetection.IsAlpine)
- {
- // some tests fail due to precision
- return;
- }
AreEqual(expectedOld, expectedNew, Financial.IPmt(Rate, Per, NPer, PV, FV, Due));
}
AreEqual(131.224540233228, 131.2245402332282, Financial.Pmt(0.007, 25, -3000));
}
- [Theory]
+ [ConditionalTheory(nameof(IsNotArmOrAlpine))] // some tests fail due to precision
[InlineData(0, 1.0, 1.0, 0, 0, DueDate.EndOfPeriod, 0, 0)]
[InlineData(0.02 / 12, 1.0, 24, -10000, 0, DueDate.BegOfPeriod, 424.694809003121, 424.6948090031214)]
[InlineData(0.008, 4, 12, 3000, 0, DueDate.EndOfPeriod, -244.976482926292, -244.97648292629228)]
[InlineData(0.008, 4, 12, 3000, 0, 7, -243.03222512529, -243.03222512529004)] // type <> 0 and type <> 1
public void PPmt(double Rate, double Per, double NPer, double PV, double FV, DueDate Due, double expectedOld, double expectedNew)
{
- if (PlatformDetection.IsAlpine)
- {
- // some tests fail due to precision
- return;
- }
AreEqual(expectedOld, expectedNew, Financial.PPmt(Rate, Per, NPer, PV, FV, Due));
}
AreEqual(-244.976482926292, -244.97648292629228, Financial.PPmt(0.008, 4, 12, 3000));
}
- [Theory]
+ [ConditionalTheory(nameof(IsNotArmOrAlpine))] // some tests fail due to precision
[InlineData(0, 0, 0, 0, DueDate.EndOfPeriod, 0, 0)]
[InlineData(0.02 / 12, 12.0, -100.0, -100.0, DueDate.BegOfPeriod, 1287.10048252122, 1287.1004825212165)]
[InlineData(0.008, 31, 2000.0, 0, DueDate.EndOfPeriod, -54717.4159104136, -54717.41591041358)]
[InlineData(1E25, 12, 1797, 0, DueDate.BegOfPeriod, -1797, -1797)] // overflow
public void PV(double Rate, double NPer, double Pmt, double FV, DueDate Due, double expectedOld, double expectedNew)
{
- if (PlatformDetection.IsAlpine)
- {
- // some tests fail due to precision
- return;
- }
AreEqual(expectedOld, expectedNew, Financial.PV(Rate, NPer, Pmt, FV, Due));
}
AreEqual(-2952.94485232014, -2952.944852320145, Financial.PV(0.008, 4, 12, 3000));
}
- [Theory]
+ [ConditionalTheory(nameof(IsNotArmOrAlpine))] // some tests fail due to precision
[InlineData(1.0, 1.0, 1.0, 0, DueDate.EndOfPeriod, 0, -2, -2)]
[InlineData(24.0, -800.0, 10000.0, 0.0, DueDate.BegOfPeriod, 0.1, 0.0676702786565114, 0.06767027865651142)]
[InlineData(12, -263.0, 3000, 0, DueDate.EndOfPeriod, 0.1, 0.00788643837763396, 0.007886438377633958)]
[InlineData(12, -3000.0, 300, 0, DueDate.EndOfPeriod, 0.1, -1.98502387722876, -1.9850238772287565)] // pmt > pv
public void Rate(double NPer, double Pmt, double PV, double FV, DueDate Due, double Guess, double expectedOld, double expectedNew)
{
- if (PlatformDetection.IsAlpine)
- {
- // some tests fail due to precision
- return;
- }
AreEqual(expectedOld, expectedNew, Financial.Rate(NPer, Pmt, PV, FV, Due, Guess));
}
{
Assert.Throws<ArgumentException>(() => Financial.SYD(Cost, Salvage, Life, Period));
}
-
}
}