Skip to content

Commit

Permalink
Improve performance from O(n2) to O(n) (#2)
Browse files Browse the repository at this point in the history
* First commit of new version

* Improve error handling also remove unnecessary tests

* Improve error handling also remove unnecessary tests

* Fix total number of statements

* Make ParseTotalStatements a method of CoverProfile instead of normal function

* Sum the total statements in the ParseCoverProfile function

* Uses ok instead exists to follow Go community common pratices

* Simplify code using os.ReadDir instead of filepath.Walk since there is no subdirectories

* Improves outputs

* Unexport function already called in the object instantiation (newCoverProfile)

* Rename testdata directory

* New line should be added by print

* Fix bug on output for many functions

* Generate cover profiles

* Remove useless check

* Got everything working

* Update gitignore

* Refactored

* Improve test to check stringer interface

* Delete code commented out

* Add table tests for two biggest behaviours

* Add simplecode testdata directory

* Add integration tests using testscript

* Move specific test of String() method to testscript

* Nothing else on my code uses dash

* Update the readme
  • Loading branch information
thiagonache authored Sep 30, 2022
1 parent 7ab48bb commit f2411f6
Show file tree
Hide file tree
Showing 28 changed files with 1,034 additions and 198 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

*.coverprofile
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,38 @@ go install github.com/broadwing/deltacoverage/cmd/deltacoverage@latest

```shell
$ deltacoverage
TestParseCoverageResult_ErrorsIfGivenNoTests 1.0%
TestParseCoverageResult_ReturnsCorrectValueGivenTestScriptTestCoverResult 3.2%
TestParseCoverageResult_ReturnsCorrectValueGivenNoTestScriptsTestCoverResult 0.0%
TestParseListTests_ReturnsZeroTestsIfGivenNoTests 0.0%
TestParseListTests_ReturnsCorrectValuesGivenTestListResult 0.0%
TestTestScript_ 54.2%
TestCleanup_RemovesOutputPath 0.7%
TestGenerate_CreatesExpectedCoverProfilesGivenCode 7.2%
TestGenerate_ErrorsGivenCodeWithNoTests 1.4%
TestListTests_SetsExpectedTestsNamesGivenCode 0.0%
TestNewCoverProfile_ErrorsIfPathDoesNotExist 0.7%
TestNewCoverProfile_ErrorsIfPathIsNotDirectory 0.7%
TestNewCoverProfile_SetsCorrectPackagePathGivenString 0.0%
TestNewCoverProfile_SetsNonEmptyOutputPath 0.0%
TestParse_ReturnsExpectedNumberStatementsGivenOutputPath 0.0%
TestParse_ReturnsExpectedTestsBranchesGivenOutputPath 0.0%
TestParse_ReturnsExpectedUniqueBranchesGivenOutputPath 0.0%
TestString_ReturnsExpectedDeltaCoverageGivenCoverProfile 10.1%
```

The test `TestParseCoverageResult_ErrorsIfGivenNoTests` contributes to exclusive
1.0% of the total coverage while `TestScript_` is responsible for 54.2%.
The test `TestCleanup_RemovesOutputPath` contributes to exclusive
0.7% of the total coverage while
`TestString_ReturnsExpectedDeltaCoverageGivenCoverProfile` is responsible for
10.1%.

Although the tests `TestNewCoverProfile_SetsCorrectPackagePathGivenString` and
`TestNewCoverProfile_SetsNonEmptyOutputPath` have no delta coverage or 0.0%, it is okay
since we are testing behaviours and not functions. The tests run the same code
path but test different things. Also, this design allow ease understand
of what is the test supposed to do.

## Motivation

```text
Herb Derby came up with this metric of “delta coverage”.
Herb Derby came up with this metric of “delta coverage”.
You look at your test suite and you measure what coverage each test adds uniquely that no other test provides.
If you have lots of tests with no delta coverage, so that you could just delete them and not lose your
ability to exercise parts of the system, then you should delete those tests, unless they have some some
If you have lots of tests with no delta coverage, so that you could just delete them and not lose your
ability to exercise parts of the system, then you should delete those tests, unless they have some some
communication purpose.
—Kent Beck, “Is TDD Dead?”
```
Expand All @@ -40,6 +54,6 @@ Thank you [@bitfield](https://github.com/bitfield) for the suggestion.

- POC :white_check_mark:
- Brute force implementation using `go test` commands :white_check_mark:
- Get same metrics using coverprofiles of each test instead of brute force. It's going to improve performance from O(n2) to O(n) -> WIP
- Borrow `cover.go` code and create `deltagecoverage.go`
- Get same metrics using coverprofiles of each test instead of brute force. It's going to improve performance from O(n2) to O(n):white_check_mark:
- Borrow `cover.go` code and create `deltagecoverage.go` -> Under analysis
- (Dream) Implement as Go CLI feature
Loading

0 comments on commit f2411f6

Please sign in to comment.