예제 #1
0
func TestBars(t *testing.T) {
	c := pitch.New(4, 0)
	cs := pitch.New(4, 1)
	qn := time.NewDuration(1, 4)
	hn := time.NewDuration(1, 2)
	none := Untagged

	voice := NewLine(none,
		Note{c, qn, none},
		Note{cs, hn, none},
		Rest{hn, none},
		Note{c, qn, none},
	)
	bars := Bars(time.Signature(3, 4), time.Zero(), voice)

	if len(bars) != 2 {
		t.Errorf("Expected %d bars received %d", 2, len(bars))
	}

	bar1 := Bar{1, []Event{
		Event{voice.elements[0], time.Zero()},
		Event{voice.elements[1], time.NewPosition(1, 4)},
	}}

	bar2 := Bar{2, []Event{
		Event{voice.elements[2], time.Zero()},
		Event{voice.elements[3], time.NewPosition(1, 4)},
	}}

	checkBar(bars[0], bar1, t)
	checkBar(bars[1], bar2, t)
}
예제 #2
0
func TestLine(t *testing.T) {
	r1 := Rest{qn, Untagged}
	r2 := Rest{hn, Untagged}

	a := Line{[]Element{r1, r2, r1}, Attributes{}}
	b := Line{[]Element{r1, r2, r1}, Attributes{}}
	c := Line{[]Element{a, b}, Attributes{}}

	e := c.Events(time.Zero())
	if l := len(e); l != 6 {
		t.Errorf("Expected 6 events, received %v", l)
	}

	checkRational(e[0].Position, time.Zero(), t)
	checkRational(e[1].Position, time.NewPosition(1, 4), t)
	checkRational(e[2].Position, time.NewPosition(3, 4), t)
	checkRational(e[3].Position, time.NewPosition(1, 1), t)
	checkRational(e[4].Position, time.NewPosition(5, 4), t)
	checkRational(e[5].Position, time.NewPosition(7, 4), t)
}