#random #random-string #unit #acceptance #testing

rustyaid

一个小型库,提供用于测试目的的随机数据

1 个不稳定版本

0.1.0 2022 年 3 月 12 日

#1748开发工具

MIT/Apache

29KB
327

此 crate 是一个简单的库,提供用于生成不同 Rust 类型随机值的方法。此 crate 受 Java 库 smt-random 的启发,以帮助进行 Mockist TDD

数字

数字模块提供了为任何原始数值类型生成数字的方法

用法

use rustyaid::number::*;

let value: i32 = some_number(); // Generate some signed integer of 32 bytes
let value = some_number::<i32>(); // Generate some signed integer of 32 bytes alternative call

some_number_between(5, 10); // Generate some signed integer between 5 and 10
some_number_less_than(9); // Generates some signed integer less or equal to 9, can be less than 0 if of signed type
some_number_greater_than(9); // Generates some number greater than 9
some_negative_number::<isize>(); // Generates some negative number
some_positive_number::<isize>(); // Generates some positive number

字节

字节模块提供了生成字节的方法,包括单个字节和作为向量一部分的字节

用法

use rustyaid::byte::*;

some_byte(); // Returns a signgular byte (u8)
some_byte_vector(1024); // Returns a vec containing 1024 random bytes

字符串

字符串模块提供了生成随机字符串的方法。

用法

use rustyaid::string::*;

some_string(); // Generates a string of random length between 1 to 1024 characters
some_string_of_length(32); // Generates a string of 32 characters
some_string_of_length_between(10, 100); // Generates a string of random length between 10 and 100 characters

some_alpha_string(); // Generates a string of random length between 1 to 1024 alphabet characters
some_alpha_string_of_length(32); // Generates a string of 32 alphabet characters
some_alpha_string_of_length_between(10, 100); // Generates a string of random length between 10 and 100 alphabet characters

some_numeric_string(); // Generates a string of random length between 1 to 1024 numerical characters
some_numeric_string_of_length(32); // Generates a string of 32 numerical characters
some_numeric_string_of_length_between(10, 100); // Generates a string of random length between 10 and 100 numerical characters

some_alphanumeric_string(); // Generates a string of random length between 1 to 1024 alphanumerical characters
some_alphanumeric_string_of_length(32); // Generates a string of 32 alphanumerical characters
some_alphanumeric_string_of_length_between(10, 100); // Generates a string of random length between 10 and 100 alphanumerical characters

依赖

~775KB
~14K SLoC