github.com/iDigitalFlame/xmt@v0.5.1/util/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 util
    18  
    19  import "testing"
    20  
    21  func TestRands(t *testing.T) {
    22  	for i := 0; i < 32; i++ {
    23  		if v := int(Rand.Int31n(30 + int32(i))); v > 30+i {
    24  			t.Fatalf(`TestRands() number value "%d" should be less than "%d"!`, v, 30+i)
    25  		}
    26  	}
    27  	for i := 0; i < 32; i++ {
    28  		if v := int(Rand.Int63n(30 + int64(i))); v > 30+i {
    29  			t.Fatalf(`TestRands() number value "%d" should be less than "%d"!`, v, 30+i)
    30  		}
    31  	}
    32  }
    33  func TestFastRandN(t *testing.T) {
    34  	for i := 0; i < 32; i++ {
    35  		if v := int(FastRandN(30 + i)); v > 30+i {
    36  			t.Fatalf(`TestFastRandN() number value "%d" should be less than "%d"!`, v, 30+i)
    37  		}
    38  	}
    39  }