<?php
namespace nur\b\date;

use nur\t\TestCase;

class DelayTest extends TestCase {
  function testGet() {
    self::assertSame(0, (new Delay(0))->getu());
    self::assertSame(-1, (new Delay(-1))->getu());
    self::assertSame(1, (new Delay(1))->getu());
    self::assertSame(120, (new Delay(120))->getu());
    self::assertSame(86400, (new Delay(86400))->getu());
    self::assertSame(-86400, (new Delay(-86400))->getu());
  }

  function testAdd() {
    $t1 = new Delay(0);
    $t2 = $t1->addu(0); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(10); self::assertNotSame($t2, $t1); self::assertSame(10, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(10); self::assertNotSame($t2, $t1); self::assertSame(20, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(100); self::assertNotSame($t2, $t1); self::assertSame(120, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(86280); self::assertNotSame($t2, $t1); self::assertSame(86400, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(86400); self::assertNotSame($t2, $t1); self::assertSame(172800, $t2->getu()); $t1 = $t2;
    $t2 = $t1->addu(-86400); self::assertNotSame($t2, $t1); self::assertSame(86400, $t2->getu()); $t1 = $t2;
  }

  function testSub() {
    $t1 = new Delay(0);
    $t2 = $t1->subu(-86400); self::assertNotSame($t2, $t1); self::assertSame(86400, $t2->getu()); $t1 = $t2;
    $t2 = $t1->subu(86400); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
    $t1 = new Time(120);
    $t2 = $t1->subu(100); self::assertNotSame($t2, $t1); self::assertSame(20, $t2->getu()); $t1 = $t2;
    $t2 = $t1->subu(10); self::assertNotSame($t2, $t1); self::assertSame(10, $t2->getu()); $t1 = $t2;
    $t2 = $t1->subu(10); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
    $t2 = $t1->subu(0); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
  }

  function test__toString() {
    self::assertSame("0:00:00", strval(new Delay(0)));
    self::assertSame("0:00:56", strval(new Delay(56)));
    self::assertSame("0:02:00", strval(new Delay(120)));
    self::assertSame("23:59:59", strval(new Delay(86399)));
    self::assertSame("24:00:00", strval(new Delay(86400)));
    self::assertSame("48:00:00", strval(new Delay(172800)));
    self::assertSame("-48:00:00", strval(new Delay(-172800)));
    self::assertSame("-24:00:00", strval(new Delay(-86400)));
    self::assertSame("-0:02:00", strval(new Delay(-120)));
  }
}
