Skip to content

Commit

Permalink
autoeq unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
indiependente committed Nov 1, 2020
1 parent 32a704b commit 068a4df
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin/
*.json
coverage.out
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.PHONY: build
build:
CGO_ENABLED=0 go build -o ./bin/autoEqMac

.PHONY: coverage
coverage:
gopherbadger -md="README.md" -png=false

.PHONY: lint
lint:
golangci-lint run
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/indiependente/autoEqMac)](https://goreportcard.com/report/github.com/indiependente/autoEqMac)

<a href='https://github.com/jpoles1/gopherbadger' target='_blank'>![gopherbadger-tag-do-not-edit](https://img.shields.io/badge/Go%20Coverage-72%25-brightgreen.svg?longCache=true&style=flat)</a>
# autoEqMac
An interactive CLI that retrieves headphones EQ data from the [AutoEq Project](https://github.com/jaakkopasanen/AutoEq) and produces a JSON preset ready to be imported into [EqMac](https://github.com/bitgapp/eqMac/).

Expand Down
3 changes: 3 additions & 0 deletions autoeq/fixed_band.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func ToFixedBandEQs(data []byte) (FixedBandEQs, error) {
var eqs FixedBandEQs
rows := strings.Split(string(data), "\n")
for _, row := range rows {
if row == "" {
continue
}
eqFields := strings.Fields(row)
freq, err := strconv.Atoi(eqFields[5])
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions autoeq/fixed_band_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package autoeq

import (
"testing"

"github.com/stretchr/testify/require"
)

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

tests := []struct {
name string
data []byte
want FixedBandEQs
wantErr bool
}{
{
name: "Happy path",
data: []byte("Filter 1: ON PK Fc 31 Hz Gain 5.8 dB Q 1.41\n"),
want: FixedBandEQs{{Frequency: 31, Gain: 5.8, Q: 1.41}},
wantErr: false,
},
{
name: "Sad path - Freq not int",
data: []byte("Filter 1: ON PK Fc AB Hz Gain 5.8 dB Q 1.41"),
want: nil,
wantErr: true,
},
{
name: "Sad path - Gain not float",
data: []byte("Filter 1: ON PK Fc 31 Hz Gain AB dB Q 1.41"),
want: nil,
wantErr: true,
},
{
name: "Sad path - Q not float",
data: []byte("Filter 1: ON PK Fc 31 Hz Gain 5.8 dB Q AB"),
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := ToFixedBandEQs(tt.data)
require.Equal(t, tt.wantErr, err != nil)
require.Equal(t, tt.want, got)
})
}
}
75 changes: 75 additions & 0 deletions autoeq/mdparser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package autoeq

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
)

const (
autoEQResults = `https://raw.githubusercontent.com/jaakkopasanen/AutoEq/master/results`
fixedBandSuffix = `%20FixedBandEQ.txt`
)

func TestMetadataParser_ParseMetadata(t *testing.T) {
t.Parallel()
type fields struct {
LinkPrefix string
FixedBandEQSuffix string
}
type args struct {
data []byte
}
var tests = []struct {
name string
fields fields
args args
want []EQMetadata
wantErr bool
}{
{
name: "Happy path",
fields: fields{
LinkPrefix: autoEQResults,
FixedBandEQSuffix: fixedBandSuffix,
},
args: args{
data: mustReadFixture(t, "testdata/autoeq_index_top.txt"),
},
want: []EQMetadata{
{
ID: "0",
Name: "1Custom SA02",
Author: "Crinacle",
Link: autoEQResults + "/crinacle/harman_in-ear_2019v2/1Custom%20SA02/1Custom%20SA02" + fixedBandSuffix,
Global: 0,
},
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
p := MetadataParser{
LinkPrefix: tt.fields.LinkPrefix,
FixedBandEQSuffix: tt.fields.FixedBandEQSuffix,
}
got, err := p.ParseMetadata(tt.args.data)
require.Equal(t, tt.wantErr, err != nil)
require.Equal(t, tt.want, got)
})
}
}

func mustReadFixture(t *testing.T, filename string) []byte {
data, err := ioutil.ReadFile(filename)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%q\n", err)
t.Fail()
}
return data
}
5 changes: 5 additions & 0 deletions autoeq/testdata/autoeq_index_top.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Index
This is a list of all equalization profiles. Target is in parentheses if there are results with multiple targets
from the same source.

- [1Custom SA02](./crinacle/harman_in-ear_2019v2/1Custom%20SA02) by Crinacle
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzf
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down

0 comments on commit 068a4df

Please sign in to comment.