Skip to content

Commit

Permalink
Fix GitHub workflow (#152)
Browse files Browse the repository at this point in the history
* Switch to Codecov
* Update Go modules
* Fix linting issues
  • Loading branch information
moorara authored Apr 22, 2023
1 parent 013d6bd commit 69c659e
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 111 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: Main
on: push
name: Go
on: [push]
jobs:
# TODO: Enable once linting generics is supported
# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Lint
# uses: gardenbed/actions/go-lint@main
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lint
uses: gardenbed/actions/go-lint@main
test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -20,7 +17,7 @@ jobs:
id: test
uses: gardenbed/actions/go-cover@main
with:
codeclimate_reporter_id: ${{ secrets.CODECLIMATE_REPORTER_ID }}
codecov_token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload Test Report
uses: actions/upload-artifact@v3
with:
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[![Go Doc][godoc-image]][godoc-url]
[![Build Status][workflow-image]][workflow-url]
[![Go Report Card][goreport-image]][goreport-url]
[![Test Coverage][coverage-image]][coverage-url]
[![Maintainability][maintainability-image]][maintainability-url]
[![Test Coverage][codecov-image]][codecov-url]

# algo

Expand Down Expand Up @@ -67,7 +66,5 @@ A collection of common data structures and algorithms for Go applications.
[workflow-image]: https://github.com/moorara/algo/workflows/Main/badge.svg
[goreport-url]: https://goreportcard.com/report/github.com/moorara/algo
[goreport-image]: https://goreportcard.com/badge/github.com/moorara/algo
[coverage-url]: https://codeclimate.com/github/moorara/algo/test_coverage
[coverage-image]: https://api.codeclimate.com/v1/badges/48efddf545789eee4132/test_coverage
[maintainability-url]: https://codeclimate.com/github/moorara/algo/maintainability
[maintainability-image]: https://api.codeclimate.com/v1/badges/48efddf545789eee4132/maintainability
[codecov-url]: https://codecov.io/gh/moorara/algo
[codecov-image]: https://codecov.io/gh/moorara/algo/branch/main/graph/badge.svg
11 changes: 3 additions & 8 deletions automata/dfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ func (d *DFA) States() States {
states := States{}

states = append(states, d.Start)
for _, s := range d.Final {
states = append(states, s)
}
states = append(states, d.Final...)

for _, kv := range d.trans.KeyValues() {
if s := kv.Key; !states.Contains(s) {
Expand Down Expand Up @@ -295,9 +293,7 @@ func (d *DFA) WithoutDeadStates() *DFA {

// 2. Add a new state with edges to all other veritcies representing the final states of the DFA.
u := State(-1)
for _, f := range d.Final {
adj[u] = append(adj[u], f)
}
adj[u] = append(adj[u], d.Final...)

// 3. Finally, we find all states reachable from this new state using a depth-first search (DFS).
// All other states not connected to this new state will be identified as dead states.
Expand Down Expand Up @@ -375,8 +371,7 @@ func (d *DFA) Graphviz() string {

// Group all the transitions with the same states and combine their symbols into one label

var edges doubleKeyMap[State, State, []string]
edges = symboltable.NewRedBlack[State, symboltable.OrderedSymbolTable[State, []string]](cmpState, nil)
edges := symboltable.NewRedBlack[State, symboltable.OrderedSymbolTable[State, []string]](cmpState, nil)

for _, kv := range d.trans.KeyValues() {
from := kv.Key
Expand Down
7 changes: 2 additions & 5 deletions automata/nfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ func (n *NFA) States() States {
states := States{}

states = append(states, n.Start)
for _, s := range n.Final {
states = append(states, s)
}
states = append(states, n.Final...)

for _, kv := range n.trans.KeyValues() {
if s := kv.Key; !states.Contains(s) {
Expand Down Expand Up @@ -347,8 +345,7 @@ func (n *NFA) Graphviz() string {

// Group all the transitions with the same states and combine their symbols into one label

var edges doubleKeyMap[State, State, []string]
edges = symboltable.NewRedBlack[State, symboltable.OrderedSymbolTable[State, []string]](cmpState, nil)
edges := symboltable.NewRedBlack[State, symboltable.OrderedSymbolTable[State, []string]](cmpState, nil)

for _, kv := range n.trans.KeyValues() {
from := kv.Key
Expand Down
42 changes: 42 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# https://docs.codecov.com/docs/codecov-yaml
# https://docs.codecov.com/docs/codecovyml-reference
# https://docs.codecov.com/docs/coverage-configuration

codecov:
# Whether or not to wait for all other statuses to pass
# See https://docs.codecov.com/docs/codecovyml-reference#codecovrequire_ci_to_pass
require_ci_to_pass: no

# See https://docs.codecov.com/docs/codecovyml-reference#coverage
# See https://docs.codecov.com/docs/coverage-configuration
coverage:
precision: 2
round: down
range: '75...95'

# See https://docs.codecov.com/docs/codecovyml-reference#coveragestatus
# See https://docs.codecov.com/docs/commit-status
status:

# See https://docs.codecov.com/docs/commit-status#changes-status
# See https://docs.codecov.com/docs/unexpected-coverage-changes
changes: yes

# Total coverage
# See https://docs.codecov.com/docs/commit-status#project-status
project:
default:
# The minimum coverage ratio for success
# See https://docs.codecov.com/docs/commit-status#target
target: 90%

# Coverage for lines adjusted in the pull request or single commit
# See https://docs.codecov.com/docs/commit-status#patch-status
patch:
default:
# The minimum coverage ratio for success
target: 90%

# See https://docs.codecov.com/docs/codecovyml-reference#comment
# See https://docs.codecov.com/docs/pull-request-comments
comment: false
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/moorara/algo

go 1.19
go 1.20

require (
github.com/stretchr/testify v1.8.1
golang.org/x/exp v0.0.0-20230130200758-8bd7c9d05862
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/exp v0.0.0-20230130200758-8bd7c9d05862 h1:z+o+cpYvJXi/DDN1avT8Ty6ebcTFA8XU8b0AVrE3coE=
golang.org/x/exp v0.0.0-20230130200758-8bd7c9d05862/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb h1:rhjz/8Mbfa8xROFiH+MQphmAmgqRM0bOMnytznhWEXk=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
20 changes: 13 additions & 7 deletions heap/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ const (
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

var r *rand.Rand

func randIntSlice(size int) []int {
vals := make([]int, size)
for i := 0; i < len(vals); i++ {
vals[i] = rand.Int()
vals[i] = r.Int()
}

return vals
}

func randStringKey(minLen, maxLen int) string {
n := len(chars)
l := minLen + rand.Intn(maxLen-minLen+1)
l := minLen + r.Intn(maxLen-minLen+1)
b := make([]byte, l)

for i := range b {
b[i] = chars[rand.Intn(n)]
b[i] = chars[r.Intn(n)]
}

return string(b)
Expand Down Expand Up @@ -97,7 +99,8 @@ func runIndexedHeapDelete(b *testing.B, heap IndexedHeap[int, string]) {
}

func BenchmarkHeap_Insert(b *testing.B) {
rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r = rand.New(rand.NewSource(seed))

const size = 1024
eqVal := generic.NewEqualFunc[string]()
Expand All @@ -116,7 +119,8 @@ func BenchmarkHeap_Insert(b *testing.B) {
}

func BenchmarkHeap_Delete(b *testing.B) {
rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r = rand.New(rand.NewSource(seed))

const size = 1024
eqVal := generic.NewEqualFunc[string]()
Expand All @@ -135,7 +139,8 @@ func BenchmarkHeap_Delete(b *testing.B) {
}

func BenchmarkIndexedHeap_Insert(b *testing.B) {
rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r = rand.New(rand.NewSource(seed))

eqVal := generic.NewEqualFunc[string]()
cmpMin := generic.NewCompareFunc[int]()
Expand All @@ -153,7 +158,8 @@ func BenchmarkIndexedHeap_Insert(b *testing.B) {
}

func BenchmarkIndexedHeap_Delete(b *testing.B) {
rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r = rand.New(rand.NewSource(seed))

eqVal := generic.NewEqualFunc[string]()
cmpMin := generic.NewCompareFunc[int]()
Expand Down
2 changes: 1 addition & 1 deletion internal/graphviz/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (e *Edge) DotCode() string {
first = addListAttr(buf, first, "color", string(e.Color))
first = addListAttr(buf, first, "style", string(e.Style))
first = addListAttr(buf, first, "arrowhead", string(e.ArrowHead))
first = addListAttr(buf, first, "arrowtail", string(e.ArrowTail))
_ = addListAttr(buf, first, "arrowtail", string(e.ArrowTail))
buf.WriteString("];")

return buf.String()
Expand Down
4 changes: 2 additions & 2 deletions internal/graphviz/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ func (g *Graph) DotCode() string {
buf.WriteString("{\n")

first = addAttr(buf, first, 2, "rankdir", string(g.RankDir))
first = addAttr(buf, first, 2, "concentrate", fmt.Sprintf("%t", g.Concentrate))
_ = addAttr(buf, first, 2, "concentrate", fmt.Sprintf("%t", g.Concentrate))

first = true
addIndent(buf, 2)
buf.WriteString("node [")
first = addListAttr(buf, first, "color", string(g.NodeColor))
first = addListAttr(buf, first, "style", string(g.NodeStyle))
first = addListAttr(buf, first, "shape", string(g.NodeShape))
_ = addListAttr(buf, first, "shape", string(g.NodeShape))
buf.WriteString("];\n")
first = false

Expand Down
2 changes: 1 addition & 1 deletion internal/graphviz/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (n *Node) DotCode() string {
first = addListAttr(buf, first, "style", string(n.Style))
first = addListAttr(buf, first, "shape", string(n.Shape))
first = addListAttr(buf, first, "fontcolor", string(n.FontColor))
first = addListAttr(buf, first, "fontname", `"`+n.FontName+`"`)
_ = addListAttr(buf, first, "fontname", `"`+n.FontName+`"`)
buf.WriteString("];")

return buf.String()
Expand Down
6 changes: 3 additions & 3 deletions internal/graphviz/subgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ func (s *Subgraph) DotCode(indent int) string {
first = addAttr(buf, first, indent+2, "color", string(s.Color))
first = addAttr(buf, first, indent+2, "style", string(s.Style))
first = addAttr(buf, first, indent+2, "rank", string(s.Rank))
first = addAttr(buf, first, indent+2, "rankdir", string(s.RankDir))
_ = addAttr(buf, first, indent+2, "rankdir", string(s.RankDir))

first = true
addIndent(buf, indent+2)
buf.WriteString("node [")
first = addListAttr(buf, first, "color", string(s.NodeColor))
first = addListAttr(buf, first, "style", string(s.NodeStyle))
first = addListAttr(buf, first, "shape", string(s.NodeShape))
_ = addListAttr(buf, first, "shape", string(s.NodeShape))
buf.WriteString("];\n")
first = false

first = addSubgraphs(buf, first, indent+2, s.Subgraphs)
first = addNodes(buf, first, indent+2, s.Nodes)
first = addEdges(buf, first, indent+2, s.Edges)
_ = addEdges(buf, first, indent+2, s.Edges)

addIndent(buf, indent)
buf.WriteString("}")
Expand Down
7 changes: 4 additions & 3 deletions list/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,23 @@ func TestQueue(t *testing.T) {
func BenchmarkQueue(b *testing.B) {
const nodeSize = 1024

rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r := rand.New(rand.NewSource(seed))

b.Run("Enqueue", func(b *testing.B) {
queue := NewQueue[int](nodeSize, nil)

b.ResetTimer()

for n := 0; n < b.N; n++ {
queue.Enqueue(rand.Int())
queue.Enqueue(r.Int())
}
})

b.Run("Dequeue", func(b *testing.B) {
queue := NewQueue[int](nodeSize, nil)
for n := 0; n < b.N; n++ {
queue.Enqueue(rand.Int())
queue.Enqueue(r.Int())
}

b.ResetTimer()
Expand Down
4 changes: 1 addition & 3 deletions list/soft_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ func (q *softQueue[T]) Contains(val T) int {
// Values returns the list of all values in the queue including the deleted ones.
func (q *softQueue[T]) Values() []T {
vals := make([]T, len(q.list))
for i, v := range q.list {
vals[i] = v
}
copy(vals, q.list)

return vals
}
10 changes: 5 additions & 5 deletions list/soft_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestSoftQueue(t *testing.T) {

val, i := squeue.Dequeue()
assert.Empty(t, val)
assert.Equal(t, -1, i)

val, i = squeue.Peek()
assert.Empty(t, val)
Expand Down Expand Up @@ -164,24 +165,23 @@ func TestSoftQueue(t *testing.T) {
}

func BenchmarkSoftQueue(b *testing.B) {
const nodeSize = 1024

rand.Seed(time.Now().UTC().UnixNano())
seed := time.Now().UTC().UnixNano()
r := rand.New(rand.NewSource(seed))

b.Run("Enqueue", func(b *testing.B) {
squeue := NewSoftQueue[int](nil)

b.ResetTimer()

for n := 0; n < b.N; n++ {
squeue.Enqueue(rand.Int())
squeue.Enqueue(r.Int())
}
})

b.Run("Dequeue", func(b *testing.B) {
squeue := NewSoftQueue[int](nil)
for n := 0; n < b.N; n++ {
squeue.Enqueue(rand.Int())
squeue.Enqueue(r.Int())
}

b.ResetTimer()
Expand Down
Loading

0 comments on commit 69c659e

Please sign in to comment.