From f9891c392a926260bae6b6cd18806958642f131d Mon Sep 17 00:00:00 2001 From: Lukas Reichwein Date: Wed, 26 Jun 2019 17:16:09 +0200 Subject: [PATCH] The funktionality Linked Matricies Check --- .../com/ugsbo/matrixcalc/MatrixCalcMath.java | 10 +++++- .../matrixcalc/MatrixMultiplicationTest.java | 31 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java index 4725418..d18d9cd 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java @@ -27,7 +27,15 @@ public class MatrixCalcMath { */ public boolean checkIfMatriciesAreLinked(Double[][] matrixA, Double[][] matrixB) { // TODO Check if the number of Rows of Matrix A equal to the coulums of Matrix B - return false; + if (matrixA != null) { + if (matrixA[0].length == matrixB.length) { + return true; + } else { + return false; + } + } else { + return false; + } } /** diff --git a/src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java b/src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java index 9fc0dc9..913227d 100644 --- a/src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java +++ b/src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java @@ -1,5 +1,6 @@ package com.ugsbo.matrixcalc; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -8,12 +9,30 @@ import org.junit.Test; * Testet die Matrix Multiplication funkionalität */ public class MatrixMultiplicationTest { - /** - * This Test only tests that the assertTrue funktion works like expected. - */ + + @Test + public void MatrixAIsLinkedToMatrixBSouldBeTrue() { + MatrixCalcMath math = new MatrixCalcMath(); + Double[][] matrixA = new Double[1][2]; + Double[][] matrixB = new Double[2][1]; + assertTrue("Matrix A is Linked to B but it is not detected that way", + math.checkIfMatriciesAreLinked(matrixA, matrixB)); + } + + @Test + public void MatrixAAndMatrixBAreNullSouldReturnFalse() { + MatrixCalcMath math = new MatrixCalcMath(); + Double[][] matrixA = null; + Double[][] matrixB = null; + assertFalse("Matrix A and B are null but detected as Linked", math.checkIfMatriciesAreLinked(matrixA, matrixB)); + } + @Test - public void shouldAlwaysBeTrue() { - //TODO replace this test through a real one!! - assertTrue("The JUnit setup is not correct, this test only assertTrue.", true); + public void MatrixAAndMatrixBAreNotLinkedSouldReturnFalse() { + MatrixCalcMath math = new MatrixCalcMath(); + Double[][] matrixA = new Double[1][1]; + Double[][] matrixB = new Double[2][1]; + assertFalse("Matrix A and B are not Linked but detected as Linked", + math.checkIfMatriciesAreLinked(matrixA, matrixB)); } }