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