Browse Source

added NUnit project

la-knuth
Marcus Cuda 16 years ago
parent
commit
4871e73491
  1. 15
      lib/NUnit-2.5.8/license.txt
  2. BIN
      lib/NUnit-2.5.8/nunit.framework.dll
  3. 10272
      lib/NUnit-2.5.8/nunit.framework.xml
  4. BIN
      lib/NUnit-2.5.8/nunit.mocks.dll
  5. BIN
      lib/NUnit-2.5.8/pnunit.framework.dll
  6. 7
      src/MathNet.Numerics.sln
  7. 281
      src/NUnitTests/AssertHelpers.cs
  8. 439
      src/NUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs
  9. 65
      src/NUnitTests/NUnitTests.csproj
  10. 36
      src/NUnitTests/Properties/AssemblyInfo.cs

15
lib/NUnit-2.5.8/license.txt

@ -0,0 +1,15 @@
Copyright © 2002-2008 Charlie Poole
Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
Copyright © 2000-2002 Philip A. Craig
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required.
Portions Copyright © 2002-2008 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

BIN
lib/NUnit-2.5.8/nunit.framework.dll

Binary file not shown.

10272
lib/NUnit-2.5.8/nunit.framework.xml

File diff suppressed because it is too large

BIN
lib/NUnit-2.5.8/nunit.mocks.dll

Binary file not shown.

BIN
lib/NUnit-2.5.8/pnunit.framework.dll

Binary file not shown.

7
src/MathNet.Numerics.sln

@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4D50FB34
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{49EE74BD-301F-4C3B-B76A-07F90CC88CE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnitTests", "NUnitTests\NUnitTests.csproj", "{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -53,6 +55,10 @@ Global
{793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Release|Any CPU.Build.0 = Release|Any CPU
{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -62,5 +68,6 @@ Global
{8239A6FF-1EF3-4DA4-A860-95C392DD6899} = {49EE74BD-301F-4C3B-B76A-07F90CC88CE7}
{F2F8032B-A31D-4E33-A05E-F2CDCBFAA75D} = {4D50FB34-10BC-495A-8B2F-482E34B4D771}
{8C9A5D3F-A20C-4D24-A09C-98E187A8D720} = {4D50FB34-10BC-495A-8B2F-482E34B4D771}
{DAF07AA8-C5C9-4963-98F7-2C3285064DAD} = {4D50FB34-10BC-495A-8B2F-482E34B4D771}
EndGlobalSection
EndGlobal

281
src/NUnitTests/AssertHelpers.cs

@ -0,0 +1,281 @@
// <copyright file="AssertHelpers.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// 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.
// </copyright>
namespace MathNet.Numerics.UnitTests
{
using System.Collections.Generic;
using System.Numerics;
using NUnit.Framework;
/// <summary>
/// A class which includes some assertion helper methods particularly for numerical code.
/// </summary>
internal class AssertHelpers
{
/// <summary>
/// Asserts that the expected value and the actual value are equal.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
public static void AreEqual(Complex expected, Complex actual)
{
if (expected.IsNaN() && actual.IsNaN())
{
return;
}
if (expected.IsInfinity() && expected.IsInfinity())
{
return;
}
bool pass = expected.Real.AlmostEqual(actual.Real);
if (!pass)
{
Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real);
}
pass = expected.Imaginary.AlmostEqual(actual.Imaginary);
if (!pass)
{
Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
public static void AreEqual(Complex32 expected, Complex32 actual)
{
if (expected.IsNaN() && actual.IsNaN())
{
return;
}
if (expected.IsInfinity() && expected.IsInfinity())
{
return;
}
bool pass = expected.Real.AlmostEqual(actual.Real);
if (!pass)
{
Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real);
}
pass = expected.Imaginary.AlmostEqual(actual.Imaginary);
if (!pass)
{
Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
/// <paramref name="expected"/> and <paramref name="actual"/> are NaN then no assert is thrown.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
/// <param name="decimalPlaces">The number of decimal places to agree on.</param>
public static void AlmostEqual(double expected, double actual, int decimalPlaces)
{
if (double.IsNaN(expected) && double.IsNaN(actual))
{
return;
}
bool pass = expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces);
if (!pass)
{
// signals Gallio that the test failed.
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
/// <paramref name="expected"/> and <paramref name="actual"/> are NaN then no assert is thrown.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
/// <param name="decimalPlaces">The number of decimal places to agree on.</param>
public static void AlmostEqual(float expected, float actual, int decimalPlaces)
{
if (float.IsNaN(expected) && float.IsNaN(actual))
{
return;
}
bool pass = expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces);
if (!pass)
{
// signals Gallio that the test failed.
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
/// <param name="decimalPlaces">The number of decimal places to agree on.</param>
public static void AlmostEqual(Complex expected, Complex actual, int decimalPlaces)
{
bool pass = expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces);
if (!pass)
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
pass = expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces);
if (!pass)
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
/// </summary>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
/// <param name="decimalPlaces">The number of decimal places to agree on.</param>
public static void AlmostEqual(Complex32 expected, Complex32 actual, int decimalPlaces)
{
bool pass = expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces);
if (!pass)
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
pass = expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces);
if (!pass)
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
/// </summary>
/// <typeparam name="T">The type of the structures. Must implement
/// <see cref="IPrecisionSupport{T}"/>.</typeparam>
/// <param name="expected">The expected value.</param>
/// <param name="actual">The actual value.</param>
/// <param name="maximumError">The accuracy required for being almost equal.</param>
public static void AlmostEqual<T>(T expected, T actual, double maximumError)
where T : IPrecisionSupport<T>
{
if (!actual.AlmostEqualWithError(expected, maximumError))
{
Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected, actual);
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
/// </summary>
/// <param name="expected">The expected value list.</param>
/// <param name="actual">The actual value list.</param>
/// <param name="maximumError">The accuracy required for being almost equal.</param>
public static void AlmostEqualList(IList<double> expected, IList<double> actual, double maximumError)
{
for (int i = 0; i < expected.Count; i++)
{
if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
{
Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
}
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
/// </summary>
/// <param name="expected">The expected value list.</param>
/// <param name="actual">The actual value list.</param>
/// <param name="maximumError">The accuracy required for being almost equal.</param>
public static void AlmostEqualList(IList<float> expected, IList<float> actual, double maximumError)
{
for (int i = 0; i < expected.Count; i++)
{
if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
{
Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
}
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
/// </summary>
/// <typeparam name="T">The type of the structures. Must implement
/// <see cref="IPrecisionSupport{T}"/>.</typeparam>
/// <param name="expected">The expected value list.</param>
/// <param name="actual">The actual value list.</param>
/// <param name="maximumError">The accuracy required for being almost equal.</param>
public static void AlmostEqualList<T>(IList<T> expected, IList<T> actual, double maximumError)
where T : IPrecisionSupport<T>
{
for (int i = 0; i < expected.Count; i++)
{
if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
{
Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
}
}
}
/// <summary>
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
/// </summary>
/// <param name="expected">The expected value list.</param>
/// <param name="actual">The actual value list.</param>
/// <param name="maximumError">The accuracy required for being almost equal.</param>
public static void AlmostEqualList(IList<Complex> expected, IList<Complex> actual, double maximumError)
{
for (int i = 0; i < expected.Count; i++)
{
if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
{
Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
}
}
}
}
}

439
src/NUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs

@ -0,0 +1,439 @@
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// 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.
// </copyright>
namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
{
using System;
using System.Collections.Generic;
using Algorithms.LinearAlgebra;
using LinearAlgebra.Double;
using NUnit.Framework;
/// <summary>
/// Base class for linear algebra provider tests.
/// </summary>
[TestFixture]
public class LinearAlgebraProviderTests
{
/// <summary>
/// Initializes a new instance of the <see cref="LinearAlgebraProviderTests"/> class.
/// </summary>
public LinearAlgebraProviderTests()
{
Provider = new ManagedLinearAlgebraProvider();
}
/// <summary>
/// Gets or sets linear algebra provider to test.
/// </summary>
protected ILinearAlgebraProvider Provider
{
get;
set;
}
/// <summary>
/// The Y double test vector.
/// </summary>
private readonly double[] _y = new[] { 1.1, 2.2, 3.3, 4.4, 5.5 };
/// <summary>
/// The X double test vector.
/// </summary>
private readonly double[] _x = new[] { 6.6, 7.7, 8.8, 9.9, 10.1 };
/// <summary>
/// Test matrix to use.
/// </summary>
private readonly IDictionary<string, DenseMatrix> _matrices = new Dictionary<string, DenseMatrix>
{
{ "Singular3x3", new DenseMatrix(new[,] { { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) },
{ "Square3x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) },
{ "Square4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { -1.1, -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) },
{ "Wide2x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) }
};
/// <summary>
/// Can add a vector to scaled vector
/// </summary>
[Test]
public void CanAddVectorToScaledVectorDouble()
{
var result = new double[_y.Length];
Array.Copy(_y, result, _y.Length);
Provider.AddVectorToScaledVector(result, 0, _x);
for (var i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i], result[i]);
}
Array.Copy(_y, result, _y.Length);
Provider.AddVectorToScaledVector(result, 1, _x);
for (var i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i] + _x[i], result[i]);
}
Array.Copy(_y, result, _y.Length);
Provider.AddVectorToScaledVector(result, Math.PI, _x);
for (var i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i] + (Math.PI * _x[i]), result[i]);
}
}
/// <summary>
/// Can scale an array.
/// </summary>
[Test]
public void CanScaleArray()
{
var result = new double[_y.Length];
Array.Copy(_y, result, _y.Length);
Provider.ScaleArray(1, result);
for (var i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i], result[i]);
}
Array.Copy(_y, result, _y.Length);
Provider.ScaleArray(Math.PI, result);
for (var i = 0; i < _y.Length; i++)
{
Assert.AreEqual(_y[i] * Math.PI, result[i]);
}
}
/// <summary>
/// Can compute the dot product.
/// </summary>
[Test]
public void CanComputeDotProduct()
{
var result = Provider.DotProduct(_x, _y);
AssertHelpers.AlmostEqual(152.35, result, 15);
}
/// <summary>
/// Can add two arrays.
/// </summary>
[Test]
public void CanAddArrays()
{
var result = new double[_y.Length];
Provider.AddArrays(_x, _y, result);
for (var i = 0; i < result.Length; i++)
{
Assert.AreEqual(_x[i] + _y[i], result[i]);
}
}
/// <summary>
/// Can subtract two arrays.
/// </summary>
[Test]
public void CanSubtractArrays()
{
var result = new double[_y.Length];
Provider.SubtractArrays(_x, _y, result);
for (var i = 0; i < result.Length; i++)
{
Assert.AreEqual(_x[i] - _y[i], result[i]);
}
}
/// <summary>
/// Can pointwise multiply two arrays.
/// </summary>
[Test]
public void CanPointWiseMultiplyArrays()
{
var result = new double[_y.Length];
Provider.PointWiseMultiplyArrays(_x, _y, result);
for (var i = 0; i < result.Length; i++)
{
Assert.AreEqual(_x[i] * _y[i], result[i]);
}
}
/// <summary>
/// Can compute L1 norm.
/// </summary>
[Test]
public void CanComputeMatrixL1Norm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
AssertHelpers.AlmostEqual(12.1, norm, 6);
}
/// <summary>
/// Can compute Frobenius norm.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
}
/// <summary>
/// Can compute Infinity norm.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can compute L1 norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
AssertHelpers.AlmostEqual(12.1, norm, 6);
}
/// <summary>
/// Can compute Frobenius norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
}
/// <summary>
/// Can compute Infinity norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can multiply two square matrices.
/// </summary>
[Test]
public void CanMultiplySquareMatrices()
{
var x = _matrices["Singular3x3"];
var y = _matrices["Square3x3"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can multiply a wide and tall matrix.
/// </summary>
[Test]
public void CanMultiplyWideAndTallMatrices()
{
var x = _matrices["Wide2x3"];
var y = _matrices["Tall3x2"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can multiply a tall and wide matrix.
/// </summary>
[Test]
public void CanMultiplyTallAndWideMatrices()
{
var x = _matrices["Tall3x2"];
var y = _matrices["Wide2x3"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiply(x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can multiply two square matrices.
/// </summary>
[Test]
public void CanMultiplySquareMatricesWithUpdate()
{
var x = _matrices["Singular3x3"];
var y = _matrices["Square3x3"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can multiply a wide and tall matrix.
/// </summary>
[Test]
public void CanMultiplyWideAndTallMatricesWithUpdate()
{
var x = _matrices["Wide2x3"];
var y = _matrices["Tall3x2"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can multiply a tall and wide matrix.
/// </summary>
[Test]
public void CanMultiplyTallAndWideMatricesWithUpdate()
{
var x = _matrices["Tall3x2"];
var y = _matrices["Wide2x3"];
var c = new DenseMatrix(x.RowCount, y.ColumnCount);
Provider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2, x.Data, x.RowCount, x.ColumnCount, y.Data, y.RowCount, y.ColumnCount, 1.0, c.Data);
for (var i = 0; i < c.RowCount; i++)
{
for (var j = 0; j < c.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(2.2 * x.Row(i) * y.Column(j), c[i, j], 15);
}
}
}
/// <summary>
/// Can compute the Cholesky factorization.
/// </summary>
[Test]
public void CanComputeCholeskyFactor()
{
var matrix = new double[] { 1, 1, 1, 1, 1, 5, 5, 5, 1, 5, 14, 14, 1, 5, 14, 15 };
Provider.CholeskyFactor(matrix, 4);
Assert.AreEqual(matrix[0], 1);
Assert.AreEqual(matrix[1], 1);
Assert.AreEqual(matrix[2], 1);
Assert.AreEqual(matrix[3], 1);
Assert.AreEqual(matrix[4], 0);
Assert.AreEqual(matrix[5], 2);
Assert.AreEqual(matrix[6], 2);
Assert.AreEqual(matrix[7], 2);
Assert.AreEqual(matrix[8], 0);
Assert.AreEqual(matrix[9], 0);
Assert.AreEqual(matrix[10], 3);
Assert.AreEqual(matrix[11], 3);
Assert.AreEqual(matrix[12], 0);
Assert.AreEqual(matrix[13], 0);
Assert.AreEqual(matrix[14], 0);
Assert.AreEqual(matrix[15], 1);
}
/// <summary>
/// Can compute the LU factor of a matrix.
/// </summary>
[Test]
public void CanComputeLuFactor()
{
var matrix = _matrices["Square3x3"];
var a = new double[matrix.RowCount * matrix.RowCount];
Array.Copy(matrix.Data, a, a.Length);
var ipiv = new int[matrix.RowCount];
Provider.LUFactor(a, matrix.RowCount, ipiv);
AssertHelpers.AlmostEqual(a[0], -4.4, 15);
AssertHelpers.AlmostEqual(a[1], 0.25, 15);
AssertHelpers.AlmostEqual(a[2], 0, 15);
AssertHelpers.AlmostEqual(a[3], 5.5, 15);
AssertHelpers.AlmostEqual(a[4], -3.575, 15);
AssertHelpers.AlmostEqual(a[5], -0.307692307692308, 15);
AssertHelpers.AlmostEqual(a[6], 6.6, 15);
AssertHelpers.AlmostEqual(a[7], -4.95, 15);
AssertHelpers.AlmostEqual(a[8], 0.676923076923077, 15);
Assert.AreEqual(ipiv[0], 2);
Assert.AreEqual(ipiv[1], 2);
Assert.AreEqual(ipiv[2], 2);
}
}
}

65
src/NUnitTests/NUnitTests.csproj

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{DAF07AA8-C5C9-4963-98F7-2C3285064DAD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MathNet.Numerics.UnitTests</RootNamespace>
<AssemblyName>MathNet.Numerics.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\out\test\debug\Net40\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\lib\NUnit-2.5.8\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssertHelpers.cs" />
<Compile Include="LinearAlgebraProviderTests\Double\LinearAlgebraProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Numerics\Numerics.csproj">
<Project>{B7CAE5F4-A23F-4438-B5BE-41226618B695}</Project>
<Name>Numerics</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

36
src/NUnitTests/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NUnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("NUnitTests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("04157581-63f3-447b-a277-83c6e69126a4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading…
Cancel
Save