2023-04-21 11:59:29 +00:00
|
|
|
package testutils
|
|
|
|
|
|
|
|
import "reflect"
|
|
|
|
|
2023-05-11 07:50:07 +00:00
|
|
|
const EthSymbol = "ETH"
|
|
|
|
const SntSymbol = "SNT"
|
|
|
|
const DaiSymbol = "DAI"
|
|
|
|
|
2023-06-13 09:25:23 +00:00
|
|
|
func SliceContains[T comparable](slice []T, value T) bool {
|
|
|
|
for _, v := range slice {
|
|
|
|
if v == value {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2023-04-21 11:59:29 +00:00
|
|
|
func StructExistsInSlice[T any](target T, slice []T) bool {
|
|
|
|
for _, item := range slice {
|
|
|
|
if reflect.DeepEqual(target, item) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2023-10-04 12:00:12 +00:00
|
|
|
|
|
|
|
func Filter[T any](ss []T, test func(T) bool) (ret []T) {
|
|
|
|
for _, s := range ss {
|
|
|
|
if test(s) {
|
|
|
|
ret = append(ret, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|