func assertClassificationResult(t *testing.T, c *Classifier, input string, expected string) {
	result := c.Process(input)

	actual := diff.TrimLinesInString(result.Description())
	expected = diff.TrimLinesInString(expected)

	if actual != expected {
		t.Errorf("Classification result mismatch for %#v.", strings.TrimSpace(input))
		t.Logf("Diff:\n%v", diff.LineDiff(expected, actual))
		// t.Logf("actual %#v != expected %#v", actual, expected)
		t.Log("------------------------------")
		t.Logf("Actual:\n%v", actual)
		t.Log("------------------------------")
		t.Logf("Expected:\n%v", expected)
	}
}
Esempio n. 2
0
func assertParseResult(t *testing.T, definition string, expected string) {
	classifier := NewFuzzyClassifier()
	err := classifier.Add(definition)
	if err != nil {
		t.Fatalf("Classifier returned a parse error: %v", err.Error())
	}

	actual := diff.TrimLinesInString(classifier.Description())
	expected = diff.TrimLinesInString(expected)

	if actual != expected {
		t.Errorf("Parse result mismatch.")
		t.Logf("Diff:\n%v", diff.LineDiff(expected, actual))
		// t.Logf("actual %#v != expected %#v", actual, expected)
		t.FailNow()
	}
}
func assertSplitResult(t *testing.T, input string, expected string) {
	words := SplitIntoWords(input)

	list := make([]string, 0, len(words))
	for _, word := range words {
		list = append(list, word.Raw)
	}

	actual := diff.TrimLinesInString(strings.Join(list, "\n"))
	expected = diff.TrimLinesInString(expected)

	if actual != expected {
		t.Errorf("SplitIntoWords mismatch for %#v.", strings.TrimSpace(input))
		t.Logf("Diff:\n%v", diff.LineDiff(expected, actual))
		// t.Logf("actual %#v != expected %#v", actual, expected)
		t.Log("------------------------------")
		t.Logf("Actual:\n%v", actual)
		t.Log("------------------------------")
		t.Logf("Expected:\n%v", expected)
	}
}