use depyler_core::transpile_python_to_rust;
#[test]
fn test_randbytes() {
let python = r#"
import random
def get_random_bytes(n: int) -> bytes:
return random.randbytes(n)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("gen") && result.contains("u8"));
}
#[test]
fn test_randint() {
let python = r#"
import random
def random_integer(a: int, b: int) -> int:
return random.randint(a, b)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("gen_range"));
}
#[test]
fn test_choice() {
let python = r#"
import random
def pick_one(items: list) -> int:
return random.choice(items)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("choose"));
}
#[test]
fn test_choices() {
let python = r#"
import random
def pick_many(items: list, k: int) -> list:
return random.choices(items, k=k)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("map") || result.contains("choose"));
}
#[test]
fn test_expovariate() {
let python = r#"
import random
def expo_random(lambd: float) -> float:
return random.expovariate(lambd)
"#;
let result = transpile_python_to_rust(python).expect("Transpilation failed");
assert!(result.contains("Exp"));
}