Skip to content

Instantly share code, notes, and snippets.

@pmkroeker
Forked from rust-play/playground.rs
Last active June 3, 2020 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmkroeker/5a51d3e0556f5c1a6cb0657104a29095 to your computer and use it in GitHub Desktop.
Save pmkroeker/5a51d3e0556f5c1a6cb0657104a29095 to your computer and use it in GitHub Desktop.
// https://dev.to/thepracticaldev/daily-challenge-29-xs-and-os-12mj
pub fn xo (value: &str) -> bool {
let value = value.to_lowercase();
let count_x = value.matches("x").count();
let count_o = value.matches("o").count();
count_x == count_o
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1() {
assert_eq!(xo("ooxx"), true);
}
#[test]
fn test_2() {
assert_eq!(xo("xooxx"), false);
}
#[test]
fn test_3() {
assert_eq!(xo("ooxXm"), true);
}
#[test]
fn test_4() {
assert_eq!(xo("zzoo"), false);
}
#[test]
fn test_5() {
assert_eq!(xo("zpzpzpp"), true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment