Skip to content

Commit 05e7ce9

Browse files
committed
Added failing test for tuple BnB metric ordering propagation
1 parent 89f5568 commit 05e7ce9

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/bnb.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ impl BnbMetric for MinExcessThenWeight {
5252
}
5353
}
5454

55+
#[derive(Clone, Copy)]
56+
struct OrderSensitive;
57+
58+
impl BnbMetric for OrderSensitive {
59+
fn score(&mut self, _cs: &CoinSelector<'_>) -> Option<Ordf32> {
60+
Some(Ordf32(0.0))
61+
}
62+
63+
fn bound(&mut self, _cs: &CoinSelector<'_>) -> Option<Ordf32> {
64+
Some(Ordf32(0.0))
65+
}
66+
67+
fn requires_ordering_by_descending_value_pwu(&self) -> bool {
68+
true
69+
}
70+
}
71+
72+
#[derive(Clone, Copy)]
73+
struct NoOrderMetric;
74+
75+
impl BnbMetric for NoOrderMetric {
76+
fn score(&mut self, _cs: &CoinSelector<'_>) -> Option<Ordf32> {
77+
Some(Ordf32(0.0))
78+
}
79+
80+
fn bound(&mut self, _cs: &CoinSelector<'_>) -> Option<Ordf32> {
81+
Some(Ordf32(0.0))
82+
}
83+
}
84+
5585
#[test]
5686
/// Detect regressions/improvements by making sure it always finds the solution in the same
5787
/// number of iterations.
@@ -139,6 +169,21 @@ fn bnb_finds_solution_if_possible_in_n_iter() {
139169
assert_eq!(excess, 0);
140170
}
141171

172+
#[test]
173+
fn bnb_tuple_metric_respects_ordering_requirement() {
174+
assert!(
175+
((OrderSensitive, 1.0), (OrderSensitive, 1.0))
176+
.requires_ordering_by_descending_value_pwu()
177+
);
178+
assert!(
179+
((OrderSensitive, 1.0), (NoOrderMetric, 1.0))
180+
.requires_ordering_by_descending_value_pwu()
181+
);
182+
assert!(
183+
!((NoOrderMetric, 1.0), (NoOrderMetric, 1.0)).requires_ordering_by_descending_value_pwu()
184+
);
185+
}
186+
142187
proptest! {
143188
#[test]
144189
fn bnb_always_finds_solution_if_possible(num_inputs in 1usize..18, target_value in 0u64..10_000) {

0 commit comments

Comments
 (0)