代码拉取完成,页面将自动刷新
同步操作将从 xiaochi/gogo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package gogo
import (
"log"
"math/rand"
"testing"
)
func Test_insertDo(t *testing.T) {
type args struct {
x int
y int
uid int
}
tests := []struct {
name string
args args
wantErr bool
}{
{"first", args{5, 5, 2}, false},
}
f := Init(false, "testdata/1.j")
defer f.Close()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := Insert(tt.args.x, tt.args.y, tt.args.uid)
if (err != nil) != tt.wantErr {
t.Errorf("Insert() error = %v, wantErr %v", err, tt.wantErr)
}
ub := mapXYUB[NewXY(5, 5)]
if ub.Bid != 1 {
t.Errorf("Insert() bid of 5,5 should be 1, real %d", ub.Bid)
}
if ub.Uid != 2 {
t.Errorf("Insert() uid of 5,5 should be 2, real %d", ub.Uid)
}
xys := mapBXYsQ[1].XYs
if len(xys) != 1 {
t.Errorf("Insert() mapBXYs should have 1 element, real %d", len(xys))
}
if mapBXYsQ[1].Qi != 4 {
t.Errorf("Insert() mapBQ should be 4, real %d", mapBXYsQ[1].Qi)
}
})
}
t.Run("eat", func(t *testing.T) {
log.SetFlags(log.LstdFlags | log.Lshortfile)
Insert(5, 4, 3)
_, _, other := neisKinds(findNeis(NewXY(5, 4)), 3)
// fmt.Printf("%x %x %x\n", empty, our, other)
// fmt.Println(allUsAlive(len(empty), len(other)))
// fmt.Printf("%x\n", mapBXYs[2])
obs := ziBids(other).Slice()
if obs[0] != 1 {
t.Errorf("other bid should be 1, real %d", obs[0])
}
if mapBXYsQ[1].Qi != 3 {
t.Errorf("5,5 should have 3 qi, real %d", mapBXYsQ[1].Qi)
}
// DebugState()
Insert(5, 3, 3)
// DebugState()
if len(mapBXYsQ[2].XYs) != 2 {
t.Errorf("block should have 2, real %d", len(mapBXYsQ[2].XYs))
}
if lenBlocks() != len(mapBXYsQ) {
t.Errorf("lenBlocks=%d mapBXYsQ=%d", lenBlocks(), len(mapBXYsQ))
}
Insert(5, 6, 3)
Insert(4, 5, 3)
// DebugState()
if mapBXYsQ[1].Qi != 1 {
t.Errorf("5,5 should have 1 qi, real %d", mapBXYsQ[1].Qi)
}
// dryInsert(6, 5, 3)
// log.Println(needReCal([]int{1}))
Insert(6, 5, 3)
if _, ok := mapXYUB[NewXY(5, 5)]; ok {
t.Error("5,5 should have no, real yes")
}
})
}
func FuzzInsert(f *testing.F) {
fj := Init(false, "testdata/fuzz.j")
defer fj.Close()
testcases := []XY{{1, 2}, {4, -9}, {0, 0}}
for _, tc := range testcases {
f.Add(tc.X, tc.Y)
}
f.Fuzz(func(t *testing.T, x, y int) {
color := rand.Int() % 0xffffff
err := Insert(x, y, color)
if err == nil {
if ub, ok := mapXYUB[NewXY(x, y)]; ok {
qi := countQi(mapBXYsQ[ub.Bid].XYs)
if qi == 0 {
t.Errorf("block %d dead", ub.Bid)
}
}
if lenBlocks() != len(mapBXYsQ) {
t.Errorf("block num not equal mapXYUB=%d mapmapBXYsQ=%d", lenBlocks(), len(mapBXYsQ))
}
if len(mapXYUB) != totalZi() {
t.Errorf("zi num not equal mapXYUB=%d totalZi=%d", len(mapXYUB), totalZi())
}
}
})
}
func lenBlocks() int {
m := map[int]bool{}
for _, ub := range mapXYUB {
b := ub.Bid
m[b] = true
}
return len(m)
}
func totalZi() (n int) {
for _, block := range mapBXYsQ {
n += len(block.XYs)
}
return
}
func Test_updateBids(t *testing.T) {
f := Init(false, "testdata/3.j")
defer f.Close()
t.Run("combine", func(t *testing.T) {
err := Insert(5, 5, 3)
if err != nil {
t.Errorf("should no error")
}
Insert(4, 5, 3)
Insert(4, 5, 3)
if len(mapBXYsQ) != 1 {
t.Errorf("should only 1 block, real %d", len(mapBXYsQ))
}
})
}
func Test_updateBids2(t *testing.T) {
f := Init(false, "testdata/4.j")
defer f.Close()
t.Run("combine 2 2", func(t *testing.T) {
Insert(2, 1, 3)
Insert(2, 2, 3)
Insert(3, 3, 3)
Insert(4, 3, 3)
// DebugState()
Insert(2, 3, 3)
if totalZi() != len(mapXYUB) {
t.Errorf("should equal totalZi()=%d len(mapXYUB)=%d", totalZi(), len(mapXYUB))
}
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。