Created
June 11, 2018 17:36
-
-
Save vporoshok/dfe8b97c72522381e76c6aa14b806bdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fizzbuzz | |
import ( | |
"math" | |
"strconv" | |
"strings" | |
"testing" | |
"github.com/leanovate/gopter" | |
"github.com/leanovate/gopter/gen" | |
"github.com/leanovate/gopter/prop" | |
) | |
func TestFizzBuzzProperties(t *testing.T) { | |
properties := gopter.NewProperties(nil) | |
properties.Property("Start with Fizz for all multiples of 3", prop.ForAll( | |
func(i int) bool { | |
result := FizzBuzz(i * 3) | |
return strings.HasPrefix(result, "Fizz") | |
}, | |
gen.IntRange(1, math.MaxInt32/3), | |
)) | |
properties.Property("Ends with Buzz for all multiples of 5", prop.ForAll( | |
func(i int) bool { | |
result := FizzBuzz(i * 5) | |
return strings.HasSuffix(result, "Buzz") | |
}, | |
gen.IntRange(1, math.MaxInt32/5), | |
)) | |
properties.Property("Int as string for all non-divisible by 3 or 5", prop.ForAll( | |
func(number int) bool { | |
result := FizzBuzz(number) | |
parsed, err := strconv.ParseInt(result, 10, 64) | |
return err == nil && parsed == int64(number) | |
}, | |
gen.IntRange(1, math.MaxInt32).SuchThat(func(v interface{}) bool { | |
return v.(int)%3 != 0 && v.(int)%5 != 0 | |
}), | |
)) | |
properties.TestingRun(t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment