Skip to content

Commit b52d4a4

Browse files
committed
More tests.
1 parent d130167 commit b52d4a4

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

CSparse.Tests/Double/DenseMatrixTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,51 @@ public void TestSubMatrix()
385385
Assert.AreEqual(1.0, C.At(2, 0));
386386
}
387387

388+
[Test]
389+
public void TestSetSubMatrix()
390+
{
391+
var A = DenseMatrix.OfRowMajor(3, 4, new double[]
392+
{
393+
0, 1, 2, 3,
394+
0, 1, 2, 3,
395+
0, 1, 2, 3
396+
});
397+
398+
var B = DenseMatrix.OfRowMajor(2, 3, new double[]
399+
{
400+
4, 5, 6,
401+
7, 8, 9
402+
});
403+
404+
A.SetSubMatrix(1, 1, B);
405+
406+
var expected = new double[3][]
407+
{
408+
new double[4] { 0, 1, 2, 3 },
409+
new double[4] { 0, 4, 5, 6 },
410+
new double[4] { 0, 7, 8, 9 }
411+
};
412+
413+
for (int i = 0; i < 3; i++)
414+
{
415+
CollectionAssert.AreEqual(expected[i], A.Row(i));
416+
}
417+
418+
A.SetSubMatrix(0, 0, B);
419+
420+
expected = new double[3][]
421+
{
422+
new double[4] { 4, 5, 6, 3 },
423+
new double[4] { 7, 8, 9, 6 },
424+
new double[4] { 0, 7, 8, 9 }
425+
};
426+
427+
for (int i = 0; i < 3; i++)
428+
{
429+
CollectionAssert.AreEqual(expected[i], A.Row(i));
430+
}
431+
}
432+
388433
#region Matrix creation
389434

390435
[TestCase(2, 2)]

CSparse.Tests/Double/SparseMatrixTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,17 @@ public void TestOfIndexed_Coo(int rows, int columns)
506506
Assert.IsNull(coo.ColumnIndices);
507507
}
508508

509+
[Test]
510+
public void TestOfIndexed_Empty()
511+
{
512+
var coord = new CoordinateStorage<double>(0, 0, 0);
513+
514+
var sparseA = new SparseMatrix(0, 0, 0);
515+
var sparseB = SparseMatrix.OfIndexed(coord);
516+
517+
Assert.IsTrue(sparseA.Equals(sparseB));
518+
}
519+
509520
[TestCase(2, 2)]
510521
[TestCase(2, 3)]
511522
public void TestOfColumnMajor(int rows, int columns)

0 commit comments

Comments
 (0)