The Trunk: CollectionsTests-mt.300.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-mt.300.mcz

commits-2
Marcel Taeumel uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-mt.300.mcz

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

Name: CollectionsTests-mt.300
Author: mt
Time: 25 January 2019, 9:34:57.376997 am
UUID: aeb1ec6d-58a9-4d42-b82f-4ff713c9a880
Ancestors: CollectionsTests-mt.299

Adds tests for try-ignore. Cleans up message categories "tests" and "testing".

=============== Diff against CollectionsTests-mt.299 ===============

Item was changed:
+ ----- Method: CollectionTest>>setUp (in category 'running') -----
- ----- Method: CollectionTest>>setUp (in category 'initialize-release') -----
  setUp
  empty := Set new.
  nonEmpty := OrderedCollection with: #x!

Item was changed:
+ ----- Method: CollectionTest>>testAsCommaString (in category 'tests') -----
- ----- Method: CollectionTest>>testAsCommaString (in category 'testing') -----
  testAsCommaString
  {OrderedCollection new. Set new.} do:
  [ :coll |
  self assert: coll asCommaString = ''.
 
  coll add: 1.
  self assert: coll asCommaString = '1'.
 
  coll add: 2; add: 3.
  self assert: coll asCommaString = '1, 2, 3'].!

Item was changed:
+ ----- Method: CollectionTest>>testAsCommaStringAnd (in category 'tests') -----
- ----- Method: CollectionTest>>testAsCommaStringAnd (in category 'testing') -----
  testAsCommaStringAnd
  {OrderedCollection new. Set new.} do:
  [ :coll |
  self assert: coll asCommaStringAnd = ''.
 
  coll add: 1.
  self assert: coll asCommaStringAnd = '1'.
 
  coll add: 2; add: 3.
  self assert: coll asCommaStringAnd = '1, 2 and 3'].!

Item was changed:
+ ----- Method: CollectionTest>>testAsStringOnDelimiter (in category 'tests') -----
- ----- Method: CollectionTest>>testAsStringOnDelimiter (in category 'testing') -----
  testAsStringOnDelimiter
  | delim |
  delim := ', '.
  {OrderedCollection new. Set new.} do:
  [ :coll | | oneItemStream emptyStream multiItemStream |
  emptyStream := String new writeStream.
  coll asStringOn: emptyStream delimiter: delim.
  self assert: emptyStream contents = ''.
 
  coll add: 1.
  oneItemStream := String new writeStream.
  coll asStringOn: oneItemStream delimiter: delim.
  self assert: oneItemStream contents = '1'.
 
  coll add: 2; add: 3.
  multiItemStream := String new writeStream.
  coll asStringOn: multiItemStream delimiter: ', '.
  self assert: multiItemStream contents = '1, 2, 3'.]!

Item was changed:
+ ----- Method: CollectionTest>>testAsStringOnDelimiterLast (in category 'tests') -----
- ----- Method: CollectionTest>>testAsStringOnDelimiterLast (in category 'testing') -----
  testAsStringOnDelimiterLast
  | delim last |
  delim := ', '.
  last := ' & '.
  {OrderedCollection new. Set new.} do:
  [ :coll | | multiItemStream emptyStream oneItemStream |
  emptyStream := String new writeStream.
  coll asStringOn: emptyStream delimiter: delim last: last.
  self assert: emptyStream contents = ''.
 
  coll add: 1.
  oneItemStream := String new writeStream.
  coll asStringOn: oneItemStream delimiter: delim last: last.
  self assert: oneItemStream contents = '1'.
 
  coll add: 2; add: 3.
  multiItemStream := String new writeStream.
  coll asStringOn: multiItemStream delimiter: ', ' last: last.
  self assert: multiItemStream contents = '1, 2 & 3'.]!

Item was changed:
+ ----- Method: CollectionTest>>testHistogramOf (in category 'tests') -----
- ----- 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.'.
  !

Item was changed:
+ ----- Method: CollectionTest>>testPrintOnDelimiter (in category 'tests') -----
- ----- Method: CollectionTest>>testPrintOnDelimiter (in category 'testing') -----
  testPrintOnDelimiter
  | delim |
  delim := ', '.
  {OrderedCollection new. Set new.} do:
  [ :coll | | emptyStream oneItemStream multiItemStream |
  emptyStream := String new writeStream.
  coll printOn: emptyStream delimiter: delim.
  self assert: emptyStream contents = ''.
 
  coll add: 1.
  oneItemStream := String new writeStream.
  coll printOn: oneItemStream delimiter: delim.
  self assert: oneItemStream contents = '1'.
 
  coll add: 2; add: 3.
  multiItemStream := String new writeStream.
  coll printOn: multiItemStream delimiter: ', '.
  self assert: multiItemStream contents = '1'', ''2'', ''3'.]!

Item was changed:
+ ----- Method: CollectionTest>>testPrintOnDelimiterLast (in category 'tests') -----
- ----- Method: CollectionTest>>testPrintOnDelimiterLast (in category 'testing') -----
  testPrintOnDelimiterLast
  | delim last |
  delim := ', '.
  last := ' & '.
  {OrderedCollection new. Set new.} do:
  [ :coll | | emptyStream oneItemStream multiItemStream |
  emptyStream := String new writeStream.
  coll printOn: emptyStream delimiter: delim last: last.
  self assert: emptyStream contents = ''.
 
  coll add: 1.
  oneItemStream := String new writeStream.
  coll printOn: oneItemStream delimiter: delim last: last.
  self assert: oneItemStream contents = '1'.
 
  coll add: 2; add: 3.
  multiItemStream := String new writeStream.
  coll printOn: multiItemStream delimiter: ', ' last: last.
  self assert: multiItemStream contents = '1'', ''2'' & ''3'.]!

Item was changed:
+ ----- Method: CollectionTest>>testPrintingArrayWithMetaclass (in category 'tests') -----
- ----- Method: CollectionTest>>testPrintingArrayWithMetaclass (in category 'testing') -----
  testPrintingArrayWithMetaclass
  self assert: {Array class} printString = '{Array class}'!

Item was added:
+ ----- Method: CollectionTest>>testTryIgnore (in category 'tests') -----
+ testTryIgnore
+
+ | someObjects sum |
+ someObjects := #(1 3 a b 7 c 2).
+ sum := 0.
+
+ someObjects
+ try: [:each | sum := sum + each]
+ ignore: NumberParserError.
+
+ self assert: 13 equals: sum.!

Item was added:
+ ----- Method: CollectionTest>>testTryIgnoreIfException (in category 'tests') -----
+ testTryIgnoreIfException
+
+ | someObjects exceptions |
+ someObjects := #(1 3 a b 7 c 2).
+ exceptions := OrderedCollection new.
+
+ someObjects
+ try: [:each | each + each]
+ ignore: Error
+ ifException: [:ex | exceptions add: ex].
+
+ self assert: 3 equals: exceptions size.!