예제 #1
0
 public function testDeterminantOrderN()
 {
     $matrix = new Matrix(4, 4, 6);
     $matrix->setPoint(1, 1, 2);
     $matrix->setPoint(1, 2, 3);
     $matrix->setPoint(1, 3, -2);
     $matrix->setPoint(1, 4, 4);
     $matrix->setPoint(2, 1, 3);
     $matrix->setPoint(2, 2, -2);
     $matrix->setPoint(2, 3, 1);
     $matrix->setPoint(2, 4, 2);
     $matrix->setPoint(3, 1, 3);
     $matrix->setPoint(3, 2, 2);
     $matrix->setPoint(3, 3, 3);
     $matrix->setPoint(3, 4, 4);
     $matrix->setPoint(4, 1, -2);
     $matrix->setPoint(4, 2, 4);
     $matrix->setPoint(4, 3, 0);
     $matrix->setPoint(4, 4, 5);
     $sut = new Determinant($matrix);
     $result = $this->checkAbsoluteEquals('-286.000000', $sut->forOrderN());
     $this->assertTrue($result);
     $result = $this->checkAbsoluteEquals('-286.000000', $sut->retrieve());
     $this->assertTrue($result);
 }
예제 #2
0
 public function testPrintPretty()
 {
     $sut = new Matrix(3, 3, 2);
     $sut->setPoint(1, 1, 2);
     $sut->setPoint(1, 2, 3);
     $sut->setPoint(1, 3, 4);
     $sut->setPoint(2, 1, 3);
     $sut->setPoint(2, 2, 4);
     $sut->setPoint(2, 3, 5);
     $sut->setPoint(3, 1, 4);
     $sut->setPoint(3, 2, 5);
     $sut->setPoint(3, 3, "6.00");
     ob_start();
     $sut->printPretty();
     $response = ob_get_clean();
     $this->assertContains('2.00', $response);
     $this->assertContains('3.00', $response);
     $this->assertContains('4.00', $response);
     $this->assertContains('5.00', $response);
     $this->assertContains('6.00', $response);
     $actual = "        2.00          3.00          4.00  \n        3.00          4.00          5.00  \n        4.00          5.00          6.00  \n";
     $this->assertEquals($actual, $response);
 }
예제 #3
0
 public function testIsTriangularLower()
 {
     $matrix = new Matrix(3, 3, 2);
     $matrix->setPoint(1, 1, 0);
     $matrix->setPoint(1, 2, 0);
     $matrix->setPoint(1, 3, 0);
     $matrix->setPoint(2, 1, 0);
     $matrix->setPoint(2, 2, 0);
     $matrix->setPoint(2, 3, 0);
     $matrix->setPoint(3, 1, 1);
     $matrix->setPoint(3, 2, 0);
     $matrix->setPoint(3, 3, 0);
     $sut = new Properties($matrix, 2);
     $this->assertTrue($sut->isTriangularLower());
     $matrix = new Matrix(1, 3, 2);
     $sut = new Properties($matrix, 2);
     $this->assertFalse($sut->isTriangularLower());
     $matrix = new Matrix(3, 3, 2);
     $matrix->setPoint(1, 1, 0);
     $matrix->setPoint(1, 2, 0);
     $matrix->setPoint(1, 3, 1);
     $matrix->setPoint(2, 1, 0);
     $matrix->setPoint(2, 2, 0);
     $matrix->setPoint(2, 3, 0);
     $matrix->setPoint(3, 1, 1);
     $matrix->setPoint(3, 2, 0);
     $matrix->setPoint(3, 3, 0);
     $sut = new Properties($matrix, 2);
     $this->assertFalse($sut->isTriangularLower());
 }
예제 #4
0
 public function testAdjugateMatrix()
 {
     $operations = new Operations($this->generarMatrix(), 2);
     $transposed = $operations->transposed();
     $operations = new Operations($transposed, 2);
     $adjugate = $operations->adjugateMatrix();
     $expected = new Matrix(3, 3, 2);
     $expected->setPoint(1, 1, 0);
     $expected->setPoint(1, 2, -1);
     $expected->setPoint(1, 3, 0);
     $expected->setPoint(2, 1, -1);
     $expected->setPoint(2, 2, 0);
     $expected->setPoint(2, 3, 1);
     $expected->setPoint(3, 1, 0);
     $expected->setPoint(3, 2, 0);
     $expected->setPoint(3, 3, -1);
     $this->assertMatrixEquals($expected, $adjugate);
 }
예제 #5
0
 /**
  * @param MatrixBase $matriz
  * @return MatrixBase
  * @depends testAdjuntoOrden4
  */
 public function testMultiplica1(MatrixBase $matriz)
 {
     $tmp1 = new Matrix(3, 3, 5);
     $tmp1->setPoint(1, 1, 2);
     $tmp1->setPoint(1, 2, 0);
     $tmp1->setPoint(1, 3, 1);
     $tmp1->setPoint(2, 1, 3);
     $tmp1->setPoint(2, 2, 0);
     $tmp1->setPoint(2, 3, 0);
     $tmp1->setPoint(3, 1, 5);
     $tmp1->setPoint(3, 2, 1);
     $tmp1->setPoint(3, 3, 1);
     $tmp2 = new Matrix(3, 3, 5);
     $tmp2->setPoint(1, 1, 1);
     $tmp2->setPoint(1, 2, 0);
     $tmp2->setPoint(1, 3, 1);
     $tmp2->setPoint(2, 1, 1);
     $tmp2->setPoint(2, 2, 2);
     $tmp2->setPoint(2, 3, 1);
     $tmp2->setPoint(3, 1, 1);
     $tmp2->setPoint(3, 2, 1);
     $tmp2->setPoint(3, 3, 0);
     $tmp3 = new Matrix(3, 3, 5);
     $tmp3->setPoint(1, 1, 3);
     $tmp3->setPoint(1, 2, 1);
     $tmp3->setPoint(1, 3, 2);
     $tmp3->setPoint(2, 1, 3);
     $tmp3->setPoint(2, 2, 0);
     $tmp3->setPoint(2, 3, 3);
     $tmp3->setPoint(3, 1, 7);
     $tmp3->setPoint(3, 2, 3);
     $tmp3->setPoint(3, 3, 6);
     $tmp4 = $tmp1->multiplicationMatrix($tmp2);
     $this->assertTrue($tmp3->isMatrixEquals($tmp4));
     return $tmp4;
 }