コード例 #1
0
ファイル: unival_test.go プロジェクト: untoldwind/gorrd
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)
}
コード例 #2
0
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)
}
コード例 #3
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)
}