MCPcopy Create free account
hub / github.com/BitVM/BitVM / test_u64_cmp

Function test_u64_cmp

bitvm/src/bigint/cmp.rs:200–278  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

198
199 #[test]
200 fn test_u64_cmp() {
201 let mut prng = ChaCha20Rng::seed_from_u64(2);
202
203 for _ in 0..100 {
204 let a: BigUint = prng.sample(RandomBits::new(64));
205 let b: BigUint = prng.sample(RandomBits::new(64));
206 let a_lessthan = if a.cmp(&b) == Ordering::Less {
207 1u32
208 } else {
209 0u32
210 };
211
212 let script = script! {
213 { U64::push_u32_le(&a.to_u32_digits()) }
214 { U64::push_u32_le(&b.to_u32_digits()) }
215 { U64::lessthan(1, 0) }
216 { a_lessthan }
217 OP_EQUAL
218 };
219 run(script);
220 }
221
222 for _ in 0..100 {
223 let a: BigUint = prng.sample(RandomBits::new(64));
224 let b: BigUint = prng.sample(RandomBits::new(64));
225 let a_lessthanorequal = if a.cmp(&b) != Ordering::Greater {
226 1u32
227 } else {
228 0u32
229 };
230
231 let script = script! {
232 { U64::push_u32_le(&a.to_u32_digits()) }
233 { U64::push_u32_le(&b.to_u32_digits()) }
234 { U64::lessthanorequal(1, 0) }
235 { a_lessthanorequal }
236 OP_EQUAL
237 };
238 run(script);
239 }
240
241 for _ in 0..100 {
242 let a: BigUint = prng.sample(RandomBits::new(64));
243 let b: BigUint = prng.sample(RandomBits::new(64));
244 let a_greaterthan = if a.cmp(&b) == Ordering::Greater {
245 1u32
246 } else {
247 0u32
248 };
249
250 let script = script! {
251 { U64::push_u32_le(&a.to_u32_digits()) }
252 { U64::push_u32_le(&b.to_u32_digits()) }
253 { U64::greaterthan(1, 0) }
254 { a_greaterthan }
255 OP_EQUAL
256 };
257 run(script);

Callers

nothing calls this directly

Calls 1

runFunction · 0.85

Tested by

no test coverage detected