Created
March 8, 2015 06:47
-
-
Save emidoots/c32c51df1a9927a65f52 to your computer and use it in GitHub Desktop.
decoder_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package drum | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"path" | |
"testing" | |
) | |
func TestDecodeFile(t *testing.T) { | |
tData := []struct { | |
path string | |
output string | |
}{ | |
{"pattern_1.splice", | |
`Saved with HW Version: 0.808-alpha | |
Tempo: 120 | |
(0) kick |x---|x---|x---|x---| | |
(1) snare |----|x---|----|x---| | |
(2) clap |----|x-x-|----|----| | |
(3) hh-open |--x-|--x-|x-x-|--x-| | |
(4) hh-close |x---|x---|----|x--x| | |
(5) cowbell |----|----|--x-|----| | |
`, | |
}, | |
{"pattern_2.splice", | |
`Saved with HW Version: 0.808-alpha | |
Tempo: 98.4 | |
(0) kick |x---|----|x---|----| | |
(1) snare |----|x---|----|x---| | |
(3) hh-open |--x-|--x-|x-x-|--x-| | |
(5) cowbell |----|----|x---|----| | |
`, | |
}, | |
{"pattern_3.splice", | |
`Saved with HW Version: 0.808-alpha | |
Tempo: 118 | |
(40) kick |x---|----|x---|----| | |
(1) clap |----|x---|----|x---| | |
(3) hh-open |--x-|--x-|x-x-|--x-| | |
(5) low-tom |----|---x|----|----| | |
(12) mid-tom |----|----|x---|----| | |
(9) hi-tom |----|----|-x--|----| | |
`, | |
}, | |
{"pattern_4.splice", | |
`Saved with HW Version: 0.909 | |
Tempo: 240 | |
(0) SubKick |----|----|----|----| | |
(1) Kick |x---|----|x---|----| | |
(99) Maracas |x-x-|x-x-|x-x-|x-x-| | |
(255) Low Conga |----|x---|----|x---| | |
`, | |
}, | |
{"pattern_5.splice", | |
`Saved with HW Version: 0.708-alpha | |
Tempo: 999 | |
(1) Kick |x---|----|x---|----| | |
(2) HiHat |x-x-|x-x-|x-x-|x-x-| | |
`, | |
}, | |
} | |
for _, exp := range tData { | |
decoded, err := DecodeFile(path.Join("fixtures", exp.path)) | |
if err != nil { | |
t.Fatalf("something went wrong decoding %s - %v", exp.path, err) | |
} | |
if fmt.Sprint(decoded) != exp.output { | |
t.Logf("decoded:\n%#v\n", fmt.Sprint(decoded)) | |
t.Logf("expected:\n%#v\n", exp.output) | |
t.Fatalf("%s wasn't decoded as expect.\nGot:\n%s\nExpected:\n%s", | |
exp.path, decoded, exp.output) | |
} | |
} | |
} | |
func BenchmarkDecode(b *testing.B) { | |
// Read the entire file into memory so that we don't benchmark the | |
// disk IO speed. | |
data, err := ioutil.ReadFile("fixtures/pattern_1.splice") | |
if err != nil { | |
b.Fatal(err) | |
} | |
for n := 0; n < b.N; n++ { | |
_, err = decode(bytes.NewReader(data)) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} | |
} | |
func BenchmarkPatternString(b *testing.B) { | |
p, err := DecodeFile("fixtures/pattern_1.splice") | |
if err != nil { | |
b.Fatal(err) | |
} | |
for n := 0; n < b.N; n++ { | |
p.String() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment