|
| 1 | +extern crate alphametics; |
| 2 | +use std::collections::HashMap; |
| 3 | + |
| 4 | +fn assert_alphametic_solution_eq(puzzle: &str, solution: &[(char, u8)]) { |
| 5 | + let answer = alphametics::solve(puzzle).unwrap(); |
| 6 | + let solution: HashMap<char, u8> = solution.iter().cloned().collect(); |
| 7 | + assert_eq!(answer, solution); |
| 8 | +} |
| 9 | + |
| 10 | +#[test] |
| 11 | +fn test_with_three_letters() { |
| 12 | + assert_alphametic_solution_eq("I + BB == ILL", &[('I', 1), ('B', 9), ('L', 0)]); |
| 13 | +} |
| 14 | + |
| 15 | +#[test] |
| 16 | +#[ignore] |
| 17 | +fn test_must_have_unique_value_for_each_letter() { |
| 18 | + let answer = alphametics::solve("A == B"); |
| 19 | + assert_eq!(answer, None); |
| 20 | +} |
| 21 | + |
| 22 | +#[test] |
| 23 | +#[ignore] |
| 24 | +fn test_leading_zero_solution_is_invalid() { |
| 25 | + let answer = alphametics::solve("ACA + DD == BD"); |
| 26 | + assert_eq!(answer, None); |
| 27 | +} |
| 28 | + |
| 29 | +#[test] |
| 30 | +#[ignore] |
| 31 | +fn test_puzzle_with_four_letters() { |
| 32 | + assert_alphametic_solution_eq("AS + A == MOM", &[('A', 9), ('S', 2), ('M', 1), ('O', 0)]); |
| 33 | +} |
| 34 | + |
| 35 | +#[test] |
| 36 | +#[ignore] |
| 37 | +fn test_puzzle_with_six_letters() { |
| 38 | + assert_alphametic_solution_eq("NO + NO + TOO == LATE", |
| 39 | + &[('N', 7), ('O', 4), ('T', 9), ('L', 1), ('A', 0), ('E', 2)]); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +#[ignore] |
| 44 | +fn test_puzzle_with_seven_letters() { |
| 45 | + assert_alphametic_solution_eq("HE + SEES + THE == LIGHT", |
| 46 | + &[('E', 4), ('G', 2), ('H', 5), ('I', 0), ('L', 1), ('S', 9), ('T', 7)]); |
| 47 | +} |
| 48 | + |
| 49 | +#[test] |
| 50 | +#[ignore] |
| 51 | +fn test_puzzle_with_eight_letters() { |
| 52 | + assert_alphametic_solution_eq("SEND + MORE == MONEY", |
| 53 | + &[('S', 9), ('E', 5), ('N', 6), ('D', 7), ('M', 1), ('O', 0), ('R', 8), ('Y', 2)]); |
| 54 | +} |
| 55 | + |
| 56 | +#[test] |
| 57 | +#[ignore] |
| 58 | +fn test_puzzle_with_ten_letters() { |
| 59 | + assert_alphametic_solution_eq("AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE", |
| 60 | + &[('A', 5), ('D', 3), ('E', 4), ('F', 7), ('G', 8), ('N', 0), ('O', 2), ('R', 1), |
| 61 | + ('S', 6), ('T', 9)]); |
| 62 | +} |
0 commit comments