DivideTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonInterval;
  12. use Carbon\CarbonInterval;
  13. use Tests\AbstractTestCase;
  14. class DivideTest extends AbstractTestCase
  15. {
  16. public function testDivideSimple()
  17. {
  18. $ci = CarbonInterval::hours(3)->minutes(43)->divide(0.25);
  19. $this->assertCarbonInterval($ci, 0, 0, 0, 14, 52, 00);
  20. }
  21. public function testDivideMoreThanOne()
  22. {
  23. $ci = CarbonInterval::create(4, 3, 2, 5, 5, 10, 11)->divide(1 / 2.75);
  24. $this->assertCarbonInterval($ci, 11, 10, 3, 20, 13, 0);
  25. }
  26. public function testDivideOne()
  27. {
  28. $ci = CarbonInterval::create(4, 3, 2, 5, 5, 10, 11)->divide(1);
  29. $this->assertCarbonInterval($ci, 4, 3, 19, 5, 10, 11);
  30. }
  31. public function testDivideLessThanOne()
  32. {
  33. $ci = CarbonInterval::create(4, 3, 2, 5, 5, 10, 11)->divide(3);
  34. $this->assertCarbonInterval($ci, 1, 5, 6, 9, 43, 23);
  35. }
  36. public function testDivideLessThanZero()
  37. {
  38. $ci = CarbonInterval::create(4, 3, 2, 5, 5, 10, 11)->divide(-1);
  39. $this->assertCarbonInterval($ci, 4, 3, 19, 5, 10, 11);
  40. $this->assertSame(1, $ci->invert);
  41. }
  42. public function testDivideLessThanZeroWithInvertedInterval()
  43. {
  44. $ci = CarbonInterval::create(4, 3, 2, 5, 5, 10, 11);
  45. $ci->invert = 1;
  46. $ci->divide(-1);
  47. $this->assertCarbonInterval($ci, 4, 3, 19, 5, 10, 11);
  48. $this->assertSame(0, $ci->invert);
  49. }
  50. }