Skip to content

Commit

Permalink
Cleanup tests - part 5
Browse files Browse the repository at this point in the history
  • Loading branch information
astares committed Jun 26, 2023
1 parent fc8c47e commit c700c0b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 51 deletions.
44 changes: 29 additions & 15 deletions src/Glorp-Unit-Tests/GlorpBreadthFirstTopologicalSortTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ Class {
#category : #'Glorp-Unit-Tests-Tests'
}

{ #category : #support }
{ #category : #asserting }
GlorpBreadthFirstTopologicalSortTest >> assertSortOrder: aCollection [

| ids |
ids := (sorted collect: [:each | each id]) asArray.
self assert: ids = aCollection asArray.
ids := (sorted collect: [ :each | each id ]) asArray.
self assert: ids equals: aCollection asArray
]

{ #category : #data }
GlorpBreadthFirstTopologicalSortTest >> data1 [

| one two three |
one := GlorpBreadthFirstTopologicalSortItem new id: 1.
two := GlorpBreadthFirstTopologicalSortItem new id: 2.
three := GlorpBreadthFirstTopologicalSortItem new id: 3.
one relateTo: two.
two relateTo: three.
^Array with: one with: two with: three.
^ Array with: one with: two with: three
]

{ #category : #data }
GlorpBreadthFirstTopologicalSortTest >> dataForGroupNamed: aString [

| one two three four |
one := GlorpBreadthFirstTopologicalSortItem new id: aString, '1'.
two := GlorpBreadthFirstTopologicalSortItem new id: aString, '2'.
three := GlorpBreadthFirstTopologicalSortItem new id: aString, '3'.
four := GlorpBreadthFirstTopologicalSortItem new id: aString, '4'.
^Array with: one with: two with: three with: four.
^Array with: one with: two with: three with: four
]

{ #category : #data }
GlorpBreadthFirstTopologicalSortTest >> dataForMedium [
"Data to ensure that things tend to stay together. This is a simple grouping a1->b, b->c, b->a2, repeated, with some extra floating b's and c's."

groupA := self dataForGroupNamed: 'a'.
groupB := self dataForGroupNamed: 'b'.
groupC := self dataForGroupNamed: 'c'.
Expand All @@ -51,57 +55,63 @@ GlorpBreadthFirstTopologicalSortTest >> dataForMedium [
(groupB at: 3) relateTo: (groupC at: 3).
groupB first relateTo: (groupA at: 2).
(groupB at: 3) relateTo: (groupA at: 4).
^groupA, groupB, groupC.
^groupA, groupB, groupC
]

{ #category : #data }
GlorpBreadthFirstTopologicalSortTest >> dataForNoCyclesMedium [
"Data to ensure that things tend to stay together. This is a simple grouping a->b, b->c repeated"

groupA := self dataForGroupNamed: 'a'.
groupB := self dataForGroupNamed: 'b'.
groupC := self dataForGroupNamed: 'c'.
1 to: 4 do: [:i |
(groupA at: i) relateTo: (groupB at: i).
(groupB at: i) relateTo: (groupC at: i)].
^groupC, groupB, groupA.
^groupC, groupB, groupA
]

{ #category : #data }
GlorpBreadthFirstTopologicalSortTest >> dataForNoCyclesMediumPermuted [
"Data to ensure that things tend to stay together. This is a simple grouping a->b, b->c repeated"

groupA := self dataForGroupNamed: 'a'.
groupB := self dataForGroupNamed: 'b'.
groupC := self dataForGroupNamed: 'c'.
1 to: 4 do: [:i |
(groupA at: i) relateTo: (groupB at: i).
(groupB at: i) relateTo: (groupC at: i)].
^groupB, groupA, groupC.
^groupB, groupA, groupC
]

{ #category : #support }
GlorpBreadthFirstTopologicalSortTest >> sort [

| sorter |
sorter := GlorpRowSorter new getChildrenVia: #relatedItems.
sorted := sorter sort: unsorted.
sorted := sorter sort: unsorted
]

{ #category : #support }
GlorpBreadthFirstTopologicalSortTest >> sort: aCollection [

unsorted := aCollection.
self sort.
self sort
]

{ #category : #tests }
GlorpBreadthFirstTopologicalSortTest >> testBasicSort1 [

self sort: self data1.
self assertSortOrder: #(3 2 1).
self assertSortOrder: #( 3 2 1 )
]

{ #category : #tests }
GlorpBreadthFirstTopologicalSortTest >> testBasicSort2 [
"Try it with a different initial order. The sort is a convoluted way of writing the questionably-portable reverse"
self sort: (self data1 asSortedCollection: [:a :b | a id >= b id]).
self assertSortOrder: #(3 2 1).

self sort: (self data1 asSortedCollection: [ :a :b | a id >= b id ]).
self assertSortOrder: #( 3 2 1 )
]

{ #category : #tests }
Expand All @@ -123,14 +133,18 @@ GlorpBreadthFirstTopologicalSortTest >> testBasicSortCompleteGraph [

{ #category : #tests }
GlorpBreadthFirstTopologicalSortTest >> testMedium1 [

self sort: self dataForMedium.
self assertSortOrder: #('c1' 'a2' 'b1' 'a1' 'c3' 'a4' 'b3' 'a3' 'b2' 'b4' 'c2' 'c4').
self assertSortOrder:
#( 'c1' 'a2' 'b1' 'a1' 'c3' 'a4' 'b3' 'a3' 'b2' 'b4' 'c2' 'c4' )
]

{ #category : #tests }
GlorpBreadthFirstTopologicalSortTest >> testNoCyclesMedium [

self sort: self dataForNoCyclesMedium.
self assertSortOrder: #('c1' 'c2' 'c3' 'c4' 'b1' 'b2' 'b3' 'b4' 'a1' 'a2' 'a3' 'a4').
self assertSortOrder:
#( 'c1' 'c2' 'c3' 'c4' 'b1' 'b2' 'b3' 'b4' 'a1' 'a2' 'a3' 'a4' )
]

{ #category : #tests }
Expand Down
21 changes: 11 additions & 10 deletions src/Glorp-Unit-Tests/GlorpCommandTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GlorpCommandTest >> testSplittingInserts1 [
subCommands := command subCommands.
self assert: subCommands size equals: 1.
self assert: subCommands first allRows size equals: 1.
self assert: subCommands first allRows first == rows first
self assert: subCommands first allRows first identicalTo: rows first
]

{ #category : #tests }
Expand All @@ -57,21 +57,22 @@ GlorpCommandTest >> testSplittingInserts1000 [
subCommands := command subCommands.
self assert: subCommands size equals: 1.
self assert: subCommands first allRows size equals: 1000.
self assert: subCommands first allRows first == rows first
self assert: subCommands first allRows first identicalTo: rows first
]

{ #category : #tests }
GlorpCommandTest >> testSplittingInserts1001 [

| rows command subCommands |
rows := (Array new: 1001) atAllPut: DatabaseRow new.
rows at: rows size put: DatabaseRow new.
command := InsertCommand forRows: rows useBinding: false session: nil.
subCommands := command subCommands.
self assert: subCommands size equals: 2.
self assert: subCommands first allRows size equals: 1000.
self assert: subCommands first allRows first == rows first.
self assert: subCommands first allRows first identicalTo: rows first.
self assert: subCommands last allRows size equals: 1.
self assert:subCommands last allRows first == rows last.
self assert: subCommands last allRows first identicalTo: rows last
]

{ #category : #tests }
Expand All @@ -83,11 +84,11 @@ GlorpCommandTest >> testSplittingInserts1003 [
command := InsertCommand forRows: rows useBinding: false session: nil.
subCommands := command subCommands.
self assert: subCommands size equals: 2.
self assert: subCommands first allRows size = 1000.
self assert: subCommands first allRows first == rows first.
self assert: subCommands first allRows size equals: 1000.
self assert: subCommands first allRows first identicalTo: rows first.
self assert: subCommands last allRows size equals: 3.
self assert:subCommands last allRows last == rows last.
self assert: subCommands last allRows first == rows first
self assert: subCommands last allRows last identicalTo: rows last.
self assert: subCommands last allRows first identicalTo: rows first
]

{ #category : #tests }
Expand All @@ -99,6 +100,6 @@ GlorpCommandTest >> testSplittingInserts2 [
subCommands := command subCommands.
self assert: subCommands size equals: 1.
self assert: subCommands first allRows size equals: 2.
self assert: subCommands first allRows first == rows first.
self assert: subCommands first allRows last == rows last.
self assert: subCommands first allRows first identicalTo: rows first.
self assert: subCommands first allRows last identicalTo: rows last
]
3 changes: 2 additions & 1 deletion src/Glorp-Unit-Tests/GlorpConstantMappingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GlorpConstantMappingTest >> testGetValue [

{ #category : #tests }
GlorpConstantMappingTest >> testSessionValue [

mappingToClass constantValueIsSession.
self assert: (mappingToClass constantValueIn: 38)== 38.
self assert: (mappingToClass constantValueIn: 38) identicalTo: 38
]
22 changes: 12 additions & 10 deletions src/Glorp-Unit-Tests/GlorpDatabaseAccessorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ Class {

{ #category : #tests }
GlorpDatabaseAccessorTest >> testLoggingSwitch [

| currentSetting accessor |
currentSetting := DatabaseAccessor loggingEnabled.
accessor := DatabaseAccessor new.
[DatabaseAccessor loggingEnabled: true.
self assert: accessor logging.
DatabaseAccessor loggingEnabled: false.
self deny: accessor logging.
accessor logging: true.
self assert: accessor logging.
accessor logging: false.
self deny: accessor logging.
DatabaseAccessor loggingEnabled: true.
self deny: accessor logging] ensure: [DatabaseAccessor loggingEnabled: currentSetting].

[ DatabaseAccessor loggingEnabled: true.
self assert: accessor logging.
DatabaseAccessor loggingEnabled: false.
self deny: accessor logging.
accessor logging: true.
self assert: accessor logging.
accessor logging: false.
self deny: accessor logging.
DatabaseAccessor loggingEnabled: true.
self deny: accessor logging ] ensure: [ DatabaseAccessor loggingEnabled: currentSetting ]
]
19 changes: 12 additions & 7 deletions src/Glorp-Unit-Tests/GlorpDatabasePlatformTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#category : #'Glorp-Unit-Tests-Tests'
}

{ #category : #tests }
{ #category : #utilities }
GlorpDatabasePlatformTest >> addToString: aString [
"Append a couple of special characters. The result will utf-8 encode to be 3 characters longer than its number of characters"
^aString, (String with: (Character value: 16r2022) "bullet point" with: (Character value: 16r0131) "Turkish i with no dot")
Expand All @@ -16,25 +16,29 @@ double-byte entries. The VA could be implemented as
"
]

{ #category : #tests }
{ #category : #utilities }
GlorpDatabasePlatformTest >> helpTestPrintTimestamp: aTimestampString [

| aStream ts timestamp |
ts := DatabasePlatform new readTimestamp: aTimestampString for: nil.
aStream := WriteStream on: String new.
DatabasePlatform new printDate: ts isoFormatOn: aStream.
aStream nextPut: Character space.
DatabasePlatform new printTime: ts isoFormatOn: aStream milliseconds: Dialect supportsMillisecondsInTimes .
DatabasePlatform new
printTime: ts
isoFormatOn: aStream
milliseconds: Dialect supportsMillisecondsInTimes.
timestamp := aStream contents.
self assert: timestamp = aTimestampString.
self assert: timestamp equals: aTimestampString
]

{ #category : #tests }
{ #category : #utilities }
GlorpDatabasePlatformTest >> string20 [

| platform |
platform := PostgresPlatform new.
platform characterEncoding: #'utf-8'.
^platform varchar: 20.
^ platform varchar: 20
]

{ #category : #tests }
Expand All @@ -59,7 +63,7 @@ GlorpDatabasePlatformTest >> testPrintTimestamp [
| strings |
strings := #( '2005-01-01 21:29:28.337' '2005-01-01 01:02:00.037' '2005-01-01 21:29:28.002' '2005-01-01 21:29:28.001').
strings do: [:each |
self helpTestPrintTimestamp: each].
self helpTestPrintTimestamp: each]
]

{ #category : #tests }
Expand Down Expand Up @@ -159,6 +163,7 @@ GlorpDatabasePlatformTest >> testTrimString1 [
{ #category : #tests }
GlorpDatabasePlatformTest >> testTrimString2 [
"Some special characters"

| type plat string |

type := self string20.
Expand Down
27 changes: 19 additions & 8 deletions src/Glorp-Unit-Tests/GlorpDeleteInUnitOfWorkTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Class {

{ #category : #running }
GlorpDeleteInUnitOfWorkTest >> setUp [

| session |
super setUp.
session := GlorpMockSession new.
session beginUnitOfWork.
unitOfWork := session privateGetCurrentUnitOfWork.
Expand Down Expand Up @@ -40,29 +42,34 @@ GlorpDeleteInUnitOfWorkTest >> testCommit [

unitOfWork delete: GlorpAddress example1.
unitOfWork commit.
self assert: (unitOfWork numberOfRows) = 1.
self assert: unitOfWork numberOfRows equals: 1
]

{ #category : #tests }
GlorpDeleteInUnitOfWorkTest >> testDeleteRegistration [

| obj |
obj := Object new.
unitOfWork delete: obj.
self assert: (unitOfWork willDelete: obj).
self deny: (unitOfWork willDelete: 3).
self deny: (unitOfWork willDelete: 3)
]

{ #category : #tests }
GlorpDeleteInUnitOfWorkTest >> testDeletesComeAfterUpdates [

unitOfWork delete: GlorpAddress example1.
unitOfWork register: GlorpCustomer example1.
unitOfWork commit.
self assert: unitOfWork session rows last table == (self tableNamed: 'GR_ADDRESS').
self
assert: unitOfWork session rows last table
identicalTo: (self tableNamed: 'GR_ADDRESS')
]

{ #category : #tests }
GlorpDeleteInUnitOfWorkTest >> testDeletesInReverseOrder [
"Not that good a test, because it could be luck with only two tables. Should test this at a lower level"

| cust trans |
cust := GlorpCustomer example2.
trans := cust transactions first.
Expand All @@ -71,15 +78,19 @@ GlorpDeleteInUnitOfWorkTest >> testDeletesInReverseOrder [
unitOfWork delete: cust.
unitOfWork delete: trans.
unitOfWork commit.
self assert: unitOfWork session rows last owner == cust.
self assert: (unitOfWork session rows reverse at: 2) owner == trans.
self assert: unitOfWork session rows last owner identicalTo: cust.
self
assert: (unitOfWork session rows reverse at: 2) owner
identicalTo: trans
]

{ #category : #tests }
GlorpDeleteInUnitOfWorkTest >> testGeneratingDeleteRows [

unitOfWork delete: GlorpAddress example1.
unitOfWork createRows.
self assert: unitOfWork privateGetRowMap numberOfEntries = 1.
unitOfWork rowsForTable: (self tableNamed: 'GR_ADDRESS')
do: [:each | self assert: each forDeletion]
self assert: unitOfWork privateGetRowMap numberOfEntries equals: 1.
unitOfWork
rowsForTable: (self tableNamed: 'GR_ADDRESS')
do: [ :each | self assert: each forDeletion ]
]
14 changes: 14 additions & 0 deletions src/Glorp-Unit-Tests/ManifestGlorpTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ ManifestGlorpTests class >> ruleEqualNilRuleV1FalsePositive [
^ #(#(#(#RGMethodDefinition #(#GlorpExpressionTest #testIsNullPrint #false)) #'2023-06-26T17:18:01.373504+02:00') #(#(#RGMethodDefinition #(#GlorpExpressionTest #testNotNullPrint #false)) #'2023-06-26T17:18:26.409147+02:00') )
]

{ #category : #'code-critics' }
ManifestGlorpTests class >> ruleLiteralArrayContainsSuspiciousTrueFalseOrNilRuleV1FalsePositive [

<ignoreForCoverage>
^ #(#(#(#RGMetaclassDefinition #(#'ManifestGlorpTests class' #ManifestGlorpTests)) #'2023-06-26T17:49:36.133076+02:00') )
]

{ #category : #'code-critics' }
ManifestGlorpTests class >> ruleSentNotImplementedRuleV1FalsePositive [

Expand All @@ -27,3 +34,10 @@ ManifestGlorpTests class >> ruleUncommonMessageSendRuleV1FalsePositive [
<ignoreForCoverage>
^ #(#(#(#RGMethodDefinition #(#GlorpExpressionTest #testAndOperation2 #false)) #'2023-06-26T17:13:37.574583+02:00') #(#(#RGMethodDefinition #(#GlorpExpressionTest #testOrOperation2 #false)) #'2023-06-26T17:18:49.992423+02:00') )
]

{ #category : #'code-critics' }
ManifestGlorpTests class >> ruleUtilityMethodsRuleV1FalsePositive [

<ignoreForCoverage>
^ #(#(#(#RGClassDefinition #(#GlorpDatabasePlatformTest)) #'2023-06-26T17:48:39.700269+02:00') #(#(#RGMethodDefinition #(#GlorpBreadthFirstTopologicalSortTest #dataForGroupNamed: #false)) #'2023-06-26T17:48:57.821673+02:00') )
]

0 comments on commit c700c0b

Please sign in to comment.