Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/auto-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ list-ops
luhn
markdown
matching-brackets
matrix
meetup
micro-blog
nucleotide-count
Expand Down
9 changes: 3 additions & 6 deletions exercises/practice/matrix/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Instructions

Given a string representing a matrix of numbers, return the rows and columns of
that matrix.
Given a string representing a matrix of numbers, return the rows and columns of that matrix.

So given a string with embedded newlines like:

Expand All @@ -23,10 +22,8 @@ representing this matrix:

your code should be able to spit out:

- A list of the rows, reading each row left-to-right while moving
top-to-bottom across the rows,
- A list of the columns, reading each column top-to-bottom while moving
from left-to-right.
- A list of the rows, reading each row left-to-right while moving top-to-bottom across the rows,
- A list of the columns, reading each column top-to-bottom while moving from left-to-right.

The rows for our example matrix:

Expand Down
7 changes: 5 additions & 2 deletions exercises/practice/matrix/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"authors": [
"MichaelBunker"
"MichaelBunker",
"Narkunan"
],
"files": {
"solution": [
Expand All @@ -13,5 +14,7 @@
".meta/example.php"
]
},
"blurb": "Given a string representing a matrix of numbers, return the rows and columns of that matrix."
"blurb": "Given a string representing a matrix of numbers, return the rows and columns of that matrix.",
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
"source_url": "https://www.turing.edu/"
}
22 changes: 0 additions & 22 deletions exercises/practice/matrix/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class Matrix
Expand Down
34 changes: 34 additions & 0 deletions exercises/practice/matrix/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[ca733dab-9d85-4065-9ef6-a880a951dafd]
description = "extract row from one number matrix"

[5c93ec93-80e1-4268-9fc2-63bc7d23385c]
description = "can extract row"

[2f1aad89-ad0f-4bd2-9919-99a8bff0305a]
description = "extract row where numbers have different widths"

[68f7f6ba-57e2-4e87-82d0-ad09889b5204]
description = "can extract row from non-square matrix with no corresponding column"

[e8c74391-c93b-4aed-8bfe-f3c9beb89ebb]
description = "extract column from one number matrix"

[7136bdbd-b3dc-48c4-a10c-8230976d3727]
description = "can extract column"

[ad64f8d7-bba6-4182-8adf-0c14de3d0eca]
description = "can extract column from non-square matrix with no corresponding row"

[9eddfa5c-8474-440e-ae0a-f018c2a0dd89]
description = "extract column where numbers have different widths"
22 changes: 0 additions & 22 deletions exercises/practice/matrix/Matrix.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class Matrix
Expand Down
43 changes: 19 additions & 24 deletions exercises/practice/matrix/MatrixTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

class MatrixTest extends TestCase
Expand All @@ -33,59 +12,75 @@ public static function setUpBeforeClass(): void
require_once 'Matrix.php';
}

/** uuid: ca733dab-9d85-4065-9ef6-a880a951dafd */
#[TestDox('extract row from one number matrix')]
public function testExtractRowFromOneNumberMatrix(): void
{
$matrix = new Matrix("1");

$this->assertEquals([1], $matrix->getRow(1));
}

/** uuid: 5c93ec93-80e1-4268-9fc2-63bc7d23385c */
#[TestDox('can extract row')]
public function testExtractRow(): void
{
$matrix = new Matrix("1 2\n3 4");

$this->assertEquals([3, 4], $matrix->getRow(2));
}

/** uuid: 2f1aad89-ad0f-4bd2-9919-99a8bff0305a */
#[TestDox('extract row where numbers have different widths')]
public function testExtractRowWhereNumbersHaveDifferentWidths(): void
{
$matrix = new Matrix("1, 2\n10 20");

$this->assertEquals([10, 20], $matrix->getRow(2));
}

/** uuid: 68f7f6ba-57e2-4e87-82d0-ad09889b5204 */
#[TestDox('can extract row from non-square matrix with no corresponding column')]
public function testExtractRowFromNonSquareMatrixWithNoMatchingColumn(): void
{
$matrix = new Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6");

$this->assertEquals([8, 7, 6], $matrix->getRow(4));
}

/** uuid: e8c74391-c93b-4aed-8bfe-f3c9beb89ebb */
#[TestDox('extract column from one number matrix')]
public function testExtractColumnFromOneNumberMatrix(): void
{
$matrix = new Matrix("1");

$this->assertEquals([1], $matrix->getColumn(1));
}

/** uuid: 7136bdbd-b3dc-48c4-a10c-8230976d3727 */
#[TestDox('can extract column')]
public function testExtractColumn(): void
{
$matrix = new Matrix("1 2 3\n4 5 6\n7 8 9");

$this->assertEquals([3, 6, 9], $matrix->getColumn(3));
}

/** uuid: ad64f8d7-bba6-4182-8adf-0c14de3d0eca */
#[TestDox('can extract column from non-square matrix with no corresponding row')]
public function testExtractColumnFromNonSquareMatrixWithNoMatchRow(): void
{
$matrix = new Matrix("1 2 3 4\n5 6 7 8\n9 8 7 6");

$this->assertEquals([4, 8, 6], $matrix->getColumn(4));
}

/** uuid: 9eddfa5c-8474-440e-ae0a-f018c2a0dd89 */
#[TestDox('extract column where numbers have different widths')]
public function testExtractColumnWhenNumbersHaveDifferentWidths(): void
{
$matrix = new Matrix("89 1903 3\n18 3 1\n9 41 800");
$matrix = new Matrix("89 1903 3\n18 3 1\n9 4 800");

$this->assertEquals([1903, 3, 41], $matrix->getColumn(2));
$this->assertEquals([1903, 3, 4], $matrix->getColumn(2));
}
}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
<exclude-pattern>*/.meta/*\.php</exclude-pattern>
<exclude-pattern>src/*</exclude-pattern>
<exclude-pattern>contribution/*.php</exclude-pattern>
<exclude-pattern>*/matrix/*</exclude-pattern>
</rule>
</ruleset>
Loading