github.com/iDigitalFlame/xmt@v0.5.4/util/text/rand_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package text 18 19 import "testing" 20 21 func TestRandomString(t *testing.T) { 22 if v, c := Rand.String(10), Rand.String(10); v == c { 23 t.Fatalf(`TestRandomString(): Random string 2 "%s" should not equal random string 2 "%s"!`, v, c) 24 } 25 } 26 func TestRandomSetUpper(t *testing.T) { 27 for _, v := range Upper.String(16) { 28 if v < 'A' || v > 'Z' { 29 t.Fatalf(`TestRandomString(): Non-upper character "%c" found in 'Upper' generator!`, v) 30 } 31 } 32 } 33 func TestRandomSetLower(t *testing.T) { 34 for _, v := range Lower.String(16) { 35 if v < 'a' || v > 'z' { 36 t.Fatalf(`TestRandomString(): Non-lower character "%c" found in 'Lower' generator!`, v) 37 } 38 } 39 } 40 func TestRandomSetNumbers(t *testing.T) { 41 for _, v := range Numbers.String(16) { 42 if v < '0' || v > '9' { 43 t.Fatalf(`TestRandomString(): Non-number character "%c" found in 'Numbers' generator!`, v) 44 } 45 } 46 }