The Trunk: CollectionsTests-topa.295.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: CollectionsTests-topa.295.mcz

commits-2
Tobias Pape uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-topa.295.mcz

==================== Summary ====================

Name: CollectionsTests-topa.295
Author: topa
Time: 28 October 2018, 8:14:02.430507 pm
UUID: dc71a7c1-c330-4af2-a4c9-78459f5193f3
Ancestors: CollectionsTests-ul.294

Add #histogramOf: convenience + test

=============== Diff against CollectionsTests-ul.294 ===============

Item was added:
+ ----- Method: CollectionTest>>testHistogramOf (in category 'testing') -----
+ testHistogramOf
+ " could be collect:as: Bag, but histogram is what it's used for "
+ | baseCollection collection |
+ baseCollection := {#x -> 2 . #y -> 3 . #y -> 4. #z -> 2 }.
+ { Array . OrderedCollection . Set } do:
+ [:collectionClass |
+ collection := baseCollection as: collectionClass.
+ self
+ assert: collection asBag
+ equals: (collection histogramOf: [:ea | ea])
+ description: 'For ', collectionClass, ', #asBag and identity-histograms should match'.
+ self
+ assert: (Bag withAll: #( x y y z))
+ equals: (collection histogramOf: [:ea | ea key])
+ description:  'For ', collectionClass, ', histogramming contents should work '.
+ self
+ assert: (Bag withAll: #( 2 3 4 2 ))
+ equals: (collection histogramOf: [:ea | ea value])
+ description:  'For ', collectionClass, ', histogramming contents should work'].
+
+ collection := baseCollection as: KeyedSet.
+ self
+ assert: collection asBag
+ equals: (collection histogramOf: [:ea | ea])
+ description: 'For KeyedSet, #asBag and identity-histograms should match'.
+ self
+ assert: (Bag withAll: #( x y z))
+ equals: (collection histogramOf: [:ea | ea key])
+ description:  'For KeyedSet, histogramming contents should work '.
+ self
+ assert: (Bag withAll: #( 2 3 2 ))
+ equals: (collection histogramOf: [:ea | ea value])
+ description:  'For KeyedSet, histogramming contents should work'.
+
+ baseCollection := {#x -> 2 . "#y -> 3 ." #y -> 4. #z -> 2 }. "No duplicate keyes"
+ collection := baseCollection as: Dictionary.
+ self
+ assert:  (Bag withAll: #( 2 2 4 ))
+ equals: (collection histogramOf: [:ea | ea])
+ description: 'For Dictionary, histogramming should work on values.'.
+ self
+ assert:  (collection values histogramOf: [:ea | ea])
+ equals: (collection histogramOf: [:ea | ea])
+ description: 'For Dictionary, histogramming should be the same as histogramming the values.'.
+ self
+ assert: collection asBag
+ equals: (collection histogramOf: [:ea | ea])
+ description: 'For Dictionary, #asBag should match histogramming.'.
+ self
+ assert: (Bag withAll: #(x y z))
+ equals: (collection keys histogramOf: [:ea |ea])
+ description:  'For Dictionary, histogramming keys is ok to be less convenient.'.
+ !