Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from mll-lab/wells-matchers
Browse files Browse the repository at this point in the history
Add methods `AbstractMicroplate::matchRow()` and `AbstractMicroplate::matchColumn()`
  • Loading branch information
simbig authored Jan 21, 2022
2 parents aaa6c4f + d253b9e commit 69f2dbf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v3.2.0

### Added

- Add methods `AbstractMicroplate::matchRow()` and `AbstractMicroplate::matchColumn()`

## v3.1.0

### Added
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"thecodingmachine/phpstan-safe-rule": "^1.1"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "7.4.24"
},
Expand Down
6 changes: 2 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/AbstractMicroplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,28 @@ public function filledWells(): Collection
static fn ($value): bool => self::EMPTY_WELL !== $value
);
}

/**
* @return callable(mixed $value, string $coordinateString): bool
*/
public function matchRow(string $row): callable
{
return function ($value, string $coordinateString) use ($row): bool {
$coordinate = Coordinate::fromString($coordinateString, $this->coordinateSystem);

return $coordinate->row === $row;
};
}

/**
* @return callable(mixed $value, string $coordinateString): bool
*/
public function matchColumn(int $column): callable
{
return function ($value, string $coordinateString) use ($column): bool {
$coordinate = Coordinate::fromString($coordinateString, $this->coordinateSystem);

return $coordinate->column === $column;
};
}
}
43 changes: 42 additions & 1 deletion tests/Unit/MicroplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class MicroplateTest extends Framework\TestCase
{
public function testCanAddAndRetriedWellBasedOnCoordinateSystem(): void
public function testCanAddAndRetrieveWellBasedOnCoordinateSystem(): void
{
$coordinateSystem = new CoordinateSystem96Well();

Expand All @@ -36,6 +36,47 @@ public function testCanAddAndRetriedWellBasedOnCoordinateSystem(): void
$microplate->addWell($coordinateWithOtherCoordinateSystem, 'foo');
}

public function testMatchRow(): void
{
$coordinateSystem = new CoordinateSystem96Well();

$microplate = new Microplate($coordinateSystem);

$content = 'foo';
$coordinate = new Coordinate('A', 1, $coordinateSystem);
$key = $coordinate->toString();
$microplate->addWell($coordinate, $content);

$microplate->addWell(new Coordinate('B', 1, $coordinateSystem), 'bar');

$wells = $microplate->wells();

$a = $wells->filter($microplate->matchRow('A'));
self::assertCount($coordinateSystem->columnsCount(), $a);
self::assertSame($content, $a[$key]);

$notA = $wells->reject($microplate->matchRow('A'));
self::assertCount($coordinateSystem->positionsCount() - $coordinateSystem->columnsCount(), $notA);

$noMatch = $microplate->filledWells()
->filter($microplate->matchRow('C'));
self::assertCount(0, $noMatch);
}

public function testMatchColumn(): void
{
$coordinateSystem = new CoordinateSystem96Well();

$microplate = new Microplate($coordinateSystem);

$coordinateColumn1 = (new Coordinate('A', 1, $coordinateSystem))->toString();
$coordinateColumn2 = (new Coordinate('A', 2, $coordinateSystem))->toString();

$matchColumn = $microplate->matchColumn(1);
self::assertTrue($matchColumn('foo', $coordinateColumn1));
self::assertFalse($matchColumn('foo', $coordinateColumn2));
}

public function testSortedWells(): void
{
$microplate = $this->preparePlate();
Expand Down

0 comments on commit 69f2dbf

Please sign in to comment.