use super::super::{Broadcast, Change, Claim, Decision, Exchange, Rules};
use crate::id::AgentId;
const I: AgentId = AgentId(1);
const K: AgentId = AgentId(2);
const M: AgentId = AgentId(0);
const fn claim(winner: AgentId, bid: u64, time: u64) -> Claim {
Claim {
winner: Some(winner),
bid,
time,
}
}
fn decide(rules: Rules, sent: Claim, held: Claim) -> Decision {
Exchange {
receiver: I,
sender: K,
epsilon: 1,
rules,
third_party_ties: true,
}
.decide(sent, held)
}
fn marked(row: u8, sent: Claim, held: Claim, change: Change, broadcast: Broadcast) {
let expected = Decision {
change,
broadcast,
row,
};
assert_eq!(decide(Rules::Thesis2012, sent, held), expected, "row {row}");
}
#[test]
fn marked_updates_push_the_senders_time() {
marked(
1,
claim(K, 9, 5),
claim(I, 5, 5),
Change::UpdatePast,
Broadcast::Own,
);
marked(
17,
claim(M, 9, 5),
claim(I, 5, 5),
Change::UpdatePast,
Broadcast::Own,
);
}
#[test]
fn marked_leaves_push_the_receivers_time() {
let none = Claim::empty_at(9);
marked(
3,
claim(K, 4, 5),
claim(I, 5, 5),
Change::KeepPast,
Broadcast::Own,
);
marked(
13,
claim(I, 5, 5),
claim(I, 5, 5),
Change::KeepPast,
Broadcast::Nothing,
);
marked(
15,
claim(I, 5, 5),
claim(M, 5, 5),
Change::KeepPast,
Broadcast::Own,
);
marked(
19,
claim(M, 4, 5),
claim(I, 5, 5),
Change::KeepPast,
Broadcast::Own,
);
marked(31, none, claim(I, 5, 5), Change::KeepPast, Broadcast::Own);
marked(32, none, claim(K, 5, 5), Change::KeepPast, Broadcast::Own);
}
#[test]
fn other_rows_follow_2011() {
let cases = [
(claim(K, 5, 9), claim(K, 5, 5)),
(claim(K, 4, 9), claim(M, 5, 5)),
(claim(I, 5, 5), claim(K, 5, 5)),
(claim(M, 5, 9), claim(K, 5, 5)),
(Claim::empty_at(9), claim(M, 5, 5)),
];
for (sent, held) in cases {
assert_eq!(
decide(Rules::Thesis2012, sent, held),
decide(Rules::Infotech2011, sent, held)
);
}
}