Skip to content

Commit

Permalink
letter_boxed_solver: St/Ch index_too_big()
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Mar 30, 2021
1 parent f1a066c commit 52d1e6b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions letter_boxed_solver/src/lib.rs
Expand Up @@ -98,6 +98,10 @@ impl Index<u8> for St {
type Output = Ch;

fn index(&self, index: u8) -> &Self::Output {
if index >= 12 {
panic!("Out of range");
}

let c = (self.0 >> (4 + 5 * index)) & 0x1F;
match c {
1 => &Ch::A,
Expand Down Expand Up @@ -352,4 +356,25 @@ mod tests {

let _ = max + Ch::X;
}

#[test]
#[should_panic(expected = "Out of range")]
fn index_too_big()
{
let max = St::empty()
+ Ch::A
+ Ch::B
+ Ch::C
+ Ch::D
+ Ch::E
+ Ch::F
+ Ch::G
+ Ch::H
+ Ch::I
+ Ch::J
+ Ch::K
+ Ch::L;

let _ = max[12];
}
}

0 comments on commit 52d1e6b

Please sign in to comment.