Browse Source

Unit Tests: added sparse vector unit tests confirming gh-18.

pull/36/head
Christoph Ruegg 15 years ago
parent
commit
45ed83ac12
  1. 6
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  2. 6
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  3. 6
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  4. 6
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  5. 62
      src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs
  6. 62
      src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs
  7. 64
      src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs
  8. 62
      src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs

6
src/Numerics/LinearAlgebra/Complex/SparseVector.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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

6
src/Numerics/LinearAlgebra/Complex32/SparseVector.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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

6
src/Numerics/LinearAlgebra/Double/SparseVector.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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

6
src/Numerics/LinearAlgebra/Single/SparseVector.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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

62
src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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
@ -183,13 +187,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
public void CanCallUnaryPlusOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = +vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(vector[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = +vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can add two sparse vectors using "+" operator.
/// </summary>
@ -198,16 +215,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector + other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Data[i] * 2.0, result[i]);
}
}
[Test, Timeout(100)]
public void CanAddSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector + other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can call unary negate operator on a sparse vector.
/// </summary>
@ -215,13 +245,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
public void CanCallUnaryNegationOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = -vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(-Data[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = -vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can subtract two sparse vectors using "-" operator.
/// </summary>
@ -230,16 +273,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector - other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Complex.Zero, result[i]);
}
}
[Test, Timeout(100)]
public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector - other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can multiply a sparse vector by a scalar using "*" operator.
/// </summary>

62
src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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
@ -183,13 +187,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void CanCallUnaryPlusOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = +vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(vector[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = +vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can add two sparse vectors using "+" operator.
/// </summary>
@ -198,16 +215,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector + other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Data[i] * 2.0f, result[i]);
}
}
[Test, Timeout(100)]
public void CanAddSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector + other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can call unary negate operator on a sparse vector.
/// </summary>
@ -215,13 +245,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void CanCallUnaryNegationOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = -vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(-Data[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = -vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can subtract two sparse vectors using "-" operator.
/// </summary>
@ -230,16 +273,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector - other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Complex32.Zero, result[i]);
}
}
[Test, Timeout(100)]
public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector - other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can multiply a sparse vector by a Complex using "*" operator.
/// </summary>

64
src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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
@ -182,13 +186,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
public void CanCallUnaryPlusOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = +vector;
var result = +vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(vector[i], other[i]);
Assert.AreEqual(vector[i], result[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = +vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can add two sparse vectors using "+" operator.
/// </summary>
@ -197,16 +214,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector + other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Data[i] * 2.0, result[i]);
}
}
[Test, Timeout(100)]
public void CanAddSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector + other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can call unary negate operator on a sparse vector.
/// </summary>
@ -221,6 +251,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
}
[Test, Timeout(100)]
public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = -vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can subtract two sparse vectors using "-" operator.
/// </summary>
@ -229,16 +270,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector - other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(0.0, result[i]);
}
}
[Test, Timeout(100)]
public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector - other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can multiply a sparse vector by a scalar using "*" operator.
/// </summary>

62
src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2011 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
@ -12,8 +14,10 @@
// 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
@ -182,13 +186,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
public void CanCallUnaryPlusOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = +vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(vector[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = +vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can add two sparse vectors using "+" operator.
/// </summary>
@ -197,16 +214,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector + other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Data[i] * 2.0f, result[i]);
}
}
[Test, Timeout(100)]
public void CanAddSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector + other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can call unary negate operator on a sparse vector.
/// </summary>
@ -214,13 +244,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
public void CanCallUnaryNegationOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var other = -vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(-Data[i], other[i]);
}
}
[Test, Timeout(100)]
public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var result = -vector;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can subtract two sparse vectors using "-" operator.
/// </summary>
@ -229,16 +272,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
var vector = new SparseVector(Data);
var other = new SparseVector(Data);
var result = vector - other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(0.0f, result[i]);
}
}
[Test, Timeout(100)]
public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength()
{
var vector = new SparseVector(int.MaxValue);
var other = new SparseVector(int.MaxValue);
var result = vector - other;
Assert.AreEqual(0, result.AbsoluteMaximum());
Assert.AreEqual(0, result.AbsoluteMinimum());
}
/// <summary>
/// Can multiply a sparse vector by a scalar using "*" operator.
/// </summary>

Loading…
Cancel
Save