<?php
namespace nur\data\types;

use nur\data\types\impl\Point;
use nur\t\TestCase;

class GenericTypeTest extends TestCase {
  static function assertPoint(?Point $a, ?Point $b) {
    if ($a === null) self::assertNull($b);
    if ($b === null) self::assertNull($a);
    if ($a !== null && $b !== null) {
      self::assertSame($a->x, $b->x);
      self::assertSame($a->y, $b->y);
    }
  }

  function testVerifix() {
    $type = new GenericType(Point::class);

    $value = null; $type->verifix($value);
    self::assertPoint(null, $value);
    $value = 1; $type->verifix($value);
    self::assertPoint(new Point(1, Point::Y), $value);
    $value = [1]; $type->verifix($value);
    self::assertPoint(new Point(1, Point::Y), $value);
    $value = [1, 2]; $type->verifix($value);
    self::assertPoint(new Point(1, 2), $value);
  }
}
