Пример #1
0
// Float64Shrinker is a shrinker for float64 numbers
func Float64Shrinker(v interface{}) gopter.Shrink {
	negShrink := float64Shrink{
		original: -v.(float64),
		half:     -v.(float64),
	}
	posShrink := float64Shrink{
		original: v.(float64),
		half:     v.(float64) / 2,
	}
	return gopter.Shrink(negShrink.Next).Interleave(gopter.Shrink(posShrink.Next))
}
Пример #2
0
// TimeShrinker is a shrinker for time.Time structs
func TimeShrinker(v interface{}) gopter.Shrink {
	t := v.(time.Time)
	sec := t.Unix()
	nsec := int64(t.Nanosecond())
	secShrink := int64Shrink{
		original: sec,
		half:     sec,
	}
	nsecShrink := int64Shrink{
		original: nsec,
		half:     nsec,
	}
	return gopter.Shrink(secShrink.Next).Map(func(v interface{}) interface{} {
		return time.Unix(v.(int64), nsec)
	}).Interleave(gopter.Shrink(nsecShrink.Next).Map(func(v interface{}) interface{} {
		return time.Unix(sec, v.(int64))
	}))
}