Skip to content

Commit 4333be3

Browse files
author
Andreas Auernhammer
committed
sioutil: add tests for Random and MustRandom
This commit adds two unit tests for `Random` and `MustRandom`. The main purpose of the unit tests is to ensure that `sioutil.Random(0)` behaves as expected.
1 parent a453e49 commit 4333be3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sioutil/sio_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2019 Andreas Auernhammer. All rights reserved.
2+
// Use of this source code is governed by a license that can be
3+
// found in the LICENSE file.
4+
5+
package sioutil
6+
7+
import "testing"
8+
9+
func TestRandom(t *testing.T) {
10+
b, err := Random(0)
11+
if err != nil || len(b) != 0 {
12+
t.Fatalf("Failed to generate empty slice: %v - got %d - want %d", err, len(b), 0)
13+
}
14+
15+
b, err = Random(16)
16+
if err != nil || len(b) != 16 {
17+
t.Fatalf("Failed to generate empty slice: %v - got %d - want %d", err, len(b), 16)
18+
}
19+
}
20+
21+
func TestMustRandom(t *testing.T) {
22+
b := MustRandom(0)
23+
if len(b) != 0 {
24+
t.Fatalf("Failed to generate empty slice: got %d - want %d", len(b), 0)
25+
}
26+
27+
b = MustRandom(16)
28+
if len(b) != 16 {
29+
t.Fatalf("Failed to generate random slice: got %d - want %d", len(b), 16)
30+
}
31+
}

0 commit comments

Comments
 (0)