Browse Source

* finished linq stuff

master
bergmann 7 years ago
parent
commit
77ee5bce60
29 changed files with 4909 additions and 1440 deletions
  1. +80
    -18
      tests/tests.lpi
  2. +13
    -2
      tests/tests.lpr
  3. +411
    -208
      tests/tests.lps
  4. +9
    -11
      tests/uutlAlgorithmTests.pas
  5. +0
    -151
      tests/uutlArrayTests.pas
  6. +369
    -128
      tests/uutlEnumeratorTests.pas
  7. +1
    -1
      tests/uutlHashSetTests.pas
  8. +855
    -0
      tests/uutlLinqTests.pas
  9. +1
    -4
      tests/uutlMapTests.pas
  10. +140
    -0
      tests/uutlObservableListTests.pas
  11. +134
    -6
      uutlAlgorithm.pas
  12. +4
    -7
      uutlArrayContainer.pas
  13. +403
    -4
      uutlCommon.pas
  14. +27
    -3
      uutlComparer.pas
  15. +645
    -155
      uutlEnumerator.pas
  16. +138
    -128
      uutlEvent.pas
  17. +23
    -13
      uutlEventManager.pas
  18. +0
    -110
      uutlExceptions.pas
  19. +45
    -21
      uutlFilter.pas
  20. +109
    -132
      uutlGenerics.pas
  21. +30
    -13
      uutlInterfaces.pas
  22. +436
    -0
      uutlLinq.pas
  23. +20
    -12
      uutlListBase.pas
  24. +2
    -2
      uutlLogger.pas
  25. +288
    -0
      uutlObservable.pas
  26. +475
    -237
      uutlStreamHelper.pas
  27. +180
    -21
      uutlSyncObjs.pas
  28. +23
    -0
      uutlTypes.pas
  29. +48
    -53
      uutlXmlHelper.pas

+ 80
- 18
tests/tests.lpi View File

@@ -37,7 +37,7 @@
<PackageName Value="FCL"/>
</Item3>
</RequiredPackages>
<Units Count="21">
<Units Count="35">
<Unit0>
<Filename Value="tests.lpr"/>
<IsPartOfProject Value="True"/>
@@ -55,73 +55,129 @@
<IsPartOfProject Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\uutlExceptions.pas"/>
<Filename Value="..\uutlListBase.pas"/>
<IsPartOfProject Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\uutlListBase.pas"/>
<Filename Value="uutlListTest.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
<Unit6>
<Filename Value="uutlListTest.pas"/>
<Filename Value="uutlQueueTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit6>
<Unit7>
<Filename Value="uutlQueueTests.pas"/>
<Filename Value="uutlStackTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit7>
<Unit8>
<Filename Value="uutlStackTests.pas"/>
<Filename Value="uTestHelper.pas"/>
<IsPartOfProject Value="True"/>
</Unit8>
<Unit9>
<Filename Value="uTestHelper.pas"/>
<Filename Value="..\uutlComparer.pas"/>
<IsPartOfProject Value="True"/>
</Unit9>
<Unit10>
<Filename Value="_uutlInterfaces.pas"/>
<Filename Value="..\uutlAlgorithm.pas"/>
<IsPartOfProject Value="True"/>
</Unit10>
<Unit11>
<Filename Value="..\uutlComparer.pas"/>
<Filename Value="uutlHashSetTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit11>
<Unit12>
<Filename Value="..\uutlAlgorithm.pas"/>
<Filename Value="uutlAlgorithmTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit12>
<Unit13>
<Filename Value="uutlHashSetTests.pas"/>
<Filename Value="uutlMapTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit13>
<Unit14>
<Filename Value="uutlArrayTests.pas"/>
<Filename Value="..\uutlEnumerator.pas"/>
<IsPartOfProject Value="True"/>
</Unit14>
<Unit15>
<Filename Value="uutlAlgorithmTests.pas"/>
<Filename Value="uutlEnumeratorTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit15>
<Unit16>
<Filename Value="uutlMapTests.pas"/>
<Filename Value="..\uutlFilter.pas"/>
<IsPartOfProject Value="True"/>
</Unit16>
<Unit17>
<Filename Value="..\uutlEnumerator.pas"/>
<Filename Value="..\uutlInterfaces.pas"/>
<IsPartOfProject Value="True"/>
</Unit17>
<Unit18>
<Filename Value="uutlEnumeratorTests.pas"/>
<Filename Value="..\uutlLinq.pas"/>
<IsPartOfProject Value="True"/>
</Unit18>
<Unit19>
<Filename Value="..\uutlFilter.pas"/>
<Filename Value="uutlLinqTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit19>
<Unit20>
<Filename Value="..\uutlInterfaces.pas"/>
<Filename Value="..\uutlTypes.pas"/>
<IsPartOfProject Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\uutlSyncObjs.pas"/>
<IsPartOfProject Value="True"/>
</Unit21>
<Unit22>
<Filename Value="..\uutlLogger.pas"/>
<IsPartOfProject Value="True"/>
</Unit22>
<Unit23>
<Filename Value="..\uutlXmlHelper.pas"/>
<IsPartOfProject Value="True"/>
</Unit23>
<Unit24>
<Filename Value="..\uutlStreamHelper.pas"/>
<IsPartOfProject Value="True"/>
</Unit24>
<Unit25>
<Filename Value="..\uutlCompression.pas"/>
<IsPartOfProject Value="True"/>
</Unit25>
<Unit26>
<Filename Value="..\uutlEmbeddedProfiler.pas"/>
<IsPartOfProject Value="True"/>
</Unit26>
<Unit27>
<Filename Value="..\uutlKeyCodes.pas"/>
<IsPartOfProject Value="True"/>
</Unit27>
<Unit28>
<Filename Value="..\uutlMCF.pas"/>
<IsPartOfProject Value="True"/>
</Unit28>
<Unit29>
<Filename Value="..\uutlSScanf.pas"/>
<IsPartOfProject Value="True"/>
</Unit29>
<Unit30>
<Filename Value="..\uutlThreads.pas"/>
<IsPartOfProject Value="True"/>
</Unit30>
<Unit31>
<Filename Value="..\uutlEvent.pas"/>
<IsPartOfProject Value="True"/>
</Unit31>
<Unit32>
<Filename Value="..\uutlEventManager.pas"/>
<IsPartOfProject Value="True"/>
</Unit32>
<Unit33>
<Filename Value="..\uutlObservable.pas"/>
<IsPartOfProject Value="True"/>
</Unit33>
<Unit34>
<Filename Value="uutlObservableListTests.pas"/>
<IsPartOfProject Value="True"/>
</Unit34>
</Units>
</ProjectOptions>
<CompilerOptions>
@@ -150,6 +206,12 @@
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
</CompilerMessages>
<OtherDefines Count="4">
<Define0 Value="UTL_ADVANCED_ENUMERATORS"/>
<Define1 Value="UTL_NESTED_PROCVARS"/>
<Define2 Value="UTL_DELPHI_GENERICS"/>
<Define3 Value="UTL_ENUMERATORS"/>
</OtherDefines>
</Other>
</CompilerOptions>
<Debugging>


+ 13
- 2
tests/tests.lpr View File

@@ -1,11 +1,22 @@
program tests;

{$mode objfpc}{$H+}
{$WARN 5023 off}

uses
Interfaces, Forms, GUITestRunner,
uutlStackTests, uutlQueueTests, uutlListTest, uutlHashSetTests, uutlArrayTests,
uutlAlgorithmTests, uutlMapTests, uutlEnumeratorTests;

// test cases
uutlAlgorithmTests, uutlEnumeratorTests, uutlHashSetTests, uutlLinqTests,
uutlListTest, uutlMapTests, uutlQueueTests, uutlStackTests,

// test misc
uTestHelper,

// units unter test
uutlAlgorithm, uutlArrayContainer, uutlCommon, uutlComparer, uutlEnumerator,
uutlFilter, uutlGenerics, uutlInterfaces, uutlLinq, uutlListBase, uutlLogger,
uutlStreamHelper, uutlSyncObjs, uutlTypes, uutlXmlHelper, uutlObservable, uutlObservableListTests;

{$R *.res}



+ 411
- 208
tests/tests.lps View File

@@ -4,402 +4,605 @@
<PathDelim Value="\"/>
<Version Value="9"/>
<BuildModes Active="Default"/>
<Units Count="34">
<Units Count="60">
<Unit0>
<Filename Value="tests.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<CursorPos X="5" Y="15"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="23" Y="10"/>
<UsageCount Value="70"/>
</Unit0>
<Unit1>
<Filename Value="..\uutlGenerics.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="1045"/>
<CursorPos X="25" Y="1060"/>
<UsageCount Value="30"/>
<CursorPos X="26" Y="504"/>
<UsageCount Value="70"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="..\uutlArrayContainer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="24"/>
<CursorPos X="14" Y="38"/>
<UsageCount Value="30"/>
<TopLine Value="96"/>
<CursorPos X="50" Y="115"/>
<UsageCount Value="70"/>
</Unit2>
<Unit3>
<Filename Value="..\uutlCommon.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="3"/>
<CursorPos X="29" Y="8"/>
<UsageCount Value="30"/>
<WindowIndex Value="-1"/>
<TopLine Value="351"/>
<CursorPos X="12" Y="356"/>
<UsageCount Value="70"/>
</Unit3>
<Unit4>
<Filename Value="..\uutlExceptions.pas"/>
<Filename Value="..\uutlListBase.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="9"/>
<CursorPos X="35" Y="14"/>
<UsageCount Value="30"/>
<TopLine Value="85"/>
<CursorPos Y="104"/>
<UsageCount Value="70"/>
</Unit4>
<Unit5>
<Filename Value="..\uutlListBase.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="4"/>
<CursorPos X="23" Y="9"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="uutlListTest.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="357"/>
<CursorPos X="7" Y="376"/>
<UsageCount Value="30"/>
</Unit6>
<Unit7>
<UsageCount Value="70"/>
</Unit5>
<Unit6>
<Filename Value="uutlQueueTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<UsageCount Value="30"/>
</Unit7>
<Unit8>
<UsageCount Value="70"/>
</Unit6>
<Unit7>
<Filename Value="uutlStackTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="3" Y="9"/>
<UsageCount Value="30"/>
</Unit8>
<Unit9>
<UsageCount Value="70"/>
</Unit7>
<Unit8>
<Filename Value="uTestHelper.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<CursorPos X="3" Y="12"/>
<UsageCount Value="30"/>
<UsageCount Value="70"/>
</Unit8>
<Unit9>
<Filename Value="..\uutlComparer.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="4"/>
<CursorPos X="90" Y="6"/>
<UsageCount Value="60"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="_uutlInterfaces.pas"/>
<Filename Value="..\uutlAlgorithm.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="42" Y="6"/>
<UsageCount Value="30"/>
<TopLine Value="115"/>
<CursorPos Y="132"/>
<UsageCount Value="70"/>
</Unit10>
<Unit11>
<Filename Value="..\uutlComparer.pas"/>
<Filename Value="uutlHashSetTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<CursorPos X="25" Y="13"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="32" Y="13"/>
<UsageCount Value="70"/>
</Unit11>
<Unit12>
<Filename Value="..\uutlAlgorithm.pas"/>
<Filename Value="uutlAlgorithmTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="43"/>
<CursorPos X="33" Y="55"/>
<UsageCount Value="30"/>
<TopLine Value="72"/>
<CursorPos X="43" Y="87"/>
<UsageCount Value="69"/>
</Unit12>
<Unit13>
<Filename Value="uutlHashSetTests.pas"/>
<Filename Value="uutlMapTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<UsageCount Value="30"/>
<TopLine Value="206"/>
<CursorPos X="66" Y="221"/>
<UsageCount Value="68"/>
</Unit13>
<Unit14>
<Filename Value="uutlArrayTests.pas"/>
<Filename Value="..\uutlEnumerator.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="118"/>
<CursorPos X="29" Y="137"/>
<UsageCount Value="29"/>
<EditorIndex Value="6"/>
<CursorPos X="3" Y="10"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
<Filename Value="uutlAlgorithmTests.pas"/>
<Filename Value="uutlEnumeratorTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos Y="77"/>
<UsageCount Value="29"/>
<TopLine Value="69"/>
<CursorPos X="3" Y="64"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit15>
<Unit16>
<Filename Value="..\..\Utils\uutlGenerics2.pas"/>
<IsVisibleTab Value="True"/>
<WindowIndex Value="1"/>
<TopLine Value="1902"/>
<CursorPos Y="1905"/>
<UsageCount Value="11"/>
<Filename Value="..\uutlFilter.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="5"/>
<TopLine Value="17"/>
<CursorPos X="13" Y="159"/>
<UsageCount Value="63"/>
<Loaded Value="True"/>
</Unit16>
<Unit17>
<Filename Value="..\..\Utils\uutlCommon2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="9"/>
<CursorPos X="15" Y="26"/>
<UsageCount Value="11"/>
<Filename Value="..\uutlInterfaces.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="3"/>
<TopLine Value="68"/>
<CursorPos X="47" Y="72"/>
<UsageCount Value="63"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="..\..\Utils\uutlExceptions.pas"/>
<EditorIndex Value="-1"/>
<Filename Value="..\uutlLinq.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<WindowIndex Value="1"/>
<TopLine Value="77"/>
<CursorPos X="3" Y="18"/>
<UsageCount Value="9"/>
<TopLine Value="31"/>
<CursorPos X="3" Y="52"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="..\..\Utils\tests\uutlInterfaces2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="49"/>
<CursorPos X="35" Y="60"/>
<UsageCount Value="11"/>
<Filename Value="uutlLinqTests.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="252"/>
<CursorPos X="70" Y="270"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="..\..\Utils\uutlComparer.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="84"/>
<CursorPos X="28" Y="28"/>
<UsageCount Value="11"/>
<Filename Value="..\uutlTypes.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="7"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\..\Utils\uutlAlgorithm2.pas"/>
<Filename Value="..\uutlSyncObjs.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="66"/>
<CursorPos X="5" Y="93"/>
<UsageCount Value="11"/>
<TopLine Value="241"/>
<CursorPos X="20" Y="263"/>
<UsageCount Value="48"/>
</Unit21>
<Unit22>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\objpas.pp"/>
<Filename Value="..\uutlLogger.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="62"/>
<CursorPos X="5" Y="77"/>
<UsageCount Value="13"/>
<TopLine Value="419"/>
<CursorPos X="55" Y="434"/>
<UsageCount Value="46"/>
</Unit22>
<Unit23>
<Filename Value="..\..\Utils\uutlInterfaces.pas"/>
<Filename Value="..\uutlXmlHelper.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="31"/>
<CursorPos X="22" Y="45"/>
<UsageCount Value="12"/>
<TopLine Value="188"/>
<CursorPos X="26" Y="203"/>
<UsageCount Value="47"/>
</Unit23>
<Unit24>
<Filename Value="G:\Eigene Datein\Projekte\_Active Projekte\TotoStarRedesign\utils\uutlAlgorithm.pas"/>
<Filename Value="..\uutlStreamHelper.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="48"/>
<CursorPos X="45" Y="56"/>
<UsageCount Value="11"/>
<TopLine Value="216"/>
<CursorPos X="10" Y="241"/>
<UsageCount Value="46"/>
</Unit24>
<Unit25>
<Filename Value="uutlMapTests.pas"/>
<Filename Value="..\uutlCompression.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="65"/>
<CursorPos X="60" Y="75"/>
<UsageCount Value="28"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit25>
<Unit26>
<Filename Value="..\..\Utils\uutlEnumerator2.pas"/>
<Filename Value="..\uutlEmbeddedProfiler.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="126"/>
<CursorPos X="22" Y="128"/>
<UsageCount Value="10"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit26>
<Unit27>
<Filename Value="..\uutlEnumerator.pas"/>
<Filename Value="..\uutlKeyCodes.pas"/>
<IsPartOfProject Value="True"/>
<TopLine Value="76"/>
<CursorPos X="39" Y="90"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit27>
<Unit28>
<Filename Value="uutlEnumeratorTests.pas"/>
<Filename Value="..\uutlMCF.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="247"/>
<CursorPos X="29" Y="262"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit28>
<Unit29>
<Filename Value="C:\Zusatzprogramme\Lazarus\components\fptest\src\FPCUnitCompatibleInterface.inc"/>
<Filename Value="..\uutlSScanf.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="90"/>
<CursorPos X="16" Y="97"/>
<UsageCount Value="10"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit29>
<Unit30>
<Filename Value="C:\Zusatzprogramme\Lazarus\components\fptest\src\TestFramework.pas"/>
<Filename Value="..\uutlThreads.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="2964"/>
<CursorPos Y="2979"/>
<UsageCount Value="9"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="46"/>
</Unit30>
<Unit31>
<Filename Value="..\uutlFilter.pas"/>
<Filename Value="..\uutlEvent.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="7"/>
<TopLine Value="19"/>
<CursorPos X="40" Y="62"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="54" Y="9"/>
<UsageCount Value="45"/>
</Unit31>
<Unit32>
<Filename Value="..\uutlInterfaces.pas"/>
<Filename Value="..\uutlEventManager.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="5"/>
<CursorPos X="21" Y="10"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="246"/>
<CursorPos X="39" Y="264"/>
<UsageCount Value="45"/>
</Unit32>
<Unit33>
<Filename Value="..\uutlObservable.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="134"/>
<CursorPos X="13" Y="147"/>
<UsageCount Value="45"/>
</Unit33>
<Unit34>
<Filename Value="uutlObservableListTests.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="24"/>
<CursorPos X="76" Y="130"/>
<UsageCount Value="37"/>
</Unit34>
<Unit35>
<Filename Value="..\uutlExceptions.pas"/>
<EditorIndex Value="-1"/>
<CursorPos X="21" Y="3"/>
<UsageCount Value="32"/>
</Unit35>
<Unit36>
<Filename Value="_uutlInterfaces.pas"/>
<EditorIndex Value="-1"/>
<CursorPos X="42" Y="6"/>
<UsageCount Value="33"/>
</Unit36>
<Unit37>
<Filename Value="uutlArrayTests.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="9"/>
<CursorPos X="25" Y="38"/>
<UsageCount Value="32"/>
</Unit37>
<Unit38>
<Filename Value="..\uutlGenerics2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="1902"/>
<CursorPos Y="1905"/>
<UsageCount Value="7"/>
</Unit38>
<Unit39>
<Filename Value="..\uutlCommon2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="9"/>
<CursorPos X="15" Y="26"/>
<UsageCount Value="7"/>
</Unit39>
<Unit40>
<Filename Value="uutlInterfaces2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="49"/>
<CursorPos X="35" Y="60"/>
<UsageCount Value="7"/>
</Unit40>
<Unit41>
<Filename Value="..\uutlAlgorithm2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="66"/>
<CursorPos X="5" Y="93"/>
<UsageCount Value="7"/>
</Unit41>
<Unit42>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\objpas.pp"/>
<EditorIndex Value="-1"/>
<TopLine Value="63"/>
<CursorPos X="16" Y="78"/>
<UsageCount Value="11"/>
</Unit42>
<Unit43>
<Filename Value="G:\Eigene Datein\Projekte\_Active Projekte\TotoStarRedesign\utils\uutlAlgorithm.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="48"/>
<CursorPos X="45" Y="56"/>
<UsageCount Value="7"/>
</Unit43>
<Unit44>
<Filename Value="..\uutlEnumerator2.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="126"/>
<CursorPos X="22" Y="128"/>
<UsageCount Value="6"/>
</Unit44>
<Unit45>
<Filename Value="C:\Zusatzprogramme\Lazarus\components\fptest\src\FPCUnitCompatibleInterface.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="64"/>
<CursorPos Y="105"/>
<UsageCount Value="14"/>
</Unit45>
<Unit46>
<Filename Value="C:\Zusatzprogramme\Lazarus\components\fptest\src\TestFramework.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="2963"/>
<CursorPos Y="2979"/>
<UsageCount Value="10"/>
</Unit46>
<Unit47>
<Filename Value="..\internal_uutlInterfaces.pas"/>
<EditorIndex Value="-1"/>
<CursorPos Y="11"/>
<UsageCount Value="10"/>
</Unit33>
<UsageCount Value="6"/>
</Unit47>
<Unit48>
<Filename Value="..\uutlUtils.inc"/>
<EditorIndex Value="-1"/>
<CursorPos X="46" Y="3"/>
<UsageCount Value="7"/>
</Unit48>
<Unit49>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\classes\classesh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="118"/>
<CursorPos X="3" Y="143"/>
<UsageCount Value="13"/>
</Unit49>
<Unit50>
<Filename Value="G:\Eigene Datein\Projekte\_Active Projekte\TotoStarRedesign\utils\uutlCommon.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="474"/>
<CursorPos X="16" Y="500"/>
<UsageCount Value="9"/>
</Unit50>
<Unit51>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\ascdef.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="202"/>
<CursorPos X="10" Y="217"/>
<UsageCount Value="8"/>
</Unit51>
<Unit52>
<Filename Value="G:\Eigene Datein\Projekte\_Active Projekte\TotoStarRedesign\utils\uutlSyncObjs.pas"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="1"/>
<TopLine Value="64"/>
<CursorPos X="13" Y="76"/>
<UsageCount Value="14"/>
</Unit52>
<Unit53>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\sysutilh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="97"/>
<CursorPos X="19" Y="112"/>
<UsageCount Value="14"/>
</Unit53>
<Unit54>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\win\wininc\func.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="244"/>
<CursorPos X="10" Y="259"/>
<UsageCount Value="9"/>
</Unit54>
<Unit55>
<Filename Value="G:\Eigene Datein\Projekte\_Active Projekte\TotoStarRedesign\utils\uutlXmlHelper.pas"/>
<EditorIndex Value="-1"/>
<CursorPos X="29" Y="30"/>
<UsageCount Value="8"/>
</Unit55>
<Unit56>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\packages\fcl-base\src\contnrs.pp"/>
<EditorIndex Value="-1"/>
<TopLine Value="136"/>
<CursorPos X="3" Y="151"/>
<UsageCount Value="9"/>
</Unit56>
<Unit57>
<Filename Value="..\uutlEmbeddedProfiler.inc"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="19"/>
</Unit57>
<Unit58>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\inc\objpash.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="181"/>
<CursorPos X="10" Y="196"/>
<UsageCount Value="12"/>
</Unit58>
<Unit59>
<Filename Value="C:\Zusatzprogramme\Lazarus\fpc\3.1.1\source\rtl\objpas\sysutils\osutilsh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="40"/>
<CursorPos X="3" Y="62"/>
<UsageCount Value="12"/>
</Unit59>
</Units>
<OtherDefines Count="4">
<Define0 Value="UTL_ADVANCED_ENUMERATORS"/>
<Define1 Value="UTL_NESTED_PROCVARS"/>
<Define2 Value="UTL_DELPHI_GENERICS"/>
<Define3 Value="UTL_ENUMERATORS"/>
</OtherDefines>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="52" Column="24" TopLine="29"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="784" Column="21" TopLine="773"/>
</Position1>
<Position2>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="71" Column="17" TopLine="58"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="139" Column="35" TopLine="120"/>
</Position2>
<Position3>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="78" TopLine="63"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="159" Column="46" TopLine="143"/>
</Position3>
<Position4>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="69" Column="43" TopLine="55"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="832" Column="39" TopLine="810"/>
</Position4>
<Position5>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="144" Column="11" TopLine="123"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="838" Column="20" TopLine="811"/>
</Position5>
<Position6>
<Filename Value="..\uutlFilter.pas"/>
<Caret Line="60" Column="58" TopLine="43"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="432" Column="38" TopLine="402"/>
</Position6>
<Position7>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="156" Column="82" TopLine="133"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="829" Column="57" TopLine="813"/>
</Position7>
<Position8>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="478" Column="12" TopLine="453"/>
<Caret Line="915" Column="28" TopLine="899"/>
</Position8>
<Position9>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="151" Column="30" TopLine="136"/>
<Caret Line="299" Column="42" TopLine="292"/>
</Position9>
<Position10>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="476" Column="44" TopLine="453"/>
<Caret Line="914" Column="32" TopLine="899"/>
</Position10>
<Position11>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="26" Column="37" TopLine="9"/>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="935" Column="28" TopLine="920"/>
</Position11>
<Position12>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="273" Column="19" TopLine="244"/>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="305" Column="64" TopLine="284"/>
</Position12>
<Position13>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="263" Column="75" TopLine="248"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="413" Column="15" TopLine="401"/>
</Position13>
<Position14>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="253" Column="35" TopLine="248"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="689" Column="8" TopLine="669"/>
</Position14>
<Position15>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="262" Column="29" TopLine="247"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="821" Column="61" TopLine="808"/>
</Position15>
<Position16>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="158" Column="41" TopLine="137"/>
<Caret Line="947" TopLine="873"/>
</Position16>
<Position17>
<Filename Value="..\uutlInterfaces.pas"/>
<Caret Line="44" Column="39" TopLine="29"/>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="12" Column="11"/>
</Position17>
<Position18>
<Filename Value="..\uutlInterfaces.pas"/>
<Caret Line="48" Column="51" TopLine="28"/>
<Filename Value="uutlEnumeratorTests.pas"/>
<Caret Line="64" Column="3" TopLine="69"/>
</Position18>
<Position19>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="37" Column="39" TopLine="22"/>
<Filename Value="..\uutlInterfaces.pas"/>
<Caret Line="89" Column="15" TopLine="69"/>
</Position19>
<Position20>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="90" Column="39" TopLine="77"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="10" Column="25"/>
</Position20>
<Position21>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="343" Column="27" TopLine="338"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="63" Column="24" TopLine="51"/>
</Position21>
<Position22>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="344" Column="11" TopLine="338"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="242" Column="34" TopLine="227"/>
</Position22>
<Position23>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="348" Column="19" TopLine="338"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="432" Column="9" TopLine="405"/>
</Position23>
<Position24>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="393" Column="20" TopLine="373"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="265" Column="51" TopLine="256"/>
</Position24>
<Position25>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="1369" Column="30" TopLine="1347"/>
<Filename Value="..\uutlLinq.pas"/>
<Caret Line="395" Column="36" TopLine="381"/>
</Position25>
<Position26>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="9" Column="92"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="59" Column="12" TopLine="121"/>
</Position26>
<Position27>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="401" Column="48" TopLine="377"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="269" Column="34" TopLine="258"/>
</Position27>
<Position28>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="1352" Column="15" TopLine="1337"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="852" TopLine="824"/>
</Position28>
<Position29>
<Filename Value="..\uutlEnumerator.pas"/>
<Caret Line="90" Column="39" TopLine="76"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="27" Column="38" TopLine="12"/>
</Position29>
<Position30>
<Filename Value="..\uutlGenerics.pas"/>
<Caret Line="1060" Column="25" TopLine="1045"/>
<Filename Value="uutlLinqTests.pas"/>
<Caret Line="82" Column="49" TopLine="67"/>
</Position30>
</JumpHistory>
</ProjectSession>
<Debugging>
<Watches Count="1">
<Item1>
<Expression Value="fCurrentSkip"/>
<Expression Value="(aArray+2)^"/>
</Item1>
</Watches>
</Debugging>


+ 9
- 11
tests/uutlAlgorithmTests.pas View File

@@ -19,7 +19,7 @@ type
implementation

uses
uutlGenerics, uutlAlgorithm;
uutlTypes, uutlGenerics, uutlAlgorithm;

type
TIntArray = specialize TutlArray<Integer>;
@@ -36,8 +36,7 @@ var
index: Integer;
ret: Boolean;
begin
arr := TIntArray.Create;
arr.Count := 10;
SetLength(arr, 10);
arr[0] := 1;
arr[1] := 4;
arr[2] := 5;
@@ -49,23 +48,23 @@ begin
arr[8] := 21;
arr[9] := 22;

ret := TBinarySearch.Search(arr, TIntComparer.Create, 4, index);
ret := TBinarySearch.Search(arr[0], Length(arr), TIntComparer.Create, 4, index);
AssertTrue (ret);
AssertEquals(1, index);

ret := TBinarySearch.Search(arr, TIntComparer.Create, 7, index);
ret := TBinarySearch.Search(arr[0], Length(arr), TIntComparer.Create, 7, index);
AssertFalse (ret);
AssertEquals(4, index);

ret := TBinarySearch.Search(arr, TIntComparer.Create, 13, index);
ret := TBinarySearch.Search(arr[0], Length(arr), TIntComparer.Create, 13, index);
AssertTrue (ret);
AssertEquals(6, index);

ret := TBinarySearch.Search(arr, TIntComparer.Create, 19, index);
ret := TBinarySearch.Search(arr[0], Length(arr), TIntComparer.Create, 19, index);
AssertFalse (ret);
AssertEquals(7, index);

ret := TBinarySearch.Search(arr, TIntComparer.Create, 25, index);
ret := TBinarySearch.Search(arr[0], Length(arr), TIntComparer.Create, 25, index);
AssertFalse (ret);
AssertEquals(10, index);
end;
@@ -75,8 +74,7 @@ procedure TutlAlgorithmTest.QuickSort;
var
arr: TIntArray;
begin
arr := TIntArray.Create;
arr.Count := 20;
SetLength(arr, 20);
arr[ 0] := 134;
arr[ 1] := 314;
arr[ 2] := 721;
@@ -97,7 +95,7 @@ begin
arr[17] := 456;
arr[18] := 678;
arr[19] := 832;
TQuickSort.Sort(arr, TIntComparer.Create);
TQuickSort.Sort(arr[0], Length(arr), TIntComparer.Create);
AssertEquals(126, arr[ 0]);
AssertEquals(134, arr[ 1]);
AssertEquals(163, arr[ 2]);


+ 0
- 151
tests/uutlArrayTests.pas View File

@@ -1,151 +0,0 @@
unit uutlArrayTests;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, TestFramework,
uutlGenerics;

type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIntArray = specialize TutlArray<Integer>;

TutlArrayTest = class(TTestCase)
published
procedure Prop_Get_Count;
procedure Prop_Set_Count;
procedure Prop_Get_Items;
procedure Prop_Set_Items;
procedure Prop_Get_Data;
procedure Prop_Set_Data;

procedure Meth_Ctor;
end;

implementation

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlArrayTest/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Get_Count;
var
arr: TIntArray;
begin
arr := TIntArray.Create;
try
AssertEquals(0, arr.Count);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Set_Count;
var
arr: TIntArray;
begin
arr := TIntArray.Create;
try
AssertEquals(0, arr.Count);
arr.Count := 1;
AssertEquals(1, arr.Count);
arr.Count := 5;
AssertEquals(5, arr.Count);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Get_Items;
var
arr: TIntArray;
begin
arr := TIntArray.Create;
try
arr.Count := 1;
AssertEquals(0, arr[0]);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Set_Items;
var
arr: TIntArray;
begin
arr := TIntArray.Create;
try
arr.Count := 3;
arr[0] := 1;
arr[1] := 3;
arr[2] := 5;
AssertEquals(1, arr[0]);
AssertEquals(3, arr[1]);
AssertEquals(5, arr[2]);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Get_Data;
var
arr: TIntArray;
data: TIntArray.TData;
begin
arr := TIntArray.Create;
try
arr.Count := 3;
arr[0] := 1;
arr[1] := 3;
arr[2] := 5;
data := arr.Data;
AssertEquals(3, Length(data));
AssertEquals(1, data[0]);
AssertEquals(3, data[1]);
AssertEquals(5, data[2]);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Prop_Set_Data;
var
arr: TIntArray;
data: TIntArray.TData;
begin
arr := TIntArray.Create;
try
SetLength(data, 5);
arr.Data := data;
AssertEquals(5, arr.Count);
finally
FreeAndNil(arr);
end;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayTest.Meth_Ctor;
var
arr: TIntArray;
data: TIntArray.TData;
begin
SetLength(data, 5);
arr := TIntArray.Create(data);
try
AssertEquals(5, arr.Count);
finally
FreeAndNil(arr);
end;
end;

initialization
RegisterTest(TutlArrayTest.Suite);

end.


+ 369
- 128
tests/uutlEnumeratorTests.pas View File

@@ -1,281 +1,522 @@
unit uutlEnumeratorTests;

{$mode objfpc}{$H+}
{$modeswitch nestedprocvars}
{$IFDEF UTL_NESTED_PROCVARS}
{$modeswitch nestedprocvars}
{$ENDIF}

interface

uses
Classes, SysUtils, TestFramework,
uutlEnumerator;
uutlEnumerator, uutlInterfaces;

type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
IIntEnumerator = specialize {$IFDEF UTL_ENUMERATORS}IutlEnumerator{$ELSE}IEnumerator{$ENDIF}<Integer>;
TutlEnumeratorTests = class(TTestCase)
protected
fEnumerator: IIntEnumerator;

function GenerateOther(const aData: array of Integer): IIntEnumerator;
procedure Generate(const aData: array of Integer); virtual; abstract;

published
procedure ArrayEnumerator;
procedure ArrayEnumerator_Reverse;
procedure ArrayEnumerator_Count;
procedure ArrayEnumerator_Skip;
procedure ArrayEnumerator_Take;
procedure ArrayEnumerator_Skip_Reverse;
procedure ArrayEnumerator_Take_Reverse;
procedure ArrayEnumerator_Reverse_Skip;
procedure ArrayEnumerator_Reverse_Take;
procedure ArrayEnumerator_Where;
procedure ArrayEnumerator_Select;
// Procedure Names: ProcedureUnderTest_[Parameter]_EnumeratorItems_Result
procedure Iterate_1to5_1to5;
{$IFDEF UTL_ENUMERATORS}
procedure Count_1to5_5;
procedure Any_Empty_False;
procedure Any_1to5_True;
procedure Reverse_1to5_5to1;
procedure Skip2_1to5_3to5;
procedure Take3_1to5_1to3;
procedure Skip5_Reverse_0to9_9to5;
procedure Take5_Reverse_0to9_4to0;
procedure Reverse_Skip5_0to9_4to0;
procedure Reverse_Take5_0to9_9to5;
procedure Contains3_1to5_true;
procedure Contains9_1to5_false;
procedure Concat6to8_1to5_1to8;
{$IFDEF UTL_ADVANCED_ENUMERATORS}
procedure Sort;
procedure Where_IsEven;
procedure Distinct;
procedure Intersect;
procedure Union;
procedure Without;
procedure Select;
{$ENDIF}
{$ENDIF}
end;

TutlArrayEnumeratorTests = class(TutlEnumeratorTests)
protected
procedure Generate(const aData: array of Integer); override;

public
procedure SetUp; override;
end;

implementation

uses
uutlFilter;
uutlFilter, uutlComparer;

type
TIntCalbackFilter = specialize TutlCalbackFilter<Integer>;
TIntArrEnumerator = specialize TutlArrayEnumerator<Integer>;
TFloatArrEnumerator = specialize TutlArrayEnumerator<Single>;
TIntArrayEnumerator = specialize TutlArrayEnumerator<Integer>;

function CreateArrayEnumerator(const aSize: Integer): TIntArrEnumerator.IEnumerator;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlEnumeratorTests///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TutlEnumeratorTests.GenerateOther(const aData: array of Integer): IIntEnumerator;
var
arr: array of Integer;
i: Integer;
arr: TIntArrayEnumerator.TArray;
begin
SetLength(arr, aSize);
for i := low(arr) to high(arr) do
arr[i] := i + 1;
result := TIntArrEnumerator.Create(arr);
SetLength(arr, Length(aData));
for i := low(aData) to high(aData) do
arr[i] := aData[i];
result := TIntArrayEnumerator.Create(arr);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlEnumeratorTests///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Iterate_1to5_1to5;
begin
Generate([1, 2, 3, 4, 5]);
fEnumerator.Reset;
AssertTrue (fEnumerator.MoveNext);
AssertEquals(1, fEnumerator.GetCurrent);
AssertTrue (fEnumerator.MoveNext);
AssertEquals(2, fEnumerator.GetCurrent);
AssertTrue (fEnumerator.MoveNext);
AssertEquals(3, fEnumerator.GetCurrent);
AssertTrue (fEnumerator.MoveNext);
AssertEquals(4, fEnumerator.GetCurrent);
AssertTrue (fEnumerator.MoveNext);
AssertEquals(5, fEnumerator.GetCurrent);
AssertFalse (fEnumerator.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{$IFDEF UTL_ENUMERATORS}
procedure TutlEnumeratorTests.Count_1to5_5;
var
i: Integer;
begin
Generate([1, 2, 3, 4, 5]);
i := fEnumerator.Count;
AssertEquals(5, i);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Any_Empty_False;
begin
AssertFalse(fEnumerator.Any);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator;
procedure TutlEnumeratorTests.Any_1to5_True;
begin
Generate([1, 2, 3, 4, 5]);
AssertTrue(fEnumerator.Any);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Reverse_1to5_5to1;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(5);
e := fEnumerator.Reverse;
Generate([1, 2, 3, 4, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertEquals(5, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertEquals(3, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertEquals(1, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Reverse;
procedure TutlEnumeratorTests.Skip2_1to5_3to5;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(5)
.Reverse;
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
e := fEnumerator.Skip(2);
Generate([1, 2, 3, 4, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertEquals(3, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertEquals(5, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Count;
procedure TutlEnumeratorTests.Take3_1to5_1to3;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(5);
AssertEquals(5, e.Count);
e := fEnumerator.Take(3);
Generate([1, 2, 3, 4, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(3, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Skip;
procedure TutlEnumeratorTests.Skip5_Reverse_0to9_9to5;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Skip(5);
e := fEnumerator.Skip(5).Reverse;
Generate([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(6, e.Current);
AssertEquals(9, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(7, e.Current);
AssertEquals(8, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertEquals(7, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(9, e.Current);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(10, e.Current);
AssertEquals(5, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Take;
procedure TutlEnumeratorTests.Take5_Reverse_0to9_4to0;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Take(5);
e := fEnumerator.Take(5).Reverse;
Generate([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertEquals(3, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertEquals(1, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertEquals(0, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Skip_Reverse;
procedure TutlEnumeratorTests.Reverse_Skip5_0to9_4to0;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Skip(5)
.Reverse;
e := fEnumerator.Reverse.Skip(5);
Generate([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(10, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(9, e.Current);
AssertEquals(3, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(7, e.Current);
AssertEquals(1, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.Current);
AssertEquals(0, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Take_Reverse;
procedure TutlEnumeratorTests.Reverse_Take5_0to9_9to5;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Take(5)
.Reverse;
e := fEnumerator.Reverse.Take(5);
Generate([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertEquals(9, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertEquals(8, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertEquals(7, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertEquals(5, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Reverse_Skip;
procedure TutlEnumeratorTests.Contains3_1to5_true;
var
e: TIntArrEnumerator.IEnumerator;
b: Boolean;
begin
e := CreateArrayEnumerator(10)
.Reverse
.Skip(5);
Generate([1, 2, 3, 4, 5]);
b := fEnumerator.Contains(3, specialize TutlEqualityComparer<Integer>.Create);
AssertTrue(b);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Contains9_1to5_false;
var
b: Boolean;
begin
Generate([1, 2, 3, 4, 5]);
b := fEnumerator.Contains(9, specialize TutlEqualityComparer<Integer>.Create);
AssertFalse(b);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Concat6to8_1to5_1to8;
var
e: IIntEnumerator;
begin
e := fEnumerator.Concat(GenerateOther([6, 7, 8]));
Generate([1, 2, 3, 4, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertEquals(1, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertEquals(3, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertEquals(5, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(7, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Reverse_Take;
{$IFDEF UTL_ADVANCED_ENUMERATORS}
procedure TutlEnumeratorTests.Sort;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Reverse
.Take(5);
e := fEnumerator.Sort(specialize TutlComparer<Integer>.Create);
Generate([5, 8, 2, 6, 9, 4, 2, 6, 8, 4, 2, 5, 8, 4]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(10, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(9, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(7, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.Current);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(5, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(5, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(9, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Where;
function IsEven(constref i: Integer): Boolean;
begin
result := (i mod 2) = 0;
end;

function IsEven(constref i: Integer): Boolean;
begin
result := (i mod 2) = 0;
end;
procedure TutlEnumeratorTests.Where_IsEven;
var
e: IIntEnumerator;
begin
e := fEnumerator.Where(specialize TutlCallbackFilter<Integer>.Create(@IsEven));
Generate([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(0, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(2, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(4, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(6, e.GetCurrent);
AssertTrue (e.MoveNext);
AssertEquals(8, e.GetCurrent);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Distinct;
var
e: TIntArrEnumerator.IEnumerator;
e: IIntEnumerator;
begin
e := CreateArrayEnumerator(10)
.Where(TIntCalbackFilter.Create(@IsEven));
e := fEnumerator.Distinct(specialize TutlComparer<Integer>.Create);
Generate([1, 5, 2, 7, 1, 3, 7, 4, 5, 8]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(7, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Intersect;
var
e: IIntEnumerator;
begin
e := fEnumerator
.Intersect(GenerateOther([5, 6, 8]), specialize TutlComparer<Integer>.Create);
Generate([1, 6, 4, 8, 2, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(6, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(10, e.Current);
AssertEquals(5, e.Current);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.ArrayEnumerator_Select;
procedure TutlEnumeratorTests.Union;
var
e: IIntEnumerator;
begin
e := fEnumerator
.Union(GenerateOther([9, 3, 4, 6, 7]), specialize TutlComparer<Integer>.Create);
Generate([1, 6, 4, 8, 2, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(6, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(8, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(5, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(9, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(3, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(7, e.Current);
AssertFalse (e.MoveNext);
end;

function ConvertToFloat(constref a: Integer): Single;
begin
result := Single(a);
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlEnumeratorTests.Without;
var
e: IIntEnumerator;
begin
e := fEnumerator
.Without(GenerateOther([6, 8, 5]), specialize TutlComparer<Integer>.Create);
Generate([1, 6, 4, 8, 2, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(4, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(2, e.Current);
AssertFalse (e.MoveNext);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ConvertToFloat(constref a: Integer): Single;
begin
result := Single(a) / 2.0;
end;

procedure TutlEnumeratorTests.Select;
var
e: TFloatArrEnumerator.IEnumerator;
e: specialize IutlEnumerator<Single>;
begin
e := specialize TutlSelectEnumerator<Integer, Single>.Create(
CreateArrayEnumerator(5),
specialize TutlCalbackSelector<Integer, Single>.Create(@ConvertToFloat));
fEnumerator,
specialize TutlCallbackSelector<Integer, Single>.Create(@ConvertToFloat));
Generate([1, 2, 3, 4, 5]);
e.Reset;
AssertTrue (e.MoveNext);
AssertEquals(1.0, e.Current);
AssertEquals(0.5, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(2.0, e.Current);
AssertEquals(1.0, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(3.0, e.Current);
AssertEquals(1.5, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(4.0, e.Current);
AssertEquals(2.0, e.Current);
AssertTrue (e.MoveNext);
AssertEquals(5.0, e.Current);
AssertEquals(2.5, e.Current);
AssertFalse (e.MoveNext);
end;
{$ENDIF}
{$ENDIF}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TutlArrayEnumeratorTests//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayEnumeratorTests.Generate(const aData: array of Integer);
var
i: Integer;
arr: TIntArrayEnumerator.TArray;
begin
SetLength(arr, Length(aData));
for i := low(aData) to high(aData) do
arr[i] := aData[i];
(fEnumerator as TIntArrayEnumerator).Data := arr;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TutlArrayEnumeratorTests.SetUp;
begin
fEnumerator := TIntArrayEnumerator.Create;
end;

initialization
RegisterTest(TutlEnumeratorTests.Suite);
RegisterTest(TutlArrayEnumeratorTests.Suite);

end.


+ 1
- 1
tests/uutlHashSetTests.pas View File

@@ -10,7 +10,7 @@ uses

type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIntSet = specialize TutlHastSet<Integer>;
TIntSet = specialize TutlHashSet<Integer>;
TutlHastSetTests = class(TTestCase)
private
fIntSet: TIntSet;


+ 855
- 0
tests/uutlLinqTests.pas View File

@@ -0,0 +1,855 @@
unit uutlLinqTests;

{$mode objfpc}{$H+}
{$IFDEF UTL_NESTED_PROCVARS}
{$modeswitch nestedprocvars}
{$ENDIF}

interface

{$IFDEF UTL_ENUMERATORS}
uses
Classes, SysUtils, TestFramework,
uutlLinq;

type
TutlLinqTests = class(TTestCase)
published
procedure proc_Count;
procedure proc_Any;
procedure proc_Contains;
procedure proc_Contains_WithComparer;
procedure proc_ToArray;

procedure proc_Reverse;
procedure proc_Skip;
procedure proc_Take;
procedure proc_Concat;
procedure proc_Concat_WithArray;
{$IFDEF UTL_ADVANCED_ENUMERATORS}
procedure proc_Sort;
procedure proc_Sort_WithComparer;
procedure proc_Where_WithFilter;
procedure proc_Where_WithNormalCallback;
procedure proc_Where_WithObjectCallback;
{$IFDEF UTL_NESTED_PROCVARS}
procedure proc_Where_WithNestedCallback;
{$ENDIF}
procedure proc_Distinct;
procedure proc_Distinct_WithComparer;
procedure proc_Intersect;
procedure proc_Intersect_WithComparer;
procedure proc_Union;
procedure proc_Union_WithComparer;
procedure proc_Without;
procedure proc_Without_WithComparer;
procedure proc_Select_WithSelector;
procedure proc_Select_WithNormalCallback;
procedure proc_Select_WithObjectCallback;
{$IFDEF UTL_NESTED_PROCVARS}
procedure proc_Select_WithNestedCallback;
{$ENDIF}
procedure proc_SelectMany_WithSelector;
procedure proc_SelectMany_WithNormalCallback;
procedure proc_SelectMany_WithObjectCallback;
{$IFDEF UTL_NESTED_PROCVARS}
procedure proc_SelectMany_WithNestedCallback;
{$ENDIF}
procedure proc_Zip;
{$ENDIF}
end;
{$ENDIF}

implementation

{$IFDEF UTL_ENUMERATORS}
uses
uutlEnumerator, uutlComparer, uutlFilter, uutlTypes, uutlInterfaces;

type
TIntArrEnumerator = specialize TutlArrayEnumerator<Integer>;
TStringArrEnumerator = specialize TutlArrayEnumerator<String>;

TCallbackObject = class(TInterfacedObject,
specialize IutlFilter<Integer>,
specialize IutlSelector<Integer, Single>)
public
function Filter(constref i: Integer): Boolean;
function Select(constref i: Integer): Single;
end;

TSelectManyObject = class(TInterfacedObject,
specialize IutlSelector<Integer, specialize IutlEnumerator<Single>>)
public
function Select(constref i: Integer): specialize IutlEnumerator<Single>;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Helper////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TestFilter(constref i: Integer): Boolean;
begin
result := (i mod 2) = 0;
end;

function TestSelector(constref i: Integer): Single;
begin
result := i / 2.0;
end;

function TestManySelector(constref i: Integer): specialize IutlEnumerator<Single>;
var
data: array of Single;
begin
SetLength(data, 3);
data[0] := 10 * i + 1.5;
data[1] := 10 * i + 5.0;
data[2] := 10 * i + 7.5;
result := specialize TutlArrayEnumerator<Single>.Create(data);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TCallbackObject.Filter(constref i: Integer): Boolean;
begin
result := TestFilter(i);
end;

function TCallbackObject.Select(constref i: Integer): Single;
begin
result := TestSelector(i);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TSelectManyObject.Select(constref i: Integer): specialize IutlEnumerator<Single>;
begin
result := TestManySelector(i);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CreateArrayEnumerator(const aSize: Integer; const aStartIndex: Integer = 1): TIntArrEnumerator.IEnumerator;
var
arr: array of Integer;
i: Integer;
begin
SetLength(arr, aSize);
for i := low(arr) to high(arr) do
arr[i] := aStartIndex + i;
result := TIntArrEnumerator.Create(arr);
end;