github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/csprng/bbs/impl_test.go (about)

     1  package bbs
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestParams(t *testing.T) {
     9  	p, q, x, _ := Params(64, 0)
    10  	bbs := New(p, q, x, 0)
    11  	r := bbs.Bytes(32)
    12  	bbs2 := New(p, q, x, 0)
    13  	r2 := bbs2.Bytes(32)
    14  	if !bytes.Equal(r, r2) {
    15  		t.Error("Bad bytes")
    16  	}
    17  	t1 := bbs.BytesAt(10012, 12)
    18  	t2 := bbs.BytesAt(10018, 12)
    19  	if !bytes.Equal(t1[6:], t2[:6]) {
    20  		t.Error("BytesAt incorrect for positional/positional")
    21  	}
    22  	t3 := bbs.BytesAt(0, 32)
    23  	if !bytes.Equal(r, t3) {
    24  		t.Error("BytesAt incorrect for positional/non-positional")
    25  	}
    26  	t3 = bbs.BytesAt(1, 32)
    27  	if bytes.Equal(r, t3) {
    28  		t.Error("BytesAt incorrect, shift may not match")
    29  	}
    30  	t3 = bbs.BytesAt(31, 32)
    31  	if bytes.Equal(r, t3) {
    32  		t.Error("BytesAt incorrect, shift may not match")
    33  	}
    34  	t3 = bbs.BytesAt(32, 32)
    35  	if bytes.Equal(r, t3) {
    36  		t.Error("BytesAt incorrect, shift may not match")
    37  	}
    38  	t3 = bbs.BytesAt(33, 32)
    39  	if bytes.Equal(r, t3) {
    40  		t.Error("BytesAt incorrect, shift may not match")
    41  	}
    42  	b := make([]byte, 10)
    43  	bbs.Read(b)
    44  	if bytes.Equal(b, make([]byte, 10)) {
    45  		t.Error("Read returns zeros")
    46  	}
    47  	b = make([]byte, 10)
    48  	Reader.Read(b)
    49  	if bytes.Equal(b, make([]byte, 10)) {
    50  		t.Error("Read returns zeros")
    51  	}
    52  	c := make([]byte, 10)
    53  	Reader.Read(c)
    54  	if bytes.Equal(c, make([]byte, 10)) {
    55  		t.Error("Read returns zeros")
    56  	}
    57  	if bytes.Equal(b, c) {
    58  		t.Error("RNG produces repetition")
    59  	}
    60  }