Browse Source

Added GainLossRatio Tests

Added tests around GainLossRatio, but I still have some questions as
noted per test.
pull/108/head
Phil 14 years ago
parent
commit
f9af5aa844
  1. 82
      src/UnitTests/FinancialTests/GainLossRatioTests.cs
  2. 1
      src/UnitTests/UnitTests.csproj

82
src/UnitTests/FinancialTests/GainLossRatioTests.cs

@ -29,7 +29,6 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathNet.Numerics.Financial;
using MathNet.Numerics.Statistics;
using NUnit.Framework;
@ -37,6 +36,87 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
[TestFixture]
public class GainLossRatioTests
{
[Test]
[ExpectedException(typeof(ArgumentNullException))] //assert
public void throws_when_input_data_is_null()
{
//arrange
List<double> inputData = null;
//act
inputData.GainLossRatio();
}
[Test]
//Not sure this is correct. Undefined may be more correct.
public void returns_zero_for_a_single_positive_input()
{
//arrange
var inputData = new[] { 1.0 };
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(0.0, gainLossRatio);
}
[Test]
//Not sure this is correct. Undefined may be more correct.
public void returns_zero_for_a_single_negative_input()
{
//arrange
var inputData = new[] { -1.0 };
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(0.0, gainLossRatio);
}
[Test]
//Not sure this is correct. Undefined may be more correct.
public void returns_zero_for_a_set_of_all_positive_numbers()
{
//arrange
var inputData = new[] { 1.0, 2.0, 3.0 };
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(0.0, gainLossRatio);
}
[Test]
//Not sure this is correct. Undefined may be more correct.
public void returns_zero_for_a_set_of_all_negative_numbers()
{
//arrange
var inputData = new[] { -1.0, -2.0, -3.0 };
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(0.0, gainLossRatio);
}
[Test]
public void handles_a_value_of_zero_as_a_positive()
{
//arrange
var inputData = new[] { 0.0, 1.0, 2.0 };
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(0.0, gainLossRatio);
}
[Test]
public void calculates_the_correct_ratio_given_a_set_of_gains_and_losses()
{
//arrange
var inputData = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
var meanOfGains = inputData.Where(x => x >= 0).Mean();
var meanOfLosses = inputData.Where(x => x < 0).Mean();
var expectedRatio = Math.Abs(meanOfGains / meanOfLosses);
//act
var gainLossRatio = inputData.GainLossRatio();
//assert
Assert.AreEqual(expectedRatio, gainLossRatio);
}
}
}

1
src/UnitTests/UnitTests.csproj

@ -123,6 +123,7 @@
<Compile Include="DistributionTests\Multivariate\NormalGammaTests.cs" />
<Compile Include="DistributionTests\Multivariate\WishartTests.cs" />
<Compile Include="FinancialTests\DownsideDeviationTests.cs" />
<Compile Include="FinancialTests\GainLossRatioTests.cs" />
<Compile Include="FinancialTests\GainStandardDeviationTests.cs" />
<Compile Include="FinancialTests\LossMeanTests.cs" />
<Compile Include="FinancialTests\GainMeanTests.cs" />

Loading…
Cancel
Save