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

Commit

Permalink
feat: Add isConsecutive() method to AbstractMicroplate
Browse files Browse the repository at this point in the history
  • Loading branch information
simbig authored May 26, 2023
1 parent 445eb04 commit f3b2550
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v5.2.0

### Added

- Add `isConsecutive()` method to `AbstractMicroplate`

## v5.1.0

### Changed
Expand Down
18 changes: 18 additions & 0 deletions src/AbstractMicroplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ public function toWellWithCoordinateMapper(): callable
Coordinate::fromString($coordinateString, $this->coordinateSystem)
);
}

/**
* Are all filled wells placed in a single connected block without gaps between them?
*
* Returns `false` if all wells are empty.
*/
public function isConsecutive(FlowDirection $flowDirection): bool
{
$positions = $this->filledWells()
/**
* @param TWell $content
*/
->map(
fn ($content, string $coordinateString): int => Coordinate::fromString($coordinateString, $this->coordinateSystem)->position($flowDirection)
);

return ($positions->max() - $positions->min() + 1) === $positions->count();
}
}
64 changes: 64 additions & 0 deletions tests/Unit/MicroplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,70 @@ public function testThrowsPlateFullException(): void
$microplate->nextFreeWellCoordinate(FlowDirection::ROW());
}

public function testIsConsecutiveForColumn(): void
{
$coordinateSystem = new CoordinateSystem96Well();
$microplate = new Microplate($coordinateSystem);

$data = [
'A1', 'B1', 'C1',
];
foreach ($data as $wellData) {
$microplateCoordinate = Coordinate::fromString($wellData, $coordinateSystem);
$microplate->addWell($microplateCoordinate, 'test');
}

self::assertTrue($microplate->isConsecutive(FlowDirection::COLUMN()));
self::assertFalse($microplate->isConsecutive(FlowDirection::ROW()));

// is not consecutive anymore after adding a gap at E1
$microplate->addWell(Coordinate::fromString('E1', $coordinateSystem), 'test');
self::assertFalse($microplate->isConsecutive(FlowDirection::COLUMN()));
}

public function testIsConsecutiveForRow(): void
{
$coordinateSystem = new CoordinateSystem96Well();
$microplate = new Microplate($coordinateSystem);

$data = [
'A1', 'A2', 'A3',
];
foreach ($data as $wellData) {
$microplateCoordinate = Coordinate::fromString($wellData, $coordinateSystem);
$microplate->addWell($microplateCoordinate, 'test');
}

self::assertTrue($microplate->isConsecutive(FlowDirection::ROW()));
self::assertFalse($microplate->isConsecutive(FlowDirection::COLUMN()));

// is not consecutive anymore after adding a gap at A5
$microplate->addWell(Coordinate::fromString('A5', $coordinateSystem), 'test');
self::assertFalse($microplate->isConsecutive(FlowDirection::ROW()));
}

public function testIsConsecutiveForEmptyPlate(): void
{
$coordinateSystem = new CoordinateSystem96Well();
$microplate = new Microplate($coordinateSystem);

self::assertFalse($microplate->isConsecutive(FlowDirection::ROW()));
self::assertFalse($microplate->isConsecutive(FlowDirection::COLUMN()));
}

public function testIsConsecutiveForFullPlate(): void
{
$coordinateSystem = new CoordinateSystem96Well();
$microplate = new Microplate($coordinateSystem);

foreach ($coordinateSystem->all() as $coordinate) {
$microplate->addWell($coordinate, 'test');
}

self::assertTrue($microplate->isConsecutive(FlowDirection::ROW()));
self::assertTrue($microplate->isConsecutive(FlowDirection::COLUMN()));
}

/**
* @return list<array{row: string, column: int, rowFlowPosition: int, columnFlowPosition: int}>
*/
Expand Down

0 comments on commit f3b2550

Please sign in to comment.