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

Optimize Diff creation #12

Merged
merged 6 commits into from
Jul 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Class {
#name : #BaselineOfGitLabHealth,
#superclass : #BaselineOf,
#category : #BaselineOfGitLabHealth
#name : 'BaselineOfGitLabHealth',
#superclass : 'BaselineOf',
#category : 'BaselineOfGitLabHealth',
#package : 'BaselineOfGitLabHealth'
}

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfGitLabHealth >> baseline: spec [

<baseline>
Expand All @@ -21,14 +22,14 @@ BaselineOfGitLabHealth >> baseline: spec [
spec package: 'GitLabHealth-Model' with: [ spec requires: #( 'Moose' ) ] ] ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfGitLabHealth >> customProjectAttributes [
self class environment at: #MooseEntity ifAbsent: [ ^ #(#WithoutFamix) ].

^ #()
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfGitLabHealth >> defineDependencies: spec [

spec
Expand All @@ -39,11 +40,11 @@ BaselineOfGitLabHealth >> defineDependencies: spec [
with: [ spec repository: 'github://badetitou/MoreLogger:main/src' ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfGitLabHealth >> defineGroups: spec [
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfGitLabHealth >> definePackages: spec [

spec
Expand Down Expand Up @@ -72,6 +73,8 @@ BaselineOfGitLabHealth >> definePackages: spec [
package: 'GLPHExtended-Model' with: [
spec requires:
#( 'GitLabHealth-Model' 'GitLabHealth-Model-Extension' ) ];
package: 'GLPHExtended-Model-Tests'
with: [ spec requires: #( 'GLPHExtended-Model' ) ];
package: 'GLPHExtended-Model-Extension' with: [
spec requires:
#( 'GLPHExtended-Model' 'GitLabHealth-Model' 'GitLabHealth-Model-Extension' ) ];
Expand Down
2 changes: 1 addition & 1 deletion src/BaselineOfGitLabHealth/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #BaselineOfGitLabHealth }
Package { #name : 'BaselineOfGitLabHealth' }
23 changes: 13 additions & 10 deletions src/GLPHExtended-Model-Extension/GLPHEChange.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ GLPHEChange >> name [
GLPHEChange class >> newFrom: aDiffLine [
"Factory a Change from a loc"

| aChange code|
aChange := GLPHELineOfCode new.

| aChange trimedLine code |
trimedLine := aDiffLine trim.

aChange := (trimedLine beginsWith: #+)
ifTrue: [ GLPHEAddition new ]
ifFalse: [
(aDiffLine trim beginsWith: #-)
ifTrue: [ GLPHEDeletion new ]
ifFalse: [ GLPHELineOfCode new ] ].

code := aDiffLine.
(aDiffLine beginsWith: #'@@') ifTrue: [
code := (aDiffLine splitOn: '@@') copyWithoutFirst second.
].
(aDiffLine trim beginsWith: #+) ifTrue: [ aChange := GLPHEAddition new. ].
(aDiffLine trim beginsWith: #-) ifTrue: [ aChange := GLPHEDeletion new. ].

(trimedLine beginsWith: #'@@') ifTrue: [
code := (trimedLine splitOn: '@@') copyWithoutFirst second ].
aChange sourceCode: code.

^ aChange
]
15 changes: 8 additions & 7 deletions src/GLPHExtended-Model-Extension/GLPHEDiffRange.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ GLPHEDiffRange >> name [

{ #category : #'*GLPHExtended-Model-Extension' }
GLPHEDiffRange class >> newFrom: aLine [
|range infos rangesInfo |
range := GLPHEDiffRange new.
infos := (aLine splitOn: '@@') copyWithoutFirst.
rangesInfo := infos first trim splitOn: ' '.

| range infos rangesInfo |
range := GLPHEDiffRange new.
infos := (aLine splitOn: '@@') second.
rangesInfo := infos trim splitOn: ' '.
range originalLineRange: rangesInfo first.
range newLineRange: rangesInfo second .
^ range.
range newLineRange: rangesInfo second.

^ range
]
35 changes: 35 additions & 0 deletions src/GLPHExtended-Model-Tests/GLPHEChangeTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"
A GLPHEChangeTest is a test class for testing the behavior of GLPHEChange
"
Class {
#name : #GLPHEChangeTest,
#superclass : #TestCase,
#category : #'GLPHExtended-Model-Tests-Entities'
}

{ #category : #tests }
GLPHEChangeTest >> testNewEntityFromString [

| change |
change := GLPHEChange newFrom: '+ helloWorld'.
self assert: change class equals: GLPHEAddition.
self assert: change sourceCode equals: '+ helloWorld'
]

{ #category : #tests }
GLPHEChangeTest >> testNewEntityFromStringDeletion [

| change |
change := GLPHEChange newFrom: '- helloWorld'.
self assert: change class equals: GLPHEDeletion.
self assert: change sourceCode equals: '- helloWorld'
]

{ #category : #tests }
GLPHEChangeTest >> testNewEntityFromStringLOC [

| change |
change := GLPHEChange newFrom: 'helloWorld'.
self assert: change class equals: GLPHELineOfCode.
self assert: change sourceCode equals: 'helloWorld'
]
28 changes: 28 additions & 0 deletions src/GLPHExtended-Model-Tests/GLPHEDiffRangeTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"
A GLPHEDiffRangeTest is a test class for testing the behavior of GLPHEDiffRange
"
Class {
#name : #GLPHEDiffRangeTest,
#superclass : #TestCase,
#category : 'GLPHExtended-Model-Tests-Entities'
}

{ #category : #tests }
GLPHEDiffRangeTest >> testNewEntityFromString [

| diffRange |
diffRange := GLPHEDiffRange newFrom:
'@@ -15,9 +15,9 @@ LLMModifierTest >> testGetViolationsMessage ['.
self assert: diffRange originalLineRange equals: '-15,9'.
self assert: diffRange newLineRange equals: '+15,9'
]

{ #category : #tests }
GLPHEDiffRangeTest >> testNewEntityFromStringWithDifferentValues [

| diffRange |
diffRange := GLPHEDiffRange newFrom:
'@@ -15,7 +15,8 @@ LLMModifier >> getViolationsMessage: violations ['.
self assert: diffRange originalLineRange equals: '-15,7'.
self assert: diffRange newLineRange equals: '+15,8'
]
1 change: 1 addition & 0 deletions src/GLPHExtended-Model-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'GLPHExtended-Model-Tests' }
80 changes: 80 additions & 0 deletions src/GitLabHealth-Model-Extension-Tests/GLHExtensionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,83 @@ GLHExtensionTest >> testAddAllOfTypeUnlessWithAlreadyExistingEntity [
self assert: (values includes: user).
self assert: (values includes: alreadyExistingUser)
]

{ #category : #tests }
GLHExtensionTest >> testAddAllUnless [

| col |
col := OrderedCollection new.
col addAll: { 12 } unless: [ :a :b | a = b ].
self assert: col size equals: 1.
self assert: col first equals: 12
]

{ #category : #tests }
GLHExtensionTest >> testAddAllUnlessIntersectionOfUsers [

| col result user1 user2 user3 user2b user3b user4 |
user1 := GLHUser new.
user1 id: 1.
user2 := GLHUser new.
user2 id: 2.
user3 := GLHUser new.
user3 id: 3.
col := OrderedCollection new.
col
addAll: {
user1.
user2.
user3 }
unless: [ :a :b | a id = b id ].
self assert: col size equals: 3.
user2b := GLHUser new.
user2b id: 2.
user3b := GLHUser new.
user3b id: 3.
user4 := GLHUser new.
user4 id: 4.

result := col
addAll: {
user2b.
user3b.
user4 }
unless: [ :a :b | a id = b id ].
self assert: col size equals: 4.
self assert: result size equals: 3.
self assert: (result includes: user2).
self assert: (result includes: user3).
self assert: (result includes: user4)
]

{ #category : #tests }
GLHExtensionTest >> testAddAllUnlessTwiceEqualityIsTheSameButNotObject [

| col user result userB |
user := GLHUser new.
user id: 12.
col := OrderedCollection new.
col addAll: { user } unless: [ :a :b | a id = b id ].
self assert: col size equals: 1.
self assert: col first identicalTo: user.
userB := GLHUser new.
userB id: 12.
result := col addAll: { userB } unless: [ :a :b | a id = b id ].
self assert: col size equals: 1.
self assert: result first identicalTo: user
]

{ #category : #tests }
GLHExtensionTest >> testAddAllUnlessTwiceTheSame [

| col user result |
user := GLHUser new.
user id: 12.
col := OrderedCollection new.
col addAll: { user } unless: [ :a :b | a = b ].
self assert: col size equals: 1.
self assert: col first identicalTo: user.
result := col addAll: { user } unless: [ :a :b | a = b ].
self assert: col size equals: 1.
self assert: result first identicalTo: user
]
28 changes: 16 additions & 12 deletions src/GitLabHealth-Model-Extension/OrderedCollection.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ OrderedCollection >> add: anElmt unless: aConditionAsBlock [

{ #category : #'*GitLabHealth-Model-Extension' }
OrderedCollection >> addAll: anElmtCollection unless: aConditionAsBlock [
"()>>>"
|addedElements|

addedElements := (anElmtCollection reject: [ :anElmt |
self anySatisfy: [ :existingElmt |
aConditionAsBlock value: existingElmt value: anElmt ] ]).

self addAll: addedElements.

^ (self select: [ :existingElmt |
anElmtCollection anySatisfy: [ :anElmt |
aConditionAsBlock value: anElmt value: existingElmt ] ]).

| returnCollection |
"Create same kind of collection"
returnCollection := self species new.
"For each element of this collection"

anElmtCollection do: [ :anElmt |
self
detect: [ :existingElmt |
aConditionAsBlock value: existingElmt value: anElmt ]
ifFound: [ :el | returnCollection add: el ]
ifNone: [
returnCollection add: anElmt.
self add: anElmt ] ].

^ returnCollection
]
Loading