From 8c3985c38684b89fabc35b59b49b6b43f1edf76e Mon Sep 17 00:00:00 2001 From: Gea-Suan Lin Date: Fri, 16 Feb 2024 20:49:00 +0800 Subject: [PATCH] Use testify. --- go.mod | 7 +++++++ internal/ngram/ngram_test.go | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 3772f0f..a53b445 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/gslin/go-ir-playground go 1.21.6 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.8.4 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/internal/ngram/ngram_test.go b/internal/ngram/ngram_test.go index 5903bee..a1953cd 100644 --- a/internal/ngram/ngram_test.go +++ b/internal/ngram/ngram_test.go @@ -2,18 +2,18 @@ package ngram_test import ( "testing" + "github.com/stretchr/testify/assert" "github.com/gslin/go-ir-playground/internal/ngram" ) func TestUnigram(t *testing.T) { a := ngram.Unigram("test") - if len(a) != 1 || a[0] != "test" { - t.Error() - } + assert.Equal(t, len(a), 1) + assert.Equal(t, a[0], "test") a = ngram.Unigram("測試") - if len(a) != 2 || a[0] != "測" || a[1] != "試" { - t.Error() - } + assert.Equal(t, len(a), 2) + assert.Equal(t, a[0], "測") + assert.Equal(t, a[1], "試") }