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

Function test_u254_cmp

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

Source from the content-addressed store, hash-verified

117
118 #[test]
119 fn test_u254_cmp() {
120 let mut prng = ChaCha20Rng::seed_from_u64(2);
121
122 for _ in 0..100 {
123 let a: BigUint = prng.sample(RandomBits::new(254));
124 let b: BigUint = prng.sample(RandomBits::new(254));
125 let a_lessthan = if a.cmp(&b) == Ordering::Less {
126 1u32
127 } else {
128 0u32
129 };
130
131 let script = script! {
132 { U254::push_u32_le(&a.to_u32_digits()) }
133 { U254::push_u32_le(&b.to_u32_digits()) }
134 { U254::lessthan(1, 0) }
135 { a_lessthan }
136 OP_EQUAL
137 };
138 run(script);
139 }
140
141 for _ in 0..100 {
142 let a: BigUint = prng.sample(RandomBits::new(254));
143 let b: BigUint = prng.sample(RandomBits::new(254));
144 let a_lessthanorequal = if a.cmp(&b) != Ordering::Greater {
145 1u32
146 } else {
147 0u32
148 };
149
150 let script = script! {
151 { U254::push_u32_le(&a.to_u32_digits()) }
152 { U254::push_u32_le(&b.to_u32_digits()) }
153 { U254::lessthanorequal(1, 0) }
154 { a_lessthanorequal }
155 OP_EQUAL
156 };
157 run(script);
158 }
159
160 for _ in 0..100 {
161 let a: BigUint = prng.sample(RandomBits::new(254));
162 let b: BigUint = prng.sample(RandomBits::new(254));
163 let a_greaterthan = if a.cmp(&b) == Ordering::Greater {
164 1u32
165 } else {
166 0u32
167 };
168
169 let script = script! {
170 { U254::push_u32_le(&a.to_u32_digits()) }
171 { U254::push_u32_le(&b.to_u32_digits()) }
172 { U254::greaterthan(1, 0) }
173 { a_greaterthan }
174 OP_EQUAL
175 };
176 run(script);

Callers

nothing calls this directly

Calls 1

runFunction · 0.85

Tested by

no test coverage detected