Permalink
Browse files

Change test package

  • Loading branch information...
1 parent 316df45 commit 071f830af7f77ac68d226fe0e1e0456813d6c9eb @daviddengcn committed Jul 2, 2015
Showing with 56 additions and 97 deletions.
  1. +13 −13 crawler_test.go
  2. +13 −12 data_test.go
  3. +5 −4 db_test.go
  4. +14 −12 index_test.go
  5. +5 −9 ranking_test.go
  6. +6 −47 text_test.go
View
@@ -7,8 +7,9 @@ import (
"testing"
"time"
+ "github.com/golangplus/testing/assert"
+
"github.com/daviddengcn/gddo/doc"
- "github.com/daviddengcn/go-assert"
"github.com/daviddengcn/go-villa"
)
@@ -22,7 +23,7 @@ func TestGithubUpdates(t *testing.T) {
func TestReadmeToText(t *testing.T) {
text := strings.TrimSpace(ReadmeToText("a.md", "#abc"))
- assert.Equals(t, "text", text, "abc")
+ assert.Equal(t, "text", text, "abc")
}
func TestReadmeToText_Panic(t *testing.T) {
@@ -70,7 +71,7 @@ func TestCrawlPackage(t *testing.T) {
t.Error(err)
}
} else {
- assert.Equals(t, "pkg", p.Package, pkg)
+ assert.Equal(t, "pkg", p.Package, pkg)
}
// pkg = "git.gitorious.org/go-pkg/epubgo.git"
@@ -80,7 +81,7 @@ func TestCrawlPackage(t *testing.T) {
// t.Error(err)
// }
// } else {
- // assert.Equals(t, "pkg", p.Package, pkg)
+ // assert.Equal(t, "pkg", p.Package, pkg)
// }
pkg = "thezombie.net/libgojira"
@@ -106,15 +107,15 @@ func TestDocDB(t *testing.T) {
t.Error("db.Get failed!")
return
}
- assert.StringEquals(t, "hello", info2, info)
+ assert.StringEqual(t, "hello", info2, info)
if err := db.Iterate(func(key string, val interface{}) error {
info3, ok := val.(DocInfo)
if !ok {
return errors.New("errNotDocInfo")
}
- assert.StringEquals(t, key, info3, info)
+ assert.StringEqual(t, key, info3, info)
return nil
}); err != nil {
t.Errorf("db.Iterate failed: %v", err)
@@ -142,15 +143,15 @@ func TestDocDB_Export(t *testing.T) {
if !ok {
return errors.New("Not a DocInfo object")
}
- assert.StringEquals(t, "info.Name", info.Name,
+ assert.StringEqual(t, "info.Name", info.Name,
"github.com/daviddengcn/gcse")
count++
return nil
}); err != nil {
t.Errorf("newDB.Iterate failed: %v", err)
}
- assert.Equals(t, "count", count, 1)
+ assert.Equal(t, "count", count, 1)
}
func TestCrawlingEntry(t *testing.T) {
@@ -161,12 +162,12 @@ func TestCrawlingEntry(t *testing.T) {
}
var buf villa.ByteSlice
- assert.NoErrorf(t, "src.WriteTo failed: %v", src.WriteTo(&buf))
+ assert.NoError(t, src.WriteTo(&buf))
var dst CrawlingEntry
- assert.NoErrorf(t, "dst.ReadFrom failed: %v", dst.ReadFrom(&buf, -1))
+ assert.NoError(t, dst.ReadFrom(&buf, -1))
- assert.StringEquals(t, "dst", dst, src)
+ assert.StringEqual(t, "dst", dst, src)
}
func TestFullProjectOfPackage(t *testing.T) {
@@ -178,7 +179,6 @@ func TestFullProjectOfPackage(t *testing.T) {
for i := 0; i < len(DATA); i += 2 {
pkg, prj := DATA[i], DATA[i+1]
- assert.Equals(t, "FullProjectOfPackage "+pkg,
- FullProjectOfPackage(pkg), prj)
+ assert.Equal(t, "FullProjectOfPackage "+pkg, FullProjectOfPackage(pkg), prj)
}
}
View
@@ -4,9 +4,10 @@ import (
"testing"
"time"
- "github.com/daviddengcn/go-assert"
+ "github.com/golangplus/bytes"
+ "github.com/golangplus/testing/assert"
+
"github.com/daviddengcn/go-index"
- "github.com/daviddengcn/go-villa"
)
func TestDocInfo(t *testing.T) {
@@ -32,30 +33,30 @@ func TestDocInfo(t *testing.T) {
"DocInfo", "CheckRuneType",
},
}
- var buf villa.ByteSlice
- assert.NoErrorf(t, "src.WriteTo failed: %v", src.WriteTo(&buf))
+ var buf bytesp.ByteSlice
+ assert.NoError(t, src.WriteTo(&buf))
var dst DocInfo
- assert.NoErrorf(t, "dst.ReadFrom failed: %v", dst.ReadFrom(&buf, -1))
+ assert.NoError(t, dst.ReadFrom(&buf, -1))
- assert.StringEquals(t, "dst", dst, src)
+ assert.StringEqual(t, "dst", dst, src)
// checking the bug introduced by reusing slice
dst2 := dst
- assert.StringEquals(t, "dst2.Imports[0]", dst2.Imports[0],
+ assert.StringEqual(t, "dst2.Imports[0]", dst2.Imports[0],
"github.com/daviddengcn/go-villa")
src.Imports[0] = "github.com/daviddengcn/go-assert"
buf = nil
- assert.NoErrorf(t, "src.WriteTo failed: %v", src.WriteTo(&buf))
- assert.NoErrorf(t, "dst.ReadFrom failed: %v", dst.ReadFrom(&buf, -1))
- assert.StringEquals(t, "dst", dst, src)
+ assert.NoError(t, src.WriteTo(&buf))
+ assert.NoError(t, dst.ReadFrom(&buf, -1))
+ assert.StringEqual(t, "dst", dst, src)
- assert.StringEquals(t, "dst2.Imports[0]", dst2.Imports[0],
+ assert.StringEqual(t, "dst2.Imports[0]", dst2.Imports[0],
"github.com/daviddengcn/go-villa")
}
func TestCheckRuneType_BOM(t *testing.T) {
tp := CheckRuneType('A', 0xfeff)
- assert.Equals(t, "CheckRuneType(0, 0xfeff)", tp, index.TokenSep)
+ assert.Equal(t, "CheckRuneType(A, 0xfeff)", tp, index.TokenSep)
}
View
@@ -3,7 +3,8 @@ package gcse
import (
"testing"
- "github.com/daviddengcn/go-assert"
+ "github.com/golangplus/testing/assert"
+
"github.com/daviddengcn/go-villa"
)
@@ -20,11 +21,11 @@ func TestMemDB_Bug_Sync(t *testing.T) {
t.Error(err)
}
- assert.Equals(t, "Exists", path.Exists(), true)
+ assert.Equal(t, "Exists", path.Exists(), true)
if err := path.Remove(); err != nil {
t.Error(err)
}
- assert.Equals(t, "Exists", path.Exists(), false)
+ assert.Equal(t, "Exists", path.Exists(), false)
//if err := db.Load(); err != nil {
// t.Error(err)
@@ -59,5 +60,5 @@ func TestMemDB_Recover(t *testing.T) {
t.Error("Recover failed!")
return
}
- assert.Equals(t, "vl", vl, 1)
+ assert.Equal(t, "vl", vl, 1)
}
View
@@ -4,7 +4,9 @@ import (
"fmt"
"testing"
- "github.com/daviddengcn/go-assert"
+ "github.com/golangplus/testing/assert"
+
+ goassert "github.com/daviddengcn/go-assert"
"github.com/daviddengcn/go-villa"
"github.com/daviddengcn/sophie"
"github.com/daviddengcn/sophie/mr"
@@ -61,7 +63,7 @@ func TestIndex(t *testing.T) {
}
numDocs := ts.DocCount()
- assert.Equals(t, "DocCount", numDocs, 3)
+ assert.Equal(t, "DocCount", numDocs, 3)
var pkgs []string
if err := ts.Search(map[string]villa.StrSet{IndexTextField: nil},
@@ -74,7 +76,7 @@ func TestIndex(t *testing.T) {
t.Error(err)
return
}
- assert.LinesEqual(t, "all", pkgs,
+ assert.StringEqual(t, "all", pkgs,
[]string{
"github.com/daviddengcn/gcse",
"github.com/daviddengcn/go-villa",
@@ -91,12 +93,12 @@ func TestIndex(t *testing.T) {
t.Errorf("ts.Search: %v", err)
return
}
- assert.LinesEqual(t, "gcseInfo.Imported",
+ assert.StringEqual(t, "gcseInfo.Imported",
gcseInfo.Imported,
[]string{
"github.com/daviddengcn/gcse/indexer",
})
- assert.LinesEqual(t, "gcseInfo.TestImports",
+ assert.StringEqual(t, "gcseInfo.TestImports",
gcseInfo.TestImports,
[]string{
"github.com/daviddengcn/go-villa",
@@ -112,10 +114,10 @@ func TestIndex(t *testing.T) {
t.Errorf("ts.Search: %v", err)
return
}
- assert.LinesEqual(t, "indexerInfo.Imported",
- indexerInfo.Imported, nil)
- assert.LinesEqual(t, "indexerInfo.Imports",
- indexerInfo.Imports, nil)
+ assert.StringEqual(t, "indexerInfo.Imported",
+ indexerInfo.Imported, []string{})
+ assert.StringEqual(t, "indexerInfo.Imports",
+ indexerInfo.Imports, []string{})
if err := ts.Search(map[string]villa.StrSet{
IndexPkgField: villa.NewStrSet("github.com/daviddengcn/go-villa"),
@@ -126,10 +128,10 @@ func TestIndex(t *testing.T) {
t.Errorf("ts.Search: %v", err)
return
}
- assert.StringEquals(t, "indexerInfo.Imported",
+ assert.StringEqual(t, "indexerInfo.Imported",
fmt.Sprintf("%+v", indexerInfo.Imported),
"[]")
- assert.LinesEqual(t, "gcseInfo.TestImported",
+ assert.StringEqual(t, "gcseInfo.TestImported",
gcseInfo.TestImported,
[]string{"github.com/daviddengcn/gcse"})
}
@@ -144,6 +146,6 @@ func TestAppendTokens_filter(t *testing.T) {
SRC := SRC_DST[i].(string)
DST := villa.NewStrSet(SRC_DST[i+1].([]string)...)
- assert.StrSetEquals(t, "Tokens of "+SRC, AppendTokens(nil, []byte(SRC)), DST)
+ goassert.StrSetEquals(t, "Tokens of "+SRC, AppendTokens(nil, []byte(SRC)), DST)
}
}
View
@@ -4,7 +4,7 @@ import (
"strings"
"testing"
- "github.com/daviddengcn/go-assert"
+ "github.com/golangplus/testing/assert"
)
func TestEffectiveImported(t *testing.T) {
@@ -193,9 +193,7 @@ launchpad.net/mgo/v2`)
cnt := effectiveImported(imported, author, project)
t.Logf("cnt: %f", cnt)
- if cnt > 100 {
- t.Errorf("effectiveImported failed!")
- }
+ assert.ValueShould(t, "cnt", cnt, cnt <= 100, "> 100: effectiveImported failed!")
}
func TestEffectiveImported_projsame(t *testing.T) {
@@ -299,9 +297,7 @@ github.com/zsol/docker`)
cnt := effectiveImported(imported, author, project)
t.Logf("cnt: %f", cnt)
- if cnt > 10 {
- t.Errorf("effectiveImported failed!")
- }
+ assert.ValueShould(t, "cnt", cnt, cnt <= 10, "> 10: effectiveImported failed!")
}
func TestProjectOfPackage(t *testing.T) {
@@ -313,7 +309,7 @@ func TestProjectOfPackage(t *testing.T) {
}
for i := 0; i < len(PKG_PRJ); i += 2 {
- assert.Equals(t, "project of "+PKG_PRJ[i], ProjectOfPackage(PKG_PRJ[i]), PKG_PRJ[i+1])
+ assert.Equal(t, "project of "+PKG_PRJ[i], ProjectOfPackage(PKG_PRJ[i]), PKG_PRJ[i+1])
}
}
@@ -326,6 +322,6 @@ func TestAuthorOfPackage(t *testing.T) {
}
for i := 0; i < len(PKG_AUTHOR); i += 2 {
- assert.Equals(t, "author of "+PKG_AUTHOR[i], AuthorOfPackage(PKG_AUTHOR[i]), PKG_AUTHOR[i+1])
+ assert.Equal(t, "author of "+PKG_AUTHOR[i], AuthorOfPackage(PKG_AUTHOR[i]), PKG_AUTHOR[i+1])
}
}
View
@@ -1,9 +1,9 @@
package gcse
import (
- "github.com/daviddengcn/go-algs/ed"
- "github.com/daviddengcn/go-villa"
"testing"
+
+ "github.com/golangplus/testing/assert"
)
func TestSplitSentences(t *testing.T) {
@@ -33,7 +33,7 @@ server providing web services, including home/top/search services.
`server providing web services, including home/top/search services.`,
}
sents := SplitSentences(TEXT)
- AssertStringsEqual(t, "Sentences", sents, SENTS)
+ assert.StringEqual(t, "Sentences", sents, SENTS)
}
func TestChooseImportantSentenses(t *testing.T) {
@@ -79,7 +79,7 @@ A simple pluggable lexer package.
`A simple pluggable lexer package.`,
}
importants := ChooseImportantSentenses(TEXT, "gcse", "github/daviddengcn/core")
- AssertStringsEqual(t, "importants", importants, IMPORTANTS)
+ assert.StringEqual(t, "importants", importants, IMPORTANTS)
}
func TestChooseImportantSentenses_GoBot(t *testing.T) {
@@ -90,7 +90,7 @@ GoBot is an IRC Bot programmed in Golang![Build Status](https://secure.travis-ci
`GoBot is an IRC Bot programmed in Golang.`,
}
importants := ChooseImportantSentenses(TEXT, "main", "github.com/wei2912/GoBot")
- AssertStringsEqual(t, "importants", importants, IMPORTANTS)
+ assert.StringEqual(t, "importants", importants, IMPORTANTS)
}
func TestChooseImportantSentenses_PackageEscape(t *testing.T) {
@@ -101,46 +101,5 @@ GoBot is an IRC Bot programmed.
`GoBot is an IRC Bot programmed.`,
}
importants := ChooseImportantSentenses(TEXT, "main", "github.com/+wei2912/GoBot")
- AssertStringsEqual(t, "importants", importants, IMPORTANTS)
-}
-
-func showText(text string) string {
- return text + "."
-}
-
-func AssertStringsEqual(t *testing.T, name string, act, exp []string) {
- if villa.StringSlice(exp).Equals(act) {
- return
- }
- t.Errorf("%s unexpected(exp: %d lines, act %d lines)!", name, len(exp), len(act))
- t.Logf("exp --- act +++")
- t.Logf("Difference:")
- _, matA, matB := ed.EditDistanceFFull(len(exp), len(act), func(iA, iB int) int {
- sa, sb := exp[iA], act[iB]
- if sa == sb {
- return 0
- }
- return ed.String(sa, sb)
- }, func(iA int) int {
- return len(exp[iA]) + 1
- }, func(iB int) int {
- return len(act[iB]) + 1
- })
- for i, j := 0, 0; i < len(exp) || j < len(act); {
- switch {
- case j >= len(act) || i < len(exp) && matA[i] < 0:
- t.Logf("--- %3d: %s", i+1, showText(exp[i]))
- i++
- case i >= len(exp) || j < len(act) && matB[j] < 0:
- t.Logf("+++ %3d: %s", j+1, showText(act[j]))
- j++
- default:
- if exp[i] != act[j] {
- t.Logf("--- %3d: %s", i+1, showText(exp[i]))
- t.Logf("+++ %3d: %s", j+1, showText(act[j]))
- } // else
- i++
- j++
- }
- } // for i, j
+ assert.StringEqual(t, "importants", importants, IMPORTANTS)
}

0 comments on commit 071f830

Please sign in to comment.