sointu/compiler/encoded_song_test.go
vsariola 30379c981d feat: remove hold from song
assume songs code it as 1 always; implementations are free to change this during compilation, but this should be a compile time flag / optimization; not a concern of song.
2021-01-05 15:50:27 +02:00

79 lines
2.3 KiB
Go

package compiler_test
import (
"reflect"
"testing"
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/compiler"
)
func TestPatternReusing(t *testing.T) {
song := sointu.Song{
Tracks: []sointu.Track{{
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {72, 0, 0, 0, 0, 0, 0, 0}},
Sequence: []byte{0, 1},
}, {
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {84, 0, 0, 0, 0, 0, 0, 0}},
Sequence: []byte{0, 1},
}},
}
encodedSong, err := compiler.EncodeSong(&song)
if err != nil {
t.Fatalf("song encoding error: %v", err)
}
expected := compiler.EncodedSong{
Sequences: [][]byte{{0, 1}, {0, 2}},
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {72, 0, 0, 0, 0, 0, 0, 0}, {84, 0, 0, 0, 0, 0, 0, 0}},
}
if !reflect.DeepEqual(*encodedSong, expected) {
t.Fatalf("got different EncodedSong than expected. got: %v expected: %v", *encodedSong, expected)
}
}
func TestUnnecessaryHolds(t *testing.T) {
song := sointu.Song{
Tracks: []sointu.Track{{
Patterns: [][]byte{{64, 1, 1, 1, 0, 1, 0, 0}, {72, 0, 1, 0, 1, 0, 0, 0}},
Sequence: []byte{0, 1},
}, {
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 1, 0}, {84, 0, 0, 0, 1, 1, 0, 0}},
Sequence: []byte{0, 1},
}},
}
encodedSong, err := compiler.EncodeSong(&song)
if err != nil {
t.Fatalf("song encoding error: %v", err)
}
expected := compiler.EncodedSong{
Sequences: [][]byte{{0, 1}, {0, 2}},
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {72, 0, 0, 0, 0, 0, 0, 0}, {84, 0, 0, 0, 0, 0, 0, 0}},
}
if !reflect.DeepEqual(*encodedSong, expected) {
t.Fatalf("got different EncodedSong than expected. got: %v expected: %v", *encodedSong, expected)
}
}
func TestDontCares(t *testing.T) {
song := sointu.Song{
Tracks: []sointu.Track{{
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}},
Sequence: []byte{0, 1},
}, {
Patterns: [][]byte{{64, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0}},
Sequence: []byte{0, 1},
}},
}
encodedSong, err := compiler.EncodeSong(&song)
if err != nil {
t.Fatalf("song encoding error: %v", err)
}
expected := compiler.EncodedSong{
Sequences: [][]byte{{0, 1}, {2, 1}},
Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 0, 0, 0}, {64, 1, 1, 1, 1, 1, 1, 1}},
}
if !reflect.DeepEqual(*encodedSong, expected) {
t.Fatalf("got different EncodedSong than expected. got: %v expected: %v", *encodedSong, expected)
}
}