tests2.rs (447B)
1 // Calculates the power of 2 using a bit shift. 2 // `1 << n` is equivalent to "2 to the power of n". 3 fn power_of_2(n: u8) -> u64 { 4 1 << n 5 } 6 7 fn main() { 8 // You can optionally experiment here. 9 } 10 11 #[cfg(test)] 12 mod tests { 13 use super::*; 14 15 #[test] 16 fn you_can_assert_eq() { 17 assert_eq!(power_of_2(0), 1); 18 assert_eq!(power_of_2(1), 2); 19 assert_eq!(power_of_2(2), 4); 20 assert_eq!(power_of_2(3), 8); 21 } 22 }