github.com/KEINOS/go-countline@v1.1.0/cl/_alt/README.md (about)

     1  # Alternate implementations of the CountLines function
     2  
     3  This directory contains alternate implementations of the CountLines function.
     4  
     5  New implementations must be placed in this directory first and Pull-Requested.
     6  After benchmarking on code-review, they may be swapped into the main function.
     7  
     8  ## Files to change
     9  
    10  You need to create and edit the following 3 files:
    11  
    12  1. Create a new file for your new implementation.
    13  2. Add your function to the `TestCountLines_specs` function in [`alt_test.go`](./alt_test.go).
    14  3. Add your function to the `targetFuncions` variable in [`../benchmarks_test.go`](../benchmarks_test.go).
    15  
    16  ### Create a file
    17  
    18  - File name: `altN.go` where `N` is the next available number. e.g. `alt4.go`
    19  
    20  ```go
    21  // Replace the `N` in `CountLinesAltN` with the latest number of
    22  // implementations. e.g. `CountLinesAlt4`
    23  func CountLinesAltN(r io.Reader) (int, error) {
    24      // Your implementation here
    25  }
    26  ```
    27  
    28  ### Add the function to the test list
    29  
    30  - File name: `alt_test.go`
    31  
    32  ```diff
    33  func TestCountLines_specs(t *testing.T) {
    34      for _, targetFunc := range []struct {
    35          name string
    36          fn   func(io.Reader) (int, error)
    37      }{
    38          // Add the alternate implementations here.
    39          {"CountLinesAlt1", CountLinesAlt1},
    40          {"CountLinesAlt2", CountLinesAlt2},
    41          {"CountLinesAlt3", CountLinesAlt3},
    42  +       {"CountLinesAlt4", CountLinesAlt4},
    43      } {
    44          t.Run(targetFunc.name, func(t *testing.T) {
    45              spec.RunSpecTest(t, targetFunc.name, targetFunc.fn)
    46          })
    47      }
    48  }
    49  ```
    50  
    51  ### Add the function to the benchmark list
    52  
    53  - File name: `../benchmarks_test.go`
    54  
    55  ```diff
    56  var targetFuncions = map[string]struct {
    57      fn func(io.Reader) (int, error)
    58  }{
    59      // Current implementation
    60      "CountLinesCurr": {CountLines},
    61      // Alternate implementation. See alt_test.go.
    62      "CountLinesAlt1": {_alt.CountLinesAlt1},
    63      "CountLinesAlt2": {_alt.CountLinesAlt2},
    64      "CountLinesAlt3": {_alt.CountLinesAlt3},
    65  +   "CountLinesAlt4": {_alt.CountLinesAlt4},
    66  }
    67  
    68  ```
    69  
    70  ## Regulations
    71  
    72  You need the following to be covered in your implementation:
    73  
    74  - **Pass the tests** in all cases of [`cl/spec/spec.go`](../spec/spec.go).
    75  - **Pass the lint and static analysis checks** of [golangci-lint](https://golangci-lint.run/).
    76    - Run: `golangci-lint run`
    77    - For the rules, see: [../../.golangci.yml](../../.golangci.yml)
    78  - **Keep the code coverage** up to 100%.
    79  
    80  Use the [`make` command](https://en.wikipedia.org/wiki/Make_(software)) for convenience.
    81  
    82  ```shellsession
    83  $ # Runs unit tests, lints, and cove coverage.
    84  $ make test
    85  ...
    86  
    87  $ make benchmark
    88  ...
    89  ```