/
Given_2x3_matrix.cs
96 lines (83 loc) · 2.75 KB
/
Given_2x3_matrix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.Linq;
using NUnit.Framework;
using Stratosphere.Math;
using Stratosphere.Math.Regression;
namespace Stratosphere.Tests.Math
{
public class Given_2x3_matrix
{
private ColumnMajorMatrix _matrix;
[SetUp]
public void Given_test_matrix()
{
/* 0 2 4
1 3 5 */
_matrix = ColumnMajorMatrix.Parse("0 2 4;1 3 5");
}
[TestCase(0, ExpectedResult = 0)]
[TestCase(1, ExpectedResult = 1)]
[TestCase(2, ExpectedResult = 2)]
[TestCase(3, ExpectedResult = 3)]
[TestCase(4, ExpectedResult = 4)]
[TestCase(5, ExpectedResult = 5)]
public double Then_can_be_accessed_by_column_index(int columnIndex)
{
return _matrix.Get(columnIndex);
}
[TestCase(0, ExpectedResult = 0)]
[TestCase(1, ExpectedResult = 2)]
[TestCase(2, ExpectedResult = 4)]
[TestCase(3, ExpectedResult = 1)]
[TestCase(4, ExpectedResult = 3)]
[TestCase(5, ExpectedResult = 5)]
public double Then_can_be_accessed_by_row_index(int rowIndex)
{
return _matrix.EnumerateByRows().Skip(rowIndex).First();
}
[Test]
public void Then_can_be_enumerated_by_columns()
{
CollectionAssert.AreEqual(new double[] {0, 1, 2, 3, 4, 5}, _matrix.EnumerateByColumns());
}
[Test]
public void Then_can_be_enumerated_by_rows()
{
CollectionAssert.AreEqual(new double[] { 0, 2, 4, 1, 3, 5}, _matrix.EnumerateByRows());
}
[Test]
public void Then_can_be_multiplied_by_other_matrix()
{
Assert.AreEqual((ColumnMajorMatrix)"20 26;26 35", _matrix * "0 1;2 3;4 5");
}
[Test]
public void Then_can_be_multiplied_by_other_matrix_2()
{
Assert.AreEqual((ColumnMajorMatrix)"20;26", _matrix.Multiply("0;2;4"));
}
[Test]
public void Then_max_per_column_can_be_calculated()
{
Assert.AreEqual((ColumnMajorMatrix)"1 3 5", _matrix.Max(0));
}
[Test]
public void Then_max_per_row_can_be_calculated()
{
Assert.AreEqual((ColumnMajorMatrix)"4;5", _matrix.Max(1));
}
[Test]
public void Then_min_per_column_can_be_calculated()
{
Assert.AreEqual((ColumnMajorMatrix)"0 2 4", _matrix.Min(0));
}
[Test]
public void Then_min_per_row_can_be_calculated()
{
Assert.AreEqual((ColumnMajorMatrix)"0;1", _matrix.Min(1));
}
[Test]
public void Then_length_can_be_calculated()
{
Assert.AreEqual(1, _matrix.GetColumn(0).Length, 0.001);
}
}
}