Skip to content

Commit

Permalink
Fixing bug with matrix 2x5 mul 5x4
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanWoo committed Nov 26, 2020
1 parent cf2941f commit 6562229
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Matrix Math/Models/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Matrix(int sizeX, int sizeY, double defaultValue)
}
public static Matrix operator *(Matrix a, Matrix b)
{
if (a.SizeX != b.SizeY)
if (a.SizeY != b.SizeX)
return null;

Matrix resultMatrix = new Matrix(a.SizeX, b.SizeY);
Expand Down
34 changes: 34 additions & 0 deletions Matrix_Test/Matrix2x5and5x4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Matrix_Math.Models;
using Xunit;

namespace Matrix_Test
{
public class Matrix2x5and5x4
{
private Matrix a = new Matrix(2, 5);
private Matrix b = new Matrix(5, 4);

public Matrix2x5and5x4()
{
a[0, 0] = 1; a[0, 1] = 2; a[0, 2] = 3; a[0, 3] = 4; a[0, 4] = 5;
a[1, 0] = 6; a[1, 1] = 7; a[1, 2] = 8; a[1, 3] = 9; a[1, 4] = 10;

b[0, 0] = 1; b[0, 1] = 2; b[0, 2] = 3; b[0, 3] = 4;
b[1, 0] = 2; b[1, 1] = 3; b[1, 2] = 4; b[1, 3] = 5;
b[2, 0] = 3; b[2, 1] = 4; b[2, 2] = 5; b[2, 3] = 6;
b[3, 0] = 6; b[3, 1] = 7; b[3, 2] = 7; b[3, 3] = 7;
b[4, 0] = 8; b[4, 1] = 9; b[4, 2] = 9; b[4, 3] = 9;
}
[Fact]
public void Mul()
{
var result = a * b;

var e = new Matrix(2, 4);
e[0, 0] = 78; e[0, 1] = 93; e[0, 2] = 99; e[0, 3] = 105;
e[1, 0] = 178; e[1, 1] = 218; e[1, 2] = 239; e[1, 3] = 260;

Assert.Equal(e, result);
}
}
}

0 comments on commit 6562229

Please sign in to comment.