Exemple #1
0
func TestSynthesize(t *testing.T) {
	truth := `{"Obs":[[{"senior_staff":1}]],"Periods":[5]}
`
	pkg := "github.com/wangkuiyi/hmm/synthesize"
	model := "-model=" + path.Join(buildnrun.Pkg(pkg), "testdata/ground_truth_model.json")
	if out, err, e := buildnrun.Run(pkg, "-instances=1", "-cardi=1", "-length=5", "-seed=0", model); e != nil {
		t.Errorf("Failed build and run %s: %v\nOutput:\n%s", pkg, e, err)
	} else if string(out) != truth {
		t.Errorf("Expecting %s\ngot %s", truth, out)
	}
}
Exemple #2
0
func TestTrain(t *testing.T) {
	trainer := "github.com/wangkuiyi/hmm/trainer"
	corpus := buildnrun.Pkg(path.Join(trainer, "testdata/corpus.json"))
	truth := `{
  "S1": [
    0,
    2
  ],
  "S1Sum": 2,
  "Σγ": [
    4,
    6
  ],
  "Σξ": [
    [
      0,
      4
    ],
    [
      6,
      0
    ]
  ],
  "Σγo": [
    [
      {
        "Hist": {
          "orange": 6
        },
        "Sum": 6
      }
    ],
    [
      {
        "Hist": {
          "apple": 6
        },
        "Sum": 6
      }
    ]
  ]
}`
	if out, err, e := buildnrun.Run(trainer, "-corpus="+corpus, "-logl=/dev/null"); e != nil {
		t.Fatalf("Failed build and run trainer: %v, %s", e, err)
	} else if out != truth {
		t.Errorf("Expecting %s, got %s", truth, out)
	}
}