Skip to content

Commit

Permalink
sioutil: add tests for Random and MustRandom
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andreas Auernhammer committed Oct 29, 2019
1 parent a453e49 commit 4333be3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sioutil/sio_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2019 Andreas Auernhammer. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.

package sioutil

import "testing"

func TestRandom(t *testing.T) {
b, err := Random(0)
if err != nil || len(b) != 0 {
t.Fatalf("Failed to generate empty slice: %v - got %d - want %d", err, len(b), 0)
}

b, err = Random(16)
if err != nil || len(b) != 16 {
t.Fatalf("Failed to generate empty slice: %v - got %d - want %d", err, len(b), 16)
}
}

func TestMustRandom(t *testing.T) {
b := MustRandom(0)
if len(b) != 0 {
t.Fatalf("Failed to generate empty slice: got %d - want %d", len(b), 0)
}

b = MustRandom(16)
if len(b) != 16 {
t.Fatalf("Failed to generate random slice: got %d - want %d", len(b), 16)
}
}

0 comments on commit 4333be3

Please sign in to comment.