Commit 73bc026b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d1f63f32
...@@ -82,6 +82,8 @@ func (δtail *ΔTail) Head() Tid { ...@@ -82,6 +82,8 @@ func (δtail *ΔTail) Head() Tid {
return δtail.head return δtail.head
} }
// XXX + Tail?
// XXX add way to extend coverage without appending changed data? (i.e. if a // XXX add way to extend coverage without appending changed data? (i.e. if a
// txn did not change file at all) -> but then it is simply .Append(rev, nil)? // txn did not change file at all) -> but then it is simply .Append(rev, nil)?
...@@ -139,14 +141,14 @@ func (δtail *ΔTail) ForgetBefore(revCut Tid) { ...@@ -139,14 +141,14 @@ func (δtail *ΔTail) ForgetBefore(revCut Tid) {
// LastRevOf(id, at) = at // LastRevOf(id, at) = at
// //
// 2) if δtail has an entry corresponding to id change, it gives exactly the // 2) if δtail has an entry corresponding to id change, it gives exactly the
// last revision that changed id: // last revision that changed id:
// //
// # at ∈ [min(rev ∈ δtail), max(rev ∈ δtail)] // # at ∈ [min(rev ∈ δtail), max(rev ∈ δtail)]
// # ∃ rev ∈ δtail: rev changed id && rev ≤ at // # ∃ rev ∈ δtail: rev changed id && rev ≤ at
// LastRevOf(id, at) = max(rev: rev changed id && rev ≤ at) // LastRevOf(id, at) = max(rev: rev changed id && rev ≤ at)
// //
// 3) if δtail does not contain appropriate record with id - it returns δtail's // 3) if δtail does not contain appropriate record with id - it returns δtail's
// lower bound as the estimate for the upper bound of the last id revision: // lower bound as the estimate for the upper bound of the last id revision:
// //
// # at ∈ [min(rev ∈ δtail), max(rev ∈ δtail)] // # at ∈ [min(rev ∈ δtail), max(rev ∈ δtail)]
// # ∄ rev ∈ δtail: rev changed id && rev ≤ at // # ∄ rev ∈ δtail: rev changed id && rev ≤ at
......
...@@ -25,8 +25,6 @@ import ( ...@@ -25,8 +25,6 @@ import (
"testing" "testing"
) )
// XXX test Head
func TestΔTail(t *testing.T) { func TestΔTail(t *testing.T) {
δtail := NewΔTail() δtail := NewΔTail()
...@@ -41,7 +39,7 @@ func TestΔTail(t *testing.T) { ...@@ -41,7 +39,7 @@ func TestΔTail(t *testing.T) {
} }
// δCheck verifies that δtail state corresponds to provided tailv // δCheck verifies that δtail state corresponds to provided tailv
δCheck := func(tailv ...δRevEntry) { δCheck := func(head Tid, tailv ...δRevEntry) {
t.Helper() t.Helper()
for i := 1; i < len(tailv); i++ { for i := 1; i < len(tailv); i++ {
...@@ -50,6 +48,10 @@ func TestΔTail(t *testing.T) { ...@@ -50,6 +48,10 @@ func TestΔTail(t *testing.T) {
} }
} }
if h := δtail.Head(); h != head {
t.Fatalf("Head() -> %s ; want %s", h, head)
}
if !tailvEqual(δtail.tailv, tailv) { if !tailvEqual(δtail.tailv, tailv) {
t.Fatalf("tailv:\nhave: %v\nwant: %v", δtail.tailv, tailv) t.Fatalf("tailv:\nhave: %v\nwant: %v", δtail.tailv, tailv)
} }
...@@ -85,56 +87,67 @@ func TestΔTail(t *testing.T) { ...@@ -85,56 +87,67 @@ func TestΔTail(t *testing.T) {
} }
δCheck() δCheck(0)
δCheckLastUP(4, 12, 12) // δtail = ø δCheckLastUP(4, 12, 12) // δtail = ø
δAppend(R(10, 3,5)) δAppend(R(10, 3,5))
δCheck(R(10, 3,5)) δCheck(10, R(10, 3,5))
δCheckLastUP(3, 9, 9) // at < δtail δCheckLastUP(3, 9, 9) // at < δtail
δCheckLastUP(3, 12, 12) // at > δtail δCheckLastUP(3, 12, 12) // at > δtail
δCheckLastUP(4, 10, 10) // id ∉ δtail δCheckLastUP(4, 10, 10) // id ∉ δtail
δAppend(R(11, 7)) δAppend(R(11, 7))
δCheck(R(10, 3,5), R(11, 7)) δCheck(11, R(10, 3,5), R(11, 7))
δAppend(R(12, 7)) δAppend(R(12, 7))
δCheck(R(10, 3,5), R(11, 7), R(12, 7)) δCheck(12, R(10, 3,5), R(11, 7), R(12, 7))
δAppend(R(14, 3,8)) δAppend(R(14, 3,8))
δCheck(R(10, 3,5), R(11, 7), R(12, 7), R(14, 3,8)) δCheck(14, R(10, 3,5), R(11, 7), R(12, 7), R(14, 3,8))
δCheckLastUP(8, 12, 10) // id ∈ δtail, but has no entry with rev ≤ at δCheckLastUP(8, 12, 10) // id ∈ δtail, but has no entry with rev ≤ at
δtail.ForgetBefore(10) δtail.ForgetBefore(10)
δCheck(R(10, 3,5), R(11, 7), R(12, 7), R(14, 3,8)) δCheck(14, R(10, 3,5), R(11, 7), R(12, 7), R(14, 3,8))
δtail.ForgetBefore(11) δtail.ForgetBefore(11)
δCheck(R(11, 7), R(12, 7), R(14, 3,8)) δCheck(14, R(11, 7), R(12, 7), R(14, 3,8))
δtail.ForgetBefore(13) δtail.ForgetBefore(13)
δCheck(R(14, 3,8)) δCheck(14, R(14, 3,8))
δtail.ForgetBefore(15) δtail.ForgetBefore(15)
δCheck() δCheck(14)
// Append panics on non-↑ rev // Append panics on non-↑ rev
δAppend(R(15, 1))
func() { // δAppendPanic verifies that Append(δ.rev = rev) panics.
δAppendPanic := func(rev Tid) {
defer func() { defer func() {
r := recover() r := recover()
if r == nil { if r == nil {
t.Fatal("append non-↑: not panicked") t.Fatalf("append(rev=%s) non-↑: not panicked", rev)
} }
rev := Tid(15) want := fmt.Sprintf("δtail.Append: rev not ↑: %s -> %s", δtail.head, rev)
want := fmt.Sprintf("δtail.Append: rev not ↑: %s -> %s", rev, rev)
if r != want { if r != want {
t.Fatalf("append non-↑:\nhave: %q\nwant: %q", r, want) t.Fatalf("append non-↑:\nhave: %q\nwant: %q", r, want)
} }
}() }()
δAppend(R(15, 1)) δAppend(R(rev))
}() }
// on empty δtail
δAppendPanic(14)
δAppendPanic(13)
δAppendPanic(12)
// on !empty δtail
δAppend(R(15, 1))
δCheck(15, R(15, 1))
δAppendPanic(15)
δAppendPanic(14)
// .tailv underlying storage is not kept after forget // .tailv underlying storage is not kept after forget
......
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