diff --git a/tests/src/Enum/Enum.phpt b/tests/src/Enum/Enum.phpt index 9409d419..9e2ee987 100644 --- a/tests/src/Enum/Enum.phpt +++ b/tests/src/Enum/Enum.phpt @@ -65,17 +65,21 @@ $abcTwo = ABC::get(2); $abdOne = ABD::get(1); $fOne = E::get(1); -// get() + +get: Assert::type($aOne, A::class); Assert::equal($aOne, $aOne2); -// getValue() + +getValue: Assert::same($aOne->getValue(), 1); -// getConstantName() + +getConstantName: Assert::same($aOne->getConstantName(), 'ONE'); -// equals() + +equals: Assert::exception(static function () use ($aOne, $fOne): void { $aOne->equals($fOne); }, InvalidTypeException::class); @@ -87,15 +91,18 @@ Assert::true($abOne->equals($abcOne)); Assert::true($abOne->equals($abdOne)); Assert::true($abcOne->equals($abdOne)); -// equalsValue() + +equalsValue: Assert::false($aOne->equalsValue(2)); Assert::true($aOne->equalsValue(1)); -// isValid() + +isValid: Assert::false(A::isValid(5)); Assert::true(A::isValid(1)); -// getAllowedValues() + +getAllowedValues: Assert::same(A::getAllowedValues(), [ 'ONE' => 1, 'TWO' => 2, @@ -119,7 +126,8 @@ Assert::same(ABD::getAllowedValues(), [ 'TWO' => 2, ]); -// getInstances() + +getInstances: Assert::equal(A::getInstances(), [ 'ONE' => $aOne, 'TWO' => $aTwo, diff --git a/tests/src/Enum/Set.phpt b/tests/src/Enum/Set.phpt index 915c3c2c..4a696028 100644 --- a/tests/src/Enum/Set.phpt +++ b/tests/src/Enum/Set.phpt @@ -78,23 +78,28 @@ $jklOneTwo = JKL::get(1, 2); $jkmOneTwo = JKM::get(1, 2); $nOneTwo = N::get(1, 2); -// get() + +get: Assert::type($jOne, J::class); Assert::equal($jOne, $jOne2); -// getValue() + +getValue: Assert::same($jOne->getValue(), 1); Assert::same($jOneTwo->getValue(), 3); -// getValues() + +getValues: Assert::same($jOne->getValues(), [1]); Assert::same($jOneTwo->getValues(), [1, 2]); -// getConstantNames() + +getConstantNames: Assert::same($jOne->getConstantNames(), [1 => 'ONE']); Assert::same($jOneTwo->getConstantNames(), [1 => 'ONE', 2 => 'TWO']); -// equals() + +equals: Assert::exception(static function () use ($jOne, $nOne): void { $jOne->equals($nOne); }, InvalidTypeException::class); @@ -117,17 +122,20 @@ Assert::true($jkOneTwo->equals($jklOneTwo)); Assert::true($jkOneTwo->equals($jkmOneTwo)); Assert::true($jklOneTwo->equals($jkmOneTwo)); -// equalsValue() + +equalsValue: Assert::false($jOne->equalsValue(2)); Assert::true($jOne->equalsValue(1)); Assert::false($jOneTwo->equalsValue(6)); Assert::true($jOneTwo->equalsValue(3)); -// isValid() + +isValid: Assert::false(J::isValid(5)); Assert::true(J::isValid(1)); -// getAllowedValues() + +getAllowedValues: Assert::same(J::getAllowedValues(), [ 'ONE' => 1, 'TWO' => 2, @@ -151,7 +159,8 @@ Assert::same(JKM::getAllowedValues(), [ 'TWO' => 2, ]); -// getInstances() + +getInstances: Assert::equal(J::getInstances(), [ 'ONE' => $jOne, 'TWO' => $jTwo, @@ -164,69 +173,82 @@ Assert::equal(JKL::getInstances(), [ 'TWO' => $jklTwo, ]); -// invert() + +invert: Assert::equal($jTwoFour->invert(), $jOneEight); Assert::equal($jEmpty->invert(), $jAll); Assert::equal($jAll->invert(), $jEmpty); -// contains() + +contains: Assert::false($jOneTwo->contains($jTwoFour)); Assert::true($jOneTwo->contains($jOneTwo2)); Assert::true($jOneTwo->contains($jOne)); Assert::true($jOneTwo->contains($jEmpty)); -// intersects() + +intersects: Assert::false($jOne->intersects($jTwo)); Assert::false($jOne->intersects($jEmpty)); Assert::true($jOneTwo->intersects($jTwoFour)); -// intersect() + +intersect: Assert::equal($jOneTwo->intersect($jTwoFour), $jTwo); Assert::equal($jOneTwo->intersect($jEmpty), $jEmpty); -// union() + +union: Assert::equal($jEmpty->union($jOne), $jOne); Assert::equal($jOne->union($jTwo), $jOneTwo); Assert::equal($jOneTwo->union($jTwoFour), $jOneTwoFour); -// subtract() + +subtract: Assert::equal($jOneTwo->subtract($jOne), $jTwo); Assert::equal($jOneTwo->subtract($jEmpty), $jOneTwo); Assert::equal($jEmpty->subtract($jOne), $jEmpty); Assert::equal($jOneTwo->subtract($jEmpty), $jOneTwo); -// difference() + +difference: Assert::equal($jOneTwo->difference($jTwoFour), $jOneFour); Assert::equal($jEmpty->difference($jEmpty), $jEmpty); Assert::equal($jEmpty->difference($jAll), $jAll); Assert::equal($jAll->difference($jAll), $jEmpty); Assert::equal($jAll->difference($jEmpty), $jAll); -// containsAll() + +containsAll: Assert::false($jOneTwo->containsAll(2, 4)); Assert::true($jOneTwo->containsAll(1, 2)); Assert::true($jAll->containsAll(1, 2, 4, 8)); -// containsAny() + +containsAny: Assert::false($jOneTwo->containsAny(4, 8)); Assert::true($jOneTwo->containsAny(2, 4)); Assert::false($jEmpty->containsAny(1, 2, 4, 8)); -// filter() + +filter: Assert::equal($jOneTwo->filter(1, 4), $jOne); Assert::equal($jAll->filter(1, 2), $jOneTwo); Assert::equal($jAll->filter(), $jEmpty); Assert::equal($jEmpty->filter(1, 2), $jEmpty); -// add() + +add: Assert::equal($jOneTwo->add(2, 4), $jOneTwoFour); Assert::equal($jOneTwo->add(4, 8), $jAll); -// remove() + +remove: Assert::equal($jAll->remove(4, 8), $jOneTwo); Assert::equal($jOneTwo->remove(2, 4), $jOne); -// xor() + +_xor: Assert::equal($jOneTwo->xor(2, 4), $jOneFour); Assert::equal($jEmpty->xor(), $jEmpty); Assert::equal($jEmpty->xor(1, 2, 4, 8), $jAll); diff --git a/tests/src/Geolocation/PositionFormatter.phpt b/tests/src/Geolocation/PositionFormatter.phpt index bda991a6..c3f3cab6 100644 --- a/tests/src/Geolocation/PositionFormatter.phpt +++ b/tests/src/Geolocation/PositionFormatter.phpt @@ -11,6 +11,7 @@ require_once __DIR__ . '/../bootstrap.php'; $position = new Position(-15, -50); $positionFormatter = new PositionFormatter(); + Assert::same($positionFormatter->format($position, 'l'), '15'); Assert::same($positionFormatter->format($position, 'L'), '-15'); Assert::same($positionFormatter->format($position, 'n'), 'S'); diff --git a/tests/src/Language/Locale/Locale.phpt b/tests/src/Language/Locale/Locale.phpt index 712bd194..16feed65 100644 --- a/tests/src/Language/Locale/Locale.phpt +++ b/tests/src/Language/Locale/Locale.phpt @@ -28,11 +28,13 @@ if (PHP_VERSION_ID > 70011) { $localeString = 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@currency=CZK;numbers=arab;calendar=iso8601;collation=phonebook;colbackwards=yes;colcasefirst=lower'; $localeStringCanonicalized = 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@calendar=iso8601;colbackwards=yes;colcasefirst=lower;collation=phonebook;currency=CZK;numbers=arab'; -// get() + +get: $locale = Locale::get($localeString); $simple = Locale::get('cs'); -// create() + +create: $created = Locale::create( Language::get(Language::CZECH), Country::get(Country::CZECHIA), @@ -50,65 +52,80 @@ $created = Locale::create( ); Assert::same($created, $locale); -// removeCollation() + +removeCollation: $safeLocale = $locale->removeCollation(); Assert::type($safeLocale, Locale::class); Assert::same($safeLocale->getValue(), 'cs_Latn_CZ_VAR1_VAR2_X_PRI1_PRI2@calendar=iso8601;currency=CZK;numbers=arab'); -// getDefault() + +getDefault: Assert::type(Locale::getDefault(), Locale::class); -// getCollator() + +getCollator: $collator = $locale->getCollator(); Assert::type($collator, Collator::class); Assert::same($collator->getLocaleObject()->getValue(), 'cs'); -// matches() + +matches: Assert::true($locale->matches($simple)); -// findBestMatch() + +findBestMatch: Assert::same($locale->findBestMatch(['cs', 'cs_Latn_CZ', 'cs_CZ', 'en'])->getValue(), 'cs_Latn_CZ'); -// getValue() + +getValue: Assert::same($locale->getValue(), $localeStringCanonicalized); Assert::same($simple->getValue(), 'cs'); -// getLanguage() + +getLanguage: Assert::same($locale->getLanguage(), Language::get(Language::CZECH)); Assert::same($simple->getLanguage(), Language::get(Language::CZECH)); -// getScript() + +getScript: Assert::same($locale->getScript(), Script::get(Script::LATIN)); Assert::null($simple->getScript()); -// getCountry() + +getCountry: Assert::same($locale->getCountry(), Country::get(Country::CZECHIA)); Assert::null($simple->getCountry()); -// getVariants() + +getVariants: Assert::same($locale->getVariants(), ['VAR1', 'VAR2']); Assert::same($simple->getVariants(), []); -// getVariant() + +getVariant: Assert::same($locale->getVariant(0), 'VAR1'); Assert::same($locale->getVariant(1), 'VAR2'); Assert::null($simple->getVariant(0)); -// hasVariant() + +hasVariant: Assert::true($locale->hasVariant('VAR1')); Assert::true($locale->hasVariant('VAR2')); Assert::false($locale->hasVariant('VAR3')); -// getPrivates() + +getPrivates: Assert::same($locale->getPrivates(), ['PRI1', 'PRI2']); Assert::same($simple->getPrivates(), []); -// getPrivate() + +getPrivate: Assert::same($locale->getPrivate(0), 'PRI1'); Assert::same($locale->getPrivate(1), 'PRI2'); Assert::null($simple->getPrivate(0)); -// getKeywords() + +getKeywords: Assert::same($locale->getKeywords(), [ LocaleKeyword::CALENDAR => LocaleCalendar::ISO8601, LocaleKeyword::COL_BACKWARDS => LocaleColBackwards::YES, @@ -119,7 +136,8 @@ Assert::same($locale->getKeywords(), [ ]); Assert::same($simple->getKeywords(), []); -// getKeyword() + +getKeyword: Assert::same($locale->getKeyword(LocaleKeyword::CURRENCY), Currency::CZECH_KORUNA); Assert::same($locale->getKeyword(LocaleKeyword::NUMBERS), LocaleNumbers::ARABIC_INDIC); Assert::same($locale->getKeyword(LocaleKeyword::CALENDAR), LocaleCalendar::ISO8601); @@ -128,23 +146,28 @@ Assert::same($locale->getKeyword(LocaleKeyword::COL_BACKWARDS), LocaleColBackwar Assert::same($locale->getKeyword(LocaleKeyword::COL_CASE_FIRST), LocaleColCaseFirst::LOWER); Assert::null($locale->getKeyword('foo')); -// getCurrency() + +getCurrency: Assert::same($locale->getCurrency(), Currency::get(Currency::CZECH_KORUNA)); Assert::null($simple->getCurrency()); -// getNumbers() + +getNumbers: Assert::same($locale->getNumbers(), LocaleNumbers::get(LocaleNumbers::ARABIC_INDIC)); Assert::null($simple->getNumbers()); -// getCalendar() + +getCalendar: Assert::same($locale->getCalendar(), LocaleCalendar::get(LocaleCalendar::ISO8601)); Assert::null($simple->getCalendar()); -// getCollation() + +getCollation: Assert::same($locale->getCollation(), LocaleCollation::get(LocaleCollation::PHONEBOOK)); Assert::null($simple->getCollation()); -// getCollationOptions() + +getCollationOptions: Assert::same($locale->getCollationOptions(), [ LocaleKeyword::COL_BACKWARDS => LocaleColBackwards::get(LocaleColBackwards::YES), LocaleKeyword::COL_CASE_FIRST => LocaleColCaseFirst::get(LocaleColCaseFirst::LOWER), diff --git a/tests/src/Mapping/Type/ArrayHandler.phpt b/tests/src/Mapping/Type/ArrayHandler.phpt index b4d18ed3..e946456d 100644 --- a/tests/src/Mapping/Type/ArrayHandler.phpt +++ b/tests/src/Mapping/Type/ArrayHandler.phpt @@ -24,23 +24,27 @@ $mapper = new Mapper(new DynamicMappingContainer(new ConventionMappingBuilder( $arrayType = Type::get(Type::PHP_ARRAY); $intArrayType = Type::arrayOf(Type::INT); -// acceptType() + +acceptType: Assert::true($handler->acceptsType($arrayType)); Assert::true($handler->acceptsType($intArrayType)); Assert::false($handler->acceptsType(Type::get(SplFixedArray::class))); -// getParameters() + +getParameters: Assert::same($handler->getParameters($arrayType), null); // intentionally does not return item type. items type must be mapped by ArrayHandler, since MappingBuilder // can only handle non-iterable structures Assert::same($handler->getParameters($intArrayType), null); -// createInstance() + +createInstance: $arrayInstance = $handler->createInstance($arrayType, ['1', '2'], $mapper); Assert::same($arrayInstance, ['1', '2']); $intArrayInstance = $handler->createInstance($intArrayType, ['1', '2'], $mapper); Assert::same($intArrayInstance, [1, 2]); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($intArrayType, $intArrayInstance, $mapper), [1, 2]); // expected (viz ScalarsHandler) Assert::same($handler->exportInstance($arrayType, $arrayInstance, $mapper), ['1', '2']); diff --git a/tests/src/Mapping/Type/DefaultOneWayHandler.phpt b/tests/src/Mapping/Type/DefaultOneWayHandler.phpt index d314c068..6da82aa8 100644 --- a/tests/src/Mapping/Type/DefaultOneWayHandler.phpt +++ b/tests/src/Mapping/Type/DefaultOneWayHandler.phpt @@ -21,11 +21,13 @@ $mapper = new Mapper(new StaticMappingContainer([])); $dateTimeType = Type::get(DateTime::class); -// acceptType() + +acceptType: Assert::true($handler->acceptsType($dateTimeType)); Assert::true($handler->acceptsType(Type::get('Any'))); -// getParameters() + +getParameters: if (PHP_VERSION_ID < 80000) { Assert::equal($handler->getParameters($dateTimeType), [ 'time' => Type::get(Type::MIXED), @@ -38,7 +40,8 @@ if (PHP_VERSION_ID < 80000) { ]); } -// createInstance() + +createInstance: if (PHP_VERSION_ID < 80000) { $dateInstance = $handler->createInstance($dateTimeType, [ 'time' => '2001-02-03 04:05:06', @@ -53,7 +56,8 @@ if (PHP_VERSION_ID < 80000) { Assert::type($dateInstance, DateTime::class); Assert::same($dateInstance->format('Y-m-d H:i:s'), '2001-02-03 04:05:06'); -// exportInstance() + +exportInstance: Assert::throws(static function () use ($handler, $mapper, $dateTimeType): void { $handler->exportInstance($dateTimeType, new DateTime(), $mapper); }, OneWayHandlerException::class); diff --git a/tests/src/Mapping/Type/Enum/EnumHandler.phpt b/tests/src/Mapping/Type/Enum/EnumHandler.phpt index 4d898d6b..555eb9e7 100644 --- a/tests/src/Mapping/Type/Enum/EnumHandler.phpt +++ b/tests/src/Mapping/Type/Enum/EnumHandler.phpt @@ -25,16 +25,20 @@ $mapper = new Mapper(new StaticMappingContainer([])); $enumType = Type::get(TestEnum::class); -// acceptType() + +acceptType: Assert::true($handler->acceptsType($enumType)); Assert::false($handler->acceptsType(Type::get(Date::class))); -// getParameters() + +getParameters: Assert::equal($handler->getParameters($enumType), null); -// createInstance() + +createInstance: $enumInstance = $handler->createInstance($enumType, 1, $mapper); Assert::equal($enumInstance, TestEnum::get(TestEnum::ONE)); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($enumType, $enumInstance, $mapper), 1); diff --git a/tests/src/Mapping/Type/ExportableHandler.phpt b/tests/src/Mapping/Type/ExportableHandler.phpt index 04495296..be7c0ac2 100644 --- a/tests/src/Mapping/Type/ExportableHandler.phpt +++ b/tests/src/Mapping/Type/ExportableHandler.phpt @@ -21,20 +21,24 @@ $mapper = new Mapper(new StaticMappingContainer([])); $exportableType = Type::get(ExportableTestClass::class); -// acceptType() + +acceptType: Assert::true($handler->acceptsType($exportableType)); Assert::false($handler->acceptsType(Type::get(Date::class))); -// getParameters() + +getParameters: Assert::equal($handler->getParameters($exportableType), [ 'one' => Type::get(Type::INT), 'two' => Type::get(Type::FLOAT), ]); -// createInstance() + +createInstance: $data = ['one' => 1, 'two' => 1.23]; $exportableInstance = $handler->createInstance($exportableType, $data, $mapper); Assert::type($exportableInstance, ExportableTestClass::class); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($exportableType, $exportableInstance, $mapper), $data); diff --git a/tests/src/Mapping/Type/ScalarsHandler.phpt b/tests/src/Mapping/Type/ScalarsHandler.phpt index ec65a1d3..3e890956 100644 --- a/tests/src/Mapping/Type/ScalarsHandler.phpt +++ b/tests/src/Mapping/Type/ScalarsHandler.phpt @@ -19,7 +19,8 @@ $floatType = Type::get(Type::FLOAT); $numericType = Type::get(Type::NUMBER); $stringType = Type::get(Type::STRING); -// acceptType() + +acceptType: Assert::false($handler->acceptsType(Type::get(Assert::class))); Assert::true($handler->acceptsType($boolType)); Assert::true($handler->acceptsType($intType)); @@ -27,14 +28,16 @@ Assert::true($handler->acceptsType($floatType)); Assert::true($handler->acceptsType($numericType)); Assert::true($handler->acceptsType($stringType)); -// getParameters() + +getParameters: Assert::same($handler->getParameters($boolType), null); Assert::same($handler->getParameters($intType), null); Assert::same($handler->getParameters($floatType), null); Assert::same($handler->getParameters($numericType), null); Assert::same($handler->getParameters($stringType), null); -// createInstance() + +createInstance: $boolInstance = $handler->createInstance($boolType, '1', $mapper); Assert::same($boolInstance, true); $intInstance = $handler->createInstance($intType, '123', $mapper); @@ -48,7 +51,8 @@ Assert::same($numericFloatInstance, 1.23); $stringInstance = $handler->createInstance($stringType, 123, $mapper); Assert::same($stringInstance, '123'); -// exportInstance() + +exportInstance: // expected behavior - does not map back since the original type is unknown. proper reverse mapping must be // implemented either by a specialised handler (eg. MysqlScalarsHandler) or at an another layer (connection adapter) Assert::same($handler->exportInstance($boolType, $boolInstance, $mapper), true); diff --git a/tests/src/Mapping/Type/Time/DateTimeHandler.phpt b/tests/src/Mapping/Type/Time/DateTimeHandler.phpt index 7241cc38..14356617 100644 --- a/tests/src/Mapping/Type/Time/DateTimeHandler.phpt +++ b/tests/src/Mapping/Type/Time/DateTimeHandler.phpt @@ -20,13 +20,15 @@ $dateTimeType = Type::get(DateTime::class); $dateType = Type::get(Date::class); $timeType = Type::get(Time::class); -// acceptType() + +acceptType: Assert::false($handler->acceptsType(Type::get(Assert::class))); Assert::true($handler->acceptsType($dateTimeType)); Assert::true($handler->acceptsType($dateType)); Assert::true($handler->acceptsType($timeType)); -// getParameters() + +getParameters: Assert::same($handler->getParameters($dateTimeType), null); Assert::same($handler->getParameters($dateType), null); Assert::same($handler->getParameters($timeType), null); @@ -35,7 +37,8 @@ $dateTimeString = '2000-01-02 03:04:05'; $dateString = '2000-01-02'; $timeString = '03:04:05'; -// createInstance() + +createInstance: $dateTimeInstance = $handler->createInstance($dateTimeType, $dateTimeString, $mapper); Assert::type($dateTimeInstance, DateTime::class); Assert::same($dateTimeInstance->format(), $dateTimeString . '.000000'); @@ -48,7 +51,8 @@ $timeInstance = $handler->createInstance($timeType, $timeString, $mapper); Assert::type($timeInstance, Time::class); Assert::same($timeInstance->format(), $timeString . '.000000'); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($dateTimeType, $dateTimeInstance, $mapper), $dateTimeString); Assert::same($handler->exportInstance($dateType, $dateInstance, $mapper), $dateString); Assert::same($handler->exportInstance($timeType, $timeInstance, $mapper), $timeString); diff --git a/tests/src/Mapping/Type/TupleHandler.phpt b/tests/src/Mapping/Type/TupleHandler.phpt index 7b51ac2c..72c85ead 100644 --- a/tests/src/Mapping/Type/TupleHandler.phpt +++ b/tests/src/Mapping/Type/TupleHandler.phpt @@ -15,16 +15,20 @@ $mapper = new Mapper(new StaticMappingContainer([])); $tupleType = Type::tupleOf(Type::INT, Type::STRING); -// acceptType() + +acceptType: Assert::true($handler->acceptsType($tupleType)); Assert::false($handler->acceptsType(Type::get(Type::PHP_ARRAY))); -// getParameters() + +getParameters: Assert::same($handler->getParameters($tupleType), [Type::get(Type::INT), Type::get(Type::STRING)]); -// createInstance() + +createInstance: $tupleInstance = $handler->createInstance($tupleType, [123, 'abc'], $mapper); Assert::same($tupleInstance->toArray(), [123, 'abc']); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($tupleType, $tupleInstance, $mapper), [123, 'abc']); diff --git a/tests/src/Mapping/Type/TypeHandler.phpt b/tests/src/Mapping/Type/TypeHandler.phpt index 1e2d694f..fae1d825 100644 --- a/tests/src/Mapping/Type/TypeHandler.phpt +++ b/tests/src/Mapping/Type/TypeHandler.phpt @@ -15,16 +15,20 @@ $mapper = new Mapper(new StaticMappingContainer([])); $typeType = Type::get(Type::class); -// acceptType() + +acceptType: Assert::false($handler->acceptsType(Type::get(Assert::class))); Assert::true($handler->acceptsType($typeType)); -// getParameters() + +getParameters: Assert::same($handler->getParameters($typeType), null); -// createInstance() + +createInstance: $typeInstance = $handler->createInstance($typeType, 'array', $mapper); Assert::same($typeInstance, Type::arrayOf(Type::INT)); -// exportInstance() + +exportInstance: Assert::same($handler->exportInstance($typeType, $typeInstance, $mapper), 'array'); diff --git a/tests/src/Math/Angle/AngleFormatter.phpt b/tests/src/Math/Angle/AngleFormatter.phpt index b1e3b846..b2fbad83 100644 --- a/tests/src/Math/Angle/AngleFormatter.phpt +++ b/tests/src/Math/Angle/AngleFormatter.phpt @@ -11,6 +11,7 @@ require_once __DIR__ . '/../../bootstrap.php'; $angle = 87 + 45 / 60 + 54.765432 / 3600; $angleFormatter = new AngleFormatter(); + Assert::same($angleFormatter->format($angle, 'd'), '87'); Assert::same($angleFormatter->format($angle, 'D'), '87.765213'); Assert::same($angleFormatter->format($angle, 'D', 4), '87.7652'); diff --git a/tests/src/Math/Combinatorics.phpt b/tests/src/Math/Combinatorics.phpt index 84f10c9f..e8c61255 100644 --- a/tests/src/Math/Combinatorics.phpt +++ b/tests/src/Math/Combinatorics.phpt @@ -7,6 +7,8 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; + +sumFactorize: Assert::same(Combinatorics::sumFactorize(4), [ [4], [3, 1], @@ -18,7 +20,8 @@ Assert::same(Combinatorics::sumFactorize(4), [ [1, 1, 1, 1], ]); -// getAllSubstringCombinations() + +getAllSubstringCombinations: Assert::same(Combinatorics::getAllSubstringCombinations('abcd'), [ ['abcd'], ['abc', 'd'], diff --git a/tests/src/Math/FloatCalc.phpt b/tests/src/Math/FloatCalc.phpt index ef8c0f45..448cae30 100644 --- a/tests/src/Math/FloatCalc.phpt +++ b/tests/src/Math/FloatCalc.phpt @@ -14,7 +14,8 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; -// roundTo() + +roundTo: Assert::same(FloatCalc::roundTo(0.0, 0.25), 0.0); Assert::same(FloatCalc::roundTo(2.1, 0.25), 2.0); Assert::same(FloatCalc::roundTo(2.2, 0.25), 2.25); @@ -23,7 +24,8 @@ Assert::same(FloatCalc::roundTo(-2.2, 0.25), -2.25); Assert::same(FloatCalc::roundTo(2.1, -0.25), 2.0); Assert::same(FloatCalc::roundTo(2.2, -0.25), 2.25); -// roundUpTo() + +roundUpTo: Assert::same(FloatCalc::roundUpTo(0.0, 0.25), 0.0); Assert::same(FloatCalc::roundUpTo(2.1, 0.25), 2.25); Assert::same(FloatCalc::roundUpTo(2.2, 0.25), 2.25); @@ -32,7 +34,8 @@ Assert::same(FloatCalc::roundUpTo(-2.2, 0.25), -2.0); Assert::same(FloatCalc::roundUpTo(2.1, -0.25), 2.25); Assert::same(FloatCalc::roundUpTo(2.2, -0.25), 2.25); -// roundDownTo() + +roundDownTo: Assert::same(FloatCalc::roundDownTo(0.0, 0.25), 0.0); Assert::same(FloatCalc::roundDownTo(2.1, 0.25), 2.0); Assert::same(FloatCalc::roundDownTo(2.2, 0.25), 2.0); diff --git a/tests/src/Math/IntCalc.phpt b/tests/src/Math/IntCalc.phpt index 6bfc43c5..35b99f61 100644 --- a/tests/src/Math/IntCalc.phpt +++ b/tests/src/Math/IntCalc.phpt @@ -14,7 +14,8 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; -// roundTo() + +roundTo: Assert::same(IntCalc::roundTo(0, 3), 0); Assert::same(IntCalc::roundTo(20, 3), 21); Assert::same(IntCalc::roundTo(22, 3), 21); @@ -23,7 +24,8 @@ Assert::same(IntCalc::roundTo(-22, 3), -21); Assert::same(IntCalc::roundTo(20, -3), 21); Assert::same(IntCalc::roundTo(22, -3), 21); -// roundUpTo() + +roundUpTo: Assert::same(IntCalc::roundUpTo(0, 3), 0); Assert::same(IntCalc::roundUpTo(20, 3), 21); Assert::same(IntCalc::roundUpTo(22, 3), 24); @@ -32,7 +34,8 @@ Assert::same(IntCalc::roundUpTo(-22, 3), -21); Assert::same(IntCalc::roundUpTo(20, -3), 21); Assert::same(IntCalc::roundUpTo(22, -3), 24); -// roundDownTo() + +roundDownTo: Assert::same(IntCalc::roundDownTo(0, 3), 0); Assert::same(IntCalc::roundDownTo(20, 3), 18); Assert::same(IntCalc::roundDownTo(22, 3), 21); @@ -41,7 +44,8 @@ Assert::same(IntCalc::roundDownTo(-22, 3), -24); Assert::same(IntCalc::roundDownTo(20, -3), 18); Assert::same(IntCalc::roundDownTo(22, -3), 21); -// factorial() + +factorial: Assert::same(IntCalc::factorial(-4), -24); Assert::same(IntCalc::factorial(-3), -6); Assert::same(IntCalc::factorial(-2), -2); @@ -52,7 +56,8 @@ Assert::same(IntCalc::factorial(2), 2); Assert::same(IntCalc::factorial(3), 6); Assert::same(IntCalc::factorial(4), 24); -// factorize() + +factorize: Assert::same(IntCalc::factorize(1), [1]); Assert::same(IntCalc::factorize(2), [2]); Assert::same(IntCalc::factorize(3), [3]); @@ -61,7 +66,8 @@ Assert::same(IntCalc::factorize(8), [2, 2, 2]); Assert::same(IntCalc::factorize(60), [2, 2, 3, 5]); Assert::same(IntCalc::factorize(720), [2, 2, 2, 2, 3, 3, 5]); -// greatestCommonDivider() + +greatestCommonDivider: Assert::same(IntCalc::greatestCommonDivider(1, 1), 1); Assert::same(IntCalc::greatestCommonDivider(1, 2), 1); Assert::same(IntCalc::greatestCommonDivider(2, 2), 2); @@ -69,7 +75,8 @@ Assert::same(IntCalc::greatestCommonDivider(2, 3), 1); Assert::same(IntCalc::greatestCommonDivider(4, 6), 2); Assert::same(IntCalc::greatestCommonDivider(84, 140), 28); -// leastCommonMultiple() + +leastCommonMultiple: Assert::same(IntCalc::leastCommonMultiple(1, 1), 1); Assert::same(IntCalc::leastCommonMultiple(1, 2), 2); Assert::same(IntCalc::leastCommonMultiple(2, 2), 2); diff --git a/tests/src/Math/Interval/FloatInterval.phpt b/tests/src/Math/Interval/FloatInterval.phpt index af1bf2dd..cd4384b4 100644 --- a/tests/src/Math/Interval/FloatInterval.phpt +++ b/tests/src/Math/Interval/FloatInterval.phpt @@ -22,36 +22,44 @@ $s = static function (FloatInterval ...$items) { return new FloatIntervalSet($items); }; -// shift() + +shift: Assert::equal($closed->shift(10.0), $r(11, 15)); Assert::equal($open->shift(10.0), $r(11, 15, true, true)); -// multiply() + +multiply: Assert::equal($closed->multiply(10.0), $r(10, 50)); Assert::equal($open->multiply(10.0), $r(10, 50, true, true)); -// getStart() + +getStart: Assert::same($closed->getStart(), 1.0); Assert::same($open->getStart(), 1.0); -// getEnd() + +getEnd: Assert::same($closed->getEnd(), 5.0); Assert::same($open->getEnd(), 5.0); -// getLength() + +getLength: Assert::same($closed->getLength(), 4.0); Assert::same($open->getLength(), 4.0); Assert::same($empty->getLength(), 0.0); -// hasOpenStart() + +hasOpenStart: Assert::false($closed->hasOpenStart()); Assert::true($open->hasOpenStart()); -// hasOpenEnd() + +hasOpenEnd: Assert::false($closed->hasOpenEnd()); Assert::true($open->hasOpenEnd()); -// isEmpty() + +isEmpty: Assert::false($closed->isEmpty()); Assert::false($open->isEmpty()); @@ -61,7 +69,8 @@ Assert::true((new FloatInterval(1.0, 1.0, true, true))->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// equals() + +equals: Assert::true($closed->equals($r(1, 5))); Assert::false($closed->equals($r(1, 4))); Assert::false($closed->equals($r(2, 5))); @@ -73,7 +82,8 @@ Assert::false($open->equals($r(1, 5, false, true))); Assert::true($empty->equals(new FloatInterval(1.0, 1.0, true, true))); -// compareIntersects() + +compareIntersects: Call::withArgs(static function (array $a, array $b, int $expected): void { $a = new FloatInterval(...$a); $b = new FloatInterval(...$b); @@ -139,7 +149,8 @@ Call::withArgs(static function (array $a, array $b, int $expected): void { [[3, 4, false, false], [1, 2, false, false], IntersectResult::AFTER_END], ]); -// containsValue() + +containsValue: Assert::true($closed->containsValue(3.0)); Assert::true($closed->containsValue(1.0)); Assert::true($closed->containsValue(5.0)); @@ -152,7 +163,8 @@ Assert::false($open->containsValue(5.0)); Assert::false($open->containsValue(0.0)); Assert::false($open->containsValue(6.0)); -// contains() + +contains: Assert::true($closed->contains($r(1, 5))); Assert::true($closed->contains($r(1, 3))); Assert::true($closed->contains($r(3, 5))); @@ -168,7 +180,8 @@ Assert::false($open->contains($r(1, 5, true))); Assert::false($open->contains($r(1, 5, false, true))); Assert::true($open->contains($r(1, 5, true, true))); -// intersects() + +intersects: Assert::true($closed->intersects($r(-5, 10))); Assert::true($closed->intersects($r(1, 5))); Assert::true($closed->intersects($r(0, 1))); @@ -184,7 +197,8 @@ Assert::false($open->intersects($r(0, 1, false, true))); Assert::false($open->intersects($r(5, 6, true))); Assert::true($open->intersects(FloatInterval::open(1, 5))); -// touches() + +touches: Assert::true($closed->touches($r(-10, 1))); Assert::true($closed->touches($r(5, 10))); Assert::false($closed->touches($r(-10, 2))); @@ -197,7 +211,8 @@ Assert::true($closed->touches($r(5, 10, true, false), true)); Assert::false($open->touches($r(-10, 1, false, true), true)); Assert::false($open->touches($r(5, 10, true, false), true)); -// split() + +split: Assert::equal($closed->split(1), $s($closed)); Assert::equal($closed->split(2, FloatInterval::SPLIT_CLOSED), $s($r(1, 3), $r(3, 5))); Assert::equal( @@ -222,7 +237,8 @@ Assert::equal( ); Assert::equal($empty->split(5), $s($empty)); -// splitBy() + +splitBy: Assert::equal( $closed->splitBy([-10, 2, 4, 10], FloatInterval::SPLIT_CLOSED), $s($r(1, 2), $r(2, 4), $r(4, 5)) @@ -240,7 +256,8 @@ Assert::equal( $s($r(1, 2, false, true), $r(2, 4, false, true), $r(4, 5)) ); -// envelope() + +envelope: Assert::equal($closed->envelope($r(5, 6)), $r(1, 6)); Assert::equal($closed->envelope($r(0, 1)), $r(0, 5)); Assert::equal($closed->envelope($r(-10, -5)), $r(-10, 5)); @@ -253,7 +270,8 @@ Assert::equal($open->envelope($r(-10, -5)), $r(-10, 5, false, true)); Assert::equal($open->envelope($r(-10, -5), $r(5, 10)), $r(-10, 10)); Assert::equal($open->envelope($empty), $open); -// intersect() + +intersect: Assert::equal($closed->intersect($r(3, 6)), $r(3, 5)); Assert::equal($closed->intersect($r(0, 1)), $r(1, 1)); Assert::equal($closed->intersect($r(3, 6), $r(0, 4)), $r(3, 4)); @@ -270,7 +288,8 @@ Assert::equal($open->intersect($r(-10, -5)), $empty); Assert::equal($open->intersect($r(-10, -5), $r(5, 10)), $empty); Assert::equal($open->intersect($empty), $empty); -// union() + +union: Assert::equal($closed->union($r(3, 6)), $s($r(1, 6))); Assert::equal($closed->union($r(0, 1)), $s($r(0, 5))); Assert::equal($closed->union($r(3, 6), $r(0, 4)), $s($r(0, 6))); @@ -289,7 +308,8 @@ Assert::equal($open->union($r(10, 20)), $s($open, $r(10, 20))); Assert::equal($open->union($all), $s($all)); Assert::equal($open->union($empty), $s($open)); -// difference() + +difference: Assert::equal($closed->difference($r(3, 6)), $s($r(1, 3, false, true), $r(5, 6, true, false))); Assert::equal($closed->difference($r(0, 1)), $s($r(0, 1, false, true), $r(1, 5, true, false))); Assert::equal($closed->difference($r(3, 6), $r(0, 4)), $s($r(0, 1, false, true), $r(5, 6, true, false))); @@ -297,7 +317,8 @@ Assert::equal($closed->difference($r(10, 20)), $s($closed, $r(10, 20))); Assert::equal($closed->difference($all), $s(new FloatInterval(FloatInterval::MIN, 1.0, false, true), new FloatInterval(5.0, FloatInterval::MAX, true, false))); Assert::equal($closed->difference($empty), $s($closed)); -// subtract() + +subtract: Assert::equal($closed->subtract($r(0, 2)), $s($r(2, 5, true, false))); Assert::equal($closed->subtract($r(4, 6)), $s($r(1, 4, false, true))); Assert::equal($closed->subtract($r(2, 3)), $s($r(1, 2, false, true), $r(3, 5, true, false))); @@ -307,7 +328,8 @@ Assert::equal($closed->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s($empty)); -// invert() + +invert: Assert::equal($closed->invert(), $s( new FloatInterval(FloatInterval::MIN, 1.0, false, true), new FloatInterval(5.0, FloatInterval::MAX, true, false) @@ -315,7 +337,8 @@ Assert::equal($closed->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s()); -// countOverlaps() + +countOverlaps: Assert::equal(FloatInterval::countOverlaps($empty), []); Assert::equal(FloatInterval::countOverlaps($closed, $r(0, 1)), [ [$r(0, 1, false, true), 1], @@ -335,7 +358,8 @@ Assert::equal(FloatInterval::countOverlaps($r(0, 5), $r(1, 6), $r(2, 7)), [ [$r(6, 7, true, false), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(FloatInterval::explodeOverlaps($empty), []); Assert::equal(FloatInterval::explodeOverlaps($closed, $r(0, 1)), [ $r(0, 1, false, true), diff --git a/tests/src/Math/Interval/FloatIntervalSet.phpt b/tests/src/Math/Interval/FloatIntervalSet.phpt index 2416bd62..a7075b71 100644 --- a/tests/src/Math/Interval/FloatIntervalSet.phpt +++ b/tests/src/Math/Interval/FloatIntervalSet.phpt @@ -20,38 +20,49 @@ $s = static function (FloatInterval ...$items) { return new FloatIntervalSet($items); }; -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new FloatIntervalSet([]))->isEmpty()); Assert::true((new FloatIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 6)))); -// containsValue() + +containsValue: Assert::true($set->containsValue(1)); Assert::true($set->containsValue(5)); Assert::false($set->containsValue(6)); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 3, false, true), $i(4, 7, true, true), $i(8, 10, true, false))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (FloatInterval $interval) { return $interval; }), $set); @@ -64,7 +75,8 @@ Assert::equal($set->map(static function (FloatInterval $interval) { $set = $s(FloatInterval::empty(), $i(1, 1), $i(1, 2), $i(1, 3)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', 1), $s($i(1, 3))); Assert::equal($set->filterByLength('>=', 1), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByLength('=', 1), $s($i(1, 2))); diff --git a/tests/src/Math/Interval/IntInterval.phpt b/tests/src/Math/Interval/IntInterval.phpt index d4843de9..9a9d4ff8 100644 --- a/tests/src/Math/Interval/IntInterval.phpt +++ b/tests/src/Math/Interval/IntInterval.phpt @@ -19,45 +19,55 @@ $s = static function (IntInterval ...$items) { return new IntIntervalSet($items); }; -// shift() + +shift: Assert::equal($interval->shift(10), $r(11, 15)); -// multiply() + +multiply: Assert::equal($interval->multiply(10), $r(10, 50)); -// getStart() + +getStart: Assert::same($interval->getStart(), 1); -// getEnd() + +getEnd: Assert::same($interval->getEnd(), 5); -// getLength() + +getLength: Assert::same($interval->getLength(), 4); Assert::same($empty->getLength(), 0); -// getCount() + +getCount: Assert::same($interval->getCount(), 5); Assert::same($empty->getCount(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false((new IntInterval(1, 1))->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($r(1, 5))); Assert::false($interval->equals($r(1, 4))); Assert::false($interval->equals($r(2, 5))); -// containsValue() + +containsValue: Assert::true($interval->containsValue(1)); Assert::true($interval->containsValue(3)); Assert::true($interval->containsValue(5)); Assert::false($interval->containsValue(0)); Assert::false($interval->containsValue(6)); -// contains() + +contains: Assert::true($interval->contains($r(1, 5))); Assert::true($interval->contains($r(1, 3))); Assert::true($interval->contains($r(3, 5))); @@ -66,7 +76,8 @@ Assert::false($interval->contains($r(1, 6))); Assert::false($interval->contains($r(-1, 0))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($r(-5, 10))); Assert::true($interval->intersects($r(1, 5))); Assert::true($interval->intersects($r(0, 1))); @@ -74,13 +85,15 @@ Assert::true($interval->intersects($r(5, 6))); Assert::false($interval->intersects($r(-1, 0))); Assert::false($interval->intersects($empty)); -// touches() + +touches: Assert::true($interval->touches($r(-10, 0))); Assert::true($interval->touches($r(6, 10))); Assert::false($interval->touches($r(-10, 1))); Assert::false($interval->touches($r(5, 10))); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($r(1, 3), $r(4, 5))); Assert::equal($interval->split(3), $s($r(1, 2), $r(3, 3), $r(4, 5))); @@ -89,17 +102,20 @@ Assert::equal($interval->split(5), $s($r(1, 1), $r(2, 2), $r(3, 3), $r(4, 4), $r Assert::equal($interval->split(9), $s($r(1, 1), $r(2, 2), $r(3, 3), $r(4, 4), $r(5, 5))); Assert::equal($empty->split(5), $s($empty)); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([-10, 2, 4, 10]), $s($r(1, 1), $r(2, 3), $r(4, 5))); -// envelope() + +envelope: Assert::equal($interval->envelope($r(5, 6)), $r(1, 6)); Assert::equal($interval->envelope($r(0, 1)), $r(0, 5)); Assert::equal($interval->envelope($r(-10, -5)), $r(-10, 5)); Assert::equal($interval->envelope($r(-10, -5), $r(5, 10)), $r(-10, 10)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($r(3, 6)), $r(3, 5)); Assert::equal($interval->intersect($r(0, 1)), $r(1, 1)); Assert::equal($interval->intersect($r(3, 6), $r(0, 4)), $r(3, 4)); @@ -107,7 +123,8 @@ Assert::equal($interval->intersect($r(-10, -5)), $empty); Assert::equal($interval->intersect($r(-10, -5), $r(5, 10)), $empty); Assert::equal($interval->intersect($empty), $empty); -// union() + +union: Assert::equal($interval->union($r(3, 6)), $s($r(1, 6))); Assert::equal($interval->union($r(0, 1)), $s($r(0, 5))); Assert::equal($interval->union($r(3, 6), $r(0, 4)), $s($r(0, 6))); @@ -115,7 +132,8 @@ Assert::equal($interval->union($r(10, 20)), $s($interval, $r(10, 20))); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($r(3, 6)), $s($r(1, 2), $r(6, 6))); Assert::equal($interval->difference($r(0, 1)), $s($r(0, 0), $r(2, 5))); Assert::equal($interval->difference($r(3, 6), $r(0, 4)), $s($r(0, 0), $r(6, 6))); @@ -123,7 +141,8 @@ Assert::equal($interval->difference($r(10, 20)), $s($interval, $r(10, 20))); Assert::equal($interval->difference($all), $s($r(IntInterval::MIN, 0), $r(6, IntInterval::MAX))); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($r(0, 2)), $s($r(3, 5))); Assert::equal($interval->subtract($r(4, 6)), $s($r(1, 3))); Assert::equal($interval->subtract($r(2, 3)), $s($r(1, 1), $r(4, 5))); @@ -133,12 +152,14 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s($empty)); -// invert() + +invert: Assert::equal($interval->invert(), $s($r(IntInterval::MIN, 0), $r(6, IntInterval::MAX))); Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s()); -// countOverlaps() + +countOverlaps: Assert::equal(IntInterval::countOverlaps($empty), []); Assert::equal(IntInterval::countOverlaps($interval, $r(0, 1)), [ [$r(0, 0), 1], @@ -153,7 +174,8 @@ Assert::equal(IntInterval::countOverlaps($r(0, 5), $r(1, 6), $r(2, 7)), [ [$r(7, 7), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(IntInterval::explodeOverlaps($empty), []); Assert::equal(IntInterval::explodeOverlaps($interval, $r(0, 1)), [ $r(0, 0), diff --git a/tests/src/Math/Interval/IntIntervalSet.phpt b/tests/src/Math/Interval/IntIntervalSet.phpt index 9f07c234..e0cacc92 100644 --- a/tests/src/Math/Interval/IntIntervalSet.phpt +++ b/tests/src/Math/Interval/IntIntervalSet.phpt @@ -20,38 +20,49 @@ $s = static function (IntInterval ...$items) { return new IntIntervalSet($items); }; -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new IntIntervalSet([]))->isEmpty()); Assert::true((new IntIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 6)))); -// containsValue() + +containsValue: Assert::true($set->containsValue(1)); Assert::true($set->containsValue(5)); Assert::false($set->containsValue(6)); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 2), $i(5, 6), $i(9, 10))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (IntInterval $interval) { return $interval; }), $set); @@ -64,7 +75,8 @@ Assert::equal($set->map(static function (IntInterval $interval) { $set = $s(IntInterval::empty(), $i(1, 1), $i(1, 2), $i(1, 3)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', 1), $s($i(1, 3))); Assert::equal($set->filterByLength('>=', 1), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByLength('=', 1), $s($i(1, 2))); @@ -72,7 +84,8 @@ Assert::equal($set->filterByLength('<>', 1), $s(IntInterval::empty(), $i(1, 1), Assert::equal($set->filterByLength('<=', 1), $s(IntInterval::empty(), $i(1, 1), $i(1, 2))); Assert::equal($set->filterByLength('<', 1), $s(IntInterval::empty(), $i(1, 1))); -// filterByCount() + +filterByCount: Assert::equal($set->filterByCount('>', 1), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByCount('>=', 1), $s($i(1, 1), $i(1, 2), $i(1, 3))); Assert::equal($set->filterByCount('=', 1), $s($i(1, 1))); diff --git a/tests/src/Math/Interval/IntervalCalc.phpt b/tests/src/Math/Interval/IntervalCalc.phpt index 8f3190e1..361f04a2 100644 --- a/tests/src/Math/Interval/IntervalCalc.phpt +++ b/tests/src/Math/Interval/IntervalCalc.phpt @@ -9,7 +9,8 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../../bootstrap.php'; -// compareIntersects() + +compareIntersects: Call::withArgs(static function (array $boundaries, int $expected, int $case): void { Assert::same(IntervalCalc::compareIntersects(...$boundaries), $expected, (string) $case); }, [ diff --git a/tests/src/Math/ModuloCalc.phpt b/tests/src/Math/ModuloCalc.phpt index 67107980..45861b3b 100644 --- a/tests/src/Math/ModuloCalc.phpt +++ b/tests/src/Math/ModuloCalc.phpt @@ -17,7 +17,7 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; -// differences() +differences: Assert::same(ModuloCalc::differences([0], 60), [60]); Assert::same(ModuloCalc::differences([10], 60), [60]); Assert::same(ModuloCalc::differences([0, 10, 20, 30, 40, 50], 60), [10, 10, 10, 10, 10, 10]); @@ -33,7 +33,7 @@ Assert::throws(static function (): void { }, InvalidArgumentException::class); -// roundTo() +roundTo: Assert::same(ModuloCalc::roundTo(3, [0, 10, 20, 30, 40, 50], 60), [0, Overflow::NONE]); Assert::same(ModuloCalc::roundTo(23, [0, 10, 20, 30, 40, 50], 60), [20, Overflow::NONE]); Assert::same(ModuloCalc::roundTo(27, [0, 10, 20, 30, 40, 50], 60), [30, Overflow::NONE]); @@ -52,7 +52,7 @@ Assert::throws(static function (): void { }, InvalidArgumentException::class); -// roundUpTo() +roundUpTo: Assert::same(ModuloCalc::roundUpTo(3, [0, 10, 20, 30, 40, 50], 60), [10, Overflow::NONE]); Assert::same(ModuloCalc::roundUpTo(23, [0, 10, 20, 30, 40, 50], 60), [30, Overflow::NONE]); Assert::same(ModuloCalc::roundUpTo(27, [0, 10, 20, 30, 40, 50], 60), [30, Overflow::NONE]); @@ -71,7 +71,7 @@ Assert::throws(static function (): void { }, InvalidArgumentException::class); -// roundDownTo() +roundDownTo: Assert::same(ModuloCalc::roundDownTo(3, [0, 10, 20, 30, 40, 50], 60), [0, Overflow::NONE]); Assert::same(ModuloCalc::roundDownTo(23, [0, 10, 20, 30, 40, 50], 60), [20, Overflow::NONE]); Assert::same(ModuloCalc::roundDownTo(27, [0, 10, 20, 30, 40, 50], 60), [20, Overflow::NONE]); diff --git a/tests/src/Math/Sequence.phpt b/tests/src/Math/Sequence.phpt index 9cc768d9..286a6e12 100644 --- a/tests/src/Math/Sequence.phpt +++ b/tests/src/Math/Sequence.phpt @@ -10,7 +10,8 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../bootstrap.php'; -// lucas() + +lucas: Assert::same(Lucas::getNth(0), 2); Assert::same(Lucas::getNth(1), 1); Assert::same(Lucas::getNth(2), 3); @@ -22,7 +23,8 @@ Assert::same(Lucas::getNth(7), 29); Assert::same(Lucas::getNth(8), 47); Assert::same(Lucas::getNth(9), 76); -// fibonacci() + +fibonacci: Assert::same(Fibonacci::getNth(1), 1); Assert::same(Fibonacci::getNth(2), 1); Assert::same(Fibonacci::getNth(3), 2); @@ -35,7 +37,8 @@ Assert::same(Fibonacci::getNth(9), 34); Assert::same(Fibonacci::getNth(10), 55); Assert::same(Fibonacci::getNth(11), 89); -// tribonacci() + +tribonacci: Assert::same(Tribonacci::getNth(1), 1); Assert::same(Tribonacci::getNth(2), 1); Assert::same(Tribonacci::getNth(3), 2); @@ -46,5 +49,6 @@ Assert::same(Tribonacci::getNth(7), 24); Assert::same(Tribonacci::getNth(8), 44); Assert::same(Tribonacci::getNth(9), 81); -// prime() + +prime: Assert::same(Prime::getBetween(8192, 10000), [8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973]); diff --git a/tests/src/Time/Date.phpt b/tests/src/Time/Date.phpt index d0c0e054..abab0f0e 100644 --- a/tests/src/Time/Date.phpt +++ b/tests/src/Time/Date.phpt @@ -23,14 +23,16 @@ $dateTimeImmutable = new DateTimeImmutable($dateString); $timestamp = 946782245; $utcTimeZone = new DateTimeZone('UTC'); -// __construct() + +__construct: Assert::throws(static function (): void { new Date('asdf'); }, InvalidDateTimeException::class); Assert::type(new Date(), Date::class); Assert::same((new Date('today'))->format(), date(Date::DEFAULT_FORMAT)); -// createFromDateTimeInterface() + +createFromDateTimeInterface: Assert::type(Date::createFromDateTimeInterface($dateTime), Date::class); Assert::type(Date::createFromDateTimeInterface($dateTimeImmutable), Date::class); Assert::type(Date::createFromDateTimeInterface(new DateTime('2000-01-02')), Date::class); @@ -38,35 +40,43 @@ Assert::same(Date::createFromDateTimeInterface($dateTime)->format(), $dateString Assert::same(Date::createFromDateTimeInterface($dateTimeImmutable)->format(), $dateString); Assert::same(Date::createFromDateTimeInterface(new DateTime('2000-01-02'))->format(), $dateString); -// createFromComponents() + +createFromComponents: Assert::type(Date::createFromComponents(2001, 2, 3), Date::class); Assert::same(Date::createFromComponents(2001, 2, 3)->format('Y-m-d'), '2001-02-03'); -// createFromFormat() + +createFromFormat: Assert::type(Date::createFromFormat(Date::DEFAULT_FORMAT, $dateString), Date::class); Assert::same(Date::createFromFormat(Date::DEFAULT_FORMAT, $dateString)->format(), $dateString); Assert::exception(static function (): void { Date::createFromFormat('Y-m-d', '12:00:00'); }, InvalidDateTimeException::class); -// format() + +format: Assert::same($date->format('j.n.Y'), date('j.n.Y', $timestamp)); -// toDateTime() + +toDateTime: Assert::equal($date->toDateTime(), new DateTime('2000-01-02 00:00:00')); -// toDateTimeInterval() + +toDateTimeInterval: Assert::equal($date->toDateTimeInterval(), new DateTimeInterval(new DateTime('2000-01-02 00:00:00'), new DateTime('2000-01-03 00:00:00'))); -// getJulianDay() + +getJulianDay: Assert::same($date->getJulianDay(), 2451546); Assert::same((new Date(Date::MIN))->getJulianDay(), Date::MIN_DAY_NUMBER); Assert::same((new Date(Date::MAX))->getJulianDay(), Date::MAX_DAY_NUMBER); -// getStart() + +getStart: Assert::equal($date->getStart($utcTimeZone), new DateTime('2000-01-02 00:00:00.000000', $utcTimeZone)); -// getEnd() + +getEnd: Assert::equal($date->getEnd($utcTimeZone), new DateTime('2000-01-02 23:59:59.999999', $utcTimeZone)); $today = new Date('today 12:00'); @@ -74,13 +84,16 @@ $today2 = new Date('today 13:00'); $yesterday = new Date('yesterday'); $tomorrow = new Date('tomorrow'); -// increment() + +increment: Assert::same($today->addDay()->format(), $tomorrow->format()); -// decrement() + +decrement: Assert::same($today->subtractDay()->format(), $yesterday->format()); -// diff() + +diff: Assert::same($today->diff($today)->format('%R %y %m %d %h %i %s'), '+ 0 0 0 0 0 0'); Assert::same($today->diff($today2)->format('%R %y %m %d %h %i %s'), '+ 0 0 0 0 0 0'); Assert::same($today->diff($tomorrow)->format('%R %y %m %d %h %i %s'), '+ 0 0 1 0 0 0'); @@ -88,49 +101,58 @@ Assert::same($today->diff($yesterday)->format('%R %y %m %d %h %i %s'), '- 0 0 1 Assert::same($today->diff($tomorrow, true)->format('%R %y %m %d %h %i %s'), '+ 0 0 1 0 0 0'); Assert::same($today->diff($yesterday, true)->format('%R %y %m %d %h %i %s'), '+ 0 0 1 0 0 0'); -// compare() + +compare: Assert::same($today->compare($yesterday), 1); Assert::same($today->compare($today), 0); Assert::same($today->compare($tomorrow), -1); -// equals() + +equals: Assert::false($today->equals($yesterday)); Assert::false($today->equals($tomorrow)); Assert::true($today->equals($today)); Assert::true($today->equals($today2)); -// isBefore() + +isBefore: Assert::false($today->isBefore($yesterday)); Assert::false($today->isBefore($today)); Assert::true($today->isBefore($tomorrow)); -// isAfter() + +isAfter: Assert::true($today->isAfter($yesterday)); Assert::false($today->isAfter($today)); Assert::false($today->isAfter($tomorrow)); -// isSameOrBefore() + +isSameOrBefore: Assert::false($today->isSameOrBefore($yesterday)); Assert::true($today->isSameOrBefore($today)); Assert::true($today->isSameOrBefore($tomorrow)); -// isSameOrAfter() + +isSameOrAfter: Assert::true($today->isSameOrAfter($yesterday)); Assert::true($today->isSameOrAfter($today)); Assert::false($today->isSameOrAfter($tomorrow)); -// isBetween() + +isBetween: Assert::false($yesterday->isBetween($today, $tomorrow)); Assert::false($tomorrow->isBetween($today, $yesterday)); Assert::true($yesterday->isBetween($yesterday, $tomorrow)); Assert::true($today->isBetween($yesterday, $tomorrow)); Assert::true($tomorrow->isBetween($yesterday, $tomorrow)); -// isFuture() + +isFuture: Assert::false($yesterday->isFuture()); Assert::true($tomorrow->isFuture()); -// isPast() + +isPast: Assert::false($tomorrow->isPast()); Assert::true($yesterday->isPast()); @@ -139,13 +161,15 @@ $friday = new Date('2016-11-04'); $saturday = new Date('2016-11-05'); $sunday = new Date('2016-11-06'); -// getDayOfWeekEnum() + +getDayOfWeekEnum: Assert::equal($monday->getDayOfWeekEnum(), DayOfWeek::monday()); Assert::equal($friday->getDayOfWeekEnum(), DayOfWeek::friday()); Assert::equal($saturday->getDayOfWeekEnum(), DayOfWeek::saturday()); Assert::equal($sunday->getDayOfWeekEnum(), DayOfWeek::sunday()); -// isDayOfWeek() + +isDayOfWeek: Assert::true($monday->isDayOfWeek(1)); Assert::true($monday->isDayOfWeek(DayOfWeek::monday())); Assert::false($monday->isDayOfWeek(7)); @@ -154,16 +178,19 @@ Assert::exception(static function () use ($monday): void { $monday->isDayOfWeek(8); }, InvalidValueException::class); -// isWeekend() + +isWeekend: Assert::false($monday->isWeekend()); Assert::false($friday->isWeekend()); Assert::true($saturday->isWeekend()); Assert::true($sunday->isWeekend()); -// getMonthEnum() + +getMonthEnum: Assert::equal($monday->getMonthEnum(), Month::november()); -// isMonth() + +isMonth: Assert::true($monday->isMonth(11)); Assert::true($monday->isMonth(Month::november())); Assert::false($monday->isMonth(12)); diff --git a/tests/src/Time/DateTime.phpt b/tests/src/Time/DateTime.phpt index 52ea9a25..d7cf13e2 100644 --- a/tests/src/Time/DateTime.phpt +++ b/tests/src/Time/DateTime.phpt @@ -37,7 +37,8 @@ $dateTimeByOffset = new DateTime($dateTimeString, $localOffsetTimeZone); $dateTimeNative = new PhpDateTime($dateTimeString); $dateTimeImmutable = new DateTimeImmutable($dateTimeString); -// createFromFormat() + +createFromFormat: Assert::type(DateTime::createFromFormat(DateTime::DEFAULT_FORMAT, $dateTimeString), DateTime::class); Assert::same(DateTime::createFromFormat(DateTime::DEFAULT_FORMAT, $dateTimeString)->format(), $dateTimeString); Assert::equal(DateTime::createFromFormat(DateTime::DEFAULT_FORMAT, $dateTimeString, $utcTimeZone)->getTimezone(), $utcTimeZone); @@ -45,7 +46,8 @@ Assert::exception(static function (): void { DateTime::createFromFormat('Y-m-d', '12:00:00'); }, InvalidDateTimeException::class); -// createFromAnyFormat() + +createFromAnyFormat: $dateTimeStringOffset = '2000-01-02 03:04:05.000006+02:00'; $dateTimeStringOffset2 = '2000-01-02 03:04:05+02:00'; Assert::type(DateTime::createFromAnyFormat(DateTime::SAFE_FORMATS, $dateTimeStringOffset), DateTime::class); @@ -55,25 +57,29 @@ Assert::exception(static function (): void { DateTime::createFromAnyFormat(DateTime::SAFE_FORMATS, '2000-01-02 12:00:00'); }, InvalidDateTimeException::class); -// createFromTimestamp() + +createFromTimestamp: Assert::type(DateTime::createFromTimestamp($timestamp), DateTime::class); Assert::same(DateTime::createFromTimestamp($timestamp, $utcTimeZone)->format(), '2000-01-02 02:04:05.000000'); Assert::same(DateTime::createFromTimestamp($timestamp, $localTimeZone)->format(), '2000-01-02 03:04:05.000000'); Assert::same(DateTime::createFromTimestamp($timestamp)->format(), '2000-01-02 03:04:05.000000'); -// createFromFloatTimestamp() + +createFromFloatTimestamp: Assert::type(DateTime::createFromFloatTimestamp($floatTimestamp), DateTime::class); Assert::same(DateTime::createFromFloatTimestamp($floatTimestamp, $utcTimeZone)->format(), $dateTimeStringUtc); Assert::same(DateTime::createFromFloatTimestamp($floatTimestamp, $localTimeZone)->format(), $dateTimeString); Assert::same(DateTime::createFromFloatTimestamp($floatTimestamp)->format(), $dateTimeString); -// createFromMicroTimestamp() + +createFromMicroTimestamp: Assert::type(DateTime::createFromMicroTimestamp($microTimestamp), DateTime::class); Assert::same(DateTime::createFromMicroTimestamp($microTimestamp, $utcTimeZone)->format(), $dateTimeStringUtc); Assert::same(DateTime::createFromMicroTimestamp($microTimestamp, $localTimeZone)->format(), $dateTimeString); Assert::same(DateTime::createFromMicroTimestamp($microTimestamp)->format(), $dateTimeString); -// createFromDateTimeInterface() + +createFromDateTimeInterface: Assert::type(DateTime::createFromDateTimeInterface($dateTime), DateTime::class); Assert::same(DateTime::createFromDateTimeInterface($dateTime)->format(), $dateTimeString); Assert::same(DateTime::createFromDateTimeInterface($dateTime, $utcTimeZone)->format(), $dateTimeStringUtc); @@ -87,13 +93,15 @@ Assert::same(DateTime::createFromDateTimeInterface($dateTimeImmutable)->format() Assert::same(DateTime::createFromDateTimeInterface($dateTimeImmutable, $utcTimeZone)->format(), $dateTimeStringUtc); Assert::same(DateTime::createFromDateTimeInterface($dateTimeImmutable, $localTimeZone)->format(), $dateTimeString); -// createFromDateAndTime() + +createFromDateAndTime: Assert::type(DateTime::createFromDateAndTime($date, $time), DateTime::class); Assert::same(DateTime::createFromDateAndTime($date, $time)->format(), $dateTimeString); Assert::same(DateTime::createFromDateAndTime($date, $time, $utcTimeZone)->format(), $dateTimeString); // there is no timestamp. timezone is set as provided Assert::same(DateTime::createFromDateAndTime($date, $time, $localTimeZone)->format(), $dateTimeString); -// format() + +format: Assert::same((new DateTime($dateTimeString))->format(), $dateTimeString); $today = new DateTime('today 12:00'); @@ -106,30 +114,36 @@ $yesterdayDate = new Date('yesterday'); $tomorrow = new DateTime('tomorrow 12:00'); $tomorrowDate = new Date('tomorrow'); -// getDate() + +getDate: Assert::type($today->getDate(), Date::class); Assert::same($today->getDate()->format(), date(Date::DEFAULT_FORMAT)); -// getTime() + +getTime: Assert::type($today->getTime(), Time::class); Assert::equal($today->getTime(), new Time('12:00:00')); -// setTime() + +setTime: Assert::same($today->setTime(3, 4, 5, 6)->format(Time::DEFAULT_FORMAT), '03:04:05.000006'); Assert::same($today->setTime('03:04:05.000006')->format(Time::DEFAULT_FORMAT), '03:04:05.000006'); Assert::same($today->setTime(new Time('03:04:05.000006'))->format(Time::DEFAULT_FORMAT), '03:04:05.000006'); -// difference() + +difference: Assert::equal($today->difference($today), new DateTimeSpan(0, 0, 0)); Assert::equal($today->difference($yesterday), new DateTimeSpan(0, 0, -1)); Assert::equal($today->difference($tomorrow), new DateTimeSpan(0, 0, 1)); -// compare() + +compare: Assert::same($today->compare($yesterday), 1); Assert::same($today->compare($today), 0); Assert::same($today->compare($tomorrow), -1); -// equals() + +equals: Assert::false($today->equals($yesterday)); Assert::false($today->equals($tomorrow)); Assert::false($today->equals($today2)); @@ -137,7 +151,8 @@ Assert::true($today->equals($today)); Assert::true($dateTime->equals($dateTimeByOffset)); -// equalsUpTo() + +equalsUpTo: Assert::false($dateTime->equalsUpTo(new DateTime('2001-02-03 04:05:06.007008'), DateTimeUnit::year())); Assert::true($dateTime->equalsUpTo(new DateTime('2000-02-03 04:05:06.007008'), DateTimeUnit::year())); Assert::false($dateTime->equalsUpTo(new DateTime('2000-02-03 04:05:06.007008'), DateTimeUnit::month())); @@ -160,37 +175,44 @@ Assert::true($dateTime->equalsUpTo(new DateTime('2000-03-02 03:04:05.000006'), D Assert::false($dateTime->equalsUpTo(new DateTime('2000-01-03 03:04:05.000006'), DateTimeUnit::week())); Assert::true($dateTime->equalsUpTo(new DateTime('2000-01-01 03:04:05.000006'), DateTimeUnit::week())); -// timeOffsetEquals() + +timeOffsetEquals: Assert::false($dateTime->timeOffsetEquals(new DateTime($dateTimeString, $utcTimeZone))); Assert::true($dateTime->timeOffsetEquals(new DateTime($dateTimeString, $localTimeZone))); Assert::true($dateTime->timeOffsetEquals(new DateTime($dateTimeString, $localOffsetTimeZone))); -// isBefore() + +isBefore: Assert::false($today->isBefore($yesterday)); Assert::false($today->isBefore($today)); Assert::true($today->isBefore($tomorrow)); -// isAfter() + +isAfter: Assert::true($today->isAfter($yesterday)); Assert::false($today->isAfter($today)); Assert::false($today->isAfter($tomorrow)); -// isBetween() + +isBetween: Assert::false($yesterday->isBetween($today, $tomorrow)); Assert::false($tomorrow->isBetween($today, $yesterday)); Assert::true($yesterday->isBetween($yesterday, $tomorrow)); Assert::true($today->isBetween($yesterday, $tomorrow)); Assert::true($tomorrow->isBetween($yesterday, $tomorrow)); -// isFuture() + +isFuture: Assert::false($yesterday->isFuture()); Assert::true($tomorrow->isFuture()); -// isPast() + +isPast: Assert::false($tomorrow->isPast()); Assert::true($yesterday->isPast()); -// isSameDay() + +isSameDay: Assert::false($today->isSameDay($yesterday)); Assert::false($today->isSameDay($yesterdayDate)); Assert::false($today->isSameDay($tomorrow)); @@ -199,7 +221,8 @@ Assert::true($today->isSameDay($today)); Assert::true($today->isSameDay($today2)); Assert::true($today->isSameDay($todayDate)); -// isBeforeDay() + +isBeforeDay: Assert::false($today->isBeforeDay($yesterday)); Assert::false($today->isBeforeDay($yesterdayDate)); Assert::false($today->isBeforeDay($today)); @@ -208,7 +231,8 @@ Assert::false($today->isBeforeDay($todayDate)); Assert::true($today->isBeforeDay($tomorrow)); Assert::true($today->isBeforeDay($tomorrowDate)); -// isAfterDay() + +isAfterDay: Assert::true($today->isAfterDay($yesterday)); Assert::true($today->isAfterDay($yesterdayDate)); Assert::false($today->isAfterDay($today)); @@ -217,7 +241,8 @@ Assert::false($today->isAfterDay($tomorrowDate)); Assert::false($today->isAfterDay($tomorrow)); Assert::false($today->isAfterDay($tomorrowDate)); -// isBetweenDays() + +isBetweenDays: Assert::false($yesterday->isBetweenDays($today, $tomorrow)); Assert::false($yesterday->isBetweenDays($todayDate, $todayDate)); Assert::false($tomorrow->isBetweenDays($today, $yesterday)); @@ -229,22 +254,32 @@ Assert::true($today->isBetweenDays($yesterdayDate, $tomorrowDate)); Assert::true($tomorrow->isBetweenDays($yesterday, $tomorrow)); Assert::true($tomorrow->isBetweenDays($yesterdayDate, $tomorrowDate)); -// isToday() + +isToday: Assert::false($yesterday->isToday()); Assert::false($tomorrow->isToday()); Assert::true($today->isToday()); -// isYesterday() + +isYesterday: Assert::false($tomorrow->isYesterday()); Assert::false($today->isYesterday()); Assert::true($yesterday->isYesterday()); -// isTomorrow() + +isTomorrow: Assert::false($yesterday->isTomorrow()); Assert::false($today->isTomorrow()); Assert::true($tomorrow->isTomorrow()); -// isDayOfWeek() + +$monday = new Date('2016-11-07'); +$friday = new Date('2016-11-04'); +$saturday = new Date('2016-11-05'); +$sunday = new Date('2016-11-06'); + + +isDayOfWeek: Assert::false($dateTime->isDayOfWeek(DayOfWeek::monday())); Assert::false($dateTime->isDayOfWeek(DayOfWeek::tuesday())); Assert::false($dateTime->isDayOfWeek(DayOfWeek::wednesday())); @@ -253,11 +288,26 @@ Assert::false($dateTime->isDayOfWeek(DayOfWeek::friday())); Assert::false($dateTime->isDayOfWeek(DayOfWeek::saturday())); Assert::true($dateTime->isDayOfWeek(DayOfWeek::sunday())); -// isWeekend() +Assert::true($monday->isDayOfWeek(1)); +Assert::true($monday->isDayOfWeek(DayOfWeek::monday())); +Assert::false($monday->isDayOfWeek(7)); +Assert::false($monday->isDayOfWeek(DayOfWeek::sunday())); +Assert::exception(static function () use ($monday): void { + $monday->isDayOfWeek(8); +}, InvalidValueException::class); + + +isWeekend: Assert::false((new DateTime('2000-01-03'))->isWeekend()); Assert::true($dateTime->isWeekend()); -// isMonth() +Assert::false($monday->isWeekend()); +Assert::false($friday->isWeekend()); +Assert::true($saturday->isWeekend()); +Assert::true($sunday->isWeekend()); + + +isMonth: Assert::true($dateTime->isMonth(Month::january())); Assert::false($dateTime->isMonth(Month::february())); Assert::false($dateTime->isMonth(Month::march())); @@ -271,47 +321,27 @@ Assert::false($dateTime->isMonth(Month::october())); Assert::false($dateTime->isMonth(Month::november())); Assert::false($dateTime->isMonth(Month::december())); +Assert::true($monday->isMonth(11)); +Assert::true($monday->isMonth(Month::november())); +Assert::false($monday->isMonth(12)); +Assert::false($monday->isMonth(Month::december())); +Assert::exception(static function () use ($monday): void { + $monday->isMonth(13); +}, InvalidValueException::class); -$monday = new Date('2016-11-07'); -$friday = new Date('2016-11-04'); -$saturday = new Date('2016-11-05'); -$sunday = new Date('2016-11-06'); -// getDayOfWeekEnum() +getDayOfWeekEnum: Assert::equal($monday->getDayOfWeekEnum(), DayOfWeek::monday()); Assert::equal($friday->getDayOfWeekEnum(), DayOfWeek::friday()); Assert::equal($saturday->getDayOfWeekEnum(), DayOfWeek::saturday()); Assert::equal($sunday->getDayOfWeekEnum(), DayOfWeek::sunday()); -// isDayOfWeek() -Assert::true($monday->isDayOfWeek(1)); -Assert::true($monday->isDayOfWeek(DayOfWeek::monday())); -Assert::false($monday->isDayOfWeek(7)); -Assert::false($monday->isDayOfWeek(DayOfWeek::sunday())); -Assert::exception(static function () use ($monday): void { - $monday->isDayOfWeek(8); -}, InvalidValueException::class); - -// isWeekend() -Assert::false($monday->isWeekend()); -Assert::false($friday->isWeekend()); -Assert::true($saturday->isWeekend()); -Assert::true($sunday->isWeekend()); -// getMonthEnum() +getMonthEnum: Assert::equal($monday->getMonthEnum(), Month::november()); -// isMonth() -Assert::true($monday->isMonth(11)); -Assert::true($monday->isMonth(Month::november())); -Assert::false($monday->isMonth(12)); -Assert::false($monday->isMonth(Month::december())); -Assert::exception(static function () use ($monday): void { - $monday->isMonth(13); -}, InvalidValueException::class); - -// rounding +// rounding ------------------------------------------------------------------------------------------------------------ $hour = DateTimeUnit::hour(); $minute = DateTimeUnit::minute(); @@ -328,7 +358,8 @@ $criticalTime = new DateTime('2000-01-02 23:59:59.999999'); Assert::equal((new DateTime('2018-07-17 14:55:00.000000'))->roundUpTo($minute, [20]), new DateTime('2018-07-17 15:20:00.000000')); -// roundTo() + +roundTo: Assert::equal($dateTime->roundTo($hour, $hours), new DateTime('2000-01-02 00:00:00.000000')); Assert::equal($dateTime->roundTo($minute, $minutes), new DateTime('2000-01-02 03:00:00.000000')); Assert::equal($dateTime->roundTo($second, $seconds), new DateTime('2000-01-02 03:04:00.000000')); @@ -347,7 +378,8 @@ Assert::equal($criticalTime->roundTo($second, $seconds), new DateTime('2000-01-0 Assert::equal($criticalTime->roundTo($milisecond, $miliseconds), new DateTime('2000-01-03 00:00:00.000000')); Assert::equal($criticalTime->roundTo($microsecond, $microseconds), new DateTime('2000-01-03 00:00:00.000000')); -// roundUpTo() + +roundUpTo: Assert::equal($dateTime->roundUpTo($hour, $hours), new DateTime('2000-01-02 08:00:00.000000')); Assert::equal($dateTime->roundUpTo($minute, $minutes), new DateTime('2000-01-02 03:15:00.000000')); Assert::equal($dateTime->roundUpTo($second, $seconds), new DateTime('2000-01-02 03:04:15.000000')); @@ -366,7 +398,8 @@ Assert::equal($criticalTime->roundUpTo($second, $seconds), new DateTime('2000-01 Assert::equal($criticalTime->roundUpTo($milisecond, $miliseconds), new DateTime('2000-01-03 00:00:00.000000')); Assert::equal($criticalTime->roundUpTo($microsecond, $microseconds), new DateTime('2000-01-03 00:00:00.000000')); -// roundDownTo() + +roundDownTo: Assert::equal($dateTime->roundDownTo($hour, $hours), new DateTime('2000-01-02 00:00:00.000000')); Assert::equal($dateTime->roundDownTo($minute, $minutes), new DateTime('2000-01-02 03:00:00.000000')); Assert::equal($dateTime->roundDownTo($second, $seconds), new DateTime('2000-01-02 03:04:00.000000')); diff --git a/tests/src/Time/DayOfYear.phpt b/tests/src/Time/DayOfYear.phpt index b01f0d7a..f6eb8e92 100644 --- a/tests/src/Time/DayOfYear.phpt +++ b/tests/src/Time/DayOfYear.phpt @@ -18,7 +18,8 @@ $number = 60; $denormalizedNumber = $number + 366; $denormalizedDay = new DayOfYear($denormalizedNumber); -// __construct() + +__construct: Assert::throws(static function (): void { new DayOfYear(-200); }, ValueOutOfRangeException::class); @@ -43,7 +44,8 @@ Assert::throws(static function (): void { Assert::same((new DayOfYear($dayString))->format(), $dayString); -// createFromMonthAndDay() + +createFromMonthAndDay: Assert::throws(static function (): void { DayOfYear::createFromMonthAndDay(-1, 1); }, ValueOutOfRangeException::class); @@ -59,83 +61,100 @@ Assert::throws(static function (): void { Assert::type(DayOfYear::createFromMonthAndDay(2, 29), DayOfYear::class); Assert::same(DayOfYear::createFromMonthAndDay(2, 29)->format(), $dayString); -// createFromDate() + +createFromDate: $date = new Date('2000-02-29'); Assert::type(DayOfYear::createFromDate($date), DayOfYear::class); Assert::same(DayOfYear::createFromDate($date)->format(), $dayString); -// createFromDateTime() + +createFromDateTime: $dateTime = new DateTime('2000-02-29 00:00:00'); Assert::type(DayOfYear::createFromDateTime($dateTime), DayOfYear::class); Assert::same(DayOfYear::createFromDateTime($dateTime)->format(), $dayString); -// normalize() + +normalize: Assert::same($day->normalize()->getNumber(), $number); Assert::same($denormalizedDay->normalize()->getNumber(), $number); -// denormalize() + +denormalize: Assert::same($day->denormalize()->getNumber(), $denormalizedNumber); Assert::same($denormalizedDay->denormalize()->getNumber(), $denormalizedNumber); -// modify() + +modify: Assert::same($day->modify('+1 day')->getNumber(), $number + 1); Assert::same($denormalizedDay->modify('+1 day')->getNumber(), $denormalizedNumber + 1); // todo: overflows -// getNumber() + +getNumber: Assert::same($day->getNumber(), $number); Assert::same($denormalizedDay->getNumber(), $denormalizedNumber); -// getMonth() + +getMonth: Assert::same($day->getMonth(), 2); Assert::same($denormalizedDay->getMonth(), 2); -// getMonthEnum() + +getMonthEnum: Assert::equal($day->getMonthEnum(), Month::february()); Assert::equal($denormalizedDay->getMonthEnum(), Month::february()); -// getDayOfMonth() + +getDayOfMonth: Assert::same($day->getDayOfMonth(), 29); Assert::same($denormalizedDay->getDayOfMonth(), 29); -// toDate() + +toDate: Assert::equal($day->toDate(2000), new Date('2000-02-29')); Assert::equal($denormalizedDay->toDate(2000), new Date('2001-02-29')); $before = new DayOfYear('02-28'); $after = new DayOfYear('03-01'); -// equals() + +equals: Assert::false($day->equals($before)); Assert::true($day->equals(new DayOfYear($dayString))); Assert::true($day->equals(new DayOfYear($number))); -// compare() + +compare: Assert::same($day->compare($before), 1); Assert::same($day->compare($day), 0); Assert::same($day->compare($after), -1); -// isBefore() + +isBefore: Assert::false($day->isBefore($before)); Assert::false($day->isBefore($day)); Assert::true($day->isBefore($after)); -// isAfter() + +isAfter: Assert::true($day->isAfter($before)); Assert::false($day->isAfter($day)); Assert::false($day->isAfter($after)); -// isSameOrBefore() + +isSameOrBefore: Assert::false($day->isSameOrBefore($before)); Assert::true($day->isSameOrBefore($day)); Assert::true($day->isSameOrBefore($after)); -// isSameOrAfter() + +isSameOrAfter: Assert::true($day->isSameOrAfter($before)); Assert::true($day->isSameOrAfter($day)); Assert::false($day->isSameOrAfter($after)); -// isBetween() + +isBetween: Assert::false($day->isBetween(new DayOfYear('12-01'), new DayOfYear('01-31'))); Assert::true($day->isBetween($before, $after)); Assert::true($day->isBetween(new DayOfYear('12-01'), $after)); diff --git a/tests/src/Time/Interval/DateInterval.phpt b/tests/src/Time/Interval/DateInterval.phpt index fe05ebec..bb852406 100644 --- a/tests/src/Time/Interval/DateInterval.phpt +++ b/tests/src/Time/Interval/DateInterval.phpt @@ -33,12 +33,14 @@ $s = static function (DateInterval ...$items): DateIntervalSet { return new DateIntervalSet($items); }; -// __construct() + +__construct: Assert::exception(static function (): void { new DateInterval(new Date('today'), new Date('yesterday')); }, InvalidIntervalStartEndOrderException::class); -// createFromString() + +createFromString: Assert::equal(DateInterval::createFromString('2000-01-10,2000-01-20'), $interval); Assert::equal(DateInterval::createFromString('2000-01-10|2000-01-20'), $interval); Assert::equal(DateInterval::createFromString('2000-01-10/2000-01-20'), $interval); @@ -54,7 +56,8 @@ Assert::exception(static function (): void { DateInterval::createFromString('foo'); }, InvalidIntervalStringFormatException::class); -// createFromStartAndLength() + +createFromStartAndLength: Assert::equal(DateInterval::createFromStartAndLength($startDate, DateTimeUnit::year(), 2), new DateInterval($startDate, new Date('2002-01-09'))); Assert::equal(DateInterval::createFromStartAndLength($startDate, DateTimeUnit::quarter(), 2), new DateInterval($startDate, new Date('2000-07-09'))); Assert::equal(DateInterval::createFromStartAndLength($startDate, DateTimeUnit::month(), 2), new DateInterval($startDate, new Date('2000-03-09'))); @@ -64,58 +67,72 @@ Assert::exception(static function () use ($startDate): void { DateInterval::createFromStartAndLength($startDate, DateTimeUnit::hour(), 2); }, InvalidDateTimeUnitException::class); -// toDateTimeInterval() + +toDateTimeInterval: Assert::equal($interval->toDateTimeInterval(), DateTimeInterval::createFromString('2000-01-10 00:00 - 2000-01-21 00:00')); -// toDateArray() + +toDateArray: Assert::equal($i(1, 1)->toDateArray(), [$d(1)]); Assert::equal($i(1, 2)->toDateArray(), [$d(1), $d(2)]); Assert::equal($empty->toDateArray(), []); -// format() + +format: Assert::same($interval->format('d|-d'), '10-20'); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $i(11, 21)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new Date('2000-01-10')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new Date('2000-01-20')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 10)); -// getDateSpan() + +getDateSpan: Assert::equal($interval->getDateSpan(), new DateSpan(0, 0, 10)); -// getLengthInDays() + +getLengthInDays: Assert::same($interval->getLengthInDays(), 10); Assert::same($empty->getLengthInDays(), 0); -// getDayCount() + +getDayCount: Assert::same($interval->getDayCount(), 11); Assert::same($empty->getDayCount(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($i(10, 20))); Assert::false($interval->equals($i(10, 15))); Assert::false($interval->equals($i(15, 20))); -// compare() + +compare: Assert::same($interval->compare($i(10, 19)), 1); Assert::same($interval->compare($i(10, 21)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($i(9, 19)), 1); Assert::same($interval->compare($i(11, 21)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(20))); @@ -123,7 +140,8 @@ Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(25))); Assert::true($interval->containsValue(new DateTimeImmutable('2000-01-15'))); -// contains() + +contains: Assert::true($interval->contains($i(10, 20))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 20))); @@ -132,7 +150,8 @@ Assert::false($interval->contains($i(10, 25))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 25))); Assert::true($interval->intersects($i(10, 20))); Assert::true($interval->intersects($i(5, 15))); @@ -140,14 +159,16 @@ Assert::true($interval->intersects($i(15, 25))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($empty)); -// touches() + +touches: Assert::true($interval->touches($i(1, 9))); Assert::true($interval->touches($i(21, 25))); Assert::false($interval->touches($i(1, 10))); Assert::false($interval->touches($i(20, 25))); Assert::false($interval->touches($empty)); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($i(10, 15), $i(16, 20))); Assert::equal($interval->split(3), $s($i(10, 13), $i(14, 16), $i(17, 20))); @@ -155,11 +176,13 @@ Assert::equal($interval->split(4), $s($i(10, 12), $i(13, 15), $i(16, 17), $i(18, Assert::equal($interval->split(11), $s($i(10, 10), $i(11, 11), $i(12, 12), $i(13, 13), $i(14, 14), $i(15, 15), $i(16, 16), $i(17, 17), $i(18, 18), $i(19, 19), $i(20, 20))); Assert::equal($empty->split(5), $s()); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([$d(5), $d(15), $d(25)]), $s($i(10, 14), $i(15, 20))); Assert::equal($empty->splitBy([$d(5)]), $s()); -// envelope() + +envelope: Assert::equal($interval->envelope($i(5, 15)), $i(5, 20)); Assert::equal($interval->envelope($i(15, 25)), $i(10, 25)); Assert::equal($interval->envelope($i(1, 5)), $i(1, 20)); @@ -167,7 +190,8 @@ Assert::equal($interval->envelope($i(25, 30)), $i(10, 30)); Assert::equal($interval->envelope($i(1, 5), $i(25, 30)), $i(1, 30)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $i(10, 15)); Assert::equal($interval->intersect($i(15, 30)), $i(15, 20)); Assert::equal($interval->intersect($i(1, 18), $i(14, 30)), $i(14, 18)); @@ -175,7 +199,8 @@ Assert::equal($interval->intersect($i(1, 5)), $empty); Assert::equal($interval->intersect($i(1, 5), $i(5, 15)), $empty); Assert::equal($interval->intersect($empty), $empty); -// union() + +union: Assert::equal($interval->union($i(1, 15)), $s($i(1, 20))); Assert::equal($interval->union($i(15, 30)), $s($i(10, 30))); Assert::equal($interval->union($i(1, 15), $i(15, 30)), $s($i(1, 30))); @@ -183,7 +208,8 @@ Assert::equal($interval->union($i(25, 30)), $s($interval, $i(25, 30))); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($i(15, 30)), $s($i(10, 14), $i(21, 30))); Assert::equal($interval->difference($i(5, 15)), $s($i(5, 9), $i(16, 20))); Assert::equal($interval->difference($i(5, 15), $i(15, 30)), $s($i(5, 9), $i(21, 30))); @@ -194,7 +220,8 @@ Assert::equal($interval->difference($all), $s( )); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($i(16, 20))); Assert::equal($interval->subtract($i(15, 25)), $s($i(10, 14))); Assert::equal($interval->subtract($i(13, 17)), $s($i(10, 12), $i(18, 20))); @@ -204,7 +231,8 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s()); -// invert() + +invert: Assert::equal($interval->invert(), $s( new DateInterval(new Date(Date::MIN), $d(9)), new DateInterval($d(21), new Date(Date::MAX)) @@ -212,7 +240,8 @@ Assert::equal($interval->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s($empty)); -// countOverlaps() + +countOverlaps: Assert::equal(DateInterval::countOverlaps($empty), []); Assert::equal(DateInterval::countOverlaps($interval, $i(5, 15)), [ [$i(5, 9), 1], @@ -227,7 +256,8 @@ Assert::equal(DateInterval::countOverlaps($i(5, 15), $i(10, 20), $i(15, 25)), [ [$i(21, 25), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(DateInterval::explodeOverlaps($empty), []); Assert::equal($s(...DateInterval::explodeOverlaps($interval, $i(5, 15))), $s( $i(5, 9), diff --git a/tests/src/Time/Interval/DateIntervalSet.phpt b/tests/src/Time/Interval/DateIntervalSet.phpt index 9cf5400d..bdfeacf7 100644 --- a/tests/src/Time/Interval/DateIntervalSet.phpt +++ b/tests/src/Time/Interval/DateIntervalSet.phpt @@ -24,49 +24,62 @@ $emptyInterval = DateInterval::empty(); $set = new DateIntervalSet([$interval]); -// createFromDateArray() + +createFromDateArray: Assert::equal(DateIntervalSet::createFromDateArray([]), $s()); Assert::equal(DateIntervalSet::createFromDateArray([$d(1), $d(2), $d(3), $d(4), $d(5)]), $s($interval)); Assert::equal(DateIntervalSet::createFromDateArray([$d(1), $d(2), $d(4), $d(5)]), $s($i(1, 2), $i(4, 5))); -// toDateArray() + +toDateArray: Assert::equal($emptyInterval->toDateArray(), []); Assert::equal($interval->toDateArray(), [$d(1), $d(2), $d(3), $d(4), $d(5)]); Assert::equal($s($i(1, 2), $i(4, 5))->toDateArray(), [$d(1), $d(2), $d(4), $d(5)]); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new DateIntervalSet([]))->isEmpty()); Assert::true((new DateIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 6)))); -// containsValue() + +containsValue: Assert::true($set->containsValue($d(1))); Assert::true($set->containsValue($d(5))); Assert::false($set->containsValue($d(6))); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); Assert::equal($s($i(10, 13), $i(5, 9), $i(18, 21), $i(5, 6), $i(15, 19))->normalize(), $s($i(5, 13), $i(15, 21))); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 2), $i(5, 6), $i(9, 10))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (DateInterval $interval) { return $interval; }), $set); @@ -79,7 +92,8 @@ Assert::equal($set->map(static function (DateInterval $interval) { $set = $s($emptyInterval, $i(1, 1), $i(1, 2), $i(1, 3)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', 1), $s($i(1, 3))); Assert::equal($set->filterByLength('>=', 1), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByLength('=', 1), $s($i(1, 2))); @@ -87,7 +101,8 @@ Assert::equal($set->filterByLength('<>', 1), $s($emptyInterval, $i(1, 1), $i(1, Assert::equal($set->filterByLength('<=', 1), $s($emptyInterval, $i(1, 1), $i(1, 2))); Assert::equal($set->filterByLength('<', 1), $s($emptyInterval, $i(1, 1))); -// filterByCount() + +filterByCount: Assert::equal($set->filterByDayCount('>', 1), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByDayCount('>=', 1), $s($i(1, 1), $i(1, 2), $i(1, 3))); Assert::equal($set->filterByDayCount('=', 1), $s($i(1, 1))); diff --git a/tests/src/Time/Interval/DateTimeInterval.phpt b/tests/src/Time/Interval/DateTimeInterval.phpt index b40b77d5..7029387d 100644 --- a/tests/src/Time/Interval/DateTimeInterval.phpt +++ b/tests/src/Time/Interval/DateTimeInterval.phpt @@ -40,12 +40,14 @@ $s = static function (DateTimeInterval ...$items): DateTimeIntervalSet { return new DateTimeIntervalSet($items); }; -// __construct() + +__construct: Assert::exception(static function (): void { new DateTimeInterval(new DateTime('today'), new DateTime('yesterday')); }, InvalidIntervalStartEndOrderException::class); -// createFromString() + +createFromString: Assert::equal(DateTimeInterval::createFromString('2000-01-10 00:00,2000-01-20 00:00'), $interval); Assert::equal(DateTimeInterval::createFromString('2000-01-10 00:00|2000-01-20 00:00'), $interval); Assert::equal(DateTimeInterval::createFromString('2000-01-10 00:00/2000-01-20 00:00'), $interval); @@ -57,7 +59,8 @@ Assert::exception(static function (): void { DateTimeInterval::createFromString('foo'); }, InvalidIntervalStringFormatException::class); -// createFromStartAndLength() + +createFromStartAndLength: Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUnit::year(), 2), new DateTimeInterval($startTime, new DateTime('2002-01-10 00:00'))); Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUnit::quarter(), 2), new DateTimeInterval($startTime, new DateTime('2000-07-10 00:00'))); Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUnit::month(), 2), new DateTimeInterval($startTime, new DateTime('2000-03-10 00:00'))); @@ -69,72 +72,87 @@ Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUni Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUnit::milisecond(), 2), new DateTimeInterval($startTime, new DateTime('2000-01-10 00:00:00.002'))); Assert::equal(DateTimeInterval::createFromStartAndLength($startTime, DateTimeUnit::microsecond(), 2), new DateTimeInterval($startTime, new DateTime('2000-01-10 00:00:00.000002'))); -// createFromDateAndTimeInterval() + +createFromDateAndTimeInterval: Assert::equal(DateTimeInterval::createFromDateAndTimeInterval( new Date('2000-01-01'), new TimeInterval(new Time('10:00'), new Time('20:00')) ), DateTimeInterval::createFromString('2000-01-01 10:00 - 2000-01-01 20:00')); -// createFromDateIntervalAndTime() + +createFromDateIntervalAndTime: Assert::equal(DateTimeInterval::createFromDateIntervalAndTime( DateInterval::createFromString('2000-01-01 - 2000-01-05'), new Time('10:00') ), DateTimeInterval::createFromString('2000-01-01 10:00 - 2000-01-05 10:00')); -// format() + +format: Assert::same($interval->format('d|-d'), '10-20'); Assert::exception(static function () use ($interval): void { $interval->format('d|-d|-d'); }, InvalidFormattingStringException::class); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $i(11, 21)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new DateTime('2000-01-10 00:00:00.000000')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new DateTime('2000-01-20 00:00:00.000000')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 10)); -// toDateInterval() + +toDateInterval: Assert::equal($interval->toDateInterval(), new DateInterval(new Date('2000-01-10'), new Date('2000-01-19'))); -// getLengthInMicroseconds() + +getLengthInMicroseconds: Assert::same($interval->getLengthInMicroseconds(), Microseconds::DAY * 10); Assert::same($empty->getLengthInMicroseconds(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($i(10, 20))); Assert::false($interval->equals($i(10, 15))); Assert::false($interval->equals($i(15, 20))); -// compare() + +compare: Assert::same($interval->compare($i(10, 19)), 1); Assert::same($interval->compare($i(10, 21)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($i(9, 19)), 1); Assert::same($interval->compare($i(11, 21)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(19))); Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(20))); -// containsDateTime() + +containsDateTime: Assert::true($interval->containsDateTime(new PhpDateTime('2000-01-15'))); Assert::true($interval->containsDateTime(new DateTimeImmutable('2000-01-15'))); -// contains() + +contains: Assert::true($interval->contains($i(10, 20))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 20))); @@ -143,7 +161,8 @@ Assert::false($interval->contains($i(10, 25))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 22))); Assert::true($interval->intersects($i(10, 20))); Assert::true($interval->intersects($i(5, 15))); @@ -151,7 +170,8 @@ Assert::true($interval->intersects($i(15, 25))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($empty)); -// touches() + +touches: Assert::true($interval->touches($i(1, 10))); Assert::true($interval->touches($i(20, 25))); Assert::false($interval->touches($i(1, 11))); @@ -159,7 +179,8 @@ Assert::false($interval->touches($i(19, 25))); Assert::false($interval->touches($i(21, 25))); Assert::false($interval->touches($empty)); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($i(10, 15), $i(15, 20))); Assert::equal($interval->split(3), $s( @@ -169,11 +190,13 @@ Assert::equal($interval->split(3), $s( )); Assert::equal($empty->split(5), $s()); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([$d(5), $d(15), $d(25)]), $s($i(10, 15), $i(15, 20))); Assert::equal($empty->splitBy([$d(5)]), $s()); -// envelope() + +envelope: Assert::equal($interval->envelope($i(5, 15)), $i(5, 20)); Assert::equal($interval->envelope($i(15, 25)), $i(10, 25)); Assert::equal($interval->envelope($i(1, 5)), $i(1, 20)); @@ -181,7 +204,8 @@ Assert::equal($interval->envelope($i(25, 30)), $i(10, 30)); Assert::equal($interval->envelope($i(1, 5), $i(25, 30)), $i(1, 30)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $i(10, 15)); Assert::equal($interval->intersect($i(15, 30)), $i(15, 20)); Assert::equal($interval->intersect($i(1, 18), $i(14, 30)), $i(14, 18)); @@ -189,7 +213,8 @@ Assert::equal($interval->intersect($i(1, 5)), $empty); Assert::equal($interval->intersect($i(1, 5), $i(5, 15)), $empty); Assert::equal($interval->intersect($empty), $empty); -// union() + +union: Assert::equal($interval->union($i(1, 15)), $s($i(1, 20))); Assert::equal($interval->union($i(15, 30)), $s($i(10, 30))); Assert::equal($interval->union($i(1, 15), $i(15, 30)), $s($i(1, 30))); @@ -197,7 +222,8 @@ Assert::equal($interval->union($i(25, 30)), $s($interval, $i(25, 30))); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($i(15, 30)), $s($i(10, 15), $i(20, 30))); Assert::equal($interval->difference($i(5, 15)), $s($i(5, 10), $i(15, 20))); Assert::equal($interval->difference($i(5, 15), $i(15, 30)), $s($i(5, 10), $i(20, 30))); @@ -208,7 +234,8 @@ Assert::equal($interval->difference($all), $s( )); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($i(15, 20))); Assert::equal($interval->subtract($i(15, 25)), $s($i(10, 15))); Assert::equal($interval->subtract($i(13, 17)), $s($i(10, 13), $i(17, 20))); @@ -218,7 +245,8 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s()); -// invert() + +invert: Assert::equal($interval->invert(), $s( new DateTimeInterval(new DateTime(DateTime::MIN), $d(10)), new DateTimeInterval($d(20), new DateTime(DateTime::MAX)) @@ -226,7 +254,8 @@ Assert::equal($interval->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s($empty)); -// countOverlaps() + +countOverlaps: Assert::equal(DateTimeInterval::countOverlaps($empty), []); Assert::equal(DateTimeInterval::countOverlaps($interval, $i(5, 15)), [ [$i(5, 10), 1], @@ -244,7 +273,8 @@ Assert::equal(DateTimeInterval::countOverlaps( [$i(20, 25), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(DateTimeInterval::explodeOverlaps($empty), []); Assert::equal($s(...DateTimeInterval::explodeOverlaps($interval, $i(5, 15))), $s( $i(5, 10), diff --git a/tests/src/Time/Interval/DateTimeInterval.splitByUnit.phpt b/tests/src/Time/Interval/DateTimeInterval.splitByUnit.phpt index 985ef6b4..194681b1 100644 --- a/tests/src/Time/Interval/DateTimeInterval.splitByUnit.phpt +++ b/tests/src/Time/Interval/DateTimeInterval.splitByUnit.phpt @@ -19,7 +19,8 @@ $s = static function (string ...$is): DateTimeIntervalSet { }, $is)); }; -// year + +year: Assert::equal($i('2000-05-05 00:00 - 2000-06-05 00:00')->splitByUnitAligned(DateTimeUnit::year()), $s( '2000-05-05 00:00 - 2000-06-05 00:00' )); @@ -36,7 +37,8 @@ Assert::equal($i('2000-05-05 00:00 - 2001-10-05 00:00')->splitByUnit(DateTimeUni '2001-05-05 00:00 - 2001-10-05 00:00' )); -// quarter + +quarter: Assert::equal($i('2000-01-05 00:00 - 2000-01-06 00:00')->splitByUnitAligned(DateTimeUnit::quarter()), $s( '2000-01-05 00:00 - 2000-01-06 00:00' )); @@ -52,7 +54,8 @@ Assert::equal($i('2000-01-05 00:00 - 2000-05-05 00:00')->splitByUnit(DateTimeUni '2000-04-05 00:00 - 2000-05-05 00:00' )); -// month + +month: Assert::equal($i('2000-01-05 00:00 - 2000-01-06 00:00')->splitByUnitAligned(DateTimeUnit::month()), $s( '2000-01-05 00:00 - 2000-01-06 00:00' )); @@ -69,7 +72,8 @@ Assert::equal($i('2000-01-05 00:00 - 2000-02-05 00:00')->splitByUnit(DateTimeUni '2000-02-05 00:00 - 2000-02-05 00:00' )); -// week + +week: Assert::equal($i('2000-01-01 00:00 - 2000-01-02 00:00')->splitByUnitAligned(DateTimeUnit::week()), $s( '2000-01-01 00:00 - 2000-01-02 00:00' )); @@ -87,7 +91,8 @@ Assert::equal($i('2000-01-01 00:00 - 2000-01-12 00:00')->splitByUnit(DateTimeUni '2000-01-08 00:00 - 2000-01-12 00:00' )); -// day + +day: Assert::equal($i('2000-01-01 12:00 - 2000-01-01 13:00')->splitByUnitAligned(DateTimeUnit::day()), $s( '2000-01-01 12:00 - 2000-01-01 13:00' )); @@ -104,7 +109,8 @@ Assert::equal($i('2000-01-01 12:00 - 2000-01-02 12:00')->splitByUnit(DateTimeUni '2000-01-02 12:00 - 2000-01-02 12:00' )); -// hour + +hour: Assert::equal($i('2000-01-01 00:12 - 2000-01-01 00:13')->splitByUnitAligned(DateTimeUnit::hour()), $s( '2000-01-01 00:12 - 2000-01-01 00:13' )); @@ -121,7 +127,8 @@ Assert::equal($i('2000-01-01 00:12 - 2000-01-01 01:12')->splitByUnit(DateTimeUni '2000-01-01 00:12 - 2000-01-01 01:12' )); -// minute + +minute: Assert::equal($i('2000-01-01 00:00:12 - 2000-01-01 00:00:13')->splitByUnitAligned(DateTimeUnit::minute()), $s( '2000-01-01 00:00:12 - 2000-01-01 00:00:13' )); @@ -138,7 +145,8 @@ Assert::equal($i('2000-01-01 00:00:12 - 2000-01-01 00:01:12')->splitByUnit(DateT '2000-01-01 00:00:12 - 2000-01-01 00:01:12' )); -// second + +second: Assert::equal($i('2000-01-01 00:00:00.12 - 2000-01-01 00:00:00.13')->splitByUnitAligned(DateTimeUnit::second()), $s( '2000-01-01 00:00:00.12 - 2000-01-01 00:00:00.13' )); @@ -155,7 +163,8 @@ Assert::equal($i('2000-01-01 00:00:00.12 - 2000-01-01 00:00:01.12')->splitByUnit '2000-01-01 00:00:00.12 - 2000-01-01 00:00:01.12' )); -// milisecond + +milisecond: Assert::equal($i('2000-01-01 00:00:00.000012 - 2000-01-01 00:00:00.000013')->splitByUnitAligned(DateTimeUnit::milisecond()), $s( '2000-01-01 00:00:00.000012 - 2000-01-01 00:00:00.000013' )); @@ -172,7 +181,8 @@ Assert::equal($i('2000-01-01 00:00:00.000012 - 2000-01-01 00:00:00.001012')->spl '2000-01-01 00:00:00.000012 - 2000-01-01 00:00:00.001012' )); -// microsecond + +microsecond: Assert::equal($i('2000-01-01 00:00:00.000001 - 2000-01-01 00:00:00.000003')->splitByUnitAligned(DateTimeUnit::microsecond()), $s( '2000-01-01 00:00:00.000001 - 2000-01-01 00:00:00.000002', '2000-01-01 00:00:00.000002 - 2000-01-01 00:00:00.000003' diff --git a/tests/src/Time/Interval/DateTimeIntervalSet.phpt b/tests/src/Time/Interval/DateTimeIntervalSet.phpt index 8269518f..c89d9be1 100644 --- a/tests/src/Time/Interval/DateTimeIntervalSet.phpt +++ b/tests/src/Time/Interval/DateTimeIntervalSet.phpt @@ -34,7 +34,8 @@ $emptyInterval = DateTimeInterval::empty(); $set = new DateTimeIntervalSet([$interval]); $emptySet = new DateTimeIntervalSet([]); -// createFromDateAndTimeIntervalSet() + +createFromDateAndTimeIntervalSet: Assert::equal(DateTimeIntervalSet::createFromDateAndTimeIntervalSet( new Date('2000-01-01'), new TimeIntervalSet([ @@ -46,7 +47,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateAndTimeIntervalSet( DateTimeInterval::createFromString('2000-01-01 12:00 - 2000-01-01 13:00'), ])); -// createFromDateIntervalAndTimeInterval() + +createFromDateIntervalAndTimeInterval: Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndTimeInterval( DateInterval::createFromString('2000-01-01 - 2000-01-02'), TimeInterval::createFromString('10:00 - 11:00') @@ -55,7 +57,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndTimeInterval( DateTimeInterval::createFromString('2000-01-02 10:00 - 2000-01-02 11:00'), ])); -// createFromDateIntervalAndTimeIntervalSet() + +createFromDateIntervalAndTimeIntervalSet: Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndTimeIntervalSet( DateInterval::createFromString('2000-01-01 - 2000-01-02'), new TimeIntervalSet([ @@ -69,7 +72,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndTimeIntervalSet( DateTimeInterval::createFromString('2000-01-02 12:00 - 2000-01-02 13:00'), ])); -// createFromDateIntervalSetAndTimeInterval() + +createFromDateIntervalSetAndTimeInterval: Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndTimeInterval( new DateIntervalSet([ DateInterval::createFromString('2000-01-01 - 2000-01-02'), @@ -83,7 +87,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndTimeInterval( DateTimeInterval::createFromString('2000-01-06 10:00 - 2000-01-06 11:00'), ])); -// createFromDateIntervalSetAndTimeIntervalSet() + +createFromDateIntervalSetAndTimeIntervalSet: Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndTimeIntervalSet( new DateIntervalSet([ DateInterval::createFromString('2000-01-01 - 2000-01-02'), @@ -104,7 +109,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndTimeIntervalSet( DateTimeInterval::createFromString('2000-01-06 12:00 - 2000-01-06 13:00'), ])); -// createFromDateIntervalAndWeekDayHoursSet() + +createFromDateIntervalAndWeekDayHoursSet: Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndWeekDayHoursSet( DateInterval::createFromString('2000-01-01 - 2000-01-02'), new WeekDayHoursSet([ @@ -115,7 +121,8 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalAndWeekDayHoursSet( DateTimeInterval::createFromString('2000-01-02 12:00 - 2000-01-02 13:00'), ])); -// createFromDateIntervalSetAndWeekDayHoursSet() + +createFromDateIntervalSetAndWeekDayHoursSet: Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndWeekDayHoursSet( new DateIntervalSet([ DateInterval::createFromString('2000-01-01 - 2000-01-02'), @@ -130,43 +137,54 @@ Assert::equal(DateTimeIntervalSet::createFromDateIntervalSetAndWeekDayHoursSet( DateTimeInterval::createFromString('2000-01-09 12:00 - 2000-01-09 13:00'), ])); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new DateTimeIntervalSet([]))->isEmpty()); Assert::true((new DateTimeIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 5), $i(6, 7)))); Assert::false($set->equals($s($i(1, 6)))); Assert::false($set->equals($emptySet)); Assert::false($emptySet->equals($set)); -// containsValue() + +containsValue: Assert::true($set->containsValue($dt(1))); Assert::true($set->containsValue($dt(4))); Assert::false($set->containsValue($dt(5))); Assert::false($set->containsValue($dt(6))); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); Assert::equal($emptySet->envelope(), $emptyInterval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 3), $i(4, 7), $i(8, 10))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (DateTimeInterval $interval) { return $interval; }), $set); @@ -179,7 +197,8 @@ Assert::equal($set->map(static function (DateTimeInterval $interval) { $set = $s(DateTimeInterval::empty(), $i(1, 1), $i(1, 2), $i(1, 3)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', Microseconds::DAY), $s($i(1, 3))); Assert::equal($set->filterByLength('>=', Microseconds::DAY), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByLength('=', Microseconds::DAY), $s($i(1, 2))); diff --git a/tests/src/Time/Interval/DayOfYearInterval.phpt b/tests/src/Time/Interval/DayOfYearInterval.phpt index 98772d0c..f592bb3a 100644 --- a/tests/src/Time/Interval/DayOfYearInterval.phpt +++ b/tests/src/Time/Interval/DayOfYearInterval.phpt @@ -34,7 +34,8 @@ $s = static function (DayOfYearInterval ...$items): DayOfYearIntervalSet { return new DayOfYearIntervalSet($items); }; -// createFromString() + +createFromString: Assert::equal(DayOfYearInterval::createFromString('01-10,01-20'), $interval); Assert::equal(DayOfYearInterval::createFromString('01-10|01-20'), $interval); Assert::equal(DayOfYearInterval::createFromString('01-10/01-20'), $interval); @@ -46,7 +47,8 @@ Assert::exception(static function (): void { DayOfYearInterval::createFromString('foo'); }, InvalidIntervalStringFormatException::class); -// createFromStartAndLength() + +createFromStartAndLength: Assert::equal(DayOfYearInterval::createFromStartAndLength($startDay, DateTimeUnit::quarter(), 2), new DayOfYearInterval($startDay, new DayOfYear('07-10'))); Assert::equal(DayOfYearInterval::createFromStartAndLength($startDay, DateTimeUnit::month(), 2), new DayOfYearInterval($startDay, new DayOfYear('03-10'))); Assert::equal(DayOfYearInterval::createFromStartAndLength($startDay, DateTimeUnit::week(), 2), new DayOfYearInterval($startDay, new DayOfYear('01-24'))); @@ -58,44 +60,53 @@ Assert::exception(static function () use ($startDay): void { DayOfYearInterval::createFromStartAndLength($startDay, DateTimeUnit::year(), 2); }, InvalidDateTimeUnitException::class); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $i(11, 21)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new DayOfYear('01-10')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new DayOfYear('01-20')); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// isOverEndOfYear() + +isOverEndOfYear: Assert::false($interval->isOverEndOfYear()); Assert::true(DayOfYearInterval::createFromString('12-01 - 01-12')->isOverEndOfYear()); -// equals() + +equals: Assert::true($interval->equals($i(10, 20))); Assert::false($interval->equals($i(10, 15))); Assert::false($interval->equals($i(15, 20))); -// compare() + +compare: Assert::same($interval->compare($i(10, 19)), 1); Assert::same($interval->compare($i(10, 21)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($i(9, 19)), 1); Assert::same($interval->compare($i(11, 21)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(20))); Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(21))); -// contains() + +contains: Assert::true($interval->contains($i(10, 20))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 20))); @@ -104,7 +115,8 @@ Assert::false($interval->contains($i(10, 23))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 22))); Assert::true($interval->intersects($i(10, 20))); Assert::true($interval->intersects($i(5, 15))); @@ -123,7 +135,8 @@ $i2 = new DayOfYearInterval( ); Assert::true($i1->intersects($i2)); -// touches() + +touches: Assert::true($interval->touches($i(1, 9))); Assert::true($interval->touches($i(21, 23))); Assert::false($interval->touches($i(1, 10))); @@ -131,7 +144,8 @@ Assert::false($interval->touches($i(20, 23))); Assert::false($interval->touches($i(22, 23))); Assert::false($interval->touches($empty)); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($i(10, 15), $i(16, 20))); Assert::equal($interval->split(3), $s( @@ -141,11 +155,13 @@ Assert::equal($interval->split(3), $s( )); Assert::equal($empty->split(5), $s()); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([$d(5), $d(15), $d(25)]), $s($i(10, 15), $i(16, 20))); Assert::equal($empty->splitBy([$d(5)]), $s()); -// envelope() + +envelope: Assert::equal($interval->envelope($i(5, 15)), $i(5, 20)); Assert::equal($interval->envelope($i(15, 368)), $i(10, 368)); Assert::equal($interval->envelope($i(1, 5)), $i(1, 20)); @@ -153,7 +169,8 @@ Assert::equal($interval->envelope($i(21, 368)), $i(10, 368)); Assert::equal($interval->envelope($i(4, 5), $i(21, 368)), $i(4, 368)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $s($i(10, 15))); Assert::equal($interval->intersect($i(15, 375)), $s($i(15, 20))); Assert::equal($interval->intersect($i(1, 18), $i(14, 375)), $s($i(14, 18))); @@ -168,7 +185,8 @@ Assert::true($interval1->intersects($interval2)); Assert::equal($interval1->intersect($interval2)->format(), '03-25 - 03-31'); Assert::equal($interval2->intersect($interval1)->format(), '03-25 - 03-31'); -// union() + +union: Assert::equal($interval->union($i(1, 15)), $s($i(1, 20))); Assert::equal($interval->union($i(15, 368)), $s($i(10, 368))); Assert::equal($interval->union($i(4, 15), $i(15, 368)), $s($i(4, 368))); @@ -176,7 +194,8 @@ Assert::equal($interval->union($i(368, 369)), $s($i(368, 369), $interval)); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($i(15, 368)), $s($i(10, 14), $i(21, 368))); Assert::equal($interval->difference($i(5, 15)), $s($i(5, 9), $i(16, 20))); Assert::equal($interval->difference($i(5, 15), $i(15, 368)), $s($i(5, 9), $i(21, 368))); @@ -187,7 +206,8 @@ Assert::equal($interval->difference($all), $s( )); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($i(15, 20))); Assert::equal($interval->subtract($i(15, 368)), $s($i(10, 15))); Assert::equal($interval->subtract($i(13, 17)), $s($i(10, 13), $i(17, 20))); @@ -197,7 +217,8 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s()); -// invert() + +invert: Assert::equal($interval->invert(), $s( new DayOfYearInterval(new DayOfYear(DayOfYear::MIN), $d(10)), new DayOfYearInterval($d(20), new DayOfYear(DayOfYear::MAX)) @@ -205,7 +226,8 @@ Assert::equal($interval->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s($empty)); -// countOverlaps() + +countOverlaps: Assert::equal(DayOfYearInterval::countOverlaps($empty), []); Assert::equal(DayOfYearInterval::countOverlaps($interval, $all), [ [$i(1, 9), 1], @@ -229,7 +251,8 @@ Assert::equal(DayOfYearInterval::countOverlaps( [$i(21, 368), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(DayOfYearInterval::explodeOverlaps($empty), []); Assert::equal(DayOfYearInterval::explodeOverlaps($interval, $all), [ $i(1, 9), diff --git a/tests/src/Time/Interval/DayOfYearIntervalSet.phpt b/tests/src/Time/Interval/DayOfYearIntervalSet.phpt index 5a63cefb..53e3df71 100644 --- a/tests/src/Time/Interval/DayOfYearIntervalSet.phpt +++ b/tests/src/Time/Interval/DayOfYearIntervalSet.phpt @@ -29,38 +29,49 @@ $emptyInterval = DayOfYearInterval::empty(); $set = new DayOfYearIntervalSet([$interval]); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new DayOfYearIntervalSet([]))->isEmpty()); Assert::true((new DayOfYearIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 6)))); -// containsValue() + +containsValue: Assert::true($set->containsValue($d(1))); Assert::true($set->containsValue($d(5))); Assert::false($set->containsValue($d(6))); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 3), $i(4, 7), $i(8, 10))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (DayOfYearInterval $interval) { return $interval; }), $set); diff --git a/tests/src/Time/Interval/NightInterval.phpt b/tests/src/Time/Interval/NightInterval.phpt index a7b5b565..b3f7dabd 100644 --- a/tests/src/Time/Interval/NightInterval.phpt +++ b/tests/src/Time/Interval/NightInterval.phpt @@ -35,15 +35,18 @@ $s = static function (NightInterval ...$items): NightIntervalSet { return new NightIntervalSet($items); }; -// __construct() + +__construct: Assert::exception(static function (): void { new NightInterval(new Date('today'), new Date('yesterday')); }, InvalidIntervalStartEndOrderException::class); -// createFromDateInterval() + +createFromDateInterval: Assert::equal(NightInterval::createFromDateInterval(DateInterval::empty()), NightInterval::empty()); -// createFromString() + +createFromString: Assert::equal(NightInterval::createFromString('2000-01-10,2000-01-21'), $interval); Assert::equal(NightInterval::createFromString('2000-01-10|2000-01-21'), $interval); Assert::equal(NightInterval::createFromString('2000-01-10/2000-01-21'), $interval); @@ -59,7 +62,8 @@ Assert::exception(static function (): void { NightInterval::createFromString('foo'); }, InvalidIntervalStringFormatException::class); -// createFromStartAndLength() + +createFromStartAndLength: Assert::equal(NightInterval::createFromStartAndLength($startDate, DateTimeUnit::year(), 2), new NightInterval($startDate, new Date('2002-01-09'))); Assert::equal(NightInterval::createFromStartAndLength($startDate, DateTimeUnit::quarter(), 2), new NightInterval($startDate, new Date('2000-07-09'))); Assert::equal(NightInterval::createFromStartAndLength($startDate, DateTimeUnit::month(), 2), new NightInterval($startDate, new Date('2000-03-09'))); @@ -69,62 +73,76 @@ Assert::exception(static function () use ($startDate): void { NightInterval::createFromStartAndLength($startDate, DateTimeUnit::hour(), 2); }, InvalidDateTimeUnitException::class); -// toDateTimeInterval() + +toDateTimeInterval: Assert::equal($interval->toDateTimeInterval( new Time('12:00'), new Time('12:00') ), DateTimeInterval::createFromString('2000-01-10 12:00 - 2000-01-21 12:00')); -// toDateArray() + +toDateArray: Assert::equal($i(1, 2)->toDateArray(), [$d(1)]); Assert::equal($i(1, 3)->toDateArray(), [$d(1), $d(2)]); Assert::equal($empty->toDateArray(), []); -// format() + +format: Assert::same($interval->format('d|-d'), '10-21'); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $i(11, 22)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new Date('2000-01-10')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new Date('2000-01-21')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 11)); -// getDateSpan() + +getDateSpan: Assert::equal($interval->getDateSpan(), new DateSpan(0, 0, 11)); -// getLengthInDays() + +getLengthInDays: Assert::same($i(1, 3)->getLengthInDays(), 2); Assert::same($interval->getLengthInDays(), 11); Assert::same($empty->getLengthInDays(), 0); -// getNightsCount() + +getNightsCount: Assert::same($interval->getNightsCount(), 11); Assert::same($empty->getNightsCount(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($i(10, 21))); Assert::false($interval->equals($i(10, 15))); Assert::false($interval->equals($i(15, 21))); -// compare() + +compare: Assert::same($interval->compare($i(10, 20)), 1); Assert::same($interval->compare($i(10, 22)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($i(9, 20)), 1); Assert::same($interval->compare($i(11, 22)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(20))); @@ -133,7 +151,8 @@ Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(25))); Assert::true($interval->containsValue(new DateTimeImmutable('2000-01-15'))); -// contains() + +contains: Assert::true($interval->contains($i(10, 21))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 21))); @@ -143,7 +162,8 @@ Assert::false($interval->contains($i(10, 25))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 25))); Assert::true($interval->intersects($i(10, 21))); Assert::true($interval->intersects($i(5, 15))); @@ -153,7 +173,8 @@ Assert::false($interval->intersects($i(21, 25))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($empty)); -// touches() + +touches: Assert::false($interval->touches($i(1, 9))); Assert::true($interval->touches($i(1, 10))); Assert::false($interval->touches($i(1, 11))); @@ -162,7 +183,8 @@ Assert::true($interval->touches($i(21, 25))); Assert::false($interval->touches($i(22, 25))); Assert::false($interval->touches($empty)); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($i(10, 16), $i(16, 21))); Assert::equal($interval->split(3), $s($i(10, 14), $i(14, 17), $i(17, 21))); @@ -170,11 +192,13 @@ Assert::equal($interval->split(4), $s($i(10, 13), $i(13, 16), $i(16, 18), $i(18, Assert::equal($interval->split(11), $s($i(10, 11), $i(11, 12), $i(12, 13), $i(13, 14), $i(14, 15), $i(15, 16), $i(16, 17), $i(17, 18), $i(18, 19), $i(19, 20), $i(20, 21))); Assert::equal($empty->split(5), $s()); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([$d(5), $d(15), $d(25)]), $s($i(10, 15), $i(15, 21))); Assert::equal($empty->splitBy([$d(5)]), $s()); -// envelope() + +envelope: Assert::equal($interval->envelope($i(5, 15)), $i(5, 21)); Assert::equal($interval->envelope($i(15, 25)), $i(10, 25)); Assert::equal($interval->envelope($i(1, 5)), $i(1, 21)); @@ -182,7 +206,8 @@ Assert::equal($interval->envelope($i(25, 30)), $i(10, 30)); Assert::equal($interval->envelope($i(1, 5), $i(25, 30)), $i(1, 30)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $i(10, 15)); Assert::equal($interval->intersect($i(15, 30)), $i(15, 21)); Assert::equal($interval->intersect($i(1, 18), $i(14, 30)), $i(14, 18)); @@ -190,7 +215,8 @@ Assert::equal($interval->intersect($i(1, 5)), $empty); Assert::equal($interval->intersect($i(1, 5), $i(5, 15)), $empty); Assert::equal($interval->intersect($empty), $empty); -// union() + +union: Assert::equal($interval->union($i(1, 15)), $s($i(1, 21))); Assert::equal($interval->union($i(15, 30)), $s($i(10, 30))); Assert::equal($interval->union($i(1, 15), $i(15, 30)), $s($i(1, 30))); @@ -198,7 +224,8 @@ Assert::equal($interval->union($i(25, 30)), $s($interval, $i(25, 30))); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($i(15, 30)), $s($i(10, 15), $i(21, 30))); Assert::equal($interval->difference($i(5, 15)), $s($i(5, 10), $i(15, 21))); Assert::equal($interval->difference($i(5, 15), $i(15, 30)), $s($i(5, 10), $i(21, 30))); @@ -209,7 +236,8 @@ Assert::equal($interval->difference($all), $s( )); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($i(15, 21))); Assert::equal($interval->subtract($i(15, 25)), $s($i(10, 15))); Assert::equal($interval->subtract($i(13, 17)), $s($i(10, 13), $i(17, 21))); @@ -219,7 +247,8 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s()); -// invert() + +invert: Assert::equal($interval->invert(), $s( new NightInterval(new Date(Date::MIN), $d(10)), new NightInterval($d(21), new Date(Date::MAX)) @@ -227,7 +256,8 @@ Assert::equal($interval->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s($empty)); -// countOverlaps() + +countOverlaps: Assert::equal(NightInterval::countOverlaps($empty), []); Assert::equal(NightInterval::countOverlaps($interval, $i(5, 15)), [ [$i(5, 10), 1], @@ -241,7 +271,8 @@ Assert::equal(NightInterval::countOverlaps($i(5, 15), $i(10, 20), $i(15, 25)), [ [$i(20, 25), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(NightInterval::explodeOverlaps($empty), []); Assert::equal($s(...NightInterval::explodeOverlaps($interval, $i(5, 15))), $s( $i(5, 10), diff --git a/tests/src/Time/Interval/NightIntervalSet.phpt b/tests/src/Time/Interval/NightIntervalSet.phpt index dbf45769..0f4fd0bc 100644 --- a/tests/src/Time/Interval/NightIntervalSet.phpt +++ b/tests/src/Time/Interval/NightIntervalSet.phpt @@ -24,50 +24,63 @@ $emptyInterval = NightInterval::empty(); $set = new NightIntervalSet([$interval]); -// createFromDateArray() + +createFromDateArray: Assert::equal(NightIntervalSet::createFromDateArray([]), $s()); Assert::equal(NightIntervalSet::createFromDateArray([$d(1), $d(2), $d(3), $d(4), $d(5)]), $s($interval)); Assert::equal(NightIntervalSet::createFromDateArray([$d(1), $d(2), $d(4), $d(5)]), $s($i(1, 3), $i(4, 6))); -// toDateArray() + +toDateArray: Assert::equal($emptyInterval->toDateArray(), []); Assert::equal($interval->toDateArray(), [$d(1), $d(2), $d(3), $d(4), $d(5)]); Assert::equal($s($i(1, 3), $i(4, 6))->toDateArray(), [$d(1), $d(2), $d(4), $d(5)]); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new NightIntervalSet([]))->isEmpty()); Assert::true((new NightIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::false($set->equals($s($i(1, 5)))); Assert::true($set->equals($s($i(1, 6)))); Assert::false($set->equals($s($i(1, 7)))); -// containsValue() + +containsValue: Assert::true($set->containsValue($d(1))); Assert::true($set->containsValue($d(5))); Assert::false($set->containsValue($d(6))); -// envelope() + +envelope: Assert::equal($s($i(1, 3), $i(4, 6))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 6))->normalize(), $set); Assert::equal($s($i(10, 14), $i(5, 10), $i(18, 22), $i(5, 7), $i(15, 20))->normalize(), $s($i(5, 14), $i(15, 22))); -// add() + +add: Assert::equal($s($i(1, 3), $i(3, 5), $i(5, 7)), $s($i(1, 3))->add($s($i(3, 5), $i(5, 7)))); -// subtract() + +subtract: Assert::equal($s($i(1, 11))->subtract($s($i(3, 5), $i(7, 9))), $s($i(1, 3), $i(5, 7), $i(9, 11))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (NightInterval $interval) { return $interval; }), $set); @@ -80,7 +93,8 @@ Assert::equal($set->map(static function (NightInterval $interval) { $set = $s($emptyInterval, $i(1, 2), $i(1, 3), $i(1, 4)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', 1), $s($i(1, 3), $i(1, 4))); Assert::equal($set->filterByLength('>=', 1), $s($i(1, 2), $i(1, 3), $i(1, 4))); Assert::equal($set->filterByLength('=', 1), $s($i(1, 2))); @@ -88,7 +102,8 @@ Assert::equal($set->filterByLength('<>', 1), $s($emptyInterval, $i(1, 3), $i(1, Assert::equal($set->filterByLength('<=', 1), $s($emptyInterval, $i(1, 2))); Assert::equal($set->filterByLength('<', 1), $s($emptyInterval)); -// filterByCount() + +filterByCount: Assert::equal($set->filterByNightsCount('>', 1), $s($i(1, 3), $i(1, 4))); Assert::equal($set->filterByNightsCount('>=', 1), $s($i(1, 2), $i(1, 3), $i(1, 4))); Assert::equal($set->filterByNightsCount('=', 1), $s($i(1, 2))); diff --git a/tests/src/Time/Interval/TimeInterval.phpt b/tests/src/Time/Interval/TimeInterval.phpt index c1699e46..d3428d9f 100644 --- a/tests/src/Time/Interval/TimeInterval.phpt +++ b/tests/src/Time/Interval/TimeInterval.phpt @@ -37,7 +37,8 @@ $s = static function (TimeInterval ...$items): TimeIntervalSet { return new TimeIntervalSet($items); }; -// createFromString() + +createFromString: Assert::equal(TimeInterval::createFromString('10:00,20:00'), $interval); Assert::equal(TimeInterval::createFromString('10:00|20:00'), $interval); Assert::equal(TimeInterval::createFromString('10:00/20:00'), $interval); @@ -53,7 +54,8 @@ Assert::exception(static function (): void { TimeInterval::createFromString('foo'); }, InvalidIntervalStringFormatException::class); -// createFromStartAndLength() + +createFromStartAndLength: Assert::equal(TimeInterval::createFromStartAndLength($startTime, DateTimeUnit::hour(), 2), new TimeInterval($startTime, new Time('12:00'))); Assert::equal(TimeInterval::createFromStartAndLength($startTime, DateTimeUnit::minute(), 2), new TimeInterval($startTime, new Time('10:02'))); Assert::equal(TimeInterval::createFromStartAndLength($startTime, DateTimeUnit::second(), 2), new TimeInterval($startTime, new Time('10:00:02'))); @@ -63,54 +65,66 @@ Assert::exception(static function () use ($startTime): void { TimeInterval::createFromStartAndLength($startTime, DateTimeUnit::day(), 2); }, InvalidDateTimeUnitException::class); -// shift() + +shift: Assert::equal($interval->shift('+1 hour'), $i(11, 21)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new Time('10:00:00.000000')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new Time('20:00:00.000000')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 0, 10)); -// getTimeSpan() + +getTimeSpan: Assert::equal($interval->getTimeSpan(), new TimeSpan(10)); -// getLengthInMicroseconds() + +getLengthInMicroseconds: Assert::same($interval->getLengthInMicroseconds(), Microseconds::HOUR * 10); Assert::same($empty->getLengthInMicroseconds(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($all->isEmpty()); Assert::true($empty->isEmpty()); -// isOverMidnight() + +isOverMidnight: Assert::false($interval->isOverMidnight()); Assert::true(TimeInterval::createFromString('20:00 - 04:00')->isOverMidnight()); -// equals() + +equals: Assert::true($interval->equals($i(10, 20))); Assert::false($interval->equals($i(10, 15))); Assert::false($interval->equals($i(15, 20))); -// compare() + +compare: Assert::same($interval->compare($i(10, 19)), 1); Assert::same($interval->compare($i(10, 21)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($i(9, 19)), 1); Assert::same($interval->compare($i(11, 21)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($t(10))); Assert::true($interval->containsValue($t(15))); Assert::true($interval->containsValue($t(19))); Assert::false($interval->containsValue($t(5))); Assert::false($interval->containsValue($t(20))); -// contains() + +contains: Assert::true($interval->contains($i(10, 20))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 20))); @@ -119,7 +133,8 @@ Assert::false($interval->contains($i(10, 23))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($empty)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 22))); Assert::true($interval->intersects($i(10, 20))); Assert::true($interval->intersects($i(5, 15))); @@ -127,7 +142,8 @@ Assert::true($interval->intersects($i(15, 23))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($empty)); -// touches() + +touches: Assert::true($interval->touches($i(1, 10))); Assert::true($interval->touches($i(20, 23))); Assert::false($interval->touches($i(1, 11))); @@ -135,7 +151,8 @@ Assert::false($interval->touches($i(19, 23))); Assert::false($interval->touches($i(21, 23))); Assert::false($interval->touches($empty)); -// split() + +split: Assert::equal($interval->split(1), $s($interval)); Assert::equal($interval->split(2), $s($i(10, 15), $i(15, 20))); Assert::equal($interval->split(3), $s( @@ -145,11 +162,13 @@ Assert::equal($interval->split(3), $s( )); Assert::equal($empty->split(5), $s()); -// splitBy() + +splitBy: Assert::equal($interval->splitBy([$t(5), $t(15), $t(25)]), $s($i(10, 15), $i(15, 20))); Assert::equal($empty->splitBy([$t(5)]), $s()); -// envelope() + +envelope: Assert::equal($interval->envelope($i(5, 15)), $i(5, 20)); Assert::equal($interval->envelope($i(15, 25)), $i(10, 25)); Assert::equal($interval->envelope($i(1, 5)), $i(1, 20)); @@ -157,7 +176,8 @@ Assert::equal($interval->envelope($i(21, 25)), $i(10, 25)); Assert::equal($interval->envelope($i(4, 5), $i(21, 25)), $i(4, 25)); Assert::equal($interval->envelope($empty), $interval); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $s($i(10, 15))); Assert::equal($interval->intersect($i(15, 25)), $s($i(15, 20))); Assert::equal($interval->intersect($i(1, 18), $i(14, 25)), $s($i(14, 18))); @@ -172,7 +192,8 @@ Assert::true($interval1->intersects($interval2)); Assert::equal($interval1->intersect($interval2)->format('h:i| - h:i'), '03:25 - 03:31'); Assert::equal($interval2->intersect($interval1)->format('h:i| - h:i'), '03:25 - 03:31'); -// union() + +union: Assert::equal($interval->union($i(1, 15)), $s($i(1, 20))); Assert::equal($interval->union($i(15, 25)), $s($i(10, 25))); Assert::equal($interval->union($i(4, 15), $i(15, 25)), $s($i(4, 25))); @@ -180,7 +201,8 @@ Assert::equal($interval->union($i(25, 26)), $s($i(25, 26), $interval)); Assert::equal($interval->union($all), $s($all)); Assert::equal($interval->union($empty), $s($interval)); -// difference() + +difference: Assert::equal($interval->difference($i(15, 25)), $s($i(10, 15), $i(20, 25))); Assert::equal($interval->difference($i(5, 15)), $s($i(5, 10), $i(15, 20))); Assert::equal($interval->difference($i(5, 15), $i(15, 25)), $s($i(5, 10), $i(20, 25))); @@ -191,7 +213,8 @@ Assert::equal($interval->difference($all), $s( )); Assert::equal($interval->difference($empty), $s($interval)); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($i(15, 20))); Assert::equal($interval->subtract($i(15, 25)), $s($i(10, 15))); Assert::equal($interval->subtract($i(13, 17)), $s($i(10, 13), $i(17, 20))); @@ -201,7 +224,8 @@ Assert::equal($interval->subtract($all), $s()); Assert::equal($all->subtract($empty), $s($all)); Assert::equal($empty->subtract($empty), $s()); -// invert() + +invert: Assert::equal($interval->invert(), $s( new TimeInterval(new Time(Time::MIN), $t(10)), new TimeInterval($t(20), new Time(Time::MAX)) @@ -209,7 +233,8 @@ Assert::equal($interval->invert(), $s( Assert::equal($empty->invert(), $s($all)); Assert::equal($all->invert(), $s($empty)); -// countOverlaps() + +countOverlaps: Assert::equal(TimeInterval::countOverlaps($empty), []); Assert::equal(TimeInterval::countOverlaps($interval, $i(5, 15)), [ [$i(5, 10), 1], @@ -227,7 +252,8 @@ Assert::equal(TimeInterval::countOverlaps( [$i(20, 25), 1], ]); -// explodeOverlaps() + +explodeOverlaps: Assert::equal(TimeInterval::explodeOverlaps($empty), []); Assert::equal($s(...TimeInterval::explodeOverlaps($interval, $i(5, 15))), $s( $i(5, 10), diff --git a/tests/src/Time/Interval/TimeIntervalSet.phpt b/tests/src/Time/Interval/TimeIntervalSet.phpt index 2b3e23ed..fe1ffcc9 100644 --- a/tests/src/Time/Interval/TimeIntervalSet.phpt +++ b/tests/src/Time/Interval/TimeIntervalSet.phpt @@ -25,39 +25,50 @@ $emptyInterval = TimeInterval::empty(); $set = new TimeIntervalSet([$interval]); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new TimeIntervalSet([]))->isEmpty()); Assert::true((new TimeIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($s($i(1, 5)))); Assert::false($set->equals($s($i(1, 6)))); -// containsValue() + +containsValue: Assert::true($set->containsValue($t(1))); Assert::true($set->containsValue($t(4))); Assert::false($set->containsValue($t(5))); Assert::false($set->containsValue($t(6))); -// envelope() + +envelope: Assert::equal($s($i(1, 2), $i(4, 5))->envelope(), $interval); -// normalize() + +normalize: Assert::equal($s($i(1, 4), $i(2, 5))->normalize(), $set); -// add() + +add: Assert::equal($s($i(1, 2), $i(3, 4), $i(5, 6)), $s($i(1, 2))->add($s($i(3, 4), $i(5, 6)))); -// subtract() + +subtract: Assert::equal($s($i(1, 10))->subtract($s($i(3, 4), $i(7, 8))), $s($i(1, 3), $i(4, 7), $i(8, 10))); -// intersect() + +intersect: Assert::equal($s($i(1, 5), $i(10, 15))->intersect($s($i(4, 12), $i(14, 20))), $s($i(4, 5), $i(10, 12), $i(14, 15))); -// map() + +map: Assert::equal($set->map(static function (TimeInterval $interval) { return $interval; }), $set); @@ -70,7 +81,8 @@ Assert::equal($set->map(static function (TimeInterval $interval) { $set = $s(TimeInterval::empty(), $i(1, 1), $i(1, 2), $i(1, 3)); -// filterByLength() + +filterByLength: Assert::equal($set->filterByLength('>', Microseconds::HOUR), $s($i(1, 3))); Assert::equal($set->filterByLength('>=', Microseconds::HOUR), $s($i(1, 2), $i(1, 3))); Assert::equal($set->filterByLength('=', Microseconds::HOUR), $s($i(1, 2))); diff --git a/tests/src/Time/Interval/WeekDateInterval.phpt b/tests/src/Time/Interval/WeekDateInterval.phpt index 16787cea..45271021 100644 --- a/tests/src/Time/Interval/WeekDateInterval.phpt +++ b/tests/src/Time/Interval/WeekDateInterval.phpt @@ -18,6 +18,8 @@ $d = static function (int $day): Date { return new Date('2000-01-' . $day); }; + +__construct: // wrong start day Assert::exception(static function () use ($d): void { new WeekDateInterval($d(1), $d(8)); @@ -33,23 +35,29 @@ Assert::exception(static function () use ($startDate, $d): void { new WeekDateInterval($startDate, $d(20)); }, InvalidWeekDateIntervalException::class); -// createFromDate() + +createFromDate: Assert::equal(WeekDateInterval::createFromDate(new Date('2000-01-13')), $interval); -// createFromDateTime() + +createFromDateTime: Assert::equal(WeekDateInterval::createFromDate($d(13)), $interval); -// createFromYearAndWeekNumber() + +createFromYearAndWeekNumber: Assert::equal(WeekDateInterval::createFromIsoYearAndWeek(2000, 2), $interval); -// previous() + +previous: $previous = WeekDateInterval::createFromIsoYearAndWeek(2000, 1); Assert::equal($interval->previous(), $previous); -// next() + +next: $next = WeekDateInterval::createFromIsoYearAndWeek(2000, 3); Assert::equal($interval->next(), $next); -// createOverlappingIntervals() + +createOverlappingIntervals: Assert::equal(WeekDateInterval::createOverlappingIntervals($interval), [$interval]); Assert::equal(WeekDateInterval::createOverlappingIntervals(new DateInterval($d(5), $d(20))), [$previous, $interval, $next]); diff --git a/tests/src/Time/IntervalData/DateIntervalData.phpt b/tests/src/Time/IntervalData/DateIntervalData.phpt index 3403612b..a0849e21 100644 --- a/tests/src/Time/IntervalData/DateIntervalData.phpt +++ b/tests/src/Time/IntervalData/DateIntervalData.phpt @@ -37,61 +37,75 @@ $s = static function (DateIntervalData ...$items): DateIntervalDataSet { return new DateIntervalDataSet($items); }; -// __construct() + +__construct: Assert::exception(static function () use ($data): void { new DateIntervalData(new Date('today'), new Date('yesterday'), $data); }, InvalidIntervalStartEndOrderException::class); -// toDateInterval() + +toDateInterval: Assert::equal($interval->toDateInterval(), DateInterval::createFromString('2000-01-10 - 2000-01-20')); -// toDateDataArray() + +toDateDataArray: Assert::equal($di(1, 1)->toDateDataArray(), [[$d(1), $data]]); Assert::equal($di(1, 2)->toDateDataArray(), [[$d(1), $data], [$d(2), $data]]); Assert::equal($emptyData->toDateDataArray(), []); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $di(11, 21)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new Date('2000-01-10')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new Date('2000-01-20')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 10)); -// getDateSpan() + +getDateSpan: Assert::equal($interval->getDateSpan(), new DateSpan(0, 0, 10)); -// getLengthInDays() + +getLengthInDays: Assert::same($interval->getLengthInDays(), 10); Assert::same($emptyData->getLengthInDays(), 0); -// getDayCount() + +getDayCount: Assert::same($interval->getDayCount(), 11); Assert::same($emptyData->getDayCount(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($allData->isEmpty()); Assert::true($emptyData->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($di(10, 20))); Assert::false($interval->equals($di(10, 15))); Assert::false($interval->equals($di(15, 20))); -// compare() + +compare: Assert::same($interval->compare($di(10, 19)), 1); Assert::same($interval->compare($di(10, 21)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($di(9, 19)), 1); Assert::same($interval->compare($di(11, 21)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(20))); @@ -99,7 +113,8 @@ Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(25))); Assert::true($interval->containsValue(new DateTimeImmutable('2000-01-15'))); -// contains() + +contains: Assert::true($interval->contains($i(10, 20))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 20))); @@ -108,7 +123,8 @@ Assert::false($interval->contains($i(10, 25))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($emptyInterval)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 25))); Assert::true($interval->intersects($i(10, 20))); Assert::true($interval->intersects($i(5, 15))); @@ -116,14 +132,16 @@ Assert::true($interval->intersects($i(15, 25))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($emptyInterval)); -// touches() + +touches: Assert::true($interval->touches($i(1, 9))); Assert::true($interval->touches($i(21, 25))); Assert::false($interval->touches($i(1, 10))); Assert::false($interval->touches($i(20, 25))); Assert::false($interval->touches($emptyInterval)); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $di(10, 15)); Assert::equal($interval->intersect($i(15, 30)), $di(15, 20)); Assert::equal($interval->intersect($i(1, 18), $i(14, 30)), $di(14, 18)); @@ -131,7 +149,8 @@ Assert::equal($interval->intersect($i(1, 5)), $emptyData); Assert::equal($interval->intersect($i(1, 5), $i(5, 15)), $emptyData); Assert::equal($interval->intersect($emptyInterval), $emptyData); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($di(16, 20))); Assert::equal($interval->subtract($i(15, 25)), $s($di(10, 14))); Assert::equal($interval->subtract($i(13, 17)), $s($di(10, 12), $di(18, 20))); diff --git a/tests/src/Time/IntervalData/DateIntervalDataSet.phpt b/tests/src/Time/IntervalData/DateIntervalDataSet.phpt index 0024c901..b84e7ec8 100644 --- a/tests/src/Time/IntervalData/DateIntervalDataSet.phpt +++ b/tests/src/Time/IntervalData/DateIntervalDataSet.phpt @@ -44,41 +44,52 @@ $interval = new DateIntervalData($d(1), $d(5), 1); $emptyInterval = DateInterval::empty(); $set = new DateIntervalDataSet([$interval]); -// toDateDataArray() + +toDateDataArray: Assert::equal($emptyInterval->toDateArray(), []); Assert::equal($interval->toDateDataArray(), [[$d(1), 1], [$d(2), 1], [$d(3), 1], [$d(4), 1], [$d(5), 1]]); Assert::equal($ds('1-2, 4-5')->toDateDataArray(), [[$d(1), 1], [$d(2), 1], [$d(4), 1], [$d(5), 1]]); -// getIntervals() & getIterator() + +getIntervals: +getIterator: Assert::same($set->getIntervals(), iterator_to_array($set->getIterator())); -// isEmpty() + +isEmpty: Assert::true((new DateIntervalSet([]))->isEmpty()); Assert::true((new DateIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($ds('1-5'))); Assert::false($set->equals($ds('1-6'))); -// containsValue() + +containsValue: Assert::true($set->containsValue($d(1))); Assert::true($set->containsValue($d(5))); Assert::false($set->containsValue($d(6))); -// normalize() + +normalize: Assert::equal($ds('1-4, 2-5')->normalize(), $set); Assert::equal($ds('10-13, 5-9, 18-21, 5-6, 15-19')->normalize(), $ds('5-13, 15-21')); -// add() + +add: Assert::equal($ds('1-2')->add($ds('3-4, 5-6')), $ds('1-2, 3-4, 5-6')); -// subtract() + +subtract: Assert::equal($ds('1-10')->subtract($s('3-4, 7-8')), $ds('1-2, 5-6, 9-10')); -// intersect() + +intersect: Assert::equal($ds('1-5, 10-15')->intersect($s('4-12, 14-20')), $ds('4-5, 10-12, 14-15')); -// map() + +map: Assert::equal($set->map(static function (DateIntervalData $interval) { return $interval; }), $set); @@ -89,15 +100,18 @@ Assert::equal($set->map(static function (DateIntervalData $interval) use ($i) { return $interval->subtract($i('3-3'))->getIntervals(); }), $ds('1-2, 4-5')); -// collect() -// collectData() +collect: + + +collectData: $reducer = static function (int $state, $data): int { return $state + $data; }; -// modifyData() + +modifyData: Call::withArgs(static function ($orig, $input, $output, $i) use ($ds, $reducer): void { $orig = $ds($orig); $input = $ds($input); @@ -129,7 +143,8 @@ $reducer = static function (int $state, $data): int { return $state + $data[1]; }; -// modifyDataByStream() + +modifyDataByStream: Call::withArgs(static function ($orig, $input, $output, $i) use ($ds, $di, $mapper, $reducer): void { $orig = $ds($orig); $input = $di($input); diff --git a/tests/src/Time/IntervalData/NightIntervalData.phpt b/tests/src/Time/IntervalData/NightIntervalData.phpt index 492276f8..9cee176e 100644 --- a/tests/src/Time/IntervalData/NightIntervalData.phpt +++ b/tests/src/Time/IntervalData/NightIntervalData.phpt @@ -37,62 +37,76 @@ $s = static function (NightIntervalData ...$items): NightIntervalDataSet { return new NightIntervalDataSet($items); }; -// __construct() + +__construct: Assert::exception(static function () use ($data): void { new NightIntervalData(new Date('today'), new Date('yesterday'), $data); }, InvalidIntervalStartEndOrderException::class); -// toNightInterval() + +toNightInterval: Assert::equal($interval->toNightInterval(), NightInterval::createFromString('2000-01-10 - 2000-01-21')); -// toDateDataArray() + +toDateDataArray: Assert::equal($di(1, 2)->toDateDataArray(), [[$d(1), $data]]); Assert::equal($di(1, 3)->toDateDataArray(), [[$d(1), $data], [$d(2), $data]]); Assert::equal($emptyData->toDateDataArray(), []); -// shift() + +shift: Assert::equal($interval->shift('+1 day'), $di(11, 22)); -// getStart() + +getStart: Assert::equal($interval->getStart(), new Date('2000-01-10')); -// getEnd() + +getEnd: Assert::equal($interval->getEnd(), new Date('2000-01-21')); -// getSpan() + +getSpan: Assert::equal($interval->getSpan(), new DateTimeSpan(0, 0, 11)); -// getDateSpan() + +getDateSpan: Assert::equal($interval->getDateSpan(), new DateSpan(0, 0, 11)); -// getLengthInDays() + +getLengthInDays: Assert::same($i(1, 3)->getLengthInDays(), 2); Assert::same($interval->getLengthInDays(), 11); Assert::same($emptyData->getLengthInDays(), 0); -// getNightsCount() + +getNightsCount: Assert::same($interval->getDayCount(), 11); Assert::same($emptyData->getDayCount(), 0); -// isEmpty() + +isEmpty: Assert::false($interval->isEmpty()); Assert::false($allData->isEmpty()); Assert::true($emptyData->isEmpty()); -// equals() + +equals: Assert::true($interval->equals($di(10, 21))); Assert::false($interval->equals($di(10, 15))); Assert::false($interval->equals($di(15, 21))); -// compare() + +compare: Assert::same($interval->compare($di(10, 20)), 1); Assert::same($interval->compare($di(10, 22)), -1); Assert::same($interval->compare($interval), 0); Assert::same($interval->compare($di(9, 20)), 1); Assert::same($interval->compare($di(11, 22)), -1); -// containsValue() + +containsValue: Assert::true($interval->containsValue($d(10))); Assert::true($interval->containsValue($d(15))); Assert::true($interval->containsValue($d(20))); @@ -101,7 +115,8 @@ Assert::false($interval->containsValue($d(5))); Assert::false($interval->containsValue($d(25))); Assert::true($interval->containsValue(new DateTimeImmutable('2000-01-15'))); -// contains() + +contains: Assert::true($interval->contains($i(10, 21))); Assert::true($interval->contains($i(10, 15))); Assert::true($interval->contains($i(15, 21))); @@ -111,7 +126,8 @@ Assert::false($interval->contains($i(10, 25))); Assert::false($interval->contains($i(1, 5))); Assert::false($interval->contains($emptyInterval)); -// intersects() + +intersects: Assert::true($interval->intersects($i(5, 25))); Assert::true($interval->intersects($i(10, 21))); Assert::true($interval->intersects($i(5, 15))); @@ -121,7 +137,8 @@ Assert::false($interval->intersects($i(21, 25))); Assert::false($interval->intersects($i(1, 5))); Assert::false($interval->intersects($emptyInterval)); -// touches() + +touches: Assert::false($interval->touches($i(1, 9))); Assert::true($interval->touches($i(21, 25))); Assert::true($interval->touches($i(1, 10))); @@ -130,7 +147,8 @@ Assert::true($interval->touches($i(21, 25))); Assert::false($interval->touches($i(22, 25))); Assert::false($interval->touches($emptyInterval)); -// intersect() + +intersect: Assert::equal($interval->intersect($i(1, 15)), $di(10, 15)); Assert::equal($interval->intersect($i(15, 30)), $di(15, 21)); Assert::equal($interval->intersect($i(1, 18), $i(14, 30)), $di(14, 18)); @@ -138,7 +156,8 @@ Assert::equal($interval->intersect($i(1, 5)), $emptyData); Assert::equal($interval->intersect($i(1, 5), $i(5, 15)), $emptyData); Assert::equal($interval->intersect($emptyInterval), $emptyData); -// subtract() + +subtract: Assert::equal($interval->subtract($i(5, 15)), $s($di(15, 21))); Assert::equal($interval->subtract($i(15, 25)), $s($di(10, 15))); Assert::equal($interval->subtract($i(13, 17)), $s($di(10, 13), $di(17, 21))); diff --git a/tests/src/Time/IntervalData/NightIntervalDataSet.phpt b/tests/src/Time/IntervalData/NightIntervalDataSet.phpt index 32e593a2..0b209600 100644 --- a/tests/src/Time/IntervalData/NightIntervalDataSet.phpt +++ b/tests/src/Time/IntervalData/NightIntervalDataSet.phpt @@ -44,38 +44,47 @@ $interval = new NightIntervalData($d(1), $d(5), 1); $emptyInterval = NightInterval::empty(); $set = new NightIntervalDataSet([$interval]); -// toDateDataArray() + +toDateDataArray: Assert::equal($emptyInterval->toDateArray(), []); Assert::equal($interval->toDateDataArray(), [[$d(1), 1], [$d(2), 1], [$d(3), 1], [$d(4), 1]]); Assert::equal($ds('1-3, 4-6')->toDateDataArray(), [[$d(1), 1], [$d(2), 1], [$d(4), 1], [$d(5), 1]]); -// isEmpty() + +isEmpty: Assert::true((new NightIntervalSet([]))->isEmpty()); Assert::true((new NightIntervalSet([$emptyInterval]))->isEmpty()); -// equals() + +equals: Assert::true($set->equals($ds('1-5'))); Assert::false($set->equals($ds('1-6'))); -// containsValue() + +containsValue: Assert::true($set->containsValue($d(1))); Assert::true($set->containsValue($d(4))); Assert::false($set->containsValue($d(5))); -// normalize() + +normalize: Assert::equal($ds('1-4, 2-5')->normalize(), $set); Assert::equal($ds('10-14, 5-10, 18-22, 5-7, 15-20')->normalize(), $ds('5-14, 15-22')); -// add() + +add: Assert::equal($ds('1-2, 3-4, 5-6'), $ds('1-2')->add($ds('3-4, 5-6'))); -// subtract() + +subtract: Assert::equal($ds('1-11')->subtract($s('3-5, 7-9')), $ds('1-3, 5-7, 9-11')); -// intersect() + +intersect: Assert::equal($ds('1-5, 10-15')->intersect($s('4-12, 14-20')), $ds('4-5, 10-12, 14-15')); -// map() + +map: Assert::equal($set->map(static function (NightIntervalData $interval) { return $interval; }), $set); @@ -86,15 +95,18 @@ Assert::equal($set->map(static function (NightIntervalData $interval) use ($i) { return $interval->subtract($i('3-4'))->getIntervals(); }), $ds('1-3, 4-5')); -// collect() -// collectData() +collect: + + +collectData: $reducer = static function (int $state, int $change): int { return $state + $change; }; -// modifyData() + +modifyData: Call::withArgs(static function ($orig, $input, $output, $i) use ($ds, $reducer): void { $orig = $ds($orig); $input = $ds($input); @@ -126,7 +138,8 @@ $reducer = static function (int $state, $data): int { return $state + $data[1]; }; -// modifyDataByStream() + +modifyDataByStream: Call::withArgs(static function ($orig, $input, $output, $i) use ($ds, $di, $mapper, $reducer): void { $orig = $ds($orig); $input = $di($input); diff --git a/tests/src/Time/Time.phpt b/tests/src/Time/Time.phpt index 6ff31f40..9faa8b74 100644 --- a/tests/src/Time/Time.phpt +++ b/tests/src/Time/Time.phpt @@ -16,7 +16,8 @@ $microSeconds = 11045000006; $denormalizedTime = new Time('27:04:05.000006'); $denormalizedMicroSeconds = 97445000006; -// __construct() + +__construct: Assert::throws(static function (): void { new Time(-200); }, ValueOutOfRangeException::class); @@ -26,98 +27,117 @@ Assert::throws(static function (): void { Assert::same((new Time($timeString))->format(), $timeString); -// createFromComponents() + +createFromComponents: Assert::throws(static function (): void { Time::createFromComponents(-1, 0, 0); }, ValueOutOfRangeException::class); Assert::type(Time::createFromComponents(3, 4, 5, 6), Time::class); Assert::same(Time::createFromComponents(3, 4, 5, 6)->format(), $timeString); -// createFromSeconds() + +createFromSeconds: Assert::throws(static function (): void { Time::createFromSeconds(-1); }, ValueOutOfRangeException::class); Assert::type(Time::createFromSeconds((int) ($microSeconds / 1000000)), Time::class); Assert::same(Time::createFromSeconds((int) ($microSeconds / 1000000))->format(), '03:04:05.000000'); -// createFromFormat() + +createFromFormat: Assert::throws(static function (): void { Time::createFromFormat(Time::DEFAULT_FORMAT, 'asdf'); }, InvalidDateTimeException::class); Assert::type(Time::createFromFormat(Time::DEFAULT_FORMAT, $timeString), Time::class); Assert::same(Time::createFromFormat(Time::DEFAULT_FORMAT, $timeString)->format(), $timeString); -// normalize() + +normalize: Assert::same($time->normalize()->getMicroTime(), $microSeconds); Assert::same($denormalizedTime->normalize()->getMicroTime(), $microSeconds); -// denormalize() + +denormalize: Assert::same($time->denormalize()->getMicroTime(), $denormalizedMicroSeconds); Assert::same($denormalizedTime->denormalize()->getMicroTime(), $denormalizedMicroSeconds); -// modify() + +modify: Assert::same($time->modify('+1 hour')->getMicroTime(), $microSeconds + 3600 * 1000000); Assert::same($denormalizedTime->modify('+1 hour')->getMicroTime(), $denormalizedMicroSeconds + 3600 * 1000000); // todo: overflows -// getMicroTime() + +getMicroTime: Assert::same($time->getMicroTime(), $microSeconds); Assert::same($denormalizedTime->getMicroTime(), $denormalizedMicroSeconds); -// getHours() + +getHours: Assert::same($time->getHours(), 3); Assert::same($denormalizedTime->getHours(), 3); -// getMinutes() + +getMinutes: Assert::same($time->getMinutes(), 4); Assert::same($denormalizedTime->getMinutes(), 4); -// getSeconds() + +getSeconds: Assert::same($time->getSeconds(), 5); Assert::same($denormalizedTime->getSeconds(), 5); -// getMicroseconds() + +getMicroseconds: Assert::same($time->getMicroseconds(), 6); Assert::same($denormalizedTime->getMicroseconds(), 6); $before = new Time('02:00:00'); $after = new Time('04:00:00'); -// equals() + +equals: Assert::false($time->equals(new Time(0))); Assert::true($time->equals(new Time($timeString))); -// compare() + +compare: Assert::same($time->compare($before), 1); Assert::same($time->compare($time), 0); Assert::same($time->compare($after), -1); -// isBefore() + +isBefore: Assert::false($time->isBefore($before)); Assert::false($time->isBefore($time)); Assert::true($time->isBefore($after)); -// isAfter() + +isAfter: Assert::true($time->isAfter($before)); Assert::false($time->isAfter($time)); Assert::false($time->isAfter($after)); -// isSameOrBefore() + +isSameOrBefore: Assert::false($time->isSameOrBefore($before)); Assert::true($time->isSameOrBefore($time)); Assert::true($time->isSameOrBefore($after)); -// isSameOrAfter() + +isSameOrAfter: Assert::true($time->isSameOrAfter($before)); Assert::true($time->isSameOrAfter($time)); Assert::false($time->isSameOrAfter($after)); -// isBetween() + +isBetween: Assert::false($time->isBetween(new Time('10:00:00'), new Time('12:00:00'))); Assert::true($time->isBetween(new Time('02:00:00'), new Time('04:00:00'))); Assert::true($time->isBetween(new Time('22:00:00'), new Time('04:00:00'))); -// rounding + +// rounding ------------------------------------------------------------------------------------------------------------ $hour = DateTimeUnit::hour(); $minute = DateTimeUnit::minute(); @@ -134,7 +154,8 @@ $criticalTime = new Time('23:59:59.999999'); Assert::equal((new Time('14:55:00.000000'))->roundUpTo($minute, [20]), new Time('15:20:00.000000')); -// roundTo() + +roundTo: Assert::equal($time->roundTo($hour, $hours), new Time('00:00:00.000000')); Assert::equal($time->roundTo($minute, $minutes), new Time('03:00:00.000000')); Assert::equal($time->roundTo($second, $seconds), new Time('03:04:00.000000')); @@ -153,7 +174,8 @@ Assert::equal($criticalTime->roundTo($second, $seconds), new Time('00:00:00.0000 Assert::equal($criticalTime->roundTo($milisecond, $miliseconds), new Time('00:00:00.000000')); Assert::equal($criticalTime->roundTo($microsecond, $microseconds), new Time('00:00:00.000000')); -// roundUpTo() + +roundUpTo: Assert::equal($time->roundUpTo($hour, $hours), new Time('08:00:00.000000')); Assert::equal($time->roundUpTo($minute, $minutes), new Time('03:15:00.000000')); Assert::equal($time->roundUpTo($second, $seconds), new Time('03:04:15.000000')); @@ -172,7 +194,8 @@ Assert::equal($criticalTime->roundUpTo($second, $seconds), new Time('00:00:00.00 Assert::equal($criticalTime->roundUpTo($milisecond, $miliseconds), new Time('00:00:00.000000')); Assert::equal($criticalTime->roundUpTo($microsecond, $microseconds), new Time('00:00:00.000000')); -// roundDownTo() + +roundDownTo: Assert::equal($time->roundDownTo($hour, $hours), new Time('00:00:00.000000')); Assert::equal($time->roundDownTo($minute, $minutes), new Time('03:00:00.000000')); Assert::equal($time->roundDownTo($second, $seconds), new Time('03:04:00.000000')); diff --git a/tests/src/common/lists/Arr/Arr.basic.phpt b/tests/src/common/lists/Arr/Arr.basic.phpt index a6f635c0..0e44ec7e 100644 --- a/tests/src/common/lists/Arr/Arr.basic.phpt +++ b/tests/src/common/lists/Arr/Arr.basic.phpt @@ -11,34 +11,42 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = [1, 2, 3]; -// toArray() +toArray: Assert::same(Arr::toArray(new ImmutableArray([1, 2, 3])), [1, 2, 3]); -// combine() + +combine: Assert::same(Arr::combine([1, 2, 3], [4, 5, 6]), [1 => 4, 2 => 5, 3 => 6]); -// range() + +range: Assert::same(Arr::range(3, 5), [3, 4, 5]); Assert::same(Arr::range(5, 3), [5, 4, 3]); Assert::same(Arr::range(3, 7, 2), [3, 5, 7]); Assert::same(Arr::range(3, 6, 2), [3, 5]); -// backwards() + +backwards: Assert::type(Arr::backwards($array), ReverseArrayIterator::class); -// keys() + +keys: Assert::same(Arr::keys($array), [0, 1, 2]); -// getValues() + +getValues: Assert::same(Arr::values($array), [1, 2, 3]); -// randomKey() + +randomKey: Assert::contains(Arr::keys($array), Arr::randomKey($array)); -// randomValue() + +randomValue: Assert::contains(Arr::values($array), Arr::randomValue($array)); -// doForEach() + +doForEach: $x = 0; Arr::doForEach($array, static function (int $v) use (&$x): void { $x += $v; diff --git a/tests/src/common/lists/Arr/Arr.compare.phpt b/tests/src/common/lists/Arr/Arr.compare.phpt index 859bd3c6..9dc9fd5c 100644 --- a/tests/src/common/lists/Arr/Arr.compare.phpt +++ b/tests/src/common/lists/Arr/Arr.compare.phpt @@ -9,15 +9,18 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = [1, 2, 3, 4]; -// containsSlice() + +containsSlice: Assert::false(Arr::containsSlice($array, [3, 4, 5])); Assert::true(Arr::containsSlice($array, [2, 3, 4])); -// indexOfSlice() + +indexOfSlice: Assert::null(Arr::indexOfSlice($array, [3, 4, 5])); Assert::same(Arr::indexOfSlice($array, [2, 3, 4]), 1); -// corresponds() + +corresponds: Assert::false(Arr::corresponds($array, [1, 4, 9], static function ($a, $b): bool { return $a * $a === $b; })); @@ -31,14 +34,17 @@ Assert::false(Arr::corresponds($array, [1, 2, 3, 4], static function ($a, $b): b return $a * $a === $b; })); -// hasSameElements() + +hasSameElements: Assert::false(Arr::hasSameElements($array, [1, 1, 1, 1])); Assert::true(Arr::hasSameElements($array, [1, 2, 3, 4])); -// startsWith() + +startsWith: Assert::false(Arr::startsWith($array, [2, 3, 4])); Assert::true(Arr::startsWith($array, [1, 2, 3])); -// endsWith() + +endsWith: Assert::false(Arr::endsWith($array, [1, 2, 3])); Assert::true(Arr::endsWith($array, [2, 3, 4])); diff --git a/tests/src/common/lists/Arr/Arr.diff_intersect.phpt b/tests/src/common/lists/Arr/Arr.diff_intersect.phpt index c1133fcf..e071e9d7 100644 --- a/tests/src/common/lists/Arr/Arr.diff_intersect.phpt +++ b/tests/src/common/lists/Arr/Arr.diff_intersect.phpt @@ -17,27 +17,33 @@ $f = static function (int $a, int $b): int { return $a > $b ? 1 : ($a < $b ? -1 : 0); }; -// diff() + +diff: Assert::same(Arr::diff($array, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diff($array, $diff1, $diff2), [1, 5 => 6]); -// diffWith() + +diffWith: Assert::same(Arr::diffWith($array, $f, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffWith($array, $f, $diff1, $diff2), [1, 5 => 6]); -// diffKeys() + +diffKeys: Assert::same(Arr::diffKeys($array, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffKeys($array, $diff1, $diff2), [1, 5 => 6]); -// diffKeysWith() + +diffKeysWith: Assert::same(Arr::diffKeysWith($array, $f, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffKeysWith($array, $f, $diff1, $diff2), [1, 5 => 6]); -// diffPairs() + +diffPairs: Assert::same(Arr::diffPairs($array, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffPairs($array, $diff1, $diff2), [1, 5 => 6]); -// diffPairsWith() + +diffPairsWith: Assert::same(Arr::diffPairsWith($array, $f, $f, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffPairsWith($array, $f, $f, $diff1, $diff2), [1, 5 => 6]); Assert::same(Arr::diffPairsWith($array, null, $f, $diff1), [1, 3 => 4, 5, 6]); @@ -47,27 +53,33 @@ Assert::same(Arr::diffPairsWith($array, $f, null, $diff1, $diff2), [1, 5 => 6]); Assert::same(Arr::diffPairsWith($array, null, null, $diff1), [1, 3 => 4, 5, 6]); Assert::same(Arr::diffPairsWith($array, null, null, $diff1, $diff2), [1, 5 => 6]); -// intersect() + +intersect: Assert::same(Arr::intersect($array, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersect($array, $int1, $int2), [2 => 3, 4, 5]); -// intersectWith() + +intersectWith: Assert::same(Arr::intersectWith($array, $f, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersectWith($array, $f, $int1, $int2), [2 => 3, 4, 5]); -// intersectKeys() + +intersectKeys: Assert::same(Arr::intersectKeys($array, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersectKeys($array, $int1, $int2), [2 => 3, 4, 5]); -// intersectKeysWith() + +intersectKeysWith: Assert::same(Arr::intersectKeysWith($array, $f, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersectKeysWith($array, $f, $int1, $int2), [2 => 3, 4, 5]); -// intersectPairs() + +intersectPairs: Assert::same(Arr::intersectPairs($array, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersectPairs($array, $int1, $int2), [2 => 3, 4, 5]); -// intersectPairsWith() + +intersectPairsWith: Assert::same(Arr::intersectPairsWith($array, $f, $f, $int1), [1 => 2, 3, 4, 5]); Assert::same(Arr::intersectPairsWith($array, $f, $f, $int1, $int2), [2 => 3, 4, 5]); Assert::same(Arr::intersectPairsWith($array, null, $f, $int1), [1 => 2, 3, 4, 5]); diff --git a/tests/src/common/lists/Arr/Arr.filter.phpt b/tests/src/common/lists/Arr/Arr.filter.phpt index ea4239f3..c0139d1a 100644 --- a/tests/src/common/lists/Arr/Arr.filter.phpt +++ b/tests/src/common/lists/Arr/Arr.filter.phpt @@ -15,23 +15,28 @@ $f = static function (int $v): int { return $v % 2; }; -// collect() + +collect: Assert::same(Arr::collect($array, $f), [1, 2 => 1]); Assert::same(Arr::collect($empty, $f), []); -// filter() + +filter: Assert::same(Arr::filter($array, $f), [1, 2 => 3]); Assert::same(Arr::filter($empty, $f), []); -// filterKeys() + +filterKeys: Assert::same(Arr::filterKeys($array, $f), [1 => 2, 3 => 4]); Assert::same(Arr::filterKeys($empty, $f), []); -// filterNot() + +filterNot: Assert::same(Arr::filterNot($array, $f), [1 => 2, 3 => 4]); Assert::same(Arr::filterNot($empty, $f), []); -// partition() + +partition: /** @var ImmutableArray $a */ /** @var ImmutableArray $b */ [$a, $b] = Arr::partition($array, $f); diff --git a/tests/src/common/lists/Arr/Arr.map.phpt b/tests/src/common/lists/Arr/Arr.map.phpt index eefdd78c..93605c48 100644 --- a/tests/src/common/lists/Arr/Arr.map.phpt +++ b/tests/src/common/lists/Arr/Arr.map.phpt @@ -15,45 +15,54 @@ $f = static function (int $v): int { return $v % 2; }; -// flatMap() + +flatMap: Assert::same(Arr::flatMap($arr2, static function (array $v): array { return array_reverse($v); }), [2, 1, 4, 3]); Assert::same(Arr::flatMap($empty, $f), []); -// flatten() + +flatten: Assert::same(Arr::flatten($arr2), [1, 2, 3, 4]); Assert::same(Arr::flatten($empty), []); -// groupBy() + +groupBy: Assert::same(Arr::groupBy($array, $f), [1 => [1, 2 => 3], 0 => [1 => 2, 3 => 4]]); Assert::same(Arr::groupBy($empty, $f), []); -// map() + +map: Assert::same(Arr::map($array, $f), [1, 0, 1, 0]); Assert::same(Arr::map($empty, $f), []); -// mapPairs() + +mapPairs: Assert::same(Arr::mapPairs($array, static function (int $k, int $v): int { return $k + $v; }), [1, 3, 5, 7]); Assert::same(Arr::mapPairs($empty, $f), []); -// remap() + +remap: Assert::same(Arr::remap($array, static function (int $k, int $v): array { return [$v => $k]; }), [1 => 0, 1, 2, 3]); Assert::same(Arr::remap($empty, $f), []); -// flip() + +flip: Assert::same(Arr::flip($array), [1 => 0, 1, 2, 3]); Assert::same(Arr::flip($empty), []); -// transpose() + +transpose: Assert::same(Arr::transpose($arr2), [[1, 3], [2, 4]]); Assert::same(Arr::transpose($empty), []); -// column() + +column: Assert::same(Arr::column($arr2, 0), [1, 3]); Assert::same(Arr::column($arr2, 0, 1), [2 => 1, 4 => 3]); Assert::same(Arr::column($empty, 0), []); diff --git a/tests/src/common/lists/Arr/Arr.merge_replace.phpt b/tests/src/common/lists/Arr/Arr.merge_replace.phpt index 78c0a4f7..dab66fce 100644 --- a/tests/src/common/lists/Arr/Arr.merge_replace.phpt +++ b/tests/src/common/lists/Arr/Arr.merge_replace.phpt @@ -10,44 +10,54 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = [1, 2, 3, 4]; $empty = []; -// append() + +append: Assert::same(Arr::append($array, 5, 6), [1, 2, 3, 4, 5, 6]); Assert::same(Arr::append($empty, 5, 6), [5, 6]); -// appendAll() + +appendAll: Assert::same(Arr::appendAll($array, [5, 6]), [1, 2, 3, 4, 5, 6]); Assert::same(Arr::appendAll($empty, [5, 6]), [5, 6]); -// prepend() + +prepend: Assert::same(Arr::prepend($array, 5, 6), [5, 6, 1, 2, 3, 4]); Assert::same(Arr::prepend($empty, 5, 6), [5, 6]); -// prependAll() + +prependAll: Assert::same(Arr::prependAll($array, [5, 6]), [5, 6, 1, 2, 3, 4]); Assert::same(Arr::prependAll($empty, [5, 6]), [5, 6]); -// replace() + +replace: Assert::same(Arr::replace($array, 0, 10), [10, 2, 3, 4]); Assert::same(Arr::replace($empty, 0, 10), [10]); -// replaceAll() + +replaceAll: Assert::same(Arr::replaceAll($array, [0 => 10, 1 => 20]), [10, 20, 3, 4]); Assert::same(Arr::replaceAll($empty, [0 => 10, 1 => 20]), [10, 20]); -// hole() + +remove: Assert::same(Arr::remove($array, 1, 2), [1, 4]); Assert::same(Arr::remove($empty, 1, 2), []); -// patch() + +patch: Assert::same(Arr::patch($array, 1, [20, 30]), [1, 20, 30, 4]); Assert::same(Arr::patch($array, 1, [20, 30], 1), [1, 20, 30, 3, 4]); Assert::same(Arr::patch($empty, 1, [20, 30]), [20, 30]); Assert::same(Arr::patch($empty, 1, [20, 30], 1), [20, 30]); -// insert() + +insert: Assert::same(Arr::insert($array, 1, [20, 30]), [1, 20, 30, 2, 3, 4]); Assert::same(Arr::insert($empty, 1, [20, 30]), [20, 30]); -// merge() + +merge: Assert::same(Arr::merge($array, [5, 6]), [1, 2, 3, 4, 5, 6]); Assert::same(Arr::merge($empty, [5, 6]), [5, 6]); diff --git a/tests/src/common/lists/Arr/Arr.querries.phpt b/tests/src/common/lists/Arr/Arr.querries.phpt index 18b93895..3fd7a1e3 100644 --- a/tests/src/common/lists/Arr/Arr.querries.phpt +++ b/tests/src/common/lists/Arr/Arr.querries.phpt @@ -10,41 +10,50 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = [1, 2, 3, 2, 4]; $empty = []; -// isEmpty() + +isEmpty: Assert::true(Arr::isEmpty($empty)); Assert::false(Arr::isEmpty($array)); -// isNotEmpty() + +isNotEmpty: Assert::true(Arr::isNotEmpty($array)); Assert::false(Arr::isNotEmpty($empty)); -// contains() + +contains: Assert::true(Arr::contains($array, 2)); Assert::false(Arr::contains($array, 5)); -// containsAny() + +containsAny: Assert::true(Arr::containsAny($array, [2, 7])); Assert::false(Arr::containsAny($array, [6, 7])); -// containsAll() + +containsAll: Assert::true(Arr::containsAll($array, [1, 2])); Assert::false(Arr::containsAll($array, [2, 7])); -// indexOf() + +indexOf: Assert::null(Arr::indexOf($array, 5)); Assert::same(Arr::indexOf($array, 2), 1); Assert::same(Arr::indexOf($array, 2, 2), 3); -// indexesOf() + +indexesOf: Assert::same(Arr::indexesOf($array, 5), []); Assert::same(Arr::indexesOf($array, 2), [1, 3]); -// lastIndexOf() + +lastIndexOf: Assert::null(Arr::lastIndexOf($array, 5)); Assert::same(Arr::lastIndexOf($array, 2), 3); Assert::same(Arr::lastIndexOf($array, 2, 2), 1); -// indexWhere() + +indexWhere: Assert::null(Arr::indexWhere($array, static function (): bool { return false; })); @@ -55,7 +64,8 @@ Assert::same(Arr::indexWhere($array, static function (int $v): bool { return $v === 2; }, 2), 3); -// lastIndexWhere() + +lastIndexWhere: Assert::null(Arr::lastIndexWhere($array, static function (): bool { return false; })); @@ -66,19 +76,23 @@ Assert::same(Arr::lastIndexWhere($array, static function (int $v): bool { return $v === 2; }, 2), 1); -// containsKey() + +containsKey: Assert::false(Arr::containsKey($array, 5)); Assert::true(Arr::containsKey($array, 2)); -// containsAnyKey() + +containsAnyKey: Assert::false(Arr::containsAnyKey($array, [5, 6])); Assert::true(Arr::containsAnyKey($array, [5, 4])); -// containsAllKeys() + +containsAllKeys: Assert::false(Arr::containsAllKeys($array, [2, 7])); Assert::true(Arr::containsAllKeys($array, [0, 1])); -// exists() + +exists: Assert::false(Arr::exists($array, static function (int $v): bool { return $v > 5; })); @@ -86,7 +100,8 @@ Assert::true(Arr::exists($array, static function (int $v): bool { return $v > 1; })); -// forAll() + +forAll: Assert::false(Arr::forAll($array, static function (int $v): bool { return $v > 1; })); @@ -94,7 +109,8 @@ Assert::true(Arr::forAll($array, static function (int $v): bool { return $v < 5; })); -// find() + +find: Assert::null(Arr::find($array, static function (int $v): bool { return $v * $v === 25; })); @@ -102,12 +118,14 @@ Assert::same(Arr::find($array, static function (int $v): bool { return $v * $v === 4; }), 2); -// prefixLength() + +prefixLength: Assert::same(Arr::prefixLength([2, 2, 2, 1], static function (int $v): bool { return $v === 2; }), 3); -// segmentLength() + +segmentLength: Assert::same(Arr::segmentLength([2, 2, 2, 1], static function (int $v): bool { return $v === 2; }, 1), 2); diff --git a/tests/src/common/lists/Arr/Arr.slice.phpt b/tests/src/common/lists/Arr/Arr.slice.phpt index 1000e157..8b581a4b 100644 --- a/tests/src/common/lists/Arr/Arr.slice.phpt +++ b/tests/src/common/lists/Arr/Arr.slice.phpt @@ -15,35 +15,43 @@ $f = static function ($v): bool { return $v < 3; }; -// head() + +head: Assert::same(Arr::head($array), 1); Assert::null(Arr::head($empty)); -// first() + +first: Assert::same(Arr::first($array), 1); Assert::null(Arr::first($empty)); -// last() + +last: Assert::same(Arr::last($array), 4); Assert::null(Arr::last($empty)); -// init() + +init: Assert::same(Arr::init($array), [1, 2, 3]); Assert::same(Arr::init($empty), []); -// tail() + +tail: Assert::same(Arr::tail($array), [1 => 2, 3, 4]); Assert::same(Arr::tail($empty), []); -// inits() + +inits: Assert::same(Arr::inits($array), [[1, 2, 3, 4], [1, 2, 3], [1, 2], [1], []]); Assert::same(Arr::inits($empty), [[]]); -// tails() + +tails: Assert::same(Arr::tails($array), [[1, 2, 3, 4], [1 => 2, 3, 4], [2 => 3, 4], [3 => 4], []]); Assert::same(Arr::tails($empty), [[]]); -// headTail() + +headTail: /** @var ImmutableArray $tail */ [$head, $tail] = Arr::headTail($array); Assert::same($head, 1); @@ -52,7 +60,8 @@ Assert::same($tail, [1 => 2, 3, 4]); Assert::null($head); Assert::same($tail, []); -// initLast() + +initLast: /** @var ImmutableArray $init */ [$init, $last] = Arr::initLast($array); Assert::same($init, [1, 2, 3]); @@ -61,39 +70,47 @@ Assert::same($last, 4); Assert::same($init, []); Assert::null($last); -// slice() + +slice: Assert::same(Arr::slice($array, 1), [1 => 2, 3, 4]); Assert::same(Arr::slice($array, 1, 2), [1 => 2, 3]); Assert::same(Arr::slice($array, 10), []); Assert::same(Arr::slice($empty, 1), []); -// chunks() + +chunks: Assert::same(Arr::chunks($array, 2), [[1, 2], [2 => 3, 4]]); Assert::same(Arr::chunks($empty, 2), []); -// sliding() + +sliding: Assert::same(Arr::sliding($array, 2), [[1, 2], [1 => 2, 3], [2 => 3, 4]]); Assert::same(Arr::sliding($array, 3), [[1, 2, 3], [1 => 2, 3, 4]]); Assert::same(Arr::sliding($array, 2, 2), [[1, 2], [2 => 3, 4]]); Assert::same(Arr::sliding($empty, 2), []); -// drop() + +drop: Assert::same(Arr::drop($array, 2), [2 => 3, 4]); Assert::same(Arr::drop($empty, 2), []); -// dropRight() + +dropRight: Assert::same(Arr::dropRight($array, 2), [1, 2]); Assert::same(Arr::dropRight($empty, 2), []); -// dropWhile() + +dropWhile: Assert::same(Arr::dropWhile($array, $f), [2 => 3, 4]); Assert::same(Arr::dropWhile($empty, $f), []); -// padTo() + +padTo: Assert::same(Arr::padTo($array, 7, 6), [1, 2, 3, 4, 6, 6, 6]); Assert::same(Arr::padTo($empty, 3, 6), [6, 6, 6]); -// span() + +span: [$l, $r] = Arr::span($array, $f); Assert::same($l, [1, 2]); Assert::same($r, [2 => 3, 4]); @@ -101,24 +118,29 @@ Assert::same($r, [2 => 3, 4]); Assert::same($l, []); Assert::same($r, []); -// take() + +take: Assert::same(Arr::take($array, 2), [1, 2]); Assert::same(Arr::take($empty, 2), []); -// takeRight() + +takeRight: Assert::same(Arr::takeRight($array, 2), [2 => 3, 4]); Assert::same(Arr::takeRight($empty, 2), []); -// takeWhile() + +takeWhile: Assert::same(Arr::takeWhile($array, $f), [1, 2]); Assert::same(Arr::takeWhile($empty, $f), []); -// rotateLeft() + +rotateLeft: Assert::same(Arr::rotateLeft([], 2), []); Assert::same(Arr::rotateLeft([1, 2, 3, 4, 5, 6], 2), [3, 4, 5, 6, 1, 2]); Assert::same(Arr::rotateLeft([1, 2, 3, 4, 5, 6], 8), [3, 4, 5, 6, 1, 2]); -// rotateRight() + +rotateRight: Assert::same(Arr::rotateRight([], 2), []); Assert::same(Arr::rotateRight([1, 2, 3, 4, 5, 6], 2), [5, 6, 1, 2, 3, 4]); Assert::same(Arr::rotateRight([1, 2, 3, 4, 5, 6], 8), [5, 6, 1, 2, 3, 4]); diff --git a/tests/src/common/lists/Arr/Arr.sort.phpt b/tests/src/common/lists/Arr/Arr.sort.phpt index 04b17a87..4a246ee7 100644 --- a/tests/src/common/lists/Arr/Arr.sort.phpt +++ b/tests/src/common/lists/Arr/Arr.sort.phpt @@ -15,40 +15,47 @@ $f = static function (int $a, int $b): int { return $a < $b ? 1 : ($a > $b ? -1 : 0); }; -// reverse() + +reverse: Assert::same(Arr::reverse($empty), []); Assert::same(Arr::reverse($array), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// shuffle() + +shuffle: Assert::same(Arr::shuffle($empty), []); $sh = Arr::shuffle($array); Assert::same(Arr::values(Arr::sort($sh)), $array); -// sort() + +sort: Assert::same(Arr::sort($empty), []); Assert::same(Arr::sort($array), [1, 2, 3, 4]); Assert::same(Arr::sort($array, Order::ASCENDING), [1, 2, 3, 4]); Assert::same(Arr::sort($array, Order::DESCENDING), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// sortKeys() + +sortKeys: Assert::same(Arr::sortKeys($empty), []); Assert::same(Arr::sortKeys($array), [1, 2, 3, 4]); Assert::same(Arr::sortKeys($array, Order::ASCENDING), [1, 2, 3, 4]); Assert::same(Arr::sortKeys($array, Order::DESCENDING), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// sortWith() + +sortWith: Assert::same(Arr::sortWith($empty, $f), []); Assert::same(Arr::sortWith($array, $f), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same(Arr::sortWith($array, $f, Order::ASCENDING), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same(Arr::sortWith($array, $f, Order::DESCENDING), [1, 2, 3, 4]); -// sortKeysWith() + +sortKeysWith: Assert::same(Arr::sortKeysWith($empty, $f), []); Assert::same(Arr::sortKeysWith($array, $f), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same(Arr::sortKeysWith($array, $f, Order::ASCENDING), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same(Arr::sortKeysWith($array, $f, Order::DESCENDING), [1, 2, 3, 4]); -// distinct() + +distinct: Assert::same(Arr::distinct($empty), []); Assert::same(Arr::distinct($array), [1, 2, 3, 4]); Assert::same(Arr::distinct([1, 1, 2, 2]), [1, 2 => 2]); diff --git a/tests/src/common/lists/Arr/Arr.stats.phpt b/tests/src/common/lists/Arr/Arr.stats.phpt index 80691cfd..f0397157 100644 --- a/tests/src/common/lists/Arr/Arr.stats.phpt +++ b/tests/src/common/lists/Arr/Arr.stats.phpt @@ -10,43 +10,52 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = [1, 2, 3, 2]; $empty = []; -// count() + +count: Assert::same(Arr::count($array), 4); Assert::same(Arr::count($array, static function (int $v): bool { return $v > 1; }), 3); Assert::same(Arr::count($empty), 0); -// size() + +size: Assert::same(Arr::size($array), 4); Assert::same(Arr::size($empty), 0); -// countValues() + +countValues: Assert::same(Arr::countValues($array), [1 => 1, 2 => 2, 3 => 1]); Assert::same(Arr::countValues($empty), []); -// max() + +max: Assert::same(Arr::max($array), 3); Assert::null(Arr::max($empty)); -// min() + +min: Assert::same(Arr::min($array), 1); Assert::null(Arr::min($empty)); -// maxBy() + +maxBy: Assert::same(Arr::maxBy($array, static function ($v): float { return 1 / $v; }), 1); -// minBy() + +minBy: Assert::same(Arr::minBy($array, static function (int $v): float { return 1 / $v; }), 3); -// product() + +product: Assert::same(Arr::product($array), 12); Assert::same(Arr::product($empty), 1); -// sum() + +sum: Assert::same(Arr::sum($array), 8); Assert::same(Arr::sum($empty), 0); diff --git a/tests/src/common/lists/Arr/Arr.transform.phpt b/tests/src/common/lists/Arr/Arr.transform.phpt index 87fa40cc..92027211 100644 --- a/tests/src/common/lists/Arr/Arr.transform.phpt +++ b/tests/src/common/lists/Arr/Arr.transform.phpt @@ -14,35 +14,43 @@ $f = static function (int $a, int $b): int { return $a + $b; }; -// fold() + +fold: Assert::same(Arr::fold($array, $f, 0), 10); Assert::same(Arr::fold($empty, $f, 0), 0); Assert::same(Arr::fold($empty, $f), null); -// foldLeft() + +foldLeft: Assert::same(Arr::foldLeft($array, $f, 0), 10); Assert::same(Arr::foldLeft($empty, $f, 0), 0); Assert::same(Arr::foldLeft($empty, $f), null); -// foldRight() + +foldRight: Assert::same(Arr::foldRight($array, $f, 0), 10); Assert::same(Arr::foldRight($empty, $f, 0), 0); Assert::same(Arr::foldRight($empty, $f), null); -// reduce() + +reduce: Assert::same(Arr::reduce($array, $f), 10); Assert::same(Arr::reduce($empty, $f), null); -// reduceLeft() + +reduceLeft: Assert::same(Arr::reduceLeft($array, $f), 10); Assert::same(Arr::reduceLeft($empty, $f), null); -// reduceRight() + +reduceRight: Assert::same(Arr::reduceRight($array, $f), 10); Assert::same(Arr::reduceRight($empty, $f), null); -// scanLeft() + +scanLeft: Assert::same(Arr::scanLeft($array, $f, 0), [0, 1, 3, 6, 10]); -// scanRight() + +scanRight: Assert::same(Arr::scanRight($array, $f, 0), [10, 9, 7, 4, 0]); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.basic.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.basic.phpt index b153d251..21ef396a 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.basic.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.basic.phpt @@ -17,35 +17,45 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = new ImmutableArray([1, 2, 3]); -// __construct(), toArray() + +__construct: +toArray: Assert::same((new ImmutableArray([1, 2, 3]))->toArray(), [1, 2, 3]); -// create() + +create: Assert::same(ImmutableArray::create(1, 2, 3)->toArray(), [1, 2, 3]); -// from(), convertToArray() + +from: +convertToArray: Assert::same(ImmutableArray::from([1, 2, 3])->toArray(), [1, 2, 3]); Assert::same(ImmutableArray::from(new ImmutableArray([1, 2, 3]))->toArray(), [1, 2, 3]); Assert::same(ImmutableArray::from(new ArrayIterator([1, 2, 3]))->toArray(), [1, 2, 3]); -// combine() + +combine: Assert::same(ImmutableArray::combine([1, 2, 3], [4, 5, 6])->toArray(), [1 => 4, 2 => 5, 3 => 6]); -// range() + +range: Assert::same(ImmutableArray::range(3, 5)->toArray(), [3, 4, 5]); Assert::same(ImmutableArray::range(5, 3)->toArray(), [5, 4, 3]); Assert::same(ImmutableArray::range(3, 7, 2)->toArray(), [3, 5, 7]); Assert::same(ImmutableArray::range(3, 6, 2)->toArray(), [3, 5]); -// Countable + +Countable: Assert::type(new ImmutableArray([]), Countable::class); Assert::same(count(new ImmutableArray([1, 2, 3])), 3); -// IteratorAggregate + +IteratorAggregate: Assert::type(new ImmutableArray([]), IteratorAggregate::class); Assert::type((new ImmutableArray([]))->getIterator(), ArrayIterator::class); -// ArrayAccess + +ArrayAccess: Assert::type(new ImmutableArray([]), ArrayAccess::class); Assert::true($array->offsetExists(0)); @@ -68,25 +78,32 @@ Assert::exception(static function () use ($array): void { $array->offsetUnset(0); }, BadMethodCallException::class); -// getReverseIterator() + +getReverseIterator: Assert::type((new ImmutableArray([]))->getReverseIterator(), ReverseArrayIterator::class); -// getKeys() + +getKeys: Assert::same($array->keys()->toArray(), [0, 1, 2]); -// getValues() + +getValues: Assert::same($array->values()->toArray(), [1, 2, 3]); -// toArrayRecursive() + +toArrayRecursive: Assert::same((new ImmutableArray([1, 2, new ImmutableArray([3, 4, 5])]))->toArrayRecursive(), [1, 2, [3, 4, 5]]); -// randomKey() + +randomKey: Assert::contains($array->keys()->toArray(), $array->randomKey()); -// randomValue() + +randomValue: Assert::contains($array->values()->toArray(), $array->randomValue()); -// doForEach() + +doForEach: $x = 0; $array->doForEach(static function (int $v) use (&$x): void { $x += $v; diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.compare.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.compare.phpt index 0fa4f497..d37b91c7 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.compare.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.compare.phpt @@ -10,17 +10,20 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = new ImmutableArray([1, 2, 3, 4]); -// containsSlice() + +containsSlice: Assert::false($array->containsSlice([3, 4, 5])); Assert::true($array->containsSlice([2, 3, 4])); Assert::true($array->containsSlice(new ArrayIterator([2, 3, 4]))); -// indexOfSlice() + +indexOfSlice: Assert::null($array->indexOfSlice([3, 4, 5])); Assert::same($array->indexOfSlice([2, 3, 4]), 1); Assert::same($array->indexOfSlice(new ArrayIterator([2, 3, 4])), 1); -// corresponds() + +corresponds: Assert::false($array->corresponds([1, 4, 9], static function ($a, $b): bool { return $a * $a === $b; })); @@ -37,17 +40,20 @@ Assert::true($array->corresponds(new ArrayIterator([1, 4, 9, 16]), static functi return $a * $a === $b; })); -// hasSameElements() + +hasSameElements: Assert::false($array->hasSameElements([1, 1, 1, 1])); Assert::true($array->hasSameElements([1, 2, 3, 4])); Assert::true($array->hasSameElements(new ArrayIterator([1, 2, 3, 4]))); -// startsWith() + +startsWith: Assert::false($array->startsWith([2, 3, 4])); Assert::true($array->startsWith([1, 2, 3])); Assert::true($array->startsWith(new ArrayIterator([1, 2, 3]))); -// endsWith() + +endsWith: Assert::false($array->endsWith([1, 2, 3])); Assert::true($array->endsWith([2, 3, 4])); Assert::true($array->endsWith(new ArrayIterator([2, 3, 4]))); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.diff_intersect.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.diff_intersect.phpt index 340c274e..11906396 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.diff_intersect.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.diff_intersect.phpt @@ -17,27 +17,33 @@ $f = static function (int $a, int $b): int { return $a > $b ? 1 : ($a < $b ? -1 : 0); }; -// diff() + +diff: Assert::same($array->diff($diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diff($diff1, $diff2)->toArray(), [1, 5 => 6]); -// diffWith() + +diffWith: Assert::same($array->diffWith($f, $diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffWith($f, $diff1, $diff2)->toArray(), [1, 5 => 6]); -// diffKeys() + +diffKeys: Assert::same($array->diffKeys($diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffKeys($diff1, $diff2)->toArray(), [1, 5 => 6]); -// diffKeysWith() + +diffKeysWith: Assert::same($array->diffKeysWith($f, $diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffKeysWith($f, $diff1, $diff2)->toArray(), [1, 5 => 6]); -// diffPairs() + +diffPairs: Assert::same($array->diffPairs($diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffPairs($diff1, $diff2)->toArray(), [1, 5 => 6]); -// diffPairsWith() + +diffPairsWith: Assert::same($array->diffPairsWith($f, $f, $diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffPairsWith($f, $f, $diff1, $diff2)->toArray(), [1, 5 => 6]); Assert::same($array->diffPairsWith(null, $f, $diff1)->toArray(), [1, 3 => 4, 5, 6]); @@ -47,27 +53,33 @@ Assert::same($array->diffPairsWith($f, null, $diff1, $diff2)->toArray(), [1, 5 = Assert::same($array->diffPairsWith(null, null, $diff1)->toArray(), [1, 3 => 4, 5, 6]); Assert::same($array->diffPairsWith(null, null, $diff1, $diff2)->toArray(), [1, 5 => 6]); -// intersect() + +intersect: Assert::same($array->intersect($int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersect($int1, $int2)->toArray(), [2 => 3, 4, 5]); -// intersectWith() + +intersectWith: Assert::same($array->intersectWith($f, $int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersectWith($f, $int1, $int2)->toArray(), [2 => 3, 4, 5]); -// intersectKeys() + +intersectKeys: Assert::same($array->intersectKeys($int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersectKeys($int1, $int2)->toArray(), [2 => 3, 4, 5]); -// intersectKeysWith() + +intersectKeysWith: Assert::same($array->intersectKeysWith($f, $int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersectKeysWith($f, $int1, $int2)->toArray(), [2 => 3, 4, 5]); -// intersectPairs() + +intersectPairs: Assert::same($array->intersectPairs($int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersectPairs($int1, $int2)->toArray(), [2 => 3, 4, 5]); -// intersectPairsWith() + +intersectPairsWith: Assert::same($array->intersectPairsWith($f, $f, $int1)->toArray(), [1 => 2, 3, 4, 5]); Assert::same($array->intersectPairsWith($f, $f, $int1, $int2)->toArray(), [2 => 3, 4, 5]); Assert::same($array->intersectPairsWith(null, $f, $int1)->toArray(), [1 => 2, 3, 4, 5]); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.filter.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.filter.phpt index 9783ac01..0ee2c748 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.filter.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.filter.phpt @@ -14,23 +14,28 @@ $f = static function (int $v): int { return $v % 2; }; -// collect() + +collect: Assert::same($array->collect($f)->toArray(), [1, 2 => 1]); Assert::same($empty->collect($f)->toArray(), []); -// filter() + +filter: Assert::same($array->filter($f)->toArray(), [1, 2 => 3]); Assert::same($empty->filter($f)->toArray(), []); -// filterKeys() + +filterKeys: Assert::same($array->filterKeys($f)->toArray(), [1 => 2, 3 => 4]); Assert::same($empty->filterKeys($f)->toArray(), []); -// filterNot() + +filterNot: Assert::same($array->filterNot($f)->toArray(), [1 => 2, 3 => 4]); Assert::same($empty->filterNot($f)->toArray(), []); -// partition() + +partition: /** @var ImmutableArray $a */ /** @var ImmutableArray $b */ [$a, $b] = $array->partition($f); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.map.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.map.phpt index 4c3da176..7ff4b08e 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.map.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.map.phpt @@ -15,45 +15,54 @@ $f = static function (int $v): int { return $v % 2; }; -// flatMap() + +flatMap: Assert::same($arr2->flatMap(static function (array $v): array { return array_reverse($v); })->toArray(), [2, 1, 4, 3]); Assert::same($empty->flatMap($f)->toArray(), []); -// flatten() + +flatten: Assert::same($arr2->flatten()->toArray(), [1, 2, 3, 4]); Assert::same($empty->flatten()->toArray(), []); -// groupBy() + +groupBy: Assert::same($array->groupBy($f)->toArrayRecursive(), [1 => [1, 2 => 3], 0 => [1 => 2, 3 => 4]]); Assert::same($empty->groupBy($f)->toArrayRecursive(), []); -// map() + +map: Assert::same($array->map($f)->toArray(), [1, 0, 1, 0]); Assert::same($empty->map($f)->toArray(), []); -// mapPairs() + +mapPairs: Assert::same($array->mapPairs(static function (int $k, int $v): int { return $k + $v; })->toArray(), [1, 3, 5, 7]); Assert::same($empty->mapPairs($f)->toArray(), []); -// remap() + +remap: Assert::same($array->remap(static function (int $k, int $v): array { return [$v => $k]; })->toArray(), [1 => 0, 1, 2, 3]); Assert::same($empty->remap($f)->toArray(), []); -// flip() + +flip: Assert::same($array->flip()->toArray(), [1 => 0, 1, 2, 3]); Assert::same($empty->flip()->toArray(), []); -// transpose() + +transpose: Assert::same($arr2->transpose()->toArrayRecursive(), [[1, 3], [2, 4]]); Assert::same($empty->transpose()->toArrayRecursive(), []); -// column() + +column: Assert::same($arr2->column(0)->toArray(), [1, 3]); Assert::same($arr2->column(0, 1)->toArray(), [2 => 1, 4 => 3]); Assert::same($empty->column(0)->toArray(), []); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.merge_replace.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.merge_replace.phpt index 6aa0fb52..bdc4a804 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.merge_replace.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.merge_replace.phpt @@ -11,50 +11,60 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = new ImmutableArray([1, 2, 3, 4]); $empty = new ImmutableArray([]); -// append() + +append: Assert::same($array->append(5, 6)->toArray(), [1, 2, 3, 4, 5, 6]); Assert::same($empty->append(5, 6)->toArray(), [5, 6]); -// appendAll() + +appendAll: Assert::same($array->appendAll([5, 6])->toArray(), [1, 2, 3, 4, 5, 6]); Assert::same($array->appendAll(new ImmutableArray([5, 6]))->toArray(), [1, 2, 3, 4, 5, 6]); Assert::same($array->appendAll(new ArrayIterator([5, 6]))->toArray(), [1, 2, 3, 4, 5, 6]); Assert::same($empty->appendAll([5, 6])->toArray(), [5, 6]); -// prepend() + +prepend: Assert::same($array->prepend(5, 6)->toArray(), [5, 6, 1, 2, 3, 4]); Assert::same($empty->prepend(5, 6)->toArray(), [5, 6]); -// prependAll() + +prependAll: Assert::same($array->prependAll([5, 6])->toArray(), [5, 6, 1, 2, 3, 4]); Assert::same($array->prependAll(new ImmutableArray([5, 6]))->toArray(), [5, 6, 1, 2, 3, 4]); Assert::same($array->prependAll(new ArrayIterator([5, 6]))->toArray(), [5, 6, 1, 2, 3, 4]); Assert::same($empty->prependAll([5, 6])->toArray(), [5, 6]); -// replace() + +replace: Assert::same($array->replace(0, 10)->toArray(), [10, 2, 3, 4]); Assert::same($empty->replace(0, 10)->toArray(), [10]); -// replaceAll() + +replaceAll: Assert::same($array->replaceAll([0 => 10, 1 => 20])->toArray(), [10, 20, 3, 4]); Assert::same($array->replaceAll(new ImmutableArray([0 => 10, 1 => 20]))->toArray(), [10, 20, 3, 4]); Assert::same($array->replaceAll(new ArrayIterator([0 => 10, 1 => 20]))->toArray(), [10, 20, 3, 4]); Assert::same($empty->replaceAll([0 => 10, 1 => 20])->toArray(), [10, 20]); -// hole() + +remove: Assert::same($array->remove(1, 2)->toArray(), [1, 4]); Assert::same($empty->remove(1, 2)->toArray(), []); -// patch() + +patch: Assert::same($array->patch(1, [20, 30])->toArray(), [1, 20, 30, 4]); Assert::same($array->patch(1, [20, 30], 1)->toArray(), [1, 20, 30, 3, 4]); Assert::same($empty->patch(1, [20, 30])->toArray(), [20, 30]); Assert::same($empty->patch(1, [20, 30], 1)->toArray(), [20, 30]); -// insert() + +insert: Assert::same($array->insert(1, [20, 30])->toArray(), [1, 20, 30, 2, 3, 4]); Assert::same($empty->insert(1, [20, 30])->toArray(), [20, 30]); -// merge() + +merge: Assert::same($array->merge([5, 6])->toArray(), [1, 2, 3, 4, 5, 6]); Assert::same($empty->merge([5, 6])->toArray(), [5, 6]); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.querries.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.querries.phpt index 89f8cbdb..9ff26f00 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.querries.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.querries.phpt @@ -10,41 +10,50 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = new ImmutableArray([1, 2, 3, 2, 4]); $empty = new ImmutableArray([]); -// isEmpty() + +isEmpty: Assert::true($empty->isEmpty()); Assert::false($array->isEmpty()); -// isNotEmpty() + +isNotEmpty: Assert::true($array->isNotEmpty()); Assert::false($empty->isNotEmpty()); -// contains() + +contains: Assert::true($array->contains(2)); Assert::false($array->contains(5)); -// containsAny() + +containsAny: Assert::true($array->containsAny([2, 7])); Assert::false($array->containsAny([0, 9])); -// containsAll() + +containsAll: Assert::true($array->containsAll([1, 2])); Assert::false($array->containsAll([1, 7])); -// indexOf() + +indexOf: Assert::null($array->indexOf(5)); Assert::same($array->indexOf(2), 1); Assert::same($array->indexOf(2, 2), 3); -// indexesOf() + +indexesOf: Assert::same($array->indexesOf(5)->toArray(), []); Assert::same($array->indexesOf(2)->toArray(), [1, 3]); -// lastIndexOf() + +lastIndexOf: Assert::null($array->lastIndexOf(5)); Assert::same($array->lastIndexOf(2), 3); Assert::same($array->lastIndexOf(2, 2), 1); -// indexWhere() + +indexWhere: Assert::null($array->indexWhere(static function (): bool { return false; })); @@ -55,7 +64,8 @@ Assert::same($array->indexWhere(static function (int $v): bool { return $v === 2; }, 2), 3); -// lastIndexWhere() + +lastIndexWhere: Assert::null($array->lastIndexWhere(static function (): bool { return false; })); @@ -66,19 +76,23 @@ Assert::same($array->lastIndexWhere(static function (int $v): bool { return $v === 2; }, 2), 1); -// containsKey() + +containsKey: Assert::false($array->containsKey(5)); Assert::true($array->containsKey(2)); -// containsAnyKey() + +containsAnyKey: Assert::false($array->containsAnyKey([6, 7])); Assert::true($array->containsAnyKey([2, 7])); -// containsAllKeys() + +containsAllKeys: Assert::false($array->containsAllKeys([1, 7])); Assert::true($array->containsAllKeys([1, 2])); -// exists() + +exists: Assert::false($array->exists(static function (int $v): bool { return $v > 5; })); @@ -86,7 +100,8 @@ Assert::true($array->exists(static function (int $v): bool { return $v > 1; })); -// forAll() + +forAll: Assert::false($array->forAll(static function (int $v): bool { return $v > 1; })); @@ -94,7 +109,8 @@ Assert::true($array->forAll(static function (int $v): bool { return $v < 5; })); -// find() + +find: Assert::null($array->find(static function (int $v): bool { return $v * $v === 25; })); @@ -102,12 +118,14 @@ Assert::same($array->find(static function (int $v): bool { return $v * $v === 4; }), 2); -// prefixLength() + +prefixLength: Assert::same((new ImmutableArray([2, 2, 2, 1]))->prefixLength(static function (int $v): bool { return $v === 2; }), 3); -// segmentLength() + +segmentLength: Assert::same((new ImmutableArray([2, 2, 2, 1]))->segmentLength(static function (int $v): bool { return $v === 2; }, 1), 2); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.slice.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.slice.phpt index 204f2c81..5d4fa1a2 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.slice.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.slice.phpt @@ -14,35 +14,43 @@ $f = static function ($v): bool { return $v < 3; }; -// head() + +head: Assert::same($array->head(), 1); Assert::null($empty->head()); -// first() + +first: Assert::same($array->first(), 1); Assert::null($empty->first()); -// last() + +last: Assert::same($array->last(), 4); Assert::null($empty->last()); -// init() + +init: Assert::same($array->init()->toArray(), [1, 2, 3]); Assert::same($empty->init()->toArray(), []); -// tail() + +tail: Assert::same($array->tail()->toArray(), [1 => 2, 3, 4]); Assert::same($empty->tail()->toArray(), []); -// inits() + +inits: Assert::same($array->inits()->toArrayRecursive(), [[1, 2, 3, 4], [1, 2, 3], [1, 2], [1], []]); Assert::same($empty->inits()->toArrayRecursive(), [[]]); -// tails() + +tails: Assert::same($array->tails()->toArrayRecursive(), [[1, 2, 3, 4], [1 => 2, 3, 4], [2 => 3, 4], [3 => 4], []]); Assert::same($empty->tails()->toArrayRecursive(), [[]]); -// headTail() + +headTail: /** @var ImmutableArray $tail */ [$head, $tail] = $array->headTail(); Assert::same($head, 1); @@ -51,7 +59,8 @@ Assert::same($tail->toArray(), [1 => 2, 3, 4]); Assert::null($head); Assert::same($tail->toArray(), []); -// initLast() + +initLast: /** @var ImmutableArray $init */ [$init, $last] = $array->initLast(); Assert::same($init->toArray(), [1, 2, 3]); @@ -60,39 +69,47 @@ Assert::same($last, 4); Assert::same($init->toArray(), []); Assert::null($last); -// slice() + +slice: Assert::same($array->slice(1)->toArray(), [1 => 2, 3, 4]); Assert::same($array->slice(1, 2)->toArray(), [1 => 2, 3]); Assert::same($array->slice(10)->toArray(), []); Assert::same($empty->slice(1)->toArray(), []); -// chunks() + +chunks: Assert::same($array->chunks(2)->toArrayRecursive(), [[1, 2], [2 => 3, 4]]); Assert::same($empty->chunks(2)->toArrayRecursive(), []); -// sliding() + +sliding: Assert::same($array->sliding(2)->toArrayRecursive(), [[1, 2], [1 => 2, 3], [2 => 3, 4]]); Assert::same($array->sliding(3)->toArrayRecursive(), [[1, 2, 3], [1 => 2, 3, 4]]); Assert::same($array->sliding(2, 2)->toArrayRecursive(), [[1, 2], [2 => 3, 4]]); Assert::same($empty->sliding(2)->toArrayRecursive(), []); -// drop() + +drop: Assert::same($array->drop(2)->toArray(), [2 => 3, 4]); Assert::same($empty->drop(2)->toArray(), []); -// dropRight() + +dropRight: Assert::same($array->dropRight(2)->toArray(), [1, 2]); Assert::same($empty->dropRight(2)->toArray(), []); -// dropWhile() + +dropWhile: Assert::same($array->dropWhile($f)->toArray(), [2 => 3, 4]); Assert::same($empty->dropWhile($f)->toArray(), []); -// padTo() + +padTo: Assert::same($array->padTo(7, 6)->toArray(), [1, 2, 3, 4, 6, 6, 6]); Assert::same($empty->padTo(3, 6)->toArray(), [6, 6, 6]); -// span() + +span: [$l, $r] = $array->span($f); Assert::same($l->toArray(), [1, 2]); Assert::same($r->toArray(), [2 => 3, 4]); @@ -100,26 +117,31 @@ Assert::same($r->toArray(), [2 => 3, 4]); Assert::same($l->toArray(), []); Assert::same($r->toArray(), []); -// take() + +take: Assert::same($array->take(2)->toArray(), [1, 2]); Assert::same($empty->take(2)->toArray(), []); -// takeRight() + +takeRight: Assert::same($array->takeRight(2)->toArray(), [2 => 3, 4]); Assert::same($empty->takeRight(2)->toArray(), []); -// takeWhile() + +takeWhile: Assert::same($array->takeWhile($f)->toArray(), [1, 2]); Assert::same($empty->takeWhile($f)->toArray(), []); $array = new ImmutableArray([1, 2, 3, 4, 5, 6]); -// rotateLeft() + +rotateLeft: Assert::same($empty->rotateLeft(2)->toArray(), []); Assert::same($array->rotateLeft(2)->toArray(), [3, 4, 5, 6, 1, 2]); Assert::same($array->rotateLeft(8)->toArray(), [3, 4, 5, 6, 1, 2]); -// rotateRight() + +rotateRight: Assert::same($empty->rotateRight(2)->toArray(), []); Assert::same($array->rotateRight(2)->toArray(), [5, 6, 1, 2, 3, 4]); Assert::same($array->rotateRight(8)->toArray(), [5, 6, 1, 2, 3, 4]); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.sort.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.sort.phpt index e177d571..26d15393 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.sort.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.sort.phpt @@ -15,40 +15,47 @@ $f = static function (int $a, int $b): int { return $a < $b ? 1 : ($a > $b ? -1 : 0); }; -// reverse() + +reverse: Assert::same($empty->reverse()->toArray(), []); Assert::same($array->reverse()->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// shuffle() + +shuffle: Assert::same($empty->shuffle()->toArray(), []); $sh = $array->shuffle(); Assert::same($sh->sort()->values()->toArray(), $array->toArray()); -// sort() + +sort: Assert::same($empty->sort()->toArray(), []); Assert::same($array->sort()->toArray(), [1, 2, 3, 4]); Assert::same($array->sort(Order::ASCENDING)->toArray(), [1, 2, 3, 4]); Assert::same($array->sort(Order::DESCENDING)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// sortKeys() + +sortKeys: Assert::same($empty->sortKeys()->toArray(), []); Assert::same($array->sortKeys()->toArray(), [1, 2, 3, 4]); Assert::same($array->sortKeys(Order::ASCENDING)->toArray(), [1, 2, 3, 4]); Assert::same($array->sortKeys(Order::DESCENDING)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); -// sortWith() + +sortWith: Assert::same($empty->sortWith($f)->toArray(), []); Assert::same($array->sortWith($f)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same($array->sortWith($f, Order::ASCENDING)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same($array->sortWith($f, Order::DESCENDING)->toArray(), [1, 2, 3, 4]); -// sortKeysWith() + +sortKeysWith: Assert::same($empty->sortKeysWith($f)->toArray(), []); Assert::same($array->sortKeysWith($f)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same($array->sortKeysWith($f, Order::ASCENDING)->toArray(), [3 => 4, 2 => 3, 1 => 2, 0 => 1]); Assert::same($array->sortKeysWith($f, Order::DESCENDING)->toArray(), [1, 2, 3, 4]); -// distinct() + +distinct: Assert::same($empty->distinct()->toArray(), []); Assert::same($array->distinct()->toArray(), [1, 2, 3, 4]); Assert::same((new ImmutableArray([1, 1, 2, 2]))->distinct()->toArray(), [1, 2 => 2]); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.stats.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.stats.phpt index b7a42168..c5714e34 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.stats.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.stats.phpt @@ -10,43 +10,52 @@ require_once __DIR__ . '/../../../bootstrap.php'; $array = new ImmutableArray([1, 2, 3, 2]); $empty = new ImmutableArray([]); -// count() + +count: Assert::same($array->count(), 4); Assert::same($array->count(static function (int $v): bool { return $v > 1; }), 3); Assert::same($empty->count(), 0); -// size() + +size: Assert::same($array->size(), 4); Assert::same($empty->size(), 0); -// countValues() + +countValues: Assert::same($array->countValues()->toArray(), [1 => 1, 2 => 2, 3 => 1]); Assert::same($empty->countValues()->toArray(), []); -// max() + +max: Assert::same($array->max(), 3); Assert::null($empty->max()); -// min() + +min: Assert::same($array->min(), 1); Assert::null($empty->min()); -// maxBy() + +maxBy: Assert::same($array->maxBy(static function ($v): float { return 1 / $v; }), 1); -// minBy() + +minBy: Assert::same($array->minBy(static function (int $v): float { return 1 / $v; }), 3); -// product() + +product: Assert::same($array->product(), 12); Assert::same($empty->product(), 1); -// sum() + +sum: Assert::same($array->sum(), 8); Assert::same($empty->sum(), 0); diff --git a/tests/src/common/lists/ImmutableArray/ImmutableArray.transform.phpt b/tests/src/common/lists/ImmutableArray/ImmutableArray.transform.phpt index 782944ef..cb413d7b 100644 --- a/tests/src/common/lists/ImmutableArray/ImmutableArray.transform.phpt +++ b/tests/src/common/lists/ImmutableArray/ImmutableArray.transform.phpt @@ -14,35 +14,43 @@ $f = static function (int $a, int $b): int { return $a + $b; }; -// fold() + +fold: Assert::same($array->fold($f, 0), 10); Assert::same($empty->fold($f, 0), 0); Assert::same($empty->fold($f), null); -// foldLeft() + +foldLeft: Assert::same($array->foldLeft($f, 0), 10); Assert::same($empty->foldLeft($f, 0), 0); Assert::same($empty->foldLeft($f), null); -// foldRight() + +foldRight: Assert::same($array->foldRight($f, 0), 10); Assert::same($empty->foldRight($f, 0), 0); Assert::same($empty->foldRight($f), null); -// reduce() + +reduce: Assert::same($array->reduce($f), 10); Assert::same($empty->reduce($f), null); -// reduceLeft() + +reduceLeft: Assert::same($array->reduceLeft($f), 10); Assert::same($empty->reduceLeft($f), null); -// reduceRight() + +reduceRight: Assert::same($array->reduceRight($f), 10); Assert::same($empty->reduceRight($f), null); -// scanLeft() + +scanLeft: Assert::same($array->scanLeft($f, 0)->toArray(), [0, 1, 3, 6, 10]); -// scanRight() + +scanRight: Assert::same($array->scanRight($f, 0)->toArray(), [10, 9, 7, 4, 0]); diff --git a/tests/src/common/types/Check.basic.phpt b/tests/src/common/types/Check.basic.phpt index ce3eef80..5d4165f1 100644 --- a/tests/src/common/types/Check.basic.phpt +++ b/tests/src/common/types/Check.basic.phpt @@ -18,7 +18,8 @@ use Traversable; require_once __DIR__ . '/../../bootstrap.php'; -// negative zero + +negativeZero: $negativeZero = -(0.0); Check::float($negativeZero); Assert::same((string) $negativeZero, '0'); @@ -27,7 +28,8 @@ $negativeZero = -0.0; Check::string($negativeZero); Assert::same($negativeZero, '0'); -// nullables + +nullables: $null = null; Check::nullableType($null, Type::BOOL); @@ -41,25 +43,29 @@ $array = ['a' => 1, 'b' => 2, 'c' => 3]; $vector = [1, 2, 3]; $mixed = [1, 2, 'a', 'b']; -// type() + +type: Check::type($vector, 'array'); Assert::exception(static function () use ($mixed): void { Check::itemsOfType($mixed, Type::INT); }, InvalidTypeException::class); -// itemsOfType() + +itemsOfType: Check::itemsOfType($array, Type::INT); Assert::exception(static function () use ($mixed): void { Check::itemsOfType($mixed, Type::INT); }, InvalidTypeException::class); -// itemsOfTypes() + +itemsOfTypes: Check::itemsOfTypes($mixed, [Type::INT, Type::STRING]); Assert::exception(static function () use ($mixed): void { Check::itemsOfTypes($mixed, [Type::INT, Type::FLOAT]); }, InvalidTypeException::class); -// traversable() + +traversable: Check::traversable($array); Check::traversable($vector); Check::traversable(new SplFixedArray()); @@ -68,19 +74,22 @@ Assert::exception(static function (): void { Check::traversable(new Exception()); }, InvalidTypeException::class); -// phpArray() + +_array: Check::array($array); Assert::exception(static function () use ($null): void { Check::array($null); }, InvalidTypeException::class); -// plainArray() + +plainArray: Check::plainArray($vector); Assert::exception(static function () use ($array): void { Check::plainArray($array); }, InvalidTypeException::class); -// tuple() + +tuple: Check::tuple(new Tuple(123, 'abc'), [Type::INT, Type::STRING]); Assert::exception(static function (): void { Check::tuple(new Tuple(123, 'abc', 789), [Type::INT, Type::STRING]); @@ -96,26 +105,29 @@ Assert::exception(static function () use ($array): void { }, InvalidTypeException::class); -// object() +object: Check::object(new stdClass(), stdClass::class); Assert::exception(static function () use ($array): void { Check::object($array, stdClass::class); }, InvalidTypeException::class); -// className() + +className: Check::className(stdClass::class); Assert::exception(static function (): void { Check::className(Type::STRING); }, InvalidValueException::class); -// typeName + +typeName: Check::typeName(stdClass::class); Check::typeName(Type::STRING); Assert::exception(static function (): void { Check::typeName('asdf'); }, InvalidValueException::class); -// ranges + +ranges: $small = -100; $big = 100; @@ -146,7 +158,8 @@ Assert::exception(static function () use ($long): void { Check::string($long, 5, 6); }, ValueOutOfRangeException::class); -// oneOf() + +oneOf: Check::oneOf($short); Check::oneOf($short, $null); Check::oneOf($null, $short); @@ -172,13 +185,14 @@ class TestNonTraversable } -// isIterable() +isIterable: Assert::true(Check::isIterable([])); Assert::true(Check::isIterable(new stdClass())); Assert::true(Check::isIterable(new TestTraversable())); Assert::false(Check::isIterable(new TestNonTraversable())); -// isPlainArray() + +isPlainArray: Assert::true(Check::isPlainArray([])); Assert::true(Check::isPlainArray([1, 2, 3])); Assert::false(Check::isPlainArray([1 => 1, 2, 3])); diff --git a/tests/src/common/types/Cls.phpt b/tests/src/common/types/Cls.phpt index e0e63f82..67c1c8d6 100644 --- a/tests/src/common/types/Cls.phpt +++ b/tests/src/common/types/Cls.phpt @@ -44,7 +44,7 @@ class G } -// commonRoot() +commonRoot: Assert::same(Cls::commonRoot(new A(), new AB()), A::class); Assert::same(Cls::commonRoot(new A(), new ABD()), A::class); Assert::same(Cls::commonRoot(new AB(), new AC()), A::class); @@ -53,7 +53,8 @@ Assert::same(Cls::commonRoot(new ABD(), new ABE()), A::class); Assert::same(Cls::commonRoot(new ABD(), new ACF()), A::class); Assert::same(Cls::commonRoot(new ABD(), new G()), null); -// commonBranch() + +commonBranch: Assert::same(Cls::commonBranch(new A(), new AB()), A::class); Assert::same(Cls::commonBranch(new A(), new ABD()), A::class); Assert::same(Cls::commonBranch(new AB(), new AC()), A::class); diff --git a/tests/src/common/types/Str.phpt b/tests/src/common/types/Str.phpt index 009bccc1..6a5c3409 100644 --- a/tests/src/common/types/Str.phpt +++ b/tests/src/common/types/Str.phpt @@ -8,26 +8,31 @@ use Dogma\Tester\Assert; require_once __DIR__ . '/../../bootstrap.php'; -// toFirst() +toFirst: Assert::same(Str::toFirst('abc@def', '@'), 'abc'); Assert::same(Str::toFirst('abc@def', '#'), 'abc@def'); -// fromFirst() + +fromFirst: Assert::same(Str::fromFirst('abc@def', '@'), 'def'); Assert::same(Str::fromFirst('abc@def', '#'), ''); -// splitByFirst() + +splitByFirst: Assert::same(Str::splitByFirst('abc@def', '@'), ['abc', 'def']); Assert::same(Str::splitByFirst('abc@def@ghi', '@'), ['abc', 'def@ghi']); -// splitByLast() + +splitByLast: Assert::same(Str::splitByLast('abc@def', '@'), ['abc', 'def']); Assert::same(Str::splitByLast('abc@def@ghi', '@'), ['abc@def', 'ghi']); -// trimLinesRight() + +trimLinesRight: Assert::same(Str::trimLinesRight("foo \n bar\t\n\tbaz"), "foo\n bar\n\tbaz"); -// levenshteinUnicode() + +levenshteinUnicode: Assert::same(Str::levenshteinUnicode('příliš', 'příliš'), 0.0); Assert::same(Str::levenshteinUnicode('žluťoučký', 'Žluťoučký'), 0.25); Assert::same(Str::levenshteinUnicode('kůň', 'kuň'), 0.5); @@ -35,6 +40,7 @@ Assert::same(Str::levenshteinUnicode('úpěl', 'úpl'), 1.0); Assert::same(Str::levenshteinUnicode('ďábelské', 'ďábelskéé'), 1.0); Assert::same(Str::levenshteinUnicode('ódy', 'údy'), 1.0); -// removeDiacritics() + +removeDiacritics: Assert::same(Str::removeDiacritics('příliš žluťoučký kůň úpěl ďábelské ódy'), 'prilis zlutoucky kun upel dabelske ody'); Assert::same(Str::removeDiacritics('PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ ÚPĚL ĎÁBELSKÉ ÓDY'), 'PRILIS ZLUTOUCKY KUN UPEL DABELSKE ODY'); diff --git a/tests/src/common/types/Type.bool.phpt b/tests/src/common/types/Type.bool.phpt index 368fcb26..d1e6fcf1 100644 --- a/tests/src/common/types/Type.bool.phpt +++ b/tests/src/common/types/Type.bool.phpt @@ -12,98 +12,128 @@ require_once __DIR__ . '/../../bootstrap.php'; $bool = Type::bool(); $boolNullable = Type::bool(Type::NULLABLE); -// getId() + +getId: Assert::same($bool->getId(), 'bool'); Assert::same($boolNullable->getId(), 'bool?'); -// fromId() + +fromId: Assert::same(Type::fromId('bool'), $bool); Assert::same(Type::fromId('bool?'), $boolNullable); -// getName() + +getName: Assert::same($bool->getName(), Type::BOOL); -// isNullable() + +isNullable: Assert::false($bool->isNullable()); Assert::true($boolNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($bool->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($bool->isUnsigned()); -// isFixed() + +isFixed: Assert::false($bool->isFixed()); -// getResourceType() + +getResourceType: Assert::null($bool->getResourceType()); -// getItemType() + +getItemType: Assert::null($bool->getItemType()); -// getSize() + +getSize: Assert::null($bool->getSize()); -// getEncoding() + +getEncoding: Assert::null($bool->getEncoding()); -// getLocale() + +getLocale: Assert::null($bool->getLocale()); -// isBool() + +isBool: Assert::true($bool->isBool()); -// isInt() + +isInt: Assert::false($bool->isInt()); -// isFloat() + +isFloat: Assert::false($bool->isFloat()); -// isNumeric() + +isNumeric: Assert::false($bool->isNumeric()); -// isString() + +isString: Assert::false($bool->isString()); -// isScalar() + +isScalar: Assert::true($bool->isScalar()); -// isArray() + +isArray: Assert::false($bool->isArray()); -// isCollection() + +isCollection: Assert::false($bool->isCollection()); -// isTuple() + +isTuple: Assert::false($bool->isTuple()); -// isClass() + +isClass: Assert::false($bool->isClass()); -// isCallable() + +isCallable: Assert::false($bool->isCallable()); -// isResource() + +isResource: Assert::false($bool->isResource()); -// is() + +is: Assert::true($bool->is(Type::BOOL)); Assert::false($bool->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($bool->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($boolNullable->getBaseType(), $bool); -// getNonNullableType() + +getNonNullableType: Assert::same($boolNullable->getNonNullableType(), $bool); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($boolNullable->getTypeWithoutParams(), $boolNullable); -// getInstance() + +getInstance: Assert::exception(static function () use ($bool): void { $bool->getInstance(); }, Error::class); diff --git a/tests/src/common/types/Type.callable.phpt b/tests/src/common/types/Type.callable.phpt index e118d5f6..5da86a09 100644 --- a/tests/src/common/types/Type.callable.phpt +++ b/tests/src/common/types/Type.callable.phpt @@ -12,101 +12,131 @@ require_once __DIR__ . '/../../bootstrap.php'; $callable = Type::callable(); $callableNullable = Type::callable(Type::NULLABLE); -// getId() + +getId: Assert::same($callable->getId(), 'callable'); Assert::same($callableNullable->getId(), 'callable?'); -// fromId() + +fromId: Assert::same(Type::fromId('callable'), $callable); Assert::same(Type::fromId('callable?'), $callableNullable); -// getName() + +getName: Assert::same($callable->getName(), Type::PHP_CALLABLE); -// isNullable() + +isNullable: Assert::false($callable->isNullable()); Assert::true($callableNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($callable->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($callable->isUnsigned()); -// isFixed() + +isFixed: Assert::false($callable->isFixed()); -// getResourceType() + +getResourceType: Assert::null($callable->getResourceType()); -// getItemType() + +getItemType: Assert::null($callable->getItemType()); -// getSize() + +getSize: Assert::null($callable->getSize()); -// getEncoding() + +getEncoding: Assert::null($callable->getEncoding()); -// getLocale() + +getLocale: Assert::null($callable->getLocale()); -// isBool() + +isBool: Assert::false($callable->isBool()); -// isInt() + +isInt: Assert::false($callable->isInt()); -// isFloat() + +isFloat: Assert::false($callable->isFloat()); -// isNumeric() + +isNumeric: Assert::false($callable->isNumeric()); -// isString() + +isString: Assert::false($callable->isString()); -// isScalar() + +isScalar: Assert::false($callable->isScalar()); -// isArray() + +isArray: Assert::false($callable->isArray()); -// isCollection() + +isCollection: Assert::false($callable->isCollection()); -// isTuple() + +isTuple: Assert::false($callable->isTuple()); -// isClass() + +isClass: Assert::false($callable->isClass()); -// isCallable() + +isCallable: Assert::true($callable->isCallable()); -// isResource() + +isResource: Assert::false($callable->isResource()); -// is() + +is: Assert::true($callable->is(Type::PHP_CALLABLE)); Assert::false($callable->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($callable->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($callable->getBaseType(), $callable); Assert::same($callableNullable->getBaseType(), $callable); -// getNonNullableType() + +getNonNullableType: Assert::same($callable->getNonNullableType(), $callable); Assert::same($callableNullable->getNonNullableType(), $callable); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($callable->getTypeWithoutParams(), $callable); Assert::same($callableNullable->getTypeWithoutParams(), $callableNullable); -// getInstance() + +getInstance: Assert::exception(static function () use ($callable): void { $callable->getInstance(); }, Error::class); diff --git a/tests/src/common/types/Type.float.phpt b/tests/src/common/types/Type.float.phpt index 1a420737..89a5feeb 100644 --- a/tests/src/common/types/Type.float.phpt +++ b/tests/src/common/types/Type.float.phpt @@ -14,105 +14,135 @@ $float = Type::float(); $single = Type::float(BitSize::BITS_32); $floatNullable = Type::float(Type::NULLABLE); -// getId() + +getId: Assert::same($float->getId(), 'float'); Assert::same($single->getId(), 'float(32)'); Assert::same($floatNullable->getId(), 'float?'); -// fromId() + +fromId: Assert::same(Type::fromId('float'), $float); Assert::same(Type::fromId('float(32)'), $single); Assert::same(Type::fromId('float?'), $floatNullable); -// getName() + +getName: Assert::same($float->getName(), Type::FLOAT); -// isNullable() + +isNullable: Assert::false($float->isNullable()); Assert::true($floatNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($float->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($float->isUnsigned()); -// isFixed() + +isFixed: Assert::false($float->isFixed()); -// getResourceType() + +getResourceType: Assert::null($float->getResourceType()); -// getItemType() + +getItemType: Assert::null($float->getItemType()); -// getSize() + +getSize: Assert::null($float->getSize()); Assert::same($single->getSize(), 32); Assert::null($floatNullable->getSize()); -// getEncoding() + +getEncoding: Assert::null($float->getEncoding()); -// getLocale() + +getLocale: Assert::null($float->getLocale()); -// isBool() + +isBool: Assert::false($float->isBool()); -// isInt() + +isInt: Assert::false($float->isInt()); -// isFloat() + +isFloat: Assert::true($float->isFloat()); -// isNumeric() + +isNumeric: Assert::true($float->isNumeric()); -// isString() + +isString: Assert::false($float->isString()); -// isScalar() + +isScalar: Assert::true($float->isScalar()); -// isArray() + +isArray: Assert::false($float->isArray()); -// isCollection() + +isCollection: Assert::false($float->isCollection()); -// isTuple() + +isTuple: Assert::false($float->isTuple()); -// isClass() + +isClass: Assert::false($float->isClass()); -// isCallable() + +isCallable: Assert::false($float->isCallable()); -// isResource() + +isResource: Assert::false($float->isResource()); -// is() + +is: Assert::true($float->is(Type::FLOAT)); Assert::false($float->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($float->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($floatNullable->getBaseType(), $float); Assert::same($single->getBaseType(), $float); -// getNonNullableType() + +getNonNullableType: Assert::same($floatNullable->getNonNullableType(), $float); Assert::same($single->getNonNullableType(), $single); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($floatNullable->getTypeWithoutParams(), $floatNullable); Assert::same($single->getTypeWithoutParams(), $float); -// getInstance() + +getInstance: Assert::exception(static function () use ($float): void { $float->getInstance(); }, Error::class); diff --git a/tests/src/common/types/Type.int.phpt b/tests/src/common/types/Type.int.phpt index 3f347bc3..605e7035 100644 --- a/tests/src/common/types/Type.int.phpt +++ b/tests/src/common/types/Type.int.phpt @@ -20,7 +20,8 @@ $intSizeUnsignedNullable = Type::int(32, Sign::UNSIGNED, Type::NULLABLE); Assert::same($int, $intSigned); -// getId() + +getId: Assert::same($int->getId(), 'int'); Assert::same($intNullable->getId(), 'int?'); Assert::same($intSigned->getId(), 'int'); @@ -29,7 +30,8 @@ Assert::same($intUnsignedNullable->getId(), 'int(unsigned)?'); Assert::same($intSize->getId(), 'int(32)'); Assert::same($intSizeUnsignedNullable->getId(), 'int(32,unsigned)?'); -// fromId() + +fromId: Assert::same(Type::fromId('int'), $int); Assert::same(Type::fromId('int?'), $intNullable); Assert::same(Type::fromId('int(unsigned)'), $intUnsigned); @@ -43,95 +45,123 @@ Assert::same(Type::fromId('int(s)?'), $intNullable); Assert::same(Type::fromId('int(32)'), $intSize); Assert::same(Type::fromId('int(32,unsigned)?'), $intSizeUnsignedNullable); -// getName() + +getName: Assert::same($int->getName(), Type::INT); -// isNullable() + +isNullable: Assert::false($int->isNullable()); Assert::true($intNullable->isNullable()); -// isSigned() + +isSigned: Assert::true($int->isSigned()); Assert::false($intUnsigned->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($int->isUnsigned()); Assert::true($intUnsigned->isUnsigned()); -// isFixed() + +isFixed: Assert::false($int->isFixed()); -// getResourceType() + +getResourceType: Assert::null($int->getResourceType()); -// getItemType() + +getItemType: Assert::null($int->getItemType()); -// getSize() + +getSize: Assert::null($int->getSize()); Assert::same($intSize->getSize(), 32); -// getEncoding() + +getEncoding: Assert::null($int->getEncoding()); -// getLocale() + +getLocale: Assert::null($int->getLocale()); -// isBool() + +isBool: Assert::false($int->isBool()); -// isInt() + +isInt: Assert::true($int->isInt()); -// isFloat() + +isFloat: Assert::false($int->isFloat()); -// isNumeric() + +isNumeric: Assert::true($int->isNumeric()); -// isString() + +isString: Assert::false($int->isString()); -// isScalar() + +isScalar: Assert::true($int->isScalar()); -// isArray() + +isArray: Assert::false($int->isArray()); -// isCollection() + +isCollection: Assert::false($int->isCollection()); -// isTuple() + +isTuple: Assert::false($int->isTuple()); -// isClass() + +isClass: Assert::false($int->isClass()); -// isCallable() + +isCallable: Assert::false($int->isCallable()); -// isResource() + +isResource: Assert::false($int->isResource()); -// is() + +is: Assert::true($int->is(Type::INT)); Assert::false($int->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($int->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($intNullable->getBaseType(), $int); -// getNonNullableType() + +getNonNullableType: Assert::same($intNullable->getNonNullableType(), $int); Assert::same($intSizeUnsignedNullable->getNonNullableType(), Type::fromId('int(32u)')); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($intNullable->getTypeWithoutParams(), $intNullable); Assert::same($intSizeUnsignedNullable->getTypeWithoutParams(), $intNullable); -// getInstance() + +getInstance: Assert::exception(static function () use ($int): void { $int->getInstance(); }, Error::class); diff --git a/tests/src/common/types/Type.lists.phpt b/tests/src/common/types/Type.lists.phpt index fad1b2e1..d2d60810 100644 --- a/tests/src/common/types/Type.lists.phpt +++ b/tests/src/common/types/Type.lists.phpt @@ -16,112 +16,139 @@ $arrayNullable = Type::get(Type::PHP_ARRAY, Type::NULLABLE); $arrayOfInt = Type::arrayOf($int); $arrayOfIntNullable = Type::arrayOf($int, Type::NULLABLE); -// getId() + +getId: Assert::same($array->getId(), 'array'); Assert::same($arrayNullable->getId(), 'array?'); Assert::same($arrayOfInt->getId(), 'array'); Assert::same($arrayOfIntNullable->getId(), 'array?'); -// fromId() + +fromId: Assert::same(Type::fromId('array'), $array); Assert::same(Type::fromId('array?'), $arrayNullable); Assert::same(Type::fromId('array'), $arrayOfInt); Assert::same(Type::fromId('array?'), $arrayOfIntNullable); -// getName() + +getName: Assert::same($array->getName(), Type::PHP_ARRAY); -// isNullable() + +isNullable: Assert::false($array->isNullable()); Assert::true($arrayNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($array->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($array->isUnsigned()); -// isFixed() + +isFixed: Assert::false($array->isFixed()); -// getResourceType() + +getResourceType: Assert::null($array->getResourceType()); -// getItemType() + +getItemType: Assert::same($array->getItemType(), Type::get(Type::MIXED)); Assert::same($arrayOfInt->getItemType(), Type::int()); -// getSize() + +getSize: Assert::null($array->getSize()); -// getEncoding() + +getEncoding: Assert::null($array->getEncoding()); -// getLocale() + +getLocale: Assert::null($array->getLocale()); -// isBool() + +isBool: Assert::false($array->isBool()); -// isInt() + +isInt: Assert::false($array->isInt()); -// isFloat() + +isFloat: Assert::false($array->isFloat()); -// isNumeric() + +isNumeric: Assert::false($array->isNumeric()); -// isString() + +isString: Assert::false($array->isString()); -// isScalar() + +isScalar: Assert::false($array->isScalar()); -// isArray() + +isArray: Assert::true($array->isArray()); Assert::true($arrayOfInt->isArray()); -// isCollection() + +isCollection: Assert::false($array->isCollection()); Assert::false($arrayOfInt->isCollection()); -// isTuple() + +isTuple: Assert::false($array->isTuple()); -// isClass() + +isClass: Assert::false($array->isClass()); -// isCallable() + +isCallable: Assert::false($array->isCallable()); -// isResource() + +isResource: Assert::false($array->isResource()); -// is() + +is: Assert::true($array->is(Type::PHP_ARRAY)); Assert::false($array->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($array->isImplementing(DateTime::class)); Assert::false($array->is(DateTime::class)); -// isImplementing() -Assert::false($array->isImplementing(DateTime::class)); -// getBaseType() +getBaseType: Assert::same($arrayNullable->getBaseType(), $array); Assert::same($array->getBaseType(), $array); -// getNonNullableType() + +getNonNullableType: Assert::same($arrayNullable->getNonNullableType(), $array); Assert::same($array->getNonNullableType(), $array); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($arrayNullable->getTypeWithoutParams(), $arrayNullable); Assert::same($array->getTypeWithoutParams(), $array); -// getInstance() + +getInstance: Assert::exception(static function () use ($array): void { $array->getInstance('abc'); }, Error::class); diff --git a/tests/src/common/types/Type.object.phpt b/tests/src/common/types/Type.object.phpt index a87e96ec..92232af0 100644 --- a/tests/src/common/types/Type.object.phpt +++ b/tests/src/common/types/Type.object.phpt @@ -12,100 +12,130 @@ require_once __DIR__ . '/../../bootstrap.php'; $datetime = Type::get(DateTime::class); $datetimeNullable = Type::get(DateTime::class, Type::NULLABLE); -// getId() + +getId: Assert::same($datetime->getId(), 'DateTime'); Assert::same($datetimeNullable->getId(), 'DateTime?'); -// fromId() + +fromId: Assert::same(Type::fromId('DateTime'), $datetime); Assert::same(Type::fromId('DateTime?'), $datetimeNullable); -// getName() + +getName: Assert::same($datetime->getName(), DateTime::class); -// isNullable() + +isNullable: Assert::false($datetime->isNullable()); Assert::true($datetimeNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($datetime->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($datetime->isUnsigned()); -// isFixed() + +isFixed: Assert::false($datetime->isFixed()); -// getResourceType() + +getResourceType: Assert::null($datetime->getResourceType()); -// getItemType() + +getItemType: Assert::null($datetime->getItemType()); -// getSize() + +getSize: Assert::null($datetime->getSize()); -// getEncoding() + +getEncoding: Assert::null($datetime->getEncoding()); -// getLocale() + +getLocale: Assert::null($datetime->getLocale()); -// isBool() + +isBool: Assert::false($datetime->isBool()); -// isInt() + +isInt: Assert::false($datetime->isInt()); -// isFloat() + +isFloat: Assert::false($datetime->isFloat()); -// isNumeric() + +isNumeric: Assert::false($datetime->isNumeric()); -// isString() + +isString: Assert::false($datetime->isString()); -// isScalar() + +isScalar: Assert::false($datetime->isScalar()); -// isArray() + +isArray: Assert::false($datetime->isArray()); -// isCollection() + +isCollection: Assert::false($datetime->isCollection()); -// isTuple() + +isTuple: Assert::false($datetime->isTuple()); -// isClass() + +isClass: Assert::true($datetime->isClass()); -// isCallable() + +isCallable: Assert::false($datetime->isCallable()); -// isResource() + +isResource: Assert::false($datetime->isResource()); -// is() + +is: Assert::true($datetime->is(DateTime::class)); Assert::false($datetime->is(DateTimeImmutable::class)); -// isImplementing() + +isImplementing: Assert::true($datetime->isImplementing(DateTime::class)); Assert::false($datetime->isImplementing(DateTimeImmutable::class)); -// getBaseType() + +getBaseType: Assert::same($datetime->getBaseType(), $datetime); Assert::same($datetimeNullable->getBaseType(), $datetime); -// getNonNullableType() + +getNonNullableType: Assert::same($datetime->getNonNullableType(), $datetime); Assert::same($datetimeNullable->getNonNullableType(), $datetime); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($datetime->getTypeWithoutParams(), $datetime); Assert::same($datetimeNullable->getTypeWithoutParams(), $datetimeNullable); -// getInstance() + +getInstance: Assert::equal($datetime->getInstance('2016-01-01 00:00:00'), new DateTime('2016-01-01 00:00:00')); diff --git a/tests/src/common/types/Type.phpt b/tests/src/common/types/Type.phpt index ef79b066..5c08691f 100644 --- a/tests/src/common/types/Type.phpt +++ b/tests/src/common/types/Type.phpt @@ -10,9 +10,8 @@ use SplFixedArray; require_once __DIR__ . '/../../bootstrap.php'; -// more complex examples: -// without params +without_params: $id = 'Dogma\\Tuple,int>,SplFixedArray>'; $type = Type::fromId($id); $expected = Type::tupleOf( @@ -28,7 +27,8 @@ $expected = Type::tupleOf( Assert::same($type, $expected); Assert::same($expected->getId(), $id); -// with nullable + +with_nullable: $id = 'Dogma\\Tuple,int>?,SplFixedArray>?'; $type = Type::fromId($id); $expected = Type::tupleOf( @@ -46,7 +46,8 @@ $expected = Type::tupleOf( Assert::same($type, $expected); Assert::same($expected->getId(), $id); -// with nullable and params + +with_nullable_and_params: $id = 'Dogma\\Tuple,int>?,SplFixedArray>?'; $type = Type::fromId($id); $expected = Type::tupleOf( diff --git a/tests/src/common/types/Type.resource.phpt b/tests/src/common/types/Type.resource.phpt index 43cf4ecc..1bd3fb21 100644 --- a/tests/src/common/types/Type.resource.phpt +++ b/tests/src/common/types/Type.resource.phpt @@ -16,104 +16,134 @@ $resource = Type::resource(); $resourceAspell = Type::resource($aspell); $resourceNullable = Type::resource(Type::NULLABLE); -// getId() + +getId: Assert::same($resource->getId(), 'resource'); Assert::same($resourceAspell->getId(), 'resource(aspell)'); Assert::same($resourceNullable->getId(), 'resource?'); -// fromId() + +fromId: Assert::same(Type::fromId('resource'), $resource); Assert::same(Type::fromId('resource(aspell)'), $resourceAspell); Assert::same(Type::fromId('resource?'), $resourceNullable); -// getName() + +getName: Assert::same($resource->getName(), Type::RESOURCE); -// isNullable() + +isNullable: Assert::false($resource->isNullable()); Assert::true($resourceNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($resource->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($resource->isUnsigned()); -// isFixed() + +isFixed: Assert::false($resource->isFixed()); -// getResourceType() + +getResourceType: Assert::null($resource->getResourceType()); Assert::equal($resourceAspell->getResourceType(), $aspell); -// getItemType() + +getItemType: Assert::null($resource->getItemType()); -// getSize() + +getSize: Assert::null($resource->getSize()); -// getEncoding() + +getEncoding: Assert::null($resource->getEncoding()); -// getLocale() + +getLocale: Assert::null($resource->getLocale()); -// isBool() + +isBool: Assert::false($resource->isBool()); -// isInt() + +isInt: Assert::false($resource->isInt()); -// isFloat() + +isFloat: Assert::false($resource->isFloat()); -// isNumeric() + +isNumeric: Assert::false($resource->isNumeric()); -// isString() + +isString: Assert::false($resource->isString()); -// isScalar() + +isScalar: Assert::false($resource->isScalar()); -// isArray() + +isArray: Assert::false($resource->isArray()); -// isCollection() + +isCollection: Assert::false($resource->isCollection()); -// isTuple() + +isTuple: Assert::false($resource->isTuple()); -// isClass() + +isClass: Assert::false($resource->isClass()); -// isCallable() + +isCallable: Assert::false($resource->isCallable()); -// isResource() + +isResource: Assert::true($resource->isResource()); -// is() + +is: Assert::true($resource->is(Type::RESOURCE)); Assert::false($resource->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($resource->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($resourceNullable->getBaseType(), $resource); Assert::same($resourceAspell->getBaseType(), $resource); -// getNonNullableType() + +getNonNullableType: Assert::same($resourceNullable->getNonNullableType(), $resource); Assert::same($resourceAspell->getNonNullableType(), $resourceAspell); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($resourceNullable->getTypeWithoutParams(), $resourceNullable); Assert::same($resourceAspell->getTypeWithoutParams(), $resource); -// getInstance() + +getInstance: Assert::exception(static function () use ($resource): void { $resource->getInstance('abc'); }, Error::class); diff --git a/tests/src/common/types/Type.string.phpt b/tests/src/common/types/Type.string.phpt index 609b99d6..466d4047 100644 --- a/tests/src/common/types/Type.string.phpt +++ b/tests/src/common/types/Type.string.phpt @@ -25,7 +25,8 @@ $stringLocale = Type::string($czech); $stringNullable = Type::string(Type::NULLABLE); $stringAllParams = Type::string(32, Length::FIXED, $utf8, $czech, Type::NULLABLE); -// getId() + +getId: Assert::same($string->getId(), 'string'); Assert::same($stringLength->getId(), 'string(32)'); Assert::same($stringFixed->getId(), 'string(fixed)'); @@ -34,7 +35,8 @@ Assert::same($stringLocale->getId(), 'string(cs_CZ)'); Assert::same($stringNullable->getId(), 'string?'); Assert::same($stringAllParams->getId(), 'string(32,fixed,UTF-8,cs_CZ)?'); -// fromId() + +fromId: Assert::same(Type::fromId('string'), $string); Assert::same(Type::fromId('string(32)'), $stringLength); Assert::same(Type::fromId('string(fixed)'), $stringFixed); @@ -45,100 +47,128 @@ Assert::same(Type::fromId('string(cs_CZ)'), $stringLocale); Assert::same(Type::fromId('string?'), $stringNullable); Assert::same(Type::fromId('string(32,fixed,UTF-8,cs_CZ)?'), $stringAllParams); -// getName() + +getName: Assert::same($string->getName(), Type::STRING); -// isNullable() + +isNullable: Assert::false($string->isNullable()); Assert::true($stringNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($string->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($string->isUnsigned()); -// isFixed() + +isFixed: Assert::false($string->isFixed()); Assert::true($stringFixed->isFixed()); Assert::true($stringAllParams->isFixed()); -// getResourceType() + +getResourceType: Assert::null($string->getResourceType()); -// getItemType() + +getItemType: Assert::null($string->getItemType()); -// getSize() + +getSize: Assert::null($string->getSize()); Assert::null($stringFixed->getSize()); Assert::same($stringLength->getSize(), 32); Assert::same($stringAllParams->getSize(), 32); -// getEncoding() + +getEncoding: Assert::null($string->getEncoding()); Assert::same($stringEncoding->getEncoding(), $utf8); -// getLocale() + +getLocale: Assert::null($string->getLocale()); Assert::same($stringLocale->getLocale(), $czech); -// isBool() + +isBool: Assert::false($string->isBool()); -// isInt() + +isInt: Assert::false($string->isInt()); -// isFloat() + +isFloat: Assert::false($string->isFloat()); -// isNumeric() + +isNumeric: Assert::false($string->isNumeric()); -// isString() + +isString: Assert::true($string->isString()); -// isScalar() + +isScalar: Assert::true($string->isScalar()); -// isArray() + +isArray: Assert::false($string->isArray()); -// isCollection() + +isCollection: Assert::false($string->isCollection()); -// isTuple() + +isTuple: Assert::false($string->isTuple()); -// isClass() + +isClass: Assert::false($string->isClass()); -// isCallable() + +isCallable: Assert::false($string->isCallable()); -// isResource() + +isResource: Assert::false($string->isResource()); -// is() + +is: Assert::true($string->is(Type::STRING)); Assert::false($string->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::false($string->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($stringNullable->getBaseType(), $string); Assert::same($stringAllParams->getBaseType(), $string); -// getNonNullableType() + +getNonNullableType: Assert::same($stringNullable->getNonNullableType(), $string); Assert::same($stringAllParams->getNonNullableType(), Type::fromId('string(32,fixed,UTF-8,cs_CZ)')); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($stringNullable->getTypeWithoutParams(), $stringNullable); Assert::same($stringAllParams->getTypeWithoutParams(), $stringNullable); -// getInstance() + +getInstance: Assert::exception(static function () use ($string): void { $string->getInstance(); }, Error::class); diff --git a/tests/src/common/types/Type.tupple.phpt b/tests/src/common/types/Type.tupple.phpt index a8983cf0..328dfb91 100644 --- a/tests/src/common/types/Type.tupple.phpt +++ b/tests/src/common/types/Type.tupple.phpt @@ -12,100 +12,130 @@ require_once __DIR__ . '/../../bootstrap.php'; $tuple = Type::tupleOf(Type::INT, Type::STRING); $tupleNullable = Type::tupleOf(Type::INT, Type::STRING, Type::NULLABLE); -// getId() + +getId: Assert::same($tuple->getId(), 'Dogma\\Tuple'); Assert::same($tupleNullable->getId(), 'Dogma\\Tuple?'); -// fromId() + +fromId: Assert::same(Type::fromId('Dogma\\Tuple'), $tuple); Assert::same(Type::fromId('Dogma\\Tuple?'), $tupleNullable); -// getName() + +getName: Assert::same($tuple->getName(), Tuple::class); -// isNullable() + +isNullable: Assert::false($tuple->isNullable()); Assert::true($tupleNullable->isNullable()); -// isSigned() + +isSigned: Assert::false($tuple->isSigned()); -// isUnsigned() + +isUnsigned: Assert::false($tuple->isUnsigned()); -// isFixed() + +isFixed: Assert::false($tuple->isFixed()); -// getResourceType() + +getResourceType: Assert::null($tuple->getResourceType()); -// getItemType() + +getItemType: Assert::same($tuple->getItemType(), [Type::int(), Type::string()]); -// getSize() + +getSize: Assert::null($tuple->getSize()); -// getEncoding() + +getEncoding: Assert::null($tuple->getEncoding()); -// getLocale() + +getLocale: Assert::null($tuple->getLocale()); -// isBool() + +isBool: Assert::false($tuple->isBool()); -// isInt() + +isInt: Assert::false($tuple->isInt()); -// isFloat() + +isFloat: Assert::false($tuple->isFloat()); -// isNumeric() + +isNumeric: Assert::false($tuple->isNumeric()); -// isString() + +isString: Assert::false($tuple->isString()); -// isScalar() + +isScalar: Assert::false($tuple->isScalar()); -// isArray() + +isArray: Assert::false($tuple->isArray()); -// isCollection() + +isCollection: Assert::false($tuple->isCollection()); -// isTuple() + +isTuple: Assert::true($tuple->isTuple()); -// isClass() + +isClass: Assert::true($tuple->isClass()); -// isCallable() + +isCallable: Assert::false($tuple->isCallable()); -// isResource() + +isResource: Assert::false($tuple->isResource()); -// is() + +is: Assert::true($tuple->is(Tuple::class)); Assert::false($tuple->is(DateTime::class)); -// isImplementing() + +isImplementing: Assert::true($tuple->isImplementing(Tuple::class)); Assert::false($tuple->isImplementing(DateTime::class)); -// getBaseType() + +getBaseType: Assert::same($tuple->getBaseType(), Type::get(Tuple::class)); Assert::same($tupleNullable->getBaseType(), Type::get(Tuple::class)); -// getNonNullableType() + +getNonNullableType: Assert::same($tuple->getNonNullableType(), $tuple); Assert::same($tupleNullable->getNonNullableType(), $tuple); -// getTypeWithoutParams() + +getTypeWithoutParams: Assert::same($tuple->getTypeWithoutParams(), $tuple); Assert::same($tupleNullable->getTypeWithoutParams(), $tupleNullable); -// getInstance() + +getInstance: Assert::equal($tuple->getInstance(1, 'abc'), new Tuple(1, 'abc'));