<commit_before><?php

namespace mcordingley\LinearAlgebra;

class MatrixTest extends \PHPUnit_Framework_TestCase {
    private function buildMatrix() {
        return new Matrix([
            [1, 2, 3, 4],
            [5, 6, 7, 8],
            [9, 10, 11, 12]
        ]);
    }
    
    public function testConstruction() {
        $matrix = $this->buildMatrix();
        
        // This won't execute if there's an exception. If there is one,
        // pull a full stop, something's very wrong.
        $this->assertTrue(true);
    }
    
    public function testBadConstruction() {
        try {
            $matrix = new Matrix([
                [1, 2, 3, 4],
                [5, 6, 7],
                [9, 10]
            ]);
        }
        catch (MatrixException $exception) {
            return;
        }
        
        $this->fail('MatrixException not raised.');
    }
    
    public function testSize() {
        $matrix = $this->buildMatrix();
        
        $this->assertEquals(3, $matrix->rows);
        $this->assertEquals(4, $matrix->columns);
    }
    
    public function testMap() {
        $matrix = new Matrix([
            [1, 2],
            [3, 4]
        ]);
        
        $mapped = $matrix->map(function($value, $row, $column) {
            return $value + $row + $column;
        });
        
        $this->assertEquals(1, $mapped->get(0, 0));
        $this->assertEquals(3, $mapped->get(0, 1));
        $this->assertEquals(4, $mapped->get(1, 0));
        $this->assertEquals(6, $mapped->get(1, 1));
    }
    
    public function testGetSet() {
        $matrix = $this->buildMatrix();
        
        // Check constructed value
        $this->assertEquals(8, $matrix->get(1, 3));
        
        // Check chainable return value
        $this->assertInstanceOf('\mcordingley\Matrix\Matrix', $matrix->set(1, 3, 20));
        
        // Check that the expected element was set to the expected value
        $this->assertEquals(20, $matrix->get(1, 3));
    }
    
    public function testAddMatrix() {
        $matrix1 = new Matrix([
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ]);
        
        $matrix2 = new Matrix([
            [4, 2, 6],
            [1, 7, 3],
            [7, 3, 2]
        ]);
        
        $added = $matrix1->add($matrix2);
        
        $this->assertEquals(5, $added->get(0, 0));
        $this->assertEquals(4, $added->get(0, 1));
        $this->assertEquals(9, $added->get(0, 2));
        $this->assertEquals(5, $added->get(1, 0));
        $this->assertEquals(12, $added->get(1, 1));
        $this->assertEquals(9, $added->get(1, 2));<commit_msg>Update namespace.<commit_after><?php

namespace mcordingley\LinearAlgebra;

class MatrixTest extends \PHPUnit_Framework_TestCase {
    private function buildMatrix() {
        return new Matrix([
            [1, 2, 3, 4],
            [5, 6, 7, 8],
            [9, 10, 11, 12]
        ]);
    }
    
    public function testConstruction() {
        $matrix = $this->buildMatrix();
        
        // This won't execute if there's an exception. If there is one,
        // pull a full stop, something's very wrong.
        $this->assertTrue(true);
    }
    
    public function testBadConstruction() {
        try {
            $matrix = new Matrix([
                [1, 2, 3, 4],
                [5, 6, 7],
                [9, 10]
            ]);
        }
        catch (MatrixException $exception) {
            return;
        }
        
        $this->fail('MatrixException not raised.');
    }
    
    public function testSize() {
        $matrix = $this->buildMatrix();
        
        $this->assertEquals(3, $matrix->rows);
        $this->assertEquals(4, $matrix->columns);
    }
    
    public function testMap() {
        $matrix = new Matrix([
            [1, 2],
            [3, 4]
        ]);
        
        $mapped = $matrix->map(function($value, $row, $column) {
            return $value + $row + $column;
        });
        
        $this->assertEquals(1, $mapped->get(0, 0));
        $this->assertEquals(3, $mapped->get(0, 1));
        $this->assertEquals(4, $mapped->get(1, 0));
        $this->assertEquals(6, $mapped->get(1, 1));
    }
    
    public function testGetSet() {
        $matrix = $this->buildMatrix();
        
        // Check constructed value
        $this->assertEquals(8, $matrix->get(1, 3));
        
        // Check chainable return value
        $this->assertInstanceOf('\mcordingley\LinearAlgebra\Matrix', $matrix->set(1, 3, 20));
        
        // Check that the expected element was set to the expected value
        $this->assertEquals(20, $matrix->get(1, 3));
    }
    
    public function testAddMatrix() {
        $matrix1 = new Matrix([
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ]);
        
        $matrix2 = new Matrix([
            [4, 2, 6],
            [1, 7, 3],
            [7, 3, 2]
        ]);
        
        $added = $matrix1->add($matrix2);
        
        $this->assertEquals(5, $added->get(0, 0));
        $this->assertEquals(4, $added->get(0, 1));
        $this->assertEquals(9, $added->get(0, 2));
        $this->assertEquals(5, $added->get(1, 0));
        $this->assertEquals(12, $added->get(1, 1));
        $this->assertEquals(9, $added->get(1, 2));
{'fraction_non_alphanumeric': 0.1604288132405492, 'fraction_numerical': 0.03573443671243182, 'mean_word_length': 1.6107020127638685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3130060', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1597, 'n_words': 382}