github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/random/rand_test.go (about)

     1  package random
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/lang/types"
     7  	"github.com/lmorg/murex/test"
     8  )
     9  
    10  func TestRandInteger(t *testing.T) {
    11  	for i := 0; i < 1000; i++ {
    12  		test.RunMethodRegexTest(t, cmdRand, funcName,
    13  			"", types.Null,
    14  			[]string{types.Integer},
    15  			`^[0-9]+$`,
    16  		)
    17  	}
    18  }
    19  
    20  func TestRandIntegerMax(t *testing.T) {
    21  	for i := 0; i < 1000; i++ {
    22  		test.RunMethodRegexTest(t, cmdRand, funcName,
    23  			"", types.Null,
    24  			[]string{types.Integer, "9"},
    25  			`^[0-9]$`,
    26  		)
    27  	}
    28  }
    29  
    30  func TestRandNumber(t *testing.T) {
    31  	for i := 0; i < 1000; i++ {
    32  		test.RunMethodRegexTest(t, cmdRand, funcName,
    33  			"", types.Null,
    34  			[]string{types.Number},
    35  			`^[0-9]+$`,
    36  		)
    37  	}
    38  }
    39  
    40  func TestRandNumberMax(t *testing.T) {
    41  	for i := 0; i < 1000; i++ {
    42  		test.RunMethodRegexTest(t, cmdRand, funcName,
    43  			"", types.Null,
    44  			[]string{types.Number, "9"},
    45  			`^[0-9]$`,
    46  		)
    47  	}
    48  }
    49  
    50  func TestRandFloat(t *testing.T) {
    51  	for i := 0; i < 1000; i++ {
    52  		test.RunMethodRegexTest(t, cmdRand, funcName,
    53  			"", types.Null,
    54  			[]string{types.Float},
    55  			`^[0-9]\.[0-9]+$`,
    56  		)
    57  	}
    58  }
    59  
    60  func TestRandString(t *testing.T) {
    61  	for i := 0; i < 1000; i++ {
    62  		test.RunMethodRegexTest(t, cmdRand, funcName,
    63  			"", types.Null,
    64  			[]string{types.String},
    65  			`^[\x20-\x7E]{20}$`,
    66  		)
    67  	}
    68  }
    69  
    70  func TestRandStringMax(t *testing.T) {
    71  	for i := 0; i < 1000; i++ {
    72  		test.RunMethodRegexTest(t, cmdRand, funcName,
    73  			"", types.Null,
    74  			[]string{types.String, "1"},
    75  			`^[\x20-\x7E]$`,
    76  		)
    77  	}
    78  }