Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. package example
  2.  
  3. import (
  4. "bytes"
  5. "math/rand"
  6. "reflect"
  7. "testing"
  8. "testing/quick"
  9. )
  10.  
  11. type asciiString string
  12.  
  13. func (asciiString) Generate(rand *rand.Rand, size int) reflect.Value {
  14. var buffer bytes.Buffer
  15. for i := 0; i < size; i++ {
  16. c := rand.Intn(127)
  17. buffer.WriteByte(byte(c))
  18. }
  19. s := asciiString(buffer.String())
  20. return reflect.ValueOf(s)
  21. }
  22.  
  23. func TestRandomAscii(t *testing.T) {
  24. f := func(a asciiString) bool {
  25. s := string(a) /*s is a random string composed only of the first 128 ascii chars*/
  26. return do_something_with_random_input(s)
  27. }
  28. if err := quick.Check(f, nil); err != nil {
  29. t.Fatal(err)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement