aoc/tests/Lubiana/Aoc/Y2023/D04/NumberTest.php

67 lines
1.6 KiB
PHP
Raw Normal View History

2023-12-10 11:49:11 +00:00
<?php
namespace Lubiana\Aoc\Y2023\D04;
use PHPUnit\Framework\TestCase;
/**
* Class NumberTest
*
* This class tests the fromString method in the Number class.
* The fromString method is expected to take a string input and return an array of Number
* instances where each Number instance can be created from a numeric string found within the input.
*
* @package Lubiana\Aoc\Y2023\D04
*/
class NumberTest extends TestCase
{
/**
* Test for valid input
*/
public function testFromStringValidInput(): void
{
$input = "1 2 3";
$expectedResult = [new Number(1), new Number(2), new Number(3)];
$actualResult = Number::fromString($input);
$this->assertEquals($expectedResult, $actualResult);
}
/**
* Test for input with non-numeric values
*/
public function testFromStringWithNonNumericValues(): void
{
$input = "1 A 2 3";
$expectedResult = [new Number(1), new Number(2), new Number(3)];
$actualResult = Number::fromString($input);
$this->assertEquals($expectedResult, $actualResult);
}
/**
* Test for empty input
*/
public function testFromStringEmptyInput(): void
{
$input = "";
$expectedResult = [];
$actualResult = Number::fromString($input);
$this->assertEquals($expectedResult, $actualResult);
}
public function testFromStringWithExtraSpaces(): void
{
$input = "11 2 33";
$expectedResult = [new Number(11), new Number(2), new Number(33)];
$actualResult = Number::fromString($input);
$this->assertEquals($expectedResult, $actualResult);
}
}