Skip to content

Commit

Permalink
test: SignificantBit
Browse files Browse the repository at this point in the history
  • Loading branch information
detectivekim committed Jun 21, 2024
1 parent c09e929 commit d0f2574
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/libraries/significant_bit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,24 @@ pub impl SignificantBitImpl of SignificantBitTrait {
let index = (x & (~x + 1))
* DEBRUIJN_SEQ
/ 0x100000000000000000000000000000000000000000000000000000000000000;
return 1;
// let arr = DEBRUIJN_INDEX.span();
// arr[index]
*DEBRUIJN_INDEX.span()[index.try_into().unwrap()]
}
}

#[cfg(test)]
mod tests {
use super::SignificantBitImpl;
use clober_cairo::alexandria::fast_power::fast_power;

#[test]
fn test_least_significant_bit() {
let mut i: u256 = 0;
while i < 256 {
assert_eq!(
SignificantBitImpl::least_significant_bit(fast_power(2_u256, i)),
i.try_into().unwrap()
);
i += 1;
}
}
}

0 comments on commit d0f2574

Please sign in to comment.