func TestUnival(t *testing.T) { properties := gopter.NewProperties(nil) properties.Property("Unival from uint64", prop.ForAll( func(i uint64) bool { val := unival(i) return val.AsUnsignedLong() == i }, gen.UInt64())) properties.Property("Unival from int64", prop.ForAll( func(i int64) bool { val := unival(i) return val.AsLong() == i }, gen.Int64())) properties.Property("Unival from float64", prop.ForAll( func(f float64) bool { val := univalForDouble(f) return val.AsDouble() == f }, gen.Float64())) properties.TestingRun(t) }
func Test_ValidateFizzBuzz(t *testing.T) { parameters := gopter.DefaultTestParameters() parameters.MinSuccessfulTests = 10000 properties := gopter.NewProperties(parameters) properties.Property("FizzBuzz Returns Correct String", prop.ForAll( func(num int) bool { str := fizzBuzz(num) switch str { case "Fizz": return (num%3 == 0) && !(num%5 == 0) case "Buzz": return (num%5 == 0) && !(num%3 == 0) case "FizzBuzz": return (num%3 == 0) && (num%5 == 0) default: expectedStr := strconv.Itoa(num) return !(num%3 == 0) && !(num%5 == 0) && expectedStr == str } }, gen.Int(), )) properties.TestingRun(t) }
func TestDumpCompatibility(t *testing.T) { rrdtool, err := findRrdTool() if err != nil { t.Skipf("rrdtool not found: %s", err.Error()) return } parameters := gopter.DefaultTestParameters() if testing.Short() { parameters.MinSuccessfulTests = 3 } else { parameters.MinSuccessfulTests = 30 } properties := gopter.NewProperties(parameters) properties.Property("dump of gauge, counter, derive, absolute is compatile", prop.ForAllNoShrink( rrdtool.checkDumpCompatibility1, counterGen(1455218381), gen.SliceOf(gen.IntRange(minGauge, maxGauge)), gen.SliceOf(gen.IntRange(minCounter, maxCounter)).Map(integrateInts), gen.SliceOf(gen.IntRange(minDerive, maxDerive)).Map(integrateInts), gen.SliceOf(gen.IntRange(minAbsolute, maxAbsolute)).Map(integrateInts), )) properties.Property("dump of dcounter, dderive is compatile", prop.ForAllNoShrink( rrdtool.checkDumpCompatibility2, counterGen(1455218381), gen.SliceOf(gen.Float64Range(minDCounter, maxDCounter)).Map(integrateFloats), gen.SliceOf(gen.Float64Range(minDDerive, maxDDerive)).Map(integrateFloats), )) properties.TestingRun(t) }
func Test_ValidateRunFizzBuzz(t *testing.T) { parameters := gopter.DefaultTestParameters() parameters.MinSuccessfulTests = 100 properties := gopter.NewProperties(parameters) properties.Property("FizzBuzz Returns Correct String", prop.ForAll( func(requests [][]string) bool { handler := NewHandler(NewInMemoryCache()) for _, nums := range requests { results, _ := handler.RunFizzBuzz(nums) for i, str := range results { num, _ := strconv.Atoi(nums[i]) switch str { case "Fizz": return (num%3 == 0) && !(num%5 == 0) case "Buzz": return (num%5 == 0) && !(num%3 == 0) case "FizzBuzz": return (num%3 == 0) && (num%5 == 0) default: expectedStr := strconv.Itoa(num) return !(num%3 == 0) && !(num%5 == 0) && expectedStr == str } } } return true }, gen.SliceOf(gen.SliceOf(gen.NumString())), )) properties.TestingRun(t) }