Skip to content

Commit

Permalink
feat: implement Not for Bit
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSajid committed Jul 4, 2023
1 parent 6c76bb4 commit afe5066
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/brainfoamkit_lib/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
// * SOFTWARE.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

use std::fmt::{self, Display, Formatter};
use std::{
fmt::{self, Display, Formatter},
ops::Not,
};

/// Representation of a single bit.
///
Expand Down Expand Up @@ -198,6 +201,17 @@ impl Default for Bit {
}
}

impl Not for Bit {
type Output = Self;

fn not(self) -> Self::Output {
match self {
Self::Zero => Self::One,
Self::One => Self::Zero,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -245,4 +259,12 @@ mod tests {
let bit = Bit::one();
assert_eq!(bit.to_u8(), 1);
}

#[test]
fn test_bit_not() {
let bit = !Bit::zero();
assert_eq!(bit, Bit::One);
let bit = !Bit::one();
assert_eq!(bit, Bit::Zero);
}
}

0 comments on commit afe5066

Please sign in to comment.