Merge rust-bitcoin/rust-bitcoin#1704: Add tests to Weight type
f0a3aad5b8
Add tests to Weight type (yancy) Pull request description: Add tests for Weight type ACKs for top commit: Kixunil: ACKf0a3aad5b8
apoelstra: ACKf0a3aad5b8
Tree-SHA512: 12875cd774762743c53b55f1c56494cd4c3995fc481dd5653810efb363627dfa770bd1e147dacd452a6a61d3906910dc974c979a4a3c41655f8a32a4b4a14ef4
This commit is contained in:
commit
fa2f27ca03
|
@ -120,13 +120,89 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checked_sub_test(){
|
fn weight_constructor_test() {
|
||||||
|
assert_eq!(Weight::ZERO, Weight::from_wu(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_vb_test() {
|
||||||
|
let vb = Weight::from_vb(1).expect("expected weight unit");
|
||||||
|
assert_eq!(Weight(4), vb);
|
||||||
|
|
||||||
|
let vb = Weight::from_vb(u64::max_value());
|
||||||
|
assert_eq!(None, vb);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_vb_unchecked_test() {
|
||||||
|
let vb = Weight::from_vb_unchecked(1);
|
||||||
|
assert_eq!(Weight(4), vb);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn from_vb_unchecked_panic_test() {
|
||||||
|
Weight::from_vb_unchecked(u64::max_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_witness_data_size_test() {
|
||||||
|
let witness_data_size = 1;
|
||||||
|
assert_eq!(Weight(witness_data_size), Weight::from_witness_data_size(witness_data_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_non_witness_data_size_test() {
|
||||||
|
assert_eq!(Weight(4), Weight::from_non_witness_data_size(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_vb_floor_test() {
|
||||||
|
assert_eq!(1, Weight(4).to_vbytes_floor());
|
||||||
|
assert_eq!(1, Weight(5).to_vbytes_floor());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_vb_ceil_test() {
|
||||||
|
assert_eq!(1, Weight(4).to_vbytes_ceil());
|
||||||
|
assert_eq!(2, Weight(5).to_vbytes_ceil());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checked_add_test() {
|
||||||
|
let result = Weight(1).checked_add(Weight(1)).expect("expected weight unit");
|
||||||
|
assert_eq!(Weight(2), result);
|
||||||
|
|
||||||
|
let result = Weight::MAX.checked_add(Weight(1));
|
||||||
|
assert_eq!(None, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checked_sub_test() {
|
||||||
let result = Weight(1).checked_sub(Weight(1)).expect("expected weight unit");
|
let result = Weight(1).checked_sub(Weight(1)).expect("expected weight unit");
|
||||||
assert_eq!(Weight::ZERO, result);
|
assert_eq!(Weight::ZERO, result);
|
||||||
|
|
||||||
let result = Weight::MIN.checked_sub(Weight(1));
|
let result = Weight::MIN.checked_sub(Weight(1));
|
||||||
assert_eq!(None, result);
|
assert_eq!(None, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checked_mul_test() {
|
||||||
|
let result = Weight(2).checked_mul(2).expect("expected weight unit");
|
||||||
|
assert_eq!(Weight(4), result);
|
||||||
|
|
||||||
|
let result = Weight::MAX.checked_mul(2);
|
||||||
|
assert_eq!(None, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checked_div_test() {
|
||||||
|
let result = Weight(2).checked_div(2).expect("expected weight unit");
|
||||||
|
assert_eq!(Weight(1), result);
|
||||||
|
|
||||||
|
let result = Weight(2).checked_div(0);
|
||||||
|
assert_eq!(None, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Weight> for u64 {
|
impl From<Weight> for u64 {
|
||||||
|
|
Loading…
Reference in New Issue