4 fn test_steps_between() {
5 assert_eq!(Step::steps_between(&20_u8, &200_u8), Some(180_usize));
6 assert_eq!(Step::steps_between(&-20_i8, &80_i8), Some(100_usize));
7 assert_eq!(Step::steps_between(&-120_i8, &80_i8), Some(200_usize));
8 assert_eq!(Step::steps_between(&20_u32, &4_000_100_u32), Some(4_000_080_usize));
9 assert_eq!(Step::steps_between(&-20_i32, &80_i32), Some(100_usize));
10 assert_eq!(Step::steps_between(&-2_000_030_i32, &2_000_050_i32), Some(4_000_080_usize));
12 // Skip u64/i64 to avoid differences with 32-bit vs 64-bit platforms
14 assert_eq!(Step::steps_between(&20_u128, &200_u128), Some(180_usize));
15 assert_eq!(Step::steps_between(&-20_i128, &80_i128), Some(100_usize));
16 if cfg!(target_pointer_width = "64") {
17 assert_eq!(Step::steps_between(&10_u128, &0x1_0000_0000_0000_0009_u128), Some(usize::MAX));
19 assert_eq!(Step::steps_between(&10_u128, &0x1_0000_0000_0000_000a_u128), None);
20 assert_eq!(Step::steps_between(&10_i128, &0x1_0000_0000_0000_000a_i128), None);
22 Step::steps_between(&-0x1_0000_0000_0000_0000_i128, &0x1_0000_0000_0000_0000_i128,),
28 fn test_step_forward() {
29 assert_eq!(Step::forward_checked(55_u8, 200_usize), Some(255_u8));
30 assert_eq!(Step::forward_checked(252_u8, 200_usize), None);
31 assert_eq!(Step::forward_checked(0_u8, 256_usize), None);
32 assert_eq!(Step::forward_checked(-110_i8, 200_usize), Some(90_i8));
33 assert_eq!(Step::forward_checked(-110_i8, 248_usize), None);
34 assert_eq!(Step::forward_checked(-126_i8, 256_usize), None);
36 assert_eq!(Step::forward_checked(35_u16, 100_usize), Some(135_u16));
37 assert_eq!(Step::forward_checked(35_u16, 65500_usize), Some(u16::MAX));
38 assert_eq!(Step::forward_checked(36_u16, 65500_usize), None);
39 assert_eq!(Step::forward_checked(-110_i16, 200_usize), Some(90_i16));
40 assert_eq!(Step::forward_checked(-20_030_i16, 50_050_usize), Some(30_020_i16));
41 assert_eq!(Step::forward_checked(-10_i16, 40_000_usize), None);
42 assert_eq!(Step::forward_checked(-10_i16, 70_000_usize), None);
44 assert_eq!(Step::forward_checked(10_u128, 70_000_usize), Some(70_010_u128));
45 assert_eq!(Step::forward_checked(10_i128, 70_030_usize), Some(70_040_i128));
47 Step::forward_checked(0xffff_ffff_ffff_ffff__ffff_ffff_ffff_ff00_u128, 0xff_usize),
51 Step::forward_checked(0xffff_ffff_ffff_ffff__ffff_ffff_ffff_ff00_u128, 0x100_usize),
55 Step::forward_checked(0x7fff_ffff_ffff_ffff__ffff_ffff_ffff_ff00_i128, 0xff_usize),
59 Step::forward_checked(0x7fff_ffff_ffff_ffff__ffff_ffff_ffff_ff00_i128, 0x100_usize),
65 fn test_step_backward() {
66 assert_eq!(Step::backward_checked(255_u8, 200_usize), Some(55_u8));
67 assert_eq!(Step::backward_checked(100_u8, 200_usize), None);
68 assert_eq!(Step::backward_checked(255_u8, 256_usize), None);
69 assert_eq!(Step::backward_checked(90_i8, 200_usize), Some(-110_i8));
70 assert_eq!(Step::backward_checked(110_i8, 248_usize), None);
71 assert_eq!(Step::backward_checked(127_i8, 256_usize), None);
73 assert_eq!(Step::backward_checked(135_u16, 100_usize), Some(35_u16));
74 assert_eq!(Step::backward_checked(u16::MAX, 65500_usize), Some(35_u16));
75 assert_eq!(Step::backward_checked(10_u16, 11_usize), None);
76 assert_eq!(Step::backward_checked(90_i16, 200_usize), Some(-110_i16));
77 assert_eq!(Step::backward_checked(30_020_i16, 50_050_usize), Some(-20_030_i16));
78 assert_eq!(Step::backward_checked(-10_i16, 40_000_usize), None);
79 assert_eq!(Step::backward_checked(-10_i16, 70_000_usize), None);
81 assert_eq!(Step::backward_checked(70_010_u128, 70_000_usize), Some(10_u128));
82 assert_eq!(Step::backward_checked(70_020_i128, 70_030_usize), Some(-10_i128));
83 assert_eq!(Step::backward_checked(10_u128, 7_usize), Some(3_u128));
84 assert_eq!(Step::backward_checked(10_u128, 11_usize), None);
86 Step::backward_checked(-0x7fff_ffff_ffff_ffff__ffff_ffff_ffff_ff00_i128, 0x100_usize),