Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 12, 2025
1 parent 52116c1 commit 2a72ad2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
31 changes: 22 additions & 9 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func (i *MyInt) Clone() *MyInt {

// ############ tests ################################

func TestInvalidPrefix(t *testing.T) {
func TestInvalid(t *testing.T) {
t.Parallel()

tbl := new(Table[any])
var zero netip.Prefix
var zeroPfx netip.Prefix
var zeroIP netip.Addr
var testname string

testname = "Insert"
Expand All @@ -55,7 +56,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.Insert(zero, nil)
tbl.Insert(zeroPfx, nil)
})

testname = "Delete"
Expand All @@ -67,7 +68,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.Delete(zero)
tbl.Delete(zeroPfx)
})

testname = "Update"
Expand All @@ -79,7 +80,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.Update(zero, func(v any, _ bool) any { return v })
tbl.Update(zeroPfx, func(v any, _ bool) any { return v })
})

testname = "Get"
Expand All @@ -91,7 +92,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.Get(zero)
tbl.Get(zeroPfx)
})

testname = "LookupPrefix"
Expand All @@ -103,7 +104,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.LookupPrefix(zero)
tbl.LookupPrefix(zeroPfx)
})

testname = "LookupPrefixLPM"
Expand All @@ -115,7 +116,7 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.LookupPrefixLPM(zero)
tbl.LookupPrefixLPM(zeroPfx)
})

testname = "OverlapsPrefix"
Expand All @@ -127,7 +128,19 @@ func TestInvalidPrefix(t *testing.T) {
}
}(testname)

tbl.OverlapsPrefix(zero)
tbl.OverlapsPrefix(zeroPfx)
})

testname = "Contains"
t.Run(testname, func(t *testing.T) {
t.Parallel()
defer func(testname string) {
if r := recover(); r != nil {
t.Fatalf("%s panics on invalid ip input", testname)
}
}(testname)

tbl.Contains(zeroIP)
})
}

Expand Down
8 changes: 8 additions & 0 deletions worstcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func BenchmarkWorstCase(b *testing.B) {
tbl.Insert(p, p.String())
}

b.ResetTimer()
for range b.N {
tbl.Contains(worstCaseProbeIP4)
}
Expand All @@ -194,6 +195,7 @@ func BenchmarkWorstCase(b *testing.B) {
tbl.Insert(p, p.String())
}

b.ResetTimer()
for range b.N {
tbl.Lookup(worstCaseProbeIP4)
}
Expand All @@ -205,6 +207,7 @@ func BenchmarkWorstCase(b *testing.B) {
tbl.Insert(p, p.String())
}

b.ResetTimer()
for range b.N {
tbl.Contains(worstCaseProbeIP6)
}
Expand All @@ -216,6 +219,7 @@ func BenchmarkWorstCase(b *testing.B) {
tbl.Insert(p, p.String())
}

b.ResetTimer()
for range b.N {
tbl.Lookup(worstCaseProbeIP6)
}
Expand All @@ -229,6 +233,7 @@ func BenchmarkWorstCase(b *testing.B) {

tbl.Delete(mpp("255.255.255.255/32")) // delete matching prefix

b.ResetTimer()
for range b.N {
tbl.Contains(worstCaseProbeIP4)
}
Expand All @@ -242,6 +247,7 @@ func BenchmarkWorstCase(b *testing.B) {

tbl.Delete(mpp("255.255.255.255/32")) // delete matching prefix

b.ResetTimer()
for range b.N {
tbl.Lookup(worstCaseProbeIP4)
}
Expand All @@ -255,6 +261,7 @@ func BenchmarkWorstCase(b *testing.B) {

tbl.Delete(mpp("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128")) // delete matching prefix

b.ResetTimer()
for range b.N {
tbl.Contains(worstCaseProbeIP6)
}
Expand All @@ -268,6 +275,7 @@ func BenchmarkWorstCase(b *testing.B) {

tbl.Delete(mpp("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128")) // delete matching prefix

b.ResetTimer()
for range b.N {
tbl.Lookup(worstCaseProbeIP6)
}
Expand Down

0 comments on commit 2a72ad2

Please sign in to comment.