コード例 #1
0
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)
}
コード例 #2
0
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)
}