Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Sep 26, 2024
1 parent 0d50d7c commit 73c64fd
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,8 @@ mod tests {
effective_value_sum += eff_value;

}
let result = effective_value_sum.to_unsigned().unwrap();

// There will be a match, but there could be
// more than one possible solution.
let result = effective_value_sum.to_unsigned().unwrap();
assert_eq!(result, target);

Ok(())
Expand All @@ -843,26 +841,14 @@ mod tests {

// generate all the possible utxos subsets
let mut gen = exhaustigen::Gen::new();
let mut subsets: Vec<Vec<Utxo>> = Vec::new();
let mut subsets: Vec<Vec<&Utxo>> = Vec::new();
while !gen.done() {
let s = gen.gen_subset(&pool.utxos).collect::<Vec<_>>();
let w = s.into_iter().cloned().collect();
subsets.push(w);
subsets.push(s);
}

let non_empty_subsets: Vec<_> = subsets.clone().into_iter().filter(|x| !x.is_empty()).collect();

let selection: &Vec<Utxo> = u.choose(&non_empty_subsets).unwrap();

for s in subsets {
let sum: Amount = s.iter().map(|u| u.clone().value()).sum();
let selection_sum: Amount = selection.iter().map(|u| u.value()).sum();

// in theory this could be possible; looking for the seed.
if sum == selection_sum && selection.len() > 1 && *selection != s {
panic!();
}
}
// choose a set at random to be the target
let selection: &Vec<&Utxo> = u.choose(&subsets).unwrap();

// find the minmum fee_rate that will result in all utxos having a posiive
// effective_value
Expand Down Expand Up @@ -891,16 +877,20 @@ mod tests {
&pool.utxos,
);

let result: SignedAmount = coins.unwrap().map(|u| {
effective_value(
fee_rate,
u.satisfaction_weight(),
u.value(),
)
.unwrap()
}).sum();
if selection.is_empty() {
assert!(coins.is_none());
} else {
let result: SignedAmount = coins.unwrap().map(|u| {
effective_value(
fee_rate,
u.satisfaction_weight(),
u.value(),
)
.unwrap()
}).sum();

assert_eq!(result, target);
assert_eq!(result, target);
}

Ok(())
});
Expand Down

0 comments on commit 73c64fd

Please sign in to comment.