Skip to content

Commit

Permalink
Add Calculator::compare()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Nov 11, 2024
1 parent 1eabfca commit d819a4d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public static function make(int|string|DateTimeInterface $date): ZodiacInterface
return (new self())->zodiac($date);
}

/**
* {@inheritdoc}
*
* @see CalculatorInterface::compare()
*/
public static function compare(ZodiacInterface $zodiac1, ZodiacInterface $zodiac2): float
{
return $zodiac1->compatibility($zodiac2);
}

/**
* Normalze given date to Carbon object
*
Expand Down
9 changes: 9 additions & 0 deletions src/Interfaces/CalculatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ interface CalculatorInterface
* @return ZodiacInterface
*/
public static function zodiac(int|string|DateTimeInterface $date): ZodiacInterface;

/**
* Calculate zodiac sign compatibility between given objects
*
* @param ZodiacInterface $zodiac1
* @param ZodiacInterface $zodiac2
* @return float
*/
public static function compare(ZodiacInterface $zodiac1, ZodiacInterface $zodiac2): float;
}
12 changes: 12 additions & 0 deletions tests/CalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,16 @@ public static function invalidZodiacDataProvider(): Generator
'',
];
}

public function testCompare(): void
{
$calculator = new Calculator();
$result = $calculator->compare(new Aries(), new Leo());
$this->assertIsFloat($result);
$this->assertTrue($result >= 0 && $result <= 1);

$result = Calculator::compare(new Aries(), new Leo());
$this->assertIsFloat($result);
$this->assertTrue($result >= 0 && $result <= 1);
}
}

0 comments on commit d819a4d

Please sign in to comment.