2014-12-07 15:41:24 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-12-07 15:41:24 +00:00
|
|
|
|
2016-05-26 07:02:56 +00:00
|
|
|
package rand
|
2014-12-07 15:41:24 +00:00
|
|
|
|
2016-04-10 19:36:38 +00:00
|
|
|
import "testing"
|
2014-12-07 15:41:24 +00:00
|
|
|
|
|
|
|
func TestRandomString(t *testing.T) {
|
|
|
|
for _, l := range []int{0, 1, 2, 3, 4, 8, 42} {
|
2016-05-26 07:02:56 +00:00
|
|
|
s := String(l)
|
2014-12-07 15:41:24 +00:00
|
|
|
if len(s) != l {
|
2014-12-08 15:19:08 +00:00
|
|
|
t.Errorf("Incorrect length %d != %d", len(s), l)
|
2014-12-07 15:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strings := make([]string, 1000)
|
|
|
|
for i := range strings {
|
2016-05-26 07:02:56 +00:00
|
|
|
strings[i] = String(8)
|
2014-12-07 15:41:24 +00:00
|
|
|
for j := range strings {
|
|
|
|
if i == j {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings[i] == strings[j] {
|
|
|
|
t.Errorf("Repeated random string %q", strings[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 08:43:58 +00:00
|
|
|
func TestRandomUint64(t *testing.T) {
|
|
|
|
ints := make([]uint64, 1000)
|
2014-12-07 15:41:24 +00:00
|
|
|
for i := range ints {
|
2020-06-17 08:43:58 +00:00
|
|
|
ints[i] = Uint64()
|
2014-12-07 15:41:24 +00:00
|
|
|
for j := range ints {
|
|
|
|
if i == j {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if ints[i] == ints[j] {
|
|
|
|
t.Errorf("Repeated random int64 %d", ints[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|