Skip to content

Commit

Permalink
test: add space merge unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed May 31, 2024
1 parent 4b9b374 commit cd3c9e5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/entity/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,31 @@ func TestAddrSpaceInsertIgnoresExistingAddrWithSmallerSize(t *testing.T) {
a.Insert(addr)
assert.Equal(t, existingAddr, a[1])
}

func TestMergeAddrSpaceMergesMultipleAddrSpaces(t *testing.T) {
a1 := entity.AddrSpace{1: &entity.Addr{AddrPos: &entity.AddrPos{Addr: 1, Size: 1}}}
a2 := entity.AddrSpace{2: &entity.Addr{AddrPos: &entity.AddrPos{Addr: 2, Size: 2}}}
merged := entity.MergeAddrSpace(a1, a2)

assert.Len(t, merged, 2)
assert.Equal(t, a1[1], merged[1])
assert.Equal(t, a2[2], merged[2])
}

func TestMergeAddrSpacePrefersLargerSize(t *testing.T) {
a1 := entity.AddrSpace{1: &entity.Addr{AddrPos: &entity.AddrPos{Addr: 1, Size: 1}}}
a2 := entity.AddrSpace{1: &entity.Addr{AddrPos: &entity.AddrPos{Addr: 1, Size: 2}}}
merged := entity.MergeAddrSpace(a1, a2)

assert.Len(t, merged, 1)
assert.Equal(t, a2[1], merged[1])
}

func TestToDirtyCoverageReturnsCoverageParts(t *testing.T) {
a := entity.AddrSpace{1: &entity.Addr{AddrPos: &entity.AddrPos{Addr: 1, Size: 1}}}
coverage := a.ToDirtyCoverage()

assert.Len(t, coverage, 1)
assert.Equal(t, a[1].AddrPos, coverage[0].Pos)
assert.Equal(t, a[1], coverage[0].Addrs[0])
}

0 comments on commit cd3c9e5

Please sign in to comment.