Skip to content

Commit

Permalink
Clean up tests and some API
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jun 14, 2024
1 parent d29fa77 commit c5684c8
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 249 deletions.
38 changes: 25 additions & 13 deletions src/Famix-Diff-Core-Tests/AbstractFamixDiffWithModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ Class {
#name : #AbstractFamixDiffWithModelTest,
#superclass : #AbstractFamixDiffTest,
#instVars : [
'snapshot',
'testChanges',
'resolver'
'diff'
],
#category : #'Famix-Diff-Core-Tests'
}

{ #category : #accessing }
AbstractFamixDiffWithModelTest >> baseEntityNamed: aString [

^ diff baseModel entityNamed: aString
]

{ #category : #running }
AbstractFamixDiffWithModelTest >> createChange: changeClass with: entity [

testChanges at: entity put: (changeClass entity: entity)
self resolver changesDico at: entity put: (changeClass entity: entity)
]

{ #category : #running }
AbstractFamixDiffWithModelTest >> createChange: changeClass with: baseEntity and: targetEntity [

| change |
change := changeClass base: baseEntity target: targetEntity.
testChanges at: baseEntity put: change.
testChanges at: targetEntity put: change
self resolver changesDico
at: baseEntity put: change;
at: targetEntity put: change
]

{ #category : #accessing }
AbstractFamixDiffWithModelTest >> resolver [

^ diff resolver
]

{ #category : #running }
Expand All @@ -31,11 +42,12 @@ AbstractFamixDiffWithModelTest >> setUp [
super setUp.
model1 := self importModelNamed: 'base' fromPackages: #( #'Famix-Diff-TestResource-P3' #'Famix-Diff-TestResource-P2' ).
model2 := self importModelNamed: 'target' fromPackages: #( #'Famix-Diff-TestResource-P1' #'Famix-Diff-TestResource-P2' ).
snapshot := FXDiff baseModel: model1 targetModel: model2.
testChanges := Dictionary new.
resolver := FamixDiffResolver new.
resolver
changesDico: testChanges;
orchestrator: snapshot.
self createChange: FamixUnchangedChange with: (snapshot baseModel entityNamed: 'Smalltalk') and: (snapshot targetModel entityNamed: 'Smalltalk')
diff := FXDiff baseModel: model1 targetModel: model2.
self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk') and: (self targetEntityNamed: 'Smalltalk')
]

{ #category : #accessing }
AbstractFamixDiffWithModelTest >> targetEntityNamed: aString [

^ diff targetModel entityNamed: aString
]
99 changes: 30 additions & 69 deletions src/Famix-Diff-Core-Tests/FamixDiffAssociationsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,48 @@ Class {

{ #category : #tests }
FamixDiffAssociationsTest >> testAssocsAddP2 [
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::C3diff')
and: (snapshot targetModel entityNamed: 'Smalltalk::C3diff').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff.c3()').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff.c3().toto').
self
createChange: FamixAddChange
with: (snapshot targetModel entityNamed: 'Smalltalk::A3diff').
self
createChange: FamixAddChange
with: (snapshot targetModel entityNamed: 'Smalltalk::A3diff.c3()').
self
createChange: FamixAddChange
with: (snapshot targetModel entityNamed: 'Smalltalk::A3diff.c3().toto').
snapshot diffComputer changesDico: testChanges.
snapshot diffComputer diffAssociations.
self assert: snapshot diffComputer associationChanges size equals: 8.
self
assert: (snapshot diffComputer associationChanges select: [ :c | c isAddition ]) size
equals: 4.
self
assert: (snapshot diffComputer associationChanges select: [ :c | c isRemoval ]) size
equals: 4

self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::C3diff') and: (self targetEntityNamed: 'Smalltalk::C3diff').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A3diff').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto').
self createChange: FamixAddChange with: (self targetEntityNamed: 'Smalltalk::A3diff').
self createChange: FamixAddChange with: (self targetEntityNamed: 'Smalltalk::A3diff.c3()').
self createChange: FamixAddChange with: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto').
diff resolver diffAssociations.
self assert: diff resolver associationChanges size equals: 8.
self assert: (diff resolver associationChanges select: [ :c | c isAddition ]) size equals: 4.
self assert: (diff resolver associationChanges select: [ :c | c isRemoval ]) size equals: 4
]

{ #category : #tests }
FamixDiffAssociationsTest >> testAssocsDelP3 [
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::B3diff')
and: (snapshot targetModel entityNamed: 'Smalltalk::B3diff').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A4diff').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::B4diff').
self
createChange: FamixRemovalChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A4diff.b3()').
snapshot diffComputer changesDico: testChanges.
snapshot diffComputer diffAssociations.
self assert: snapshot diffComputer associationChanges size equals: 4.
self
assert: (snapshot diffComputer associationChanges select: [ :c | c isRemoval ]) size
equals: 4

self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::B3diff') and: (self targetEntityNamed: 'Smalltalk::B3diff').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A4diff').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::B4diff').
self createChange: FamixRemovalChange with: (self baseEntityNamed: 'Smalltalk::A4diff.b3()').
diff resolver diffAssociations.
self assert: diff resolver associationChanges size equals: 4.
self assert: (diff resolver associationChanges select: [ :c | c isRemoval ]) size equals: 4
]

{ #category : #tests }
FamixDiffAssociationsTest >> testAssocsMatching [

self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Famix-Diff-TestResource-P2')
and: (snapshot targetModel entityNamed: 'Famix-Diff-TestResource-P2').
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff')
and: (snapshot targetModel entityNamed: 'Smalltalk::A3diff').
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::C3diff')
and: (snapshot targetModel entityNamed: 'Smalltalk::C3diff').
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff.c3()')
and: (snapshot targetModel entityNamed: 'Smalltalk::A3diff.c3()').
with: (self baseEntityNamed: 'Famix-Diff-TestResource-P2')
and: (self targetEntityNamed: 'Famix-Diff-TestResource-P2').
self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::A3diff') and: (self targetEntityNamed: 'Smalltalk::A3diff').
self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::C3diff') and: (self targetEntityNamed: 'Smalltalk::C3diff').
self createChange: FamixUnchangedChange with: (self baseEntityNamed: 'Smalltalk::A3diff.c3()') and: (self targetEntityNamed: 'Smalltalk::A3diff.c3()').
self
createChange: FamixUnchangedChange
with: (snapshot baseModel entityNamed: 'Smalltalk::A3diff.c3().toto')
and: (snapshot targetModel entityNamed: 'Smalltalk::A3diff.c3().toto').
snapshot diffComputer changesDico: testChanges.
snapshot diffComputer diffAssociations.
with: (self baseEntityNamed: 'Smalltalk::A3diff.c3().toto')
and: (self targetEntityNamed: 'Smalltalk::A3diff.c3().toto').
diff resolver diffAssociations.

"because the invocations of new (in A3.c3()) does not have candidates, an exception is added"
self assert: snapshot associationChanges isEmpty
self assertEmpty: diff associationChanges
]
Loading

0 comments on commit c5684c8

Please sign in to comment.