ldiff: Len

This commit is contained in:
Sergey Cherepanov 2023-02-01 21:38:47 +03:00 committed by Mikhail Iudin
parent 887354642c
commit f6e2cc3890
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
2 changed files with 9 additions and 0 deletions

View File

@ -94,6 +94,8 @@ type Diff interface {
Ids() []string
// Hash returns hash of all elements in the diff
Hash() string
// Len returns count of elements in the diff
Len() int
}
// Remote interface for using in the Diff
@ -159,6 +161,12 @@ func (d *diff) Ids() (ids []string) {
return
}
func (d *diff) Len() int {
d.mu.RLock()
defer d.mu.RUnlock()
return d.sl.Len()
}
func (d *diff) Elements() (elements []Element) {
d.mu.RLock()
defer d.mu.RUnlock()

View File

@ -179,6 +179,7 @@ func TestDiff_Ids(t *testing.T) {
gotIds := d.Ids()
sort.Strings(gotIds)
assert.Equal(t, ids, gotIds)
assert.Equal(t, len(ids), d.Len())
}
func TestDiff_Elements(t *testing.T) {