Skip to content

Commit

Permalink
Merge pull request #7 from moosetechnology/adding-cache
Browse files Browse the repository at this point in the history
Optimize code and writting tests
  • Loading branch information
alkalinan authored Jun 27, 2024
2 parents bf78a81 + f28f39b commit a44da4c
Show file tree
Hide file tree
Showing 16 changed files with 1,364 additions and 603 deletions.
2 changes: 2 additions & 0 deletions src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ BaselineOfGitLabHealth >> definePackages: spec [
package: 'GitLabHealth-Model';
package: 'GitLabHealth-Model-Extension'
with: [ spec requires: #( 'GitLabHealth-Model' ) ];
package: 'GitLabHealth-Model-Extension-Tests'
with: [ spec requires: #( 'GitLabHealth-Model-Extension' ) ];
package: 'GitLabHealth-Model-Generator';
package: 'GitLabHealth-Model-Inspector'
with: [ spec requires: #( 'GitLabHealth-Model-Visualization' ) ];
Expand Down
245 changes: 245 additions & 0 deletions src/GitLabHealth-Model-Analysis-Tests/GitAnalyzerLocalTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
Class {
#name : #GitAnalyzerLocalTest,
#superclass : #TestCase,
#instVars : [
'glphModel',
'glphApi',
'glhImporter',
'projects',
'gitAnalyzer',
'fromCommit'
],
#category : #'GitLabHealth-Model-Analysis-Tests'
}

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

super setUp.

glphModel := GLPHEModel new.
gitAnalyzer := GitAnalyzer new onModel: glphModel.
fromCommit := GLHCommit new.
fromCommit short_id: 'testFromCommit'.
fromCommit created_at: ('3 August 2021' asDate).
glphModel add: fromCommit.

gitAnalyzer fromCommit: fromCommit.
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaComment [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaContinueComment [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ * hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaStopComment [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsMixedMultipleComments [

| diffA diffARange addition additionB additionC |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

additionB := glphModel newDeletion.
diffARange addChange: additionB.
additionB sourceCode: '- // hello world'.

additionC := glphModel newAddition.
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 2
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsMultipleComments [

| diffA diffARange addition additionB additionC |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

additionB := glphModel newAddition.
diffARange addChange: additionB.
additionB sourceCode: '+ // hello world'.

additionC := glphModel newAddition.
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 3
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsPythonComment [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsShouldBe0 [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentInSomeAroundCode [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newLineOfCode.
diffARange addChange: addition.
addition sourceCode: '// hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

{ #category : #test }
GitAnalyzerLocalTest >> testAnalyseCommentNotAnAddition [

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newDeletion.
diffARange addChange: addition.
addition sourceCode: '- // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

{ #category : #test }
GitAnalyzerLocalTest >> testArrangeCommitsByDate [

| commitA2 commitA3 commitB result |
commitA2 := GLHCommit new.
commitA2 short_id: 'testFromCommit2'.
commitA2 created_at: ('3 August 2021' asDate).
glphModel add: commitA2.

commitA3 := GLHCommit new.
commitA3 short_id: 'testFromCommit3'.
commitA3 created_at: ('3 August 2021' asDate).
glphModel add: commitA3.

commitB := GLHCommit new.
commitB short_id: 'testFromCommitB'.
commitB created_at: ('4 August 2021' asDate).
glphModel add: commitB.

result := gitAnalyzer arrangeCommitsByDate: {
fromCommit.
commitA2.
commitA3.
commitB }.

self assert: result size equals: 2.
self assert: (result at: '3 August 2021') size equals: 3.
self assert: (result at: '4 August 2021') size equals: 1.
]
17 changes: 11 additions & 6 deletions src/GitLabHealth-Model-Analysis-Tests/GitAnalyzerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ GitAnalyzerTest >> setUp [
importCommitsOProject: projects first
since: since asDate
until: nil.
gitAnalyzer := GitAnalyzer new
glhImporter: glhImporter;
onModel: glphModel.

gitAnalyzer := GitAnalyzer new
glhImporter: glhImporter;
onModel: glphModel
]

{ #category : #test }
Expand Down Expand Up @@ -135,7 +135,7 @@ GitAnalyzerTest >> testAnalyseMergeResquestValidation [
{ #category : #tests }
GitAnalyzerTest >> testChurnMetric [

| myCommits res wednesdayCommit mondayCommit tuesdayCommit |
| myCommits res wednesdayCommit mondayCommit tuesdayCommit codeJs churn4CodeJs |
glhImporter withCommitDiffs: true.

"commit chain
Expand Down Expand Up @@ -174,5 +174,10 @@ GitAnalyzerTest >> testChurnMetric [
maxChildCommit: 3;
analyseChurn.

self assert: (res at: #churns) first value equals: 5 / 7
codeJs := (res at: #churns) first.
churn4CodeJs := codeJs value.

self assert: (churn4CodeJs at: #churnLoC) equals: 3 .
self assert: (churn4CodeJs at: #locContributed) equals: 7 .

]
Loading

0 comments on commit a44da4c

Please sign in to comment.