Exemplo n.º 1
0
    public function testMatrixFromString()
    {
        $str = '
			1, 2, 4;
			5,6,8;3, 1,

			1
		';
        $expected = array(array(1, 2, 4), array(5, 6, 8), array(3, 1, 1));
        $this->assertEquals($expected, MatrixFactory::fromString($str)->getArray());
        //
        $str = '  1;5; 3';
        $expected = array(array(1), array(5), array(3));
        $this->assertEquals($expected, MatrixFactory::fromString($str)->getArray());
    }
Exemplo n.º 2
0
    public function testMap()
    {
        $callback = function ($elem) {
            return $elem * 2;
        };
        $c = MatrixFactory::fromString('2, 4;
			 6, 8');
        $this->assertEquals($c->getArray(), $this->B->map($callback)->getArray());
    }
Exemplo n.º 3
0
    public function testTranspose()
    {
        $trans_A = MatrixFactory::fromString('1, 2, 5;
			 5, 2, 5;
			 4, 2, 1');
        $this->assertEquals($trans_A->getArray(), MatrixAlgorithms::transpose($this->A)->getArray());
    }
Exemplo n.º 4
0
    public function testProdNumber()
    {
        $c = MatrixFactory::fromString('3, 6;
			 9, 12');
        $this->assertEquals($c->getArray(), $this->B->prod(3)->getArray());
    }
Exemplo n.º 5
0
 public function testInsertRow()
 {
     $value = MatrixFactory::fromString('1, 2, 3; 7, 8, 9');
     $insertion = MatrixFactory::fromString('4, 5, 6');
     $expect = MatrixFactory::fromString('1, 2, 3; 4, 5, 6; 7, 8, 9');
     $this->assertEquals($expect->getArray(), $value->insertRow(1, $insertion)->getArray());
 }