/** * Test half * * @author Tom Haskins-Vaughan <*****@*****.**> * @since 0.1.0 */ public function testHalf() { $half = new Fraction(1, 2); $this->assertEquals('1/2', (string) $half); $this->assertSame(1, $half->getNumerator()); $this->assertSame(2, $half->getDenominator()); }
/** * isSameValueAs * * ValueObject comparison * * @author Christopher Tatro <*****@*****.**> * @since 1.1.0 * * @param Fraction $fraction * * @return bool */ public function isSameValueAs(Fraction $fraction) { if ($this->getNumerator() != $fraction->getNumerator()) { return false; } if ($this->getDenominator() != $fraction->getDenominator()) { return false; } return true; }
/** * Subtract a given fraction from this fraction * * @author Tom Haskins-Vaughan <*****@*****.**> * @since 0.1.0 * * @param Fraction $fraction * * @return Fraction */ public function subtract(Fraction $fraction) { $numerator = $this->getNumerator() * $fraction->getDenominator() - $fraction->getNumerator() * $this->getDenominator(); $denominator = $this->getDenominator() * $fraction->getDenominator(); return new static($numerator, $denominator); }