If x have number 3 return true or false
fn solution(mut x: i32) -> bool { x = x.abs(); while x > 0 { if x % 10 == 3 { return true; } x /= 10; } false }
fn solution(x: i32) -> bool {x.to_string().chars().any(|x| x == '3')- fn solution(mut x: i32) -> bool {
- x = x.abs();
- while x > 0 {
- if x % 10 == 3 {
- return true;
- }
- x /= 10;
- }
- false
- }
#[cfg(test)] mod tests { use super::*; #[test] fn fixed_tests() { assert_eq!(solution(3), true); assert_eq!(solution(-3), true); assert_eq!(solution(525458), false); assert_eq!(solution(2222), false); assert_eq!(solution(354523), true); for n in 0..3 { assert_eq!(solution(n), false); } for n in 4..13 { assert_eq!(solution(n), false); } for n in 30..=39 { assert_eq!(solution(n), true); } for n in -39..=-30 { assert_eq!(solution(n), true); } } }
// Add your tests here.// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
fn test_add() {- fn fixed_tests() {
- assert_eq!(solution(3), true);
- assert_eq!(solution(-3), true);
- assert_eq!(solution(525458), false);
- assert_eq!(solution(2222), false);
assert_eq!(solution(354523), true)- assert_eq!(solution(354523), true);
- for n in 0..3 {
- assert_eq!(solution(n), false);
- }
- for n in 4..13 {
- assert_eq!(solution(n), false);
- }
- for n in 30..=39 {
- assert_eq!(solution(n), true);
- }
- for n in -39..=-30 {
- assert_eq!(solution(n), true);
- }
- }
- }