Skip to content

Commit

Permalink
tests separated, README grouming, go version up (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0rg authored Aug 4, 2023
1 parent 1c9027e commit bf53c78
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: setup golang
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ^1.19
go-version: ^1.20
check-latest: true
cache: true
- name: golangci-lint
Expand All @@ -33,13 +33,13 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: setup golang
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ^1.19
go-version: ^1.20
check-latest: true
cache: true
- name: test-coverage
uses: paambaati/codeclimate-action@v3.0.0
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
Expand All @@ -55,9 +55,9 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: setup golang
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ^1.19
go-version: ^1.20
check-latest: true
cache: true
- name: init codeql
Expand All @@ -66,3 +66,5 @@ jobs:
language: 'go'
- name: run analysis
uses: github/codeql-action/analyze@v2
- name: update goreportcard
uses: creekorful/goreportcard-action@v1.0
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ linters:
enable-all: true
disable:
- nonamedreturns
- testpackage
- structcheck
- varnamelen
- depguard
- ireturn
fast: false

Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/s0rg/trie)](https://pkg.go.dev/github.com/s0rg/trie)
[![License](https://img.shields.io/github/license/s0rg/trie)](https://github.com/s0rg/trie/blob/main/LICENSE)
[![Build](https://github.com/s0rg/trie/workflows/ci/badge.svg)](https://github.com/s0rg/trie/actions?query=workflow%3Aci)
[![Go Version](https://img.shields.io/github/go-mod/go-version/s0rg/trie)](go.mod)
[![Tag](https://img.shields.io/github/v/tag/s0rg/trie?sort=semver)](https://github.com/s0rg/trie/tags)

[![CI](https://github.com/s0rg/trie/workflows/ci/badge.svg)](https://github.com/s0rg/trie/actions?query=workflow%3Aci)
[![Go Report Card](https://goreportcard.com/badge/github.com/s0rg/trie)](https://goreportcard.com/report/github.com/s0rg/trie)
[![Maintainability](https://api.codeclimate.com/v1/badges/b476ce7fd7bbaa30e5a6/maintainability)](https://codeclimate.com/github/s0rg/trie/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/b476ce7fd7bbaa30e5a6/test_coverage)](https://codeclimate.com/github/s0rg/trie/test_coverage)

[![PkgGoDev](https://pkg.go.dev/badge/github.com/s0rg/trie)](https://pkg.go.dev/github.com/s0rg/trie)
[![Go Version](https://img.shields.io/github/go-mod/go-version/s0rg/trie)](go.mod)
[![Tag](https://img.shields.io/github/v/tag/s0rg/trie?sort=semver)](https://github.com/s0rg/trie/tags)


# trie

Generic prefix tree for golang

# example
Expand All @@ -22,16 +23,18 @@ Generic prefix tree for golang
"github.com/s0rg/trie"
)

t := trie.New[int]()
func main() {
t := trie.New[int]()

t.Add("bar", 1)
t.Add("baz", 2)
t.Add("bat", 3)
t.Add("bar", 1)
t.Add("baz", 2)
t.Add("bat", 3)

val, ok := t.Find("bar")
if !ok {
log.Fatal("not found")
}
val, ok := t.Find("bar")
if !ok {
log.Fatal("not found")
}

fmt.Println(val) // will print 1
fmt.Println(val) // will print 1
}
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/s0rg/trie

go 1.19
go 1.20
14 changes: 8 additions & 6 deletions trie_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package trie
package trie_test

import (
"strings"
"testing"

"github.com/s0rg/trie"
)

func TestTrieFind(t *testing.T) {
t.Parallel()

tr := New[int]()
tr := trie.New[int]()

type testCase struct {
Path string
Expand Down Expand Up @@ -54,7 +56,7 @@ func TestTrieFind(t *testing.T) {
func TestTrieDel(t *testing.T) {
t.Parallel()

tr := New[int]()
tr := trie.New[int]()

const (
kbar = "bar"
Expand Down Expand Up @@ -110,7 +112,7 @@ func TestTrieDel(t *testing.T) {
func TestTrieString(t *testing.T) {
t.Parallel()

tr := New[int]()
tr := trie.New[int]()

tr.Add("cup", 1)
tr.Add("cub", 2)
Expand All @@ -129,7 +131,7 @@ func TestTrieString(t *testing.T) {
func TestTrieSuggest(t *testing.T) {
t.Parallel()

tr := New[int]()
tr := trie.New[int]()

tr.Add("arc", 1)
tr.Add("bak", 2)
Expand Down Expand Up @@ -183,7 +185,7 @@ func FuzzTrie(f *testing.F) {

f.Fuzz(func(t *testing.T, input string) {
input = strings.ToValidUTF8(input, "")
tr := New[string]()
tr := trie.New[string]()
m := make(map[string]string)

for _, p := range strings.Split(input, ",") {
Expand Down

0 comments on commit bf53c78

Please sign in to comment.