Browse Source

Unit Tests: Linear algebra vectors: arighmetic theories (failing, gh-18)

la-knuth
Christoph Ruegg 15 years ago
parent
commit
7798dba82f
  1. 48
      src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs
  2. 50
      src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs
  3. 116
      src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs
  4. 112
      src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs
  5. 48
      src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs
  6. 50
      src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs
  7. 116
      src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs
  8. 112
      src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs
  9. 47
      src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs
  10. 49
      src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs
  11. 114
      src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs
  12. 111
      src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs
  13. 47
      src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs
  14. 49
      src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs
  15. 116
      src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs
  16. 111
      src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs
  17. 12
      src/UnitTests/UnitTests.csproj

48
src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs

@ -0,0 +1,48 @@
// <copyright file="DenseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex
{
using System.Numerics;
using LinearAlgebra.Complex;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public class DenseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<Complex>[] denseVectors = new Vector<Complex>[]
{
new DenseVector(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }),
new DenseVector(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) })
};
}
}

50
src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs

@ -0,0 +1,50 @@
// <copyright file="SparseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex
{
using System.Numerics;
using LinearAlgebra.Complex;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public class SparseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<Complex>[] denseVectors = new Vector<Complex>[]
{
new SparseVector(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }),
new SparseVector(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) }),
new SparseVector(5),
new SparseVector(int.MaxValue)
};
}
}

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

@ -180,122 +180,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
CollectionAssert.AreEqual(array, array);
}
/// <summary>
/// Can call unary plus operator on a vector.
/// </summary>
[Test]
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>
[Test]
public void CanAddTwoSparseVectorsUsingOperator()
{
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>
[Test]
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>
[Test]
public void CanSubtractTwoSparseVectorsUsingOperator()
{
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>

112
src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs

@ -0,0 +1,112 @@
// <copyright file="VectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex
{
using System;
using System.Numerics;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public abstract class VectorArithmeticTheory
{
[Theory, Timeout(100)]
public void CanCallUnaryPlusOperatorOnVector(Vector<Complex> vector)
{
var hash = vector.GetHashCode();
var result = +vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(result, Is.EqualTo(vector));
}
[Theory, Timeout(100)]
public void CanCallUnaryMinusOperatorOnVector(Vector<Complex> vector)
{
var hash = vector.GetHashCode();
var result = -vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(-result, Is.EqualTo(vector));
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(-vector[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanAddTwoVectorsUsingOperator(Vector<Complex> a, Vector<Complex> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a + b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] + b[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanSubtractTwoVectorsUsingOperator(Vector<Complex> a, Vector<Complex> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a - b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] - b[i]));
}
}
}
}

48
src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs

@ -0,0 +1,48 @@
// <copyright file="DenseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex32
{
using LinearAlgebra.Complex32;
using LinearAlgebra.Generic;
using Numerics;
using NUnit.Framework;
[TestFixture]
public class DenseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<Complex32>[] denseVectors = new Vector<Complex32>[]
{
new DenseVector(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }),
new DenseVector(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) })
};
}
}

50
src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs

@ -0,0 +1,50 @@
// <copyright file="SparseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex32
{
using LinearAlgebra.Complex32;
using LinearAlgebra.Generic;
using Numerics;
using NUnit.Framework;
[TestFixture]
public class SparseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<Complex32>[] denseVectors = new Vector<Complex32>[]
{
new SparseVector(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }),
new SparseVector(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) }),
new SparseVector(5),
new SparseVector(int.MaxValue)
};
}
}

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

@ -180,122 +180,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
CollectionAssert.AreEqual(array, array);
}
/// <summary>
/// Can call unary plus operator on a vector.
/// </summary>
[Test]
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>
[Test]
public void CanAddTwoSparseVectorsUsingOperator()
{
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>
[Test]
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>
[Test]
public void CanSubtractTwoSparseVectorsUsingOperator()
{
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>

112
src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs

@ -0,0 +1,112 @@
// <copyright file="VectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Complex32
{
using System;
using LinearAlgebra.Generic;
using Numerics;
using NUnit.Framework;
[TestFixture]
public abstract class VectorArithmeticTheory
{
[Theory, Timeout(100)]
public void CanCallUnaryPlusOperatorOnVector(Vector<Complex32> vector)
{
var hash = vector.GetHashCode();
var result = +vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(result, Is.EqualTo(vector));
}
[Theory, Timeout(100)]
public void CanCallUnaryMinusOperatorOnVector(Vector<Complex32> vector)
{
var hash = vector.GetHashCode();
var result = -vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(-result, Is.EqualTo(vector));
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(-vector[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanAddTwoVectorsUsingOperator(Vector<Complex32> a, Vector<Complex32> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a + b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] + b[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanSubtractTwoVectorsUsingOperator(Vector<Complex32> a, Vector<Complex32> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a - b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] - b[i]));
}
}
}
}

47
src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs

@ -0,0 +1,47 @@
// <copyright file="DenseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Double
{
using LinearAlgebra.Double;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public class DenseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<double>[] denseVectors = new Vector<double>[]
{
new DenseVector(new double[] { 1, 2, 3, 4, 5 }),
new DenseVector(new double[] { 2, 0, 0, -5, 0 }),
};
}
}

49
src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs

@ -0,0 +1,49 @@
// <copyright file="SparseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Double
{
using LinearAlgebra.Double;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public class SparseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<double>[] denseVectors = new Vector<double>[]
{
new SparseVector(new double[] { 1, 2, 3, 4, 5 }),
new SparseVector(new double[] { 2, 0, 0, -5, 0 }),
new SparseVector(5),
new SparseVector(int.MaxValue)
};
}
}

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

@ -179,120 +179,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
CollectionAssert.AreEqual(array, array);
}
/// <summary>
/// Can call unary plus operator on a vector.
/// </summary>
[Test]
public void CanCallUnaryPlusOperatorOnSparseVector()
{
var vector = new SparseVector(Data);
var result = +vector;
for (var i = 0; i < Data.Length; 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>
[Test]
public void CanAddTwoSparseVectorsUsingOperator()
{
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>
[Test]
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>
[Test]
public void CanSubtractTwoSparseVectorsUsingOperator()
{
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>

111
src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs

@ -0,0 +1,111 @@
// <copyright file="VectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Double
{
using System;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public abstract class VectorArithmeticTheory
{
[Theory, Timeout(100)]
public void CanCallUnaryPlusOperatorOnVector(Vector<double> vector)
{
var hash = vector.GetHashCode();
var result = +vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(result, Is.EqualTo(vector));
}
[Theory, Timeout(100)]
public void CanCallUnaryMinusOperatorOnVector(Vector<double> vector)
{
var hash = vector.GetHashCode();
var result = -vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(-result, Is.EqualTo(vector));
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(-vector[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanAddTwoVectorsUsingOperator(Vector<double> a, Vector<double> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a + b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] + b[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanSubtractTwoVectorsUsingOperator(Vector<double> a, Vector<double> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a - b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] - b[i]));
}
}
}
}

47
src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs

@ -0,0 +1,47 @@
// <copyright file="DenseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Single
{
using LinearAlgebra.Generic;
using LinearAlgebra.Single;
using NUnit.Framework;
[TestFixture]
public class DenseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<float>[] denseVectors = new Vector<float>[]
{
new DenseVector(new float[] { 1, 2, 3, 4, 5 }),
new DenseVector(new float[] { 2, 0, 0, -5, 0 }),
};
}
}

49
src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs

@ -0,0 +1,49 @@
// <copyright file="SparseVectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Single
{
using LinearAlgebra.Generic;
using LinearAlgebra.Single;
using NUnit.Framework;
[TestFixture]
public class SparseVectorArithmeticTheory : VectorArithmeticTheory
{
[Datapoints]
Vector<float>[] denseVectors = new Vector<float>[]
{
new SparseVector(new float[] { 1, 2, 3, 4, 5 }),
new SparseVector(new float[] { 2, 0, 0, -5, 0 }),
new SparseVector(5),
new SparseVector(int.MaxValue)
};
}
}

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

@ -179,122 +179,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
CollectionAssert.AreEqual(array, array);
}
/// <summary>
/// Can call unary plus operator on a vector.
/// </summary>
[Test]
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>
[Test]
public void CanAddTwoSparseVectorsUsingOperator()
{
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>
[Test]
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>
[Test]
public void CanSubtractTwoSparseVectorsUsingOperator()
{
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>

111
src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs

@ -0,0 +1,111 @@
// <copyright file="VectorArithmeticTheory.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-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
// 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.LinearAlgebraTests.Single
{
using System;
using LinearAlgebra.Generic;
using NUnit.Framework;
[TestFixture]
public abstract class VectorArithmeticTheory
{
[Theory, Timeout(100)]
public void CanCallUnaryPlusOperatorOnVector(Vector<float> vector)
{
var hash = vector.GetHashCode();
var result = +vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(result, Is.EqualTo(vector));
}
[Theory, Timeout(100)]
public void CanCallUnaryMinusOperatorOnVector(Vector<float> vector)
{
var hash = vector.GetHashCode();
var result = -vector;
Assert.That(vector.GetHashCode(), Is.EqualTo(hash));
Assert.That(result, Is.Not.SameAs(vector));
Assert.That(-result, Is.EqualTo(vector));
for (var i = 0; i < Math.Min(vector.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(-vector[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanAddTwoVectorsUsingOperator(Vector<float> a, Vector<float> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a + b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] + b[i]));
}
}
[Theory, Pairwise, Timeout(100)]
public void CanSubtractTwoVectorsUsingOperator(Vector<float> a, Vector<float> b)
{
Assume.That(a.Count, Is.EqualTo(b.Count));
var hasha = a.GetHashCode();
var hashb = b.GetHashCode();
var result = a - b;
Assert.That(a.GetHashCode(), Is.EqualTo(hasha));
Assert.That(b.GetHashCode(), Is.EqualTo(hashb));
Assert.That(result, Is.Not.SameAs(a));
Assert.That(result, Is.Not.SameAs(b));
for (var i = 0; i < Math.Min(a.Count, 20); i++)
{
Assert.That(result[i], Is.EqualTo(a[i] - b[i]));
}
}
}
}

12
src/UnitTests/UnitTests.csproj

@ -132,6 +132,7 @@
<Compile Include="LinearAlgebraTests\Complex32\DenseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex32\DenseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex32\DenseVectorTest.TextHandling.cs">
<SubType>Code</SubType>
</Compile>
@ -246,6 +247,7 @@
<Compile Include="LinearAlgebraTests\Complex32\SparseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex32\SparseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex32\SparseVectorTest.cs">
<SubType>Code</SubType>
</Compile>
@ -264,6 +266,7 @@
<Compile Include="LinearAlgebraTests\Complex32\UserDefinedVectorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex32\VectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex32\VectorTests.Arithmetic.cs">
<SubType>Code</SubType>
</Compile>
@ -276,6 +279,7 @@
<Compile Include="LinearAlgebraTests\Complex\DenseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex\DenseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex\DenseVectorTest.TextHandling.cs">
<SubType>Code</SubType>
</Compile>
@ -390,6 +394,7 @@
<Compile Include="LinearAlgebraTests\Complex\SparseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex\SparseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex\SparseVectorTest.cs">
<SubType>Code</SubType>
</Compile>
@ -408,6 +413,7 @@
<Compile Include="LinearAlgebraTests\Complex\UserDefinedVectorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Complex\VectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Complex\VectorTests.Arithmetic.cs">
<SubType>Code</SubType>
</Compile>
@ -417,6 +423,7 @@
<Compile Include="LinearAlgebraTests\Complex\VectorTests.Norm.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Double\SparseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Double\DenseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
@ -426,6 +433,7 @@
<Compile Include="LinearAlgebraTests\Double\DenseVectorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Double\DenseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Double\DiagonalMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
@ -564,6 +572,7 @@
<Compile Include="LinearAlgebraTests\Single\DenseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Single\DenseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Single\DenseVectorTest.TextHandling.cs">
<SubType>Code</SubType>
</Compile>
@ -678,6 +687,7 @@
<Compile Include="LinearAlgebraTests\Single\SparseMatrixTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Single\SparseVectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Single\SparseVectorTest.cs">
<SubType>Code</SubType>
</Compile>
@ -696,6 +706,7 @@
<Compile Include="LinearAlgebraTests\Single\UserDefinedVectorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Single\VectorArithmeticTheory.cs" />
<Compile Include="LinearAlgebraTests\Single\VectorTests.Arithmetic.cs">
<SubType>Code</SubType>
</Compile>
@ -705,6 +716,7 @@
<Compile Include="LinearAlgebraTests\Single\VectorTests.Norm.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebraTests\Double\VectorArithmeticTheory.cs" />
<Compile Include="NumberTheoryTests\GcdRelatedTest.cs" />
<Compile Include="NumberTheoryTests\GcdRelatedTestBigInteger.cs" />
<Compile Include="NumberTheoryTests\IntegerTheoryTest.cs" />

Loading…
Cancel
Save