Skip to main content
Glama
emicklei

melrōse musical expression player

by emicklei
probability_test.go1.48 kB
package op import ( "math/rand" "testing" "github.com/emicklei/melrose/core" ) func TestProbability_hit(t *testing.T) { p := Probability{chance: core.On(0.8), seed: rand.New(rand.NewSource(0))} trues := 0 for i := 0; i < 100; i++ { if p.hit() { trues++ } } t.Log(trues, "out of 100") p.chance = core.On(80) t.Log(p.hit()) } func TestNewProbability(t *testing.T) { p := NewProbability(core.On(0.5), core.On(core.N("c"))) if p == nil { t.Fatal("should not be nil") } } func TestProbability_ToNote_Error(t *testing.T) { p := NewProbability(core.On(0.5), core.On(core.On(1))) _, err := p.ToNote() if err == nil { t.Fatal("error expected") } p = NewProbability(core.On(0.5), core.On(failingNoteConvertable{})) _, err = p.ToNote() if err == nil { t.Fatal("error expected") } } func TestProbability_hit_halfrest(t *testing.T) { p := Probability{chance: core.On(0.0), seed: rand.New(rand.NewSource(0)), target: core.On(core.N("2c"))} n, err := p.ToNote() if err != nil { t.Fatal(err) } if got, want := n.DurationFactor(), float32(0.5); got != want { t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want) } } func TestProbability_hit_quarterrest(t *testing.T) { p := Probability{chance: core.On(0.0), seed: rand.New(rand.NewSource(0)), target: core.On(core.MustParseSequence("(C e f)"))} s := p.S() if got, want := s.Storex(), "sequence('(= = =)')"; got != want { t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/emicklei/melrose'

If you have feedback or need assistance with the MCP directory API, please join our Discord server