Skip to content

Commit

Permalink
[#403] print the changes per red commit in stats
Browse files Browse the repository at this point in the history
To generate a retro file template containing stats about the green and red commits
- implement the TcrEvent.AllLineChangesPerRedCommit
- Refactor some functions
- call the print method on the changes in red commit
- update the tests
  • Loading branch information
philou committed Aug 30, 2023
1 parent 5af23ce commit 75cf49c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/events/tcr_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,27 @@ func (events *TcrEvents) AllLineChangesPerCommit() IntAggregates {
// AllLineChangesPerGreenCommit returns the minimum, average, and maximum number of
// changed lines per green commit (source and test)
func (events *TcrEvents) AllLineChangesPerGreenCommit() IntAggregates {
passingEvents := eventsWithGreenStatus(events)
passingEvents := events.withStatus(StatusPass)
return passingEvents.lineChangesPerCommit(allLineChanges)
}

func allLineChanges(e DatedTcrEvent) int {
return e.Event.Changes.All()
// AllLineChangesPerRedCommit returns the minimum, average, and maximum number of
// changed lines per red commit (source and test)
func (events *TcrEvents) AllLineChangesPerRedCommit() IntAggregates {
failingEvents := events.withStatus(StatusFail)
return failingEvents.lineChangesPerCommit(allLineChanges)
}

func eventsWithGreenStatus(events *TcrEvents) TcrEvents {
func (events *TcrEvents) withStatus(status CommandStatus) TcrEvents {
return filter(*events, func(event DatedTcrEvent) bool {
return event.Event.Status == StatusPass
return event.Event.Status == status
})
}

func allLineChanges(e DatedTcrEvent) int {
return e.Event.Changes.All()
}

func filter[T any](slice []T, f func(T) bool) []T {
var n []T
for _, e := range slice {
Expand Down
13 changes: 9 additions & 4 deletions src/events/tcr_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,10 @@ func Test_events_time_between_commits(t *testing.T) {

func Test_average_size_of_green_commits(t *testing.T) {
testFlags := []struct {
desc string
events TcrEvents
expected IntAggregates
desc string
events TcrEvents
expectedGreen IntAggregates
expectedRed IntAggregates
}{
{
"1 passing event",
Expand All @@ -455,6 +456,7 @@ func Test_average_size_of_green_commits(t *testing.T) {
WithModifiedSrcLines(3),
WithModifiedTestLines(0))))},
IntAggregates{min: 3, avg: 3, max: 3},
IntAggregates{min: 0, avg: 0, max: 0},
},
{
"summing all tests and source line changes",
Expand All @@ -463,6 +465,7 @@ func Test_average_size_of_green_commits(t *testing.T) {
WithModifiedSrcLines(3),
WithModifiedTestLines(2))))},
IntAggregates{min: 5, avg: 5, max: 5},
IntAggregates{min: 0, avg: 0, max: 0},
},
{
"1 passing and 1 failing event",
Expand All @@ -476,11 +479,13 @@ func Test_average_size_of_green_commits(t *testing.T) {
WithModifiedSrcLines(5),
WithModifiedTestLines(0))))},
IntAggregates{min: 4, avg: 4, max: 4},
IntAggregates{min: 5, avg: 5, max: 5},
},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.events.AllLineChangesPerGreenCommit())
assert.Equal(t, tt.expectedGreen, tt.events.AllLineChangesPerGreenCommit())
assert.Equal(t, tt.expectedRed, tt.events.AllLineChangesPerRedCommit())
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/stats/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func Print(branch string, tcrEvents events.TcrEvents) {
printStatMinMaxAvg("Changes per commit (src)", tcrEvents.SrcLineChangesPerCommit())
printStatMinMaxAvg("Changes per commit (test)", tcrEvents.TestLineChangesPerCommit())
printStatMinMaxAvg("Changes per green commit", tcrEvents.AllLineChangesPerGreenCommit())
printStatMinMaxAvg("Changes per red commit", tcrEvents.AllLineChangesPerRedCommit())
printStatEvolution("Passing tests count", tcrEvents.PassingTestsEvolution())
printStatEvolution("Failing tests count", tcrEvents.FailingTestsEvolution())
printStatEvolution("Skipped tests count", tcrEvents.SkippedTestsEvolution())
Expand Down
1 change: 1 addition & 0 deletions src/stats/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func Test_print_all_stats(t *testing.T) {
"- Changes per commit (src): 1 (min) / 5 (avg) / 10 (max)",
"- Changes per commit (test): 0 (min) / 1.3 (avg) / 3 (max)",
"- Changes per green commit: 13 (min) / 13 (avg) / 13 (max)",
"- Changes per red commit: 1 (min) / 3 (avg) / 5 (max)",
"- Passing tests count: 2 --> 8",
"- Failing tests count: 1 --> 2",
"- Skipped tests count: 5 --> 1",
Expand Down

0 comments on commit 75cf49c

Please sign in to comment.