Skip to content

Commit

Permalink
Sync: Two Bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnorre committed Sep 24, 2024
1 parent 93f6ca2 commit 54d6fbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/two-bucket/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ There are some rules that your solution must follow:
b) the second bucket is full
2. Emptying a bucket and doing nothing to the other.
3. Filling a bucket and doing nothing to the other.
- After an action, you may not arrive at a state where the starting bucket is empty and the other bucket is full.
- After an action, you may not arrive at a state where the initial starting bucket is empty and the other bucket is full.

Your program will take as input:

Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/two-bucket/.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 TwoBucket
Expand Down
58 changes: 28 additions & 30 deletions exercises/practice/two-bucket/TwoBucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ public static function setUpBeforeClass(): void
require_once 'TwoBucket.php';
}

protected function setUp(): void
{
$this->twoBucket = new TwoBucket();
}

/**
* uuid: a6f2b4ba-065f-4dca-b6f0-e3eee51cb661
* @testdox Measure using bucket one of size 3 and bucket two of size 5 - start with bucket one
*/
public function testMeasureUsingBucketOneOfSize3AndBucketTwoOfSize5StartWithBucketOne(): void
{
$buckOne = 3;
$buckTwo = 5;
$goal = 1;
$starterBuck = 'one';
$solution = $this->twoBucket->solve($buckOne, $buckTwo, $goal, $starterBuck);

$subject = new TwoBucket();
$solution = $subject->solve($buckOne, $buckTwo, $goal, $starterBuck);

$this->assertEquals(4, $solution->numberOfActions);
$this->assertEquals('one', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -34,14 +32,16 @@ public function testMeasureUsingBucketOneOfSize3AndBucketTwoOfSize5StartWithBuck

/**
* uuid: 6c4ea451-9678-4926-b9b3-68364e066d40
* @testdox Measure using bucket one of size 3 and bucket two of size 5 - start with bucket two
*/
public function testMeasureUsingBucketOneOfSize3AndBucketTwoOfSize5StartWithBucketTwo(): void
{
$buckOne = 3;
$buckTwo = 5;
$goal = 1;
$starterBuck = 'two';
$solution = $this->twoBucket->solve($buckOne, $buckTwo, $goal, $starterBuck);
$subject = new TwoBucket();
$solution = $subject->solve($buckOne, $buckTwo, $goal, $starterBuck);

$this->assertEquals(8, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -50,14 +50,16 @@ public function testMeasureUsingBucketOneOfSize3AndBucketTwoOfSize5StartWithBuck

/**
* uuid: 3389f45e-6a56-46d5-9607-75aa930502ff
* @testdox Measure using bucket one of size 7 and bucket two of size 11 - start with bucket one
*/
public function testMeasureUsingBucketOneOfSize7AndBucketTwoOfSize11StartWithBucketOne(): void
{
$buckOne = 7;
$buckTwo = 11;
$goal = 2;
$starterBuck = 'one';
$solution = $this->twoBucket->solve($buckOne, $buckTwo, $goal, $starterBuck);
$subject = new TwoBucket();
$solution = $subject->solve($buckOne, $buckTwo, $goal, $starterBuck);

$this->assertEquals(14, $solution->numberOfActions);
$this->assertEquals('one', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -66,14 +68,16 @@ public function testMeasureUsingBucketOneOfSize7AndBucketTwoOfSize11StartWithBuc

/**
* uuid: fe0ff9a0-3ea5-4bf7-b17d-6d4243961aa1
* @testdox Measure using bucket one of size 7 and bucket two of size 11 - start with bucket two
*/
public function testMeasureUsingBucketOneOfSize7AndBucketTwoOfSize11StartWithBucketTwo(): void
{
$buckOne = 7;
$buckTwo = 11;
$goal = 2;
$starterBuck = 'two';
$solution = $this->twoBucket->solve($buckOne, $buckTwo, $goal, $starterBuck);
$subject = new TwoBucket();
$solution = $subject->solve($buckOne, $buckTwo, $goal, $starterBuck);

$this->assertEquals(18, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -82,10 +86,12 @@ public function testMeasureUsingBucketOneOfSize7AndBucketTwoOfSize11StartWithBuc

/**
* uuid: 0ee1f57e-da84-44f7-ac91-38b878691602
* @testdox Measure one step using bucket one of size 1 and bucket two of size 3 - start with bucket two
*/
public function testMeasureOneStepUsingBucketOneOfSize1AndBucketTwoOfSize3StartWithBucketTwo(): void
{
$solution = $this->twoBucket->solve(1, 3, 3, 'two');
$subject = new TwoBucket();
$solution = $subject->solve(1, 3, 3, 'two');

$this->assertEquals(1, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -94,10 +100,12 @@ public function testMeasureOneStepUsingBucketOneOfSize1AndBucketTwoOfSize3StartW

/**
* uuid: eb329c63-5540-4735-b30b-97f7f4df0f84
* @testdox Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two
*/
public function testMeasureUsingBucketOneOfSize2AndBucketTwoOfSize3StartWithBucketOneAndEndWithBucketTwo(): void
{
$solution = $this->twoBucket->solve(2, 3, 3, 'one');
$subject = new TwoBucket();
$solution = $subject->solve(2, 3, 3, 'one');

$this->assertEquals(2, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -106,38 +114,26 @@ public function testMeasureUsingBucketOneOfSize2AndBucketTwoOfSize3StartWithBuck

/**
* uuid: 449be72d-b10a-4f4b-a959-ca741e333b72
* @testdox Not possible to reach the goal
*/
public function testReachabilityNotPossibleToReachGoalStartWithBucketOne(): void
{
$buckOne = 6;
$buckTwo = 15;
$this->expectException(Exception::class);

$this->twoBucket->solve($buckOne, $buckTwo, 5, 'one');
$subject = new TwoBucket();
$subject->solve($buckOne, $buckTwo, 5, 'one');
}

/**
* uuid: aac38b7a-77f4-4d62-9b91-8846d533b054
* @testdox With the same buckets but a different goal, then it is possible
*/
public function testReachabilityNotPossibleToReachGoalStartWithBucketOneAndEndWithBucketTwo(): void
{
$solution = $this->twoBucket->solve(6, 15, 9, 'one');

$this->assertEquals(10, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
$this->assertEquals(0, $solution->litersLeftInOtherBucket);
}

/**
* uuid: aac38b7a-77f4-4d62-9b91-8846d533b054
*/
public function testWithSameBucketsButDifferentGoalItIsPossible(): void
{
$buckOne = 6;
$buckTwo = 15;
$goal = 9;
$starterBuck = 'one';
$solution = $this->twoBucket->solve($buckOne, $buckTwo, $goal, $starterBuck);
$subject = new TwoBucket();
$solution = $subject->solve(6, 15, 9, 'one');

$this->assertEquals(10, $solution->numberOfActions);
$this->assertEquals('two', $solution->nameOfBucketWithDesiredLiters);
Expand All @@ -146,10 +142,12 @@ public function testWithSameBucketsButDifferentGoalItIsPossible(): void

/**
* uuid: 74633132-0ccf-49de-8450-af4ab2e3b299
* @testdox Goal larger than both buckets is impossible
*/
public function testGoalLargerThanBothBucketsIsImpossible(): void
{
$this->expectException(Exception::class);
$this->twoBucket->solve(5, 7, 8, 'one');
$subject = new TwoBucket();
$subject->solve(5, 7, 8, 'one');
}
}

0 comments on commit 54d6fbe

Please sign in to comment.