| 1 |
use bigdigit::radix::RADIX_10p9_u32; |
| 2 |
use bigdigit::radix::RADIX_10p19_u64; |
| 3 |
|
| 4 |
|
| 5 |
#[test] |
| 6 |
fn split_987654321_low_3() { |
| 7 |
let (hi, lo) = BigDigitSplitter::<RADIX_10p9_u32>::mask_low(3).split(987654321); |
| 8 |
assert_eq!(hi, 987654000); |
| 9 |
assert_eq!(lo, 000000321) |
| 10 |
} |
| 11 |
|
| 12 |
#[test] |
| 13 |
fn split_987654321_high_3() { |
| 14 |
let (hi, lo) = BigDigitSplitter::<RADIX_10p9_u32>::mask_high(3).split(987654321); |
| 15 |
assert_eq!(hi, 987000000); |
| 16 |
assert_eq!(lo, 000654321) |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn split_and_shift_987654321_high_3() { |
| 21 |
let (hi, lo) = BigDigitSplitter::<RADIX_10p9_u32>::mask_high(3).split_and_shift(987654321); |
| 22 |
assert_eq!(hi, 000000987); |
| 23 |
assert_eq!(lo, 654321000) |
| 24 |
} |
| 25 |
|
| 26 |
#[test] |
| 27 |
fn split_and_shift_987654321_low_3() { |
| 28 |
let (hi, lo) = BigDigitSplitter::<RADIX_10p9_u32>::mask_low(3).split_and_shift(987654321); |
| 29 |
assert_eq!(hi, 000987654); |
| 30 |
assert_eq!(lo, 321000000) |
| 31 |
} |
| 32 |
|
| 33 |
mod from_lengths_and_scales { |
| 34 |
use super::*; |
| 35 |
use paste::*; |
| 36 |
|
| 37 |
macro_rules! impl_test { |
| 38 |
(($x:literal, -$y:literal) += $($t:tt)*) => { |
| 39 |
paste! { impl_test!([< case_ $x _n$y >]; ($x, -$y); $($t)*); } |
| 40 |
}; |
| 41 |
(($x:literal, $y:literal) += $($t:tt)*) => { |
| 42 |
paste! { impl_test!([< case_ $x _$y >]; ($x, $y); $($t)*); } |
| 43 |
}; |
| 44 |
($name:ident; ($x:literal, $y:literal); ($a:literal, -$b:literal) => $e:expr ) => { |
| 45 |
paste! { impl_test!([< $name _ $a _n $b >]; ($x, $y); ($a, -$b); $e); } |
| 46 |
}; |
| 47 |
($name:ident; ($x:literal, $y:literal); ($a:literal, $b:literal) => $e:expr ) => { |
| 48 |
paste! { impl_test!([< $name _ $a _ $b >]; ($x, $y); ($a, $b); $e); } |
| 49 |
}; |
| 50 |
($name:ident; ($x:literal, $y:literal); ($a:literal, $b:literal); $expected:expr) => { |
| 51 |
#[test] |
| 52 |
fn $name() { |
| 53 |
use self::AddAssignSliceAlignment::*; |
| 54 |
|
| 55 |
let alignment = AddAssignSliceAlignment::from_lengths_and_scales( |
| 56 |
WithScale { value: $x, scale: $y }, |
| 57 |
WithScale { value: $a, scale: $b }, |
| 58 |
); |
| 59 |
assert_eq!(alignment, $expected); |
| 60 |
} |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
// ll.llllllll |
| 65 |
// r.rrrrrrr |
| 66 |
impl_test!((10, 8) += (8, 7) => RightOverlap { count: 1 }); |
| 67 |
|
| 68 |
// lllllll. |
| 69 |
// rrrrr0. |
| 70 |
impl_test!((7, 0) += (5, -1) => RightOverlap { count: 1 }); |
| 71 |
|
| 72 |
// lll. |
| 73 |
// rrrrrr.rrr |
| 74 |
impl_test!((3, 0) += (9, 3) => LeftOverlap { count: 3 }); |
| 75 |
|
| 76 |
// lll.l |
| 77 |
// .000000rrr |
| 78 |
impl_test!((4, 1) += (3, 9) => LeftDisjoint { count: 8 }); |
| 79 |
|
| 80 |
// 0.00000llll |
| 81 |
// rrrr.rr |
| 82 |
impl_test!((4, 9) += (6, 2) => RightDisjoint{ count: 7 }); |
| 83 |
} |
| 84 |
|
| 85 |
mod from_lengths_and_icount { |
| 86 |
use super::*; |
| 87 |
use paste::*; |
| 88 |
|
| 89 |
macro_rules! impl_test { |
| 90 |
(($x:literal, -$y:literal) += $($t:tt)*) => { |
| 91 |
paste! { |
| 92 |
impl_test!([< case_ $x _n$y >]; ($x, -$y); $($t)*); |
| 93 |
} |
| 94 |
}; |
| 95 |
(($x:literal, $y:literal) += $($t:tt)*) => { |
| 96 |
paste! { |
| 97 |
impl_test!([< case_ $x _$y >]; ($x, $y); $($t)*); |
| 98 |
} |
| 99 |
}; |
| 100 |
($name:ident; ($x:literal, $y:literal); ($a:literal, -$b:literal) => $e:expr ) => { |
| 101 |
paste! { |
| 102 |
impl_test!([< $name _ $a _n $b >]; ($x, $y); ($a, -$b); $e); |
| 103 |
} |
| 104 |
}; |
| 105 |
($name:ident; ($x:literal, $y:literal); ($a:literal, $b:literal) => $e:expr ) => { |
| 106 |
paste! { |
| 107 |
impl_test!([< $name _ $a _ $b >]; ($x, $y); ($a, $b); $e); |
| 108 |
} |
| 109 |
}; |
| 110 |
($name:ident; ($x:literal, $y:literal); ($a:literal, $b:literal); $expected:expr) => { |
| 111 |
#[test] |
| 112 |
fn $name() { |
| 113 |
use self::AddAssignSliceAlignment::*; |
| 114 |
|
| 115 |
let alignment = AddAssignSliceAlignment::from_lengths_and_icount( |
| 116 |
WithIntCount { value: $x, count: $y }, |
| 117 |
WithIntCount { value: $a, count: $b }, |
| 118 |
); |
| 119 |
assert_eq!(alignment, $expected); |
| 120 |
} |
| 121 |
}; |
| 122 |
} |
| 123 |
|
| 124 |
// ll.llllllll |
| 125 |
// r.rrrrrrr |
| 126 |
impl_test!((10, 2) += (8, 1) => RightOverlap { count: 1 }); |
| 127 |
|
| 128 |
// ll.lllllll |
| 129 |
// .rrrrrrr |
| 130 |
impl_test!((9, 2) += (7, 0) => RightOverlap { count: 0 }); |
| 131 |
|
| 132 |
// ll.ll |
| 133 |
// rrrrr.rr |
| 134 |
impl_test!((4, 2) += (7, 5) => RightOverlap { count: 0 }); |
| 135 |
|
| 136 |
// lllll000. |
| 137 |
// .00rrrrrrr |
| 138 |
impl_test!((5, 8) += (7, -2) => LeftDisjoint { count: 12 }); |
| 139 |
|
| 140 |
// l0. |
| 141 |
// .0rrrrrrr |
| 142 |
impl_test!((1, 2) += (7, -1) => LeftDisjoint { count: 9 }); |
| 143 |
|
| 144 |
// ll.lllllllll |
| 145 |
// .0rrrrrrr |
| 146 |
impl_test!((11, 2) += (7, -1) => RightOverlap { count: 1 }); |
| 147 |
|
| 148 |
// ll.llllllll |
| 149 |
// .0rrrrrrr |
| 150 |
impl_test!((10, 2) += (7, -1) => RightOverlap { count: 0 }); |
| 151 |
|
| 152 |
// ll.lllllll |
| 153 |
// .0rrrrrrr |
| 154 |
impl_test!((9, 2) += (7, -1) => LeftOverlap { count: 1 }); |
| 155 |
|
| 156 |
// ll.ll |
| 157 |
// .0rrrrrrr |
| 158 |
impl_test!((4, 2) += (7, -1) => LeftOverlap { count: 6 }); |
| 159 |
|
| 160 |
// ll.l |
| 161 |
// .0rrrrrrr |
| 162 |
impl_test!((3, 2) += (7, -1) => LeftDisjoint { count: 7 }); |
| 163 |
|
| 164 |
// ll. |
| 165 |
// .0rrrrrrr |
| 166 |
impl_test!((2, 2) += (7, -1) => LeftDisjoint { count: 8 }); |
| 167 |
|
| 168 |
// rrrrr000. |
| 169 |
// .00lllllll |
| 170 |
impl_test!((7, -2) += (5, 8) => RightDisjoint { count: 12 }); |
| 171 |
|
| 172 |
// lllll.ll |
| 173 |
// r.rrrr |
| 174 |
impl_test!((7, 5) += (5, 1) => LeftOverlap { count: 2 }); |
| 175 |
|
| 176 |
// lllll.l |
| 177 |
// r.rrrr |
| 178 |
impl_test!((6, 5) += (5, 1) => LeftOverlap { count: 3 }); |
| 179 |
|
| 180 |
// lllll. |
| 181 |
// r.rrrr |
| 182 |
impl_test!((5, 5) += (5, 1) => LeftOverlap { count: 4 }); |
| 183 |
|
| 184 |
// llll0. |
| 185 |
// r.rrrr |
| 186 |
impl_test!((4, 5) += (5, 1) => LeftDisjoint { count: 5 }); |
| 187 |
|
| 188 |
// l.llll |
| 189 |
// rrr0000. |
| 190 |
impl_test!((5, 1) += (3, 7) => RightDisjoint { count: 8 }); |
| 191 |
} |