Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21357 cleanup formatting typos and lints in sorted collection test and related traits #899

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
230 changes: 141 additions & 89 deletions src/Collections-Tests/SortedCollectionTest.class.st

Large diffs are not rendered by default.

84 changes: 44 additions & 40 deletions src/Collections-Tests/TAddTest.trait.st
Expand Up @@ -26,6 +26,7 @@ TAddTest >> otherCollection [

{ #category : #'tests - fixture' }
TAddTest >> test0FixtureRequirementsOfTAddTest [

self collectionWithElement.
self otherCollection.
self element.
Expand All @@ -36,7 +37,7 @@ TAddTest >> test0FixtureRequirementsOfTAddTest [
{ #category : #'tests - adding' }
TAddTest >> testTAdd [
| added collection |
collection :=self otherCollection .
collection := self otherCollection.
added := collection add: self element.

self assert: added == self element. "test for identiy because #add: has not reason to copy its parameter."
Expand All @@ -48,10 +49,11 @@ TAddTest >> testTAdd [

{ #category : #'tests - adding' }
TAddTest >> testTAddAll [

| added collection toBeAdded |
collection := self collectionWithElement .
toBeAdded := self otherCollection .
added := collection addAll: toBeAdded .
collection := self collectionWithElement.
toBeAdded := self otherCollection.
added := collection addAll: toBeAdded.
self assert: added == toBeAdded . "test for identiy because #addAll: has not reason to copy its parameter."
self assert: (collection includesAll: toBeAdded )
]
Expand All @@ -60,84 +62,86 @@ TAddTest >> testTAddAll [
TAddTest >> testTAddIfNotPresentWithElementAlreadyIn [

| added oldSize collection anElement |
collection := self collectionWithElement .
collection := self collectionWithElement.
oldSize := collection size.
anElement := self element .
self assert: (collection includes: anElement ).
anElement := self element.
self assert: (collection includes: anElement).

added := collection addIfNotPresent: anElement .
added := collection addIfNotPresent: anElement.

self assert: added == anElement . "test for identiy because #add: has not reason to copy its parameter."
self assert: collection size = oldSize
self assert: collection size equals: oldSize
]

{ #category : #'tests - adding' }
TAddTest >> testTAddIfNotPresentWithNewElement [

| added oldSize collection elem |
collection := self otherCollection .
oldSize := collection size.
elem := self element .
self deny: (collection includes: elem ).
collection := self otherCollection.
oldSize := collection size.
elem := self element.
self deny: (collection includes: elem ).

added := collection addIfNotPresent: elem .
self assert: added == elem . "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection size = (oldSize + 1)).
self assert: collection size equals: (oldSize + 1).


]

{ #category : #'tests - adding' }
TAddTest >> testTAddTwice [

| added oldSize collection anElement |
collection := self collectionWithElement .
anElement := self element .
oldSize := collection size.
collection := self collectionWithElement.
anElement := self element.
oldSize := collection size.
added := collection
add: anElement ;
add: anElement .
self assert: added == anElement . "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: anElement ).
self assert: collection size = (oldSize + 2)
add: anElement;
add: anElement.
self assert: added == anElement. "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: anElement).
self assert: collection size equals: (oldSize + 2)
]

{ #category : #'tests - adding' }
TAddTest >> testTAddWithOccurences [
| added oldSize collection anElement |
collection := self collectionWithElement .
anElement := self element .
oldSize := collection size.
added := collection add: anElement withOccurrences: 5.
collection := self collectionWithElement.
anElement := self element.
oldSize := collection size.
added := collection add: anElement withOccurrences: 5.

self assert: added == anElement. "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: anElement).
self assert: collection size = (oldSize + 5)
self assert: (collection includes: anElement).
self assert: collection size equals: (oldSize + 5)
]

{ #category : #'tests - adding' }
TAddTest >> testTWrite [

| added collection elem |
collection := self otherCollection .
elem := self element .
added := collection write: elem .
collection := self otherCollection.
elem := self element.
added := collection write: elem.

self assert: added == elem . "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: elem ) .
self assert: (collection includes: elem ).
self assert: added == elem. "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: elem).
self assert: (collection includes: elem)


]

{ #category : #'tests - adding' }
TAddTest >> testTWriteTwice [
| added oldSize collection elem |
collection := self collectionWithElement .
elem := self element .
oldSize := collection size.
collection := self collectionWithElement.
elem := self element.
oldSize := collection size.
added := collection
write: elem ;
write: elem .
write: elem;
write: elem.
self assert: added == elem . "test for identiy because #add: has not reason to copy its parameter."
self assert: (collection includes: elem ).
self assert: collection size = (oldSize + 2)
self assert: collection size equals: (oldSize + 2)
]
Expand Up @@ -28,6 +28,7 @@ TAsStringCommaAndDelimiterSequenceableTest >> nonEmpty1Element [

{ #category : #'tests - fixture' }
TAsStringCommaAndDelimiterSequenceableTest >> test0FixtureAsStringCommaAndDelimiterTest [

self nonEmpty.
self deny: self nonEmpty isEmpty.
self empty.
Expand All @@ -40,7 +41,7 @@ TAsStringCommaAndDelimiterSequenceableTest >> test0FixtureAsStringCommaAndDelimi
TAsStringCommaAndDelimiterSequenceableTest >> testAsCommaStringEmpty [

self assert: self empty asCommaString = ''.
self assert: self empty asCommaStringAnd = ''.
self assert: self empty asCommaStringAnd = ''


]
Expand All @@ -49,8 +50,7 @@ TAsStringCommaAndDelimiterSequenceableTest >> testAsCommaStringEmpty [
TAsStringCommaAndDelimiterSequenceableTest >> testAsCommaStringMore [

"self assert: self oneTwoThreeItemCol asCommaString = '1, 2, 3'.
self assert: self oneTwoThreeItemCol asCommaStringAnd = '1, 2 and 3'
"
self assert: self oneTwoThreeItemCol asCommaStringAnd = '1, 2 and 3'"

| result resultAnd index allElementsAsString |
result:= self nonEmpty asCommaString .
Expand Down Expand Up @@ -92,18 +92,20 @@ TAsStringCommaAndDelimiterSequenceableTest >> testAsCommaStringOne [
"self assert: self oneItemCol asCommaString = '1'.
self assert: self oneItemCol asCommaStringAnd = '1'."

self assert: self nonEmpty1Element asCommaString = (self nonEmpty1Element first asString).
self assert: self nonEmpty1Element asCommaStringAnd = (self nonEmpty1Element first asString).
self assert: self nonEmpty1Element asCommaString = (self nonEmpty1Element first asString).
self assert: self nonEmpty1Element asCommaStringAnd = (self nonEmpty1Element first asString)

]

{ #category : #'tests - as string comma delimiter sequenceable' }
TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterEmpty [

self assert: (String streamContents: [ :emptyStream | self empty asStringOn: emptyStream delimiter: ', ' ]) equals: ''
]

{ #category : #'tests - as string comma delimiter sequenceable' }
TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterLastEmpty [

self assert: (String streamContents: [ :emptyStream | self empty asStringOn: emptyStream delimiter: ', ' last: 'and' ]) equals: ''
]

Expand All @@ -126,22 +128,19 @@ TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterLastMore [
i=(allElementsAsString size-1)
ifTrue:[ self deny: (allElementsAsString at:i)=(last)asString].
i=(allElementsAsString size)
ifTrue: [self assert: (allElementsAsString at:i)=((self nonEmpty at:(i-1))asString)].
].

ifTrue: [self assert: (allElementsAsString at:i)=((self nonEmpty at:(i-1))asString)]]

]

{ #category : #'tests - comma and delimiter' }
TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterLastOne [

| delim oneItemStream result |

| delim oneItemStream result |
delim := ', '.
result:=''.
oneItemStream := ReadWriteStream on: result.
self nonEmpty1Element asStringOn: oneItemStream delimiter: delim last: 'and'.
oneItemStream do:[:each | self assert: each = (self nonEmpty1Element first asString)].
oneItemStream do:[:each | self assert: each = (self nonEmpty1Element first asString)]



Expand All @@ -151,38 +150,27 @@ TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterLastOne [
TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterMore [

| delim multiItemStream result index |
"delim := ', '.
multiItemStream := '' readWrite.
self oneTwoThreeItemCol asStringOn: multiItemStream delimiter: ', '.
self assert: multiItemStream contents = '1, 2, 3'."

delim := ', '.
result:=''.
multiItemStream := ReadWriteStream on:result.
result := ''.
multiItemStream := ReadWriteStream on: result.
self nonEmpty asStringOn: multiItemStream delimiter: delim.
result := multiItemStream contents.
index:=1.
(result findBetweenSubstrings: delim )do:
(result findBetweenSubstrings: delim)do:
[:each |
self assert: each= ((self nonEmpty at:index)asString).
index:=index+1
].
self assert: each= ((self nonEmpty at:index) asString).
index:=index+1 ]
]

{ #category : #'tests - comma and delimiter' }
TAsStringCommaAndDelimiterSequenceableTest >> testAsStringOnDelimiterOne [

| delim oneItemStream result |
"delim := ', '.
oneItemStream := '' readWrite.
self oneItemCol asStringOn: oneItemStream delimiter: delim.
self assert: oneItemStream contents = '1'."

delim := ', '.
result:=''.
result := ''.
oneItemStream := ReadWriteStream on: result.
self nonEmpty1Element asStringOn: oneItemStream delimiter: delim.
oneItemStream do:[:each | self assert: each = (self nonEmpty1Element first asString)].
oneItemStream do:[:each | self assert: each = (self nonEmpty1Element first asString)]



Expand Down
13 changes: 7 additions & 6 deletions src/Collections-Tests/TBeginsEndsWith.trait.st
Expand Up @@ -18,6 +18,7 @@ TBeginsEndsWith >> nonEmpty [

{ #category : #'tests - fixture' }
TBeginsEndsWith >> test0FixtureBeginsEndsWithTest [

self nonEmpty.
self deny: self nonEmpty isEmpty.
self assert: self nonEmpty size > 1.
Expand All @@ -28,16 +29,16 @@ TBeginsEndsWith >> test0FixtureBeginsEndsWithTest [
{ #category : #'tests - begins ends with' }
TBeginsEndsWith >> testsBeginsWith [

self assert: (self nonEmpty beginsWith:(self nonEmpty copyUpTo: self nonEmpty last)).
self assert: (self nonEmpty beginsWith:(self nonEmpty )).
self deny: (self nonEmpty beginsWith:(self nonEmpty copyWith:self nonEmpty first)).
self assert: (self nonEmpty beginsWith: (self nonEmpty copyUpTo: self nonEmpty last)).
self assert: (self nonEmpty beginsWith: self nonEmpty).
self deny: (self nonEmpty beginsWith: (self nonEmpty copyWith: self nonEmpty first))
]

{ #category : #'tests - begins ends with' }
TBeginsEndsWith >> testsBeginsWithEmpty [

self deny: (self nonEmpty beginsWith:(self empty)).
self deny: (self empty beginsWith:(self nonEmpty )).
self deny: (self empty beginsWith:(self nonEmpty))

]

Expand All @@ -46,13 +47,13 @@ TBeginsEndsWith >> testsEndsWith [

self assert: (self nonEmpty endsWith: self nonEmpty copyWithoutFirst).
self assert: (self nonEmpty endsWith: self nonEmpty).
self deny: (self nonEmpty endsWith: (self nonEmpty copyWith: self nonEmpty first)).
self deny: (self nonEmpty endsWith: (self nonEmpty copyWith: self nonEmpty first))
]

{ #category : #'tests - begins ends with' }
TBeginsEndsWith >> testsEndsWithEmpty [

self deny: (self nonEmpty endsWith: self empty).
self deny: (self empty endsWith: self nonEmpty).
self deny: (self empty endsWith: self nonEmpty)

]
Expand Up @@ -10,8 +10,9 @@ Trait {

{ #category : #requirements }
TConvertAsSetForMultiplinessIdentityTest >> collectionWithCopy [
"return a collection of type 'self collectionWIithoutEqualsElements class' containing no elements equals ( with identity equality)
but 2 elements only equals with classic equality"
"Return a collection of type 'self collectionWIithoutEqualsElements class' containing no elements equals (with identity equality)
but 2 elements only equals with classic equality"

| result collection |
collection := OrderedCollection withAll: self elementsCopyNonIdenticalWithoutEqualElements.
collection add: collection first copy.
Expand All @@ -21,7 +22,8 @@ TConvertAsSetForMultiplinessIdentityTest >> collectionWithCopy [

{ #category : #requirements }
TConvertAsSetForMultiplinessIdentityTest >> collectionWithIdentical [
"return a collection of type : 'self collectionWIithoutEqualsElements class containing two elements equals ( with identity equality)"
"Return a collection of type: 'self collectionWIithoutEqualsElements class containing two elements equals (with identity equality)."

| result collection anElement |
collection := OrderedCollection withAll: self elementsCopyNonIdenticalWithoutEqualElements.
anElement := collection first.
Expand All @@ -39,7 +41,7 @@ TConvertAsSetForMultiplinessIdentityTest >> elementsCopyNonIdenticalWithoutEqual

{ #category : #'tests - fixture' }
TConvertAsSetForMultiplinessIdentityTest >> test0FixtureAsSetForIdentityMultiplinessTest [
"a collection (of elements for which copy is not identical ) without equal elements:"
"A collection (of elements for which copy is not identical ) without equal elements:"

| anElement res |
self elementsCopyNonIdenticalWithoutEqualElements.
Expand All @@ -65,15 +67,17 @@ TConvertAsSetForMultiplinessIdentityTest >> test0FixtureTConvertAsSetForMultipli

{ #category : #'tests - as set tests' }
TConvertAsSetForMultiplinessIdentityTest >> testAsIdentitySetWithEqualsElements [

| result collection |
collection := self withEqualElements .
result := collection asIdentitySet.
collection do: [ :each | self assert: (result occurrencesOf: each) = 1 ].
self assert: result class = IdentitySet.
self assert: result class = IdentitySet
]

{ #category : #'tests - as identity set' }
TConvertAsSetForMultiplinessIdentityTest >> testAsIdentitySetWithIdentityEqualsElements [

| result |
result := self collectionWithIdentical asIdentitySet.
" Only one element should have been removed as two elements are equals with Identity equality"
Expand All @@ -91,6 +95,7 @@ TConvertAsSetForMultiplinessIdentityTest >> testAsIdentitySetWithIdentityEqualsE

{ #category : #'tests - as identity set' }
TConvertAsSetForMultiplinessIdentityTest >> testAsIdentitySetWithoutIdentityEqualsElements [

| result collection |
collection := self collectionWithCopy.
result := collection asIdentitySet.
Expand All @@ -104,6 +109,7 @@ TConvertAsSetForMultiplinessIdentityTest >> testAsIdentitySetWithoutIdentityEqua

{ #category : #'tests - as set tests' }
TConvertAsSetForMultiplinessIdentityTest >> testAsSetWithEqualsElements [

| result |
result := self withEqualElements asSet.
self withEqualElements do: [ :each | self assert: (result occurrencesOf: each) = 1 ].
Expand Down