rag/main_test.go
2024-06-16 00:45:32 +08:00

29 lines
511 B
Go

package main
import (
"github.com/gin-gonic/gin"
"testing"
)
type MyInterface interface{}
type MyStruct struct{}
func BenchmarkTypeAssertionSuccess(b *testing.B) {
var x MyInterface = &MyStruct{}
for n := 0; n < b.N; n++ {
if _, ok := x.(*MyStruct); !ok {
b.Fatal("Type assertion failed")
}
}
}
func BenchmarkTypeAssertionFailure(b *testing.B) {
var x MyInterface = &MyStruct{}
for n := 0; n < b.N; n++ {
if _, ok := x.(*gin.Context); ok {
b.Fatal("Type assertion should fail")
}
}
}