Merged via Collections-ct.997 & CollectionsTests-ct.373.<br>
<br>
Best,<br>
Christoph<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
<br>
On 2022-02-28T09:21:31+01:00, marcel.taeumel@hpi.de wrote:<br>
<br>
> Wohoo! More tests. :-) Thanks. That thing about #withIndexDo: sounds reasonable.<br>
> <br>
> +1<br>
> <br>
> Best,<br>
> Marcel<br>
> Am 26.02.2022 22:19:42 schrieb christoph.thiede at student.hpi.uni-potsdam.de <christoph.thiede at student.hpi.uni-potsdam.de>:<br>
> =============== Summary ===============<br>
> <br>
> Change Set:        SparseLargeTable enumerate+tests<br>
> Date:            26 February 2022<br>
> Author:            Christoph Thiede<br>
> <br>
> This changeset makes two revisions two the enumerating protocol of SparseLargeTable and adds a few test for SparseLargeTable/SpargeLargeArray. Details:<br>
> <br>
> * Overrides #withIndexDo: to start from base index only<br>
> * Adds #sparseElementsAndIndicesDo: for efficient iterating over all non-default values<br>
> * Tests instance creation and enumeration for SparseLargeTable/SparseLargeArray<br>
> <br>
> =============== Diff ===============<br>
> <br>
> SparseLargeArrayTest<br>
> + SparseLargeTableTest subclass: #SparseLargeArrayTest<br>
> +     instanceVariableNames: ''<br>
> +     classVariableNames: ''<br>
> +     poolDictionaries: ''<br>
> +     category: 'CollectionsTests-Arrayed'<br>
> +<br>
> + SparseLargeArrayTest class<br>
> +     instanceVariableNames: ''<br>
> +<br>
> + ""<br>
> <br>
> SparseLargeArrayTest>>classUnderTest {accessing} · ct 2/26/2022 21:52<br>
> + classUnderTest<br>
> +<br>
> +     ^ SparseLargeArray<br>
> <br>
> SparseLargeArrayTest>>expectedFailures {accessing} · ct 2/26/2022 21:59<br>
> + expectedFailures<br>
> +<br>
> +     ^ super expectedFailures ,<br>
> +         #(testAccessing testSparseElementsAndIndicesDo) "SparseLargeArray(SparseLargeTable)>>zapDefaultOnlyEntries fails for last chunk"<br>
> <br>
> SparseLargeArrayTest>>testAccessingWithoutZapping {testing - accessing} · ct 2/26/2022 21:57<br>
> + testAccessingWithoutZapping<br>
> +<br>
> +     | size chunkSize indices table |<br>
> +     size := 60.<br>
> +     chunkSize := 8.<br>
> +     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
> +     table := self classUnderTest new: size chunkSize: chunkSize arrayClass: DoubleByteArray base: 11 defaultValue: 0.<br>
> +     indices do: [:index |<br>
> +         table at: index put: index squared].<br>
> +     self shouldRaiseError: [table at: 40 put: 2 << 15].<br>
> +     <br>
> +     self assert: size equals: table size.<br>
> +     self assert: chunkSize equals: table chunkSize.<br>
> +     <br>
> +     indices do: [:index |<br>
> +         self assert: index squared equals: ((table at: index))].<br>
> <br>
> SparseLargeArrayTest>>testSparseElementsAndIndicesDoWithoutZapping {testing - accessing} · ct 2/26/2022 21:59<br>
> + testSparseElementsAndIndicesDoWithoutZapping<br>
> +<br>
> +     | defaultValue indices table sparse |<br>
> +     defaultValue := 0.<br>
> +     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
> +     table := self classUnderTest new: 60 chunkSize: 8 arrayClass: DoubleByteArray base: 11 defaultValue: defaultValue.<br>
> +     indices do: [:index |<br>
> +         table at: index put: index squared].<br>
> +     <br>
> +     sparse := Dictionary new.<br>
> +     table sparseElementsAndIndicesDo: [:element :index |<br>
> +         self deny: (sparse includesKey: index).<br>
> +         sparse at: index put: element].<br>
> +     <br>
> +     table withIndexDo: [:element :index |<br>
> +         self assert: element equals: (sparse at: index ifAbsent: [0])].<br>
> <br>
> SparseLargeTable>>sparseElementsAndIndicesDo: {accessing} · ct 2/26/2022 22:06<br>
> + sparseElementsAndIndicesDo: binaryBlock<br>
> +     "Evaluate binaryBlock for each element and index in the receiver that has a non-default value."<br>
> +<br>
> +     1 to: self basicSize do: [:chunkIndex |<br>
> +         (self basicAt: chunkIndex) ifNotNil: [:chunk |<br>
> +             chunk withIndexDo: [:element :innerIndex |<br>
> +                 element ~= defaultValue ifTrue: [<br>
> +                     binaryBlock value: element value: innerIndex + base - 1 + (chunkIndex - 1 * chunkSize)]]]].<br>
> <br>
> SparseLargeTable>>withIndexDo: {enumerating} · ct 2/26/2022 22:02<br>
> + withIndexDo: binaryBlock<br>
> +<br>
> +     self base to: self size do: [:index |<br>
> +         binaryBlock<br>
> +             value: (self at: index)<br>
> +             value: index].<br>
> <br>
> SparseLargeTableTest<br>
> + TestCase subclass: #SparseLargeTableTest<br>
> +     instanceVariableNames: ''<br>
> +     classVariableNames: ''<br>
> +     poolDictionaries: ''<br>
> +     category: 'CollectionsTests-Arrayed'<br>
> +<br>
> + SparseLargeTableTest class<br>
> +     instanceVariableNames: ''<br>
> +<br>
> + ""<br>
> <br>
> SparseLargeTableTest>>classUnderTest {accessing} · ct 2/26/2022 21:51<br>
> + classUnderTest<br>
> +<br>
> +     ^ SparseLargeTable<br>
> <br>
> SparseLargeTableTest>>testAccessing {tests - accessing} · ct 2/26/2022 21:52<br>
> + testAccessing<br>
> +<br>
> +     | size chunkSize indices table |<br>
> +     size := 60.<br>
> +     chunkSize := 8.<br>
> +     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
> +     table := self classUnderTest new: size chunkSize: chunkSize arrayClass: DoubleByteArray base: 11 defaultValue: 0.<br>
> +     indices do: [:index |<br>
> +         table at: index put: index squared].<br>
> +     self shouldRaiseError: [table at: 40 put: 2 << 15].<br>
> +     table zapDefaultOnlyEntries.<br>
> +     <br>
> +     self assert: size equals: table size.<br>
> +     self assert: chunkSize equals: table chunkSize.<br>
> +     <br>
> +     indices do: [:index |<br>
> +         self assert: index squared equals: ((table at: index))].<br>
> <br>
> SparseLargeTableTest>>testNew {tests - instance creation} · ct 2/26/2022 21:52<br>
> + testNew<br>
> +     <br>
> +     | table |<br>
> +     table := self classUnderTest new.<br>
> +     self assert: 0 equals: table size.<br>
> <br>
> SparseLargeTableTest>>testNewFrom {tests - instance creation} · ct 2/26/2022 21:52<br>
> + testNewFrom<br>
> +<br>
> +     | array table |<br>
> +     array := Array streamContents: [:stream |<br>
> +         15 timesRepeat: [stream nextPutAll: #($a $b $b $b $b $c $c $a)]]. "must be longer than defaultChunkSize"<br>
> +     table := self classUnderTest newFrom: array.<br>
> +     self assert: array size equals: table size.<br>
> +     self assert: array equals: table asArray.<br>
> <br>
> SparseLargeTableTest>>testNewWithAll {tests - instance creation} · ct 2/26/2022 21:52<br>
> + testNewWithAll<br>
> +<br>
> +     | size table |<br>
> +     size := 150. "must be longer than defaultChunkSize"<br>
> +     table := self classUnderTest new: size withAll: 2.<br>
> +     self assert: size equals: table size.<br>
> +     self assert: (Array new: size withAll: 2) equals: table asArray.<br>
> <br>
> SparseLargeTableTest>>testNewWithSize {tests - instance creation} · ct 2/26/2022 21:52<br>
> + testNewWithSize<br>
> +<br>
> +     | size table |<br>
> +     size := 14.<br>
> +     table := self classUnderTest new: size chunkSize: 5.<br>
> +     self assert: size equals: table size.<br>
> +     1 to: size do: [:index | self assert: (table at: index) isNil].<br>
> +     self shouldRaiseError: [table at: 0].<br>
> +     self shouldRaiseError: [table at: size + 1].<br>
> <br>
> SparseLargeTableTest>>testSparseElementsAndIndicesDo {tests - accessing} · ct 2/26/2022 21:52<br>
> + testSparseElementsAndIndicesDo<br>
> +<br>
> +     | defaultValue indices table sparse |<br>
> +     defaultValue := 0.<br>
> +     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
> +     table := self classUnderTest new: 60 chunkSize: 8 arrayClass: DoubleByteArray base: 11 defaultValue: defaultValue.<br>
> +     indices do: [:index |<br>
> +         table at: index put: index squared].<br>
> +     table zapDefaultOnlyEntries.<br>
> +     <br>
> +     sparse := Dictionary new.<br>
> +     table sparseElementsAndIndicesDo: [:element :index |<br>
> +         self deny: (sparse includesKey: index).<br>
> +         sparse at: index put: element].<br>
> +     <br>
> +     table withIndexDo: [:element :index |<br>
> +         self assert: element equals: (sparse at: index ifAbsent: [0])].<br>
> <br>
> ---<br>
> Sent from Squeak Inbox Talk [https://github.com/hpi-swa-lab/squeak-inbox-talk]<br>
> ["SparseLargeTable enumerate+tests.1.cs"]<br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220228/a6aec3aa/attachment.html><br>
> <br>