OSDN Git Service

Update to current Go library.
[pf3gnuchains/gcc-fork.git] / libgo / go / crypto / rand / rand_test.go
1 // Copyright 2010 The Go Authors.  All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package rand
6
7 import (
8         "bytes"
9         "compress/flate"
10         "testing"
11 )
12
13 func TestRead(t *testing.T) {
14         var n int = 4e6
15         if testing.Short() {
16                 n = 1e5
17         }
18         b := make([]byte, n)
19         n, err := Read(b)
20         if n != len(b) || err != nil {
21                 t.Fatalf("Read(buf) = %d, %s", n, err)
22         }
23
24         var z bytes.Buffer
25         f := flate.NewWriter(&z, 5)
26         f.Write(b)
27         f.Close()
28         if z.Len() < len(b)*99/100 {
29                 t.Fatalf("Compressed %d -> %d", len(b), z.Len())
30         }
31 }