Skip to content

Commit 1cae801

Browse files
authored
Bump ctutils v0.3.0 (#1067)
This notably removes the `(Partial)Eq` impl(s) from `Choice`, so anywhere affected has been updated to use e.g. `to_bool` instead.
1 parent f8f09a1 commit 1cae801

File tree

16 files changed

+143
-120
lines changed

16 files changed

+143
-120
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ edition = "2024"
1717
rust-version = "1.85"
1818

1919
[dependencies]
20-
ctutils = "0.2.3"
20+
ctutils = "0.3"
2121
num-traits = { version = "0.2.19", default-features = false }
2222

2323
# optional dependencies

src/int.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ where
371371
#[cfg(test)]
372372
#[allow(clippy::unwrap_used)]
373373
mod tests {
374-
use crate::{Choice, I128, U128};
374+
use crate::{I128, U128};
375375

376376
#[cfg(target_pointer_width = "64")]
377377
#[test]
@@ -450,19 +450,19 @@ mod tests {
450450
#[test]
451451
fn is_minimal() {
452452
let min = I128::from_be_hex("80000000000000000000000000000000");
453-
assert_eq!(min.is_min(), Choice::TRUE);
453+
assert!(min.is_min().to_bool());
454454

455455
let random = I128::from_be_hex("11113333555577779999BBBBDDDDFFFF");
456-
assert_eq!(random.is_min(), Choice::FALSE);
456+
assert!(!random.is_min().to_bool());
457457
}
458458

459459
#[test]
460460
fn is_maximal() {
461461
let max = I128::from_be_hex("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
462-
assert_eq!(max.is_max(), Choice::TRUE);
462+
assert!(max.is_max().to_bool());
463463

464464
let random = I128::from_be_hex("11113333555577779999BBBBDDDDFFFF");
465-
assert_eq!(random.is_max(), Choice::FALSE);
465+
assert!(!random.is_max().to_bool());
466466
}
467467

468468
#[test]

src/int/add.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<const LIMBS: usize> WrappingAdd for Int<LIMBS> {
102102

103103
#[cfg(test)]
104104
mod tests {
105-
use crate::{Choice, I128, U128};
105+
use crate::{I128, U128};
106106

107107
#[test]
108108
fn checked_add() {
@@ -217,105 +217,105 @@ mod tests {
217217
// lhs = MIN
218218

219219
let (_val, overflow) = I128::MIN.overflowing_add(&I128::MIN);
220-
assert_eq!(overflow, Choice::TRUE);
220+
assert!(overflow.to_bool());
221221

222222
let (_val, overflow) = I128::MIN.overflowing_add(&I128::MINUS_ONE);
223-
assert_eq!(overflow, Choice::TRUE);
223+
assert!(overflow.to_bool());
224224

225225
let (val, overflow) = I128::MIN.overflowing_add(&I128::ZERO);
226-
assert_eq!(overflow, Choice::FALSE);
226+
assert!(!overflow.to_bool());
227227
assert_eq!(val, I128::MIN);
228228

229229
let (val, overflow) = I128::MIN.overflowing_add(&I128::ONE);
230-
assert_eq!(overflow, Choice::FALSE);
230+
assert!(!overflow.to_bool());
231231
assert_eq!(val, min_plus_one);
232232

233233
let (val, overflow) = I128::MIN.overflowing_add(&I128::MAX);
234-
assert_eq!(overflow, Choice::FALSE);
234+
assert!(!overflow.to_bool());
235235
assert_eq!(val, I128::MINUS_ONE);
236236

237237
// lhs = -1
238238

239239
let (_val, overflow) = I128::MINUS_ONE.overflowing_add(&I128::MIN);
240-
assert_eq!(overflow, Choice::TRUE);
240+
assert!(overflow.to_bool());
241241

242242
let (val, overflow) = I128::MINUS_ONE.overflowing_add(&I128::MINUS_ONE);
243-
assert_eq!(overflow, Choice::FALSE);
243+
assert!(!overflow.to_bool());
244244
assert_eq!(val, two.wrapping_neg());
245245

246246
let (val, overflow) = I128::MINUS_ONE.overflowing_add(&I128::ZERO);
247-
assert_eq!(overflow, Choice::FALSE);
247+
assert!(!overflow.to_bool());
248248
assert_eq!(val, I128::MINUS_ONE);
249249

250250
let (val, overflow) = I128::MINUS_ONE.overflowing_add(&I128::ONE);
251-
assert_eq!(overflow, Choice::FALSE);
251+
assert!(!overflow.to_bool());
252252
assert_eq!(val, I128::ZERO);
253253

254254
let (val, overflow) = I128::MINUS_ONE.overflowing_add(&I128::MAX);
255-
assert_eq!(overflow, Choice::FALSE);
255+
assert!(!overflow.to_bool());
256256
assert_eq!(val, max_minus_one);
257257

258258
// lhs = 0
259259

260260
let (val, overflow) = I128::ZERO.overflowing_add(&I128::MIN);
261-
assert_eq!(overflow, Choice::FALSE);
261+
assert!(!overflow.to_bool());
262262
assert_eq!(val, I128::MIN);
263263

264264
let (val, overflow) = I128::ZERO.overflowing_add(&I128::MINUS_ONE);
265-
assert_eq!(overflow, Choice::FALSE);
265+
assert!(!overflow.to_bool());
266266
assert_eq!(val, I128::MINUS_ONE);
267267

268268
let (val, overflow) = I128::ZERO.overflowing_add(&I128::ZERO);
269-
assert_eq!(overflow, Choice::FALSE);
269+
assert!(!overflow.to_bool());
270270
assert_eq!(val, I128::ZERO);
271271

272272
let (val, overflow) = I128::ZERO.overflowing_add(&I128::ONE);
273-
assert_eq!(overflow, Choice::FALSE);
273+
assert!(!overflow.to_bool());
274274
assert_eq!(val, I128::ONE);
275275

276276
let (val, overflow) = I128::ZERO.overflowing_add(&I128::MAX);
277-
assert_eq!(overflow, Choice::FALSE);
277+
assert!(!overflow.to_bool());
278278
assert_eq!(val, I128::MAX);
279279

280280
// lhs = 1
281281

282282
let (val, overflow) = I128::ONE.overflowing_add(&I128::MIN);
283-
assert_eq!(overflow, Choice::FALSE);
283+
assert!(!overflow.to_bool());
284284
assert_eq!(val, min_plus_one);
285285

286286
let (val, overflow) = I128::ONE.overflowing_add(&I128::MINUS_ONE);
287-
assert_eq!(overflow, Choice::FALSE);
287+
assert!(!overflow.to_bool());
288288
assert_eq!(val, I128::ZERO);
289289

290290
let (val, overflow) = I128::ONE.overflowing_add(&I128::ZERO);
291-
assert_eq!(overflow, Choice::FALSE);
291+
assert!(!overflow.to_bool());
292292
assert_eq!(val, I128::ONE);
293293

294294
let (val, overflow) = I128::ONE.overflowing_add(&I128::ONE);
295-
assert_eq!(overflow, Choice::FALSE);
295+
assert!(!overflow.to_bool());
296296
assert_eq!(val, two);
297297

298298
let (_val, overflow) = I128::ONE.overflowing_add(&I128::MAX);
299-
assert_eq!(overflow, Choice::TRUE);
299+
assert!(overflow.to_bool());
300300

301301
// lhs = MAX
302302

303303
let (val, overflow) = I128::MAX.overflowing_add(&I128::MIN);
304-
assert_eq!(overflow, Choice::FALSE);
304+
assert!(!overflow.to_bool());
305305
assert_eq!(val, I128::MINUS_ONE);
306306

307307
let (val, overflow) = I128::MAX.overflowing_add(&I128::MINUS_ONE);
308-
assert_eq!(overflow, Choice::FALSE);
308+
assert!(!overflow.to_bool());
309309
assert_eq!(val, max_minus_one);
310310

311311
let (val, overflow) = I128::MAX.overflowing_add(&I128::ZERO);
312-
assert_eq!(overflow, Choice::FALSE);
312+
assert!(!overflow.to_bool());
313313
assert_eq!(val, I128::MAX);
314314

315315
let (_val, overflow) = I128::MAX.overflowing_add(&I128::ONE);
316-
assert_eq!(overflow, Choice::TRUE);
316+
assert!(overflow.to_bool());
317317

318318
let (_val, overflow) = I128::MAX.overflowing_add(&I128::MAX);
319-
assert_eq!(overflow, Choice::TRUE);
319+
assert!(overflow.to_bool());
320320
}
321321
}

src/int/div.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<const LIMBS: usize> RemAssign<&NonZero<Int<LIMBS>>> for Wrapping<Int<LIMBS>
503503

504504
#[cfg(test)]
505505
mod tests {
506-
use crate::{Choice, CtSelect, DivVartime, I128, Int, NonZero, One, Zero};
506+
use crate::{CtSelect, DivVartime, I128, Int, NonZero, One, Zero};
507507

508508
#[test]
509509
#[allow(clippy::init_numbered_fields)]
@@ -622,7 +622,7 @@ mod tests {
622622
fn test_checked_div_mod_floor() {
623623
let (quotient, remainder) =
624624
I128::MIN.checked_div_rem_floor(&I128::MINUS_ONE.to_nz().unwrap());
625-
assert_eq!(quotient.is_some(), Choice::FALSE);
625+
assert!(!quotient.is_some().to_bool());
626626
assert_eq!(remainder, I128::ZERO);
627627
}
628628

src/int/mul.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<const LIMBS: usize> MulAssign<&Checked<Int<LIMBS>>> for Checked<Int<LIMBS>>
198198

199199
#[cfg(test)]
200200
mod tests {
201-
use crate::{Choice, I64, I128, I256, Int, U64, U128, U256};
201+
use crate::{I64, I128, I256, Int, U64, U128, U256};
202202

203203
#[test]
204204
#[allow(clippy::init_numbered_fields)]
@@ -522,15 +522,15 @@ mod tests {
522522
#[test]
523523
fn test_checked_square() {
524524
let res = I128::from_i64(i64::MIN).checked_square();
525-
assert_eq!(res.is_some(), Choice::TRUE);
525+
assert!(res.is_some().to_bool());
526526
assert_eq!(
527527
res.unwrap(),
528528
U128::from_be_hex("40000000000000000000000000000000")
529529
);
530530

531531
let x: I128 = I128::MINUS_ONE << 64;
532532
let res = x.checked_square();
533-
assert_eq!(res.is_none(), Choice::TRUE)
533+
assert!(res.is_none().to_bool());
534534
}
535535

536536
#[test]

src/int/neg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ mod tests {
5858

5959
let (res, overflow) = I128::MIN.overflowing_neg();
6060
assert_eq!(res, I128::MIN);
61-
assert_eq!(overflow, Choice::TRUE);
61+
assert!(overflow.to_bool());
6262

6363
let (res, overflow) = I128::MINUS_ONE.overflowing_neg();
6464
assert_eq!(res, I128::ONE);
65-
assert_eq!(overflow, Choice::FALSE);
65+
assert!(!overflow.to_bool());
6666

6767
let (res, overflow) = I128::ZERO.overflowing_neg();
6868
assert_eq!(res, I128::ZERO);
69-
assert_eq!(overflow, Choice::FALSE);
69+
assert!(!overflow.to_bool());
7070

7171
let (res, overflow) = I128::ONE.overflowing_neg();
7272
assert_eq!(res, I128::MINUS_ONE);
73-
assert_eq!(overflow, Choice::FALSE);
73+
assert!(!overflow.to_bool());
7474

7575
let (res, overflow) = I128::MAX.overflowing_neg();
7676
assert_eq!(res, min_plus_one);
77-
assert_eq!(overflow, Choice::FALSE);
77+
assert!(!overflow.to_bool());
7878
}
7979

8080
#[test]
@@ -103,7 +103,7 @@ mod tests {
103103

104104
#[test]
105105
fn checked_neg() {
106-
assert_eq!(I128::MIN.checked_neg().is_none(), Choice::TRUE);
106+
assert!(I128::MIN.checked_neg().is_none().to_bool());
107107
assert_eq!(I128::MINUS_ONE.checked_neg().unwrap(), I128::ONE);
108108
assert_eq!(I128::ZERO.checked_neg().unwrap(), I128::ZERO);
109109
assert_eq!(I128::ONE.checked_neg().unwrap(), I128::MINUS_ONE);

src/int/sign.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,63 +75,70 @@ mod tests {
7575

7676
#[test]
7777
fn new_from_abs_sign() {
78-
assert_eq!(
79-
I128::new_from_abs_sign(U128::ZERO, Choice::FALSE).is_some(),
80-
Choice::TRUE
78+
assert!(
79+
I128::new_from_abs_sign(U128::ZERO, Choice::FALSE)
80+
.is_some()
81+
.to_bool()
8182
);
82-
assert_eq!(
83-
I128::new_from_abs_sign(U128::ZERO, Choice::TRUE).is_some(),
84-
Choice::TRUE
83+
assert!(
84+
I128::new_from_abs_sign(U128::ZERO, Choice::TRUE)
85+
.is_some()
86+
.to_bool()
8587
);
86-
assert_eq!(
87-
I128::new_from_abs_sign(I128::MIN.abs(), Choice::FALSE).is_some(),
88-
Choice::FALSE
88+
assert!(
89+
I128::new_from_abs_sign(I128::MIN.abs(), Choice::FALSE)
90+
.is_none()
91+
.to_bool()
8992
);
90-
assert_eq!(
91-
I128::new_from_abs_sign(I128::MIN.abs(), Choice::TRUE).is_some(),
92-
Choice::TRUE
93+
assert!(
94+
I128::new_from_abs_sign(I128::MIN.abs(), Choice::TRUE)
95+
.is_some()
96+
.to_bool()
9397
);
94-
assert_eq!(
95-
I128::new_from_abs_sign(I128::MAX.abs(), Choice::FALSE).is_some(),
96-
Choice::TRUE
98+
assert!(
99+
I128::new_from_abs_sign(I128::MAX.abs(), Choice::FALSE)
100+
.is_some()
101+
.to_bool()
97102
);
98-
assert_eq!(
99-
I128::new_from_abs_sign(I128::MAX.abs(), Choice::TRUE).is_some(),
100-
Choice::TRUE
103+
assert!(
104+
I128::new_from_abs_sign(I128::MAX.abs(), Choice::TRUE)
105+
.is_some()
106+
.to_bool()
101107
);
102-
assert_eq!(
103-
I128::new_from_abs_sign(U128::MAX, Choice::TRUE).is_some(),
104-
Choice::FALSE
108+
assert!(
109+
I128::new_from_abs_sign(U128::MAX, Choice::TRUE)
110+
.is_none()
111+
.to_bool()
105112
);
106113
}
107114

108115
#[test]
109116
fn is_negative() {
110-
assert_eq!(I128::MIN.is_negative(), Choice::TRUE);
111-
assert_eq!(I128::MINUS_ONE.is_negative(), Choice::TRUE);
112-
assert_eq!(I128::ZERO.is_negative(), Choice::FALSE);
113-
assert_eq!(I128::ONE.is_negative(), Choice::FALSE);
114-
assert_eq!(I128::MAX.is_negative(), Choice::FALSE);
117+
assert!(I128::MIN.is_negative().to_bool());
118+
assert!(I128::MINUS_ONE.is_negative().to_bool());
119+
assert!(!I128::ZERO.is_negative().to_bool());
120+
assert!(!I128::ONE.is_negative().to_bool());
121+
assert!(!I128::MAX.is_negative().to_bool());
115122

116123
let random_negative = I128::from_be_hex("91113333555577779999BBBBDDDDFFFF");
117-
assert_eq!(random_negative.is_negative(), Choice::TRUE);
124+
assert!(random_negative.is_negative().to_bool());
118125

119126
let random_positive = I128::from_be_hex("71113333555577779999BBBBDDDDFFFF");
120-
assert_eq!(random_positive.is_negative(), Choice::FALSE);
127+
assert!(!random_positive.is_negative().to_bool());
121128
}
122129

123130
#[test]
124131
fn is_positive() {
125-
assert_eq!(I128::MIN.is_positive(), Choice::FALSE);
126-
assert_eq!(I128::MINUS_ONE.is_positive(), Choice::FALSE);
127-
assert_eq!(I128::ZERO.is_positive(), Choice::FALSE);
128-
assert_eq!(I128::ONE.is_positive(), Choice::TRUE);
129-
assert_eq!(I128::MAX.is_positive(), Choice::TRUE);
132+
assert!(!I128::MIN.is_positive().to_bool());
133+
assert!(!I128::MINUS_ONE.is_positive().to_bool());
134+
assert!(!I128::ZERO.is_positive().to_bool());
135+
assert!(I128::ONE.is_positive().to_bool());
136+
assert!(I128::MAX.is_positive().to_bool());
130137

131138
let random_negative = I128::from_be_hex("deadbeefcafebabedeadbeefcafebabe");
132-
assert_eq!(random_negative.is_positive(), Choice::FALSE);
139+
assert!(!random_negative.is_positive().to_bool());
133140

134141
let random_positive = I128::from_be_hex("0badc0dedeadc0decafebabedeadcafe");
135-
assert_eq!(random_positive.is_positive(), Choice::TRUE);
142+
assert!(random_positive.is_positive().to_bool());
136143
}
137144
}

0 commit comments

Comments
 (0)