Commit aac37c11 authored by Kirill Smelkov's avatar Kirill Smelkov

X zdata: Introduce T to start removing duplication in tests

parent f07502fc
......@@ -64,6 +64,15 @@ type setStr = set.Str
const ø = "ø"
// T is environment for doing ΔFtail tests.
//
// it is based on xbtreetest.T .
type T struct {
*xbtreetest.T
}
// ΔFTestEntry represents one entry in ΔFtail tests.
type ΔFTestEntry struct {
δblkTab map[int64]string // changes in tree part {} #blk -> ZBlk<name>
......@@ -181,7 +190,7 @@ func TestΔFtailRandom(t *testing.T) {
// testΔFtail verifies ΔFtail on sequence of testcases coming from testq.
func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
t := xbtreetest.NewT(t_)
t := newT(t_)
X := exc.Raiseif
// data built via applying changes from testq
......@@ -272,26 +281,6 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
retrack()
// δfstr/vδfstr converts δf/vδf to string taking symbolic at into account
δfstr := func(δf *ΔFile) string {
s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks)
if δf.Epoch {
s += "E"
}
if δf.Size {
s += "S"
}
return s
}
vδfstr := func(vδf []*ΔFile) string {
var s []string
for _, δf := range vδf {
s = append(s, δfstr(δf))
}
return fmt.Sprintf("%s", s)
}
i := 1 // matches t1
delfilePrev := false
for test := range testq {
......@@ -554,7 +543,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
vδf_ok := vδf[j:k+1] // [j,k]
vδf_ := δFtail.SliceByFileRev(zfile, lo, hi)
if !reflect.DeepEqual(vδf_, vδf_ok) {
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), vδfstr(vδf_), vδfstr(vδf_ok))
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), t.vδfstr(vδf_), t.vδfstr(vδf_ok))
}
}
}
......@@ -611,7 +600,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// we verify that no change to untracked block is missed, if any change to that
// block is ever present in returned slice.
func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
t := xbtreetest.NewT(t_)
t := newT(t_)
X := exc.Raiseif
at0 := t.Head().At
......@@ -664,26 +653,6 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
δFtail.Track(zfile, blk, path, zblk)
}
// δfstr/vδfstr converts δf/vδf to string taking symbolic at into account
// XXX dup
δfstr := func(δf *ΔFile) string {
s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks)
if δf.Epoch {
s += "E"
}
if δf.Size {
s += "S"
}
return s
}
vδfstr := func(vδf []*ΔFile) string {
var s []string
for _, δf := range vδf {
s = append(s, δfstr(δf))
}
return fmt.Sprintf("%s", s)
}
// track 0, but do not track 1 and 2.
// blktab[1] becomes noticed by δBtail because both 0 and 1 are in the same bucket and both are changed @at2.
// blktab[2] remains unnoticed because it is not changed past at1.
......@@ -699,7 +668,7 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
&ΔFile{Rev: t4.At, Blocks: b( 1), Size: false},
}
if !reflect.DeepEqual(vδf, vδf_ok) {
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), vδfstr(vδf), vδfstr(vδf_ok))
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), t.vδfstr(vδf), t.vδfstr(vδf_ok))
}
......@@ -710,7 +679,7 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
&ΔFile{Rev: t3.At, Blocks: b(0), Size: false},
}
if !reflect.DeepEqual(vδf, vδf_ok) {
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), vδfstr(vδf), vδfstr(vδf_ok))
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), t.vδfstr(vδf), t.vδfstr(vδf_ok))
}
// (at3, at4] -> changes to only 0, ----/----
......@@ -718,7 +687,7 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
vδf = δFtail.SliceByFileRev(zfile, lo, hi)
vδf_ok = []*ΔFile(nil)
if !reflect.DeepEqual(vδf, vδf_ok) {
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), vδfstr(vδf), vδfstr(vδf_ok))
t.Errorf("slice (@%s,@%s]:\nhave: %v\nwant: %v", t.AtSymb(lo), t.AtSymb(hi), t.vδfstr(vδf), t.vδfstr(vδf_ok))
}
}
......@@ -747,6 +716,32 @@ func dataTabTxt(dataTab map[string]string) string {
}
// newT creates new T.
func newT(t *testing.T) *T {
return &T{xbtreetest.NewT(t)}
}
// δfstr/vδfstr convert δf/vδf to string taking symbolic at into account.
func (t *T) δfstr(δf *ΔFile) string {
s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks)
if δf.Epoch {
s += "E"
}
if δf.Size {
s += "S"
}
return s
}
func (t *T) vδfstr(vδf []*ΔFile) string {
var s []string
for _, δf := range vδf {
s = append(s, t.δfstr(δf))
}
return fmt.Sprintf("%s", s)
}
// b is shorthand to create setI64(blocks).
func b(blocks ...int64) setI64 {
s := setI64{}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment