Skip to content

Commit

Permalink
Merge branch 'main' into anca/mixer-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Dec 6, 2023
2 parents a7e42f6 + 20b4ef3 commit e97227b
Showing 1 changed file with 116 additions and 1 deletion.
117 changes: 116 additions & 1 deletion Code/round/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::fmt;

use malachite_common::{Context, Round, ValueId};

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Input<Ctx>
where
Ctx: Context,
Expand Down Expand Up @@ -73,3 +74,117 @@ where
/// L65
TimeoutPrecommit,
}

impl<Ctx: Context> Clone for Input<Ctx> {
fn clone(&self) -> Self {
match self {
Input::NewRound => Input::NewRound,
Input::ProposeValue(value) => Input::ProposeValue(value.clone()),
Input::Proposal(proposal) => Input::Proposal(proposal.clone()),
Input::InvalidProposal => Input::InvalidProposal,
Input::ProposalAndPolkaPrevious(proposal) => {
Input::ProposalAndPolkaPrevious(proposal.clone())
}
Input::InvalidProposalAndPolkaPrevious(proposal) => {
Input::InvalidProposalAndPolkaPrevious(proposal.clone())
}
Input::PolkaValue(value_id) => Input::PolkaValue(value_id.clone()),
Input::PolkaAny => Input::PolkaAny,
Input::PolkaNil => Input::PolkaNil,
Input::ProposalAndPolkaCurrent(proposal) => {
Input::ProposalAndPolkaCurrent(proposal.clone())
}
Input::PrecommitAny => Input::PrecommitAny,
Input::ProposalAndPrecommitValue(proposal) => {
Input::ProposalAndPrecommitValue(proposal.clone())
}
Input::PrecommitValue(value_id) => Input::PrecommitValue(value_id.clone()),
Input::SkipRound(round) => Input::SkipRound(*round),
Input::TimeoutPropose => Input::TimeoutPropose,
Input::TimeoutPrevote => Input::TimeoutPrevote,
Input::TimeoutPrecommit => Input::TimeoutPrecommit,
}
}
}

impl<Ctx: Context> PartialEq for Input<Ctx> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Input::NewRound, Input::NewRound) => true,
(Input::ProposeValue(value), Input::ProposeValue(other_value)) => value == other_value,
(Input::Proposal(proposal), Input::Proposal(other_proposal)) => {
proposal == other_proposal
}
(Input::InvalidProposal, Input::InvalidProposal) => true,
(
Input::ProposalAndPolkaPrevious(proposal),
Input::ProposalAndPolkaPrevious(other_proposal),
) => proposal == other_proposal,
(
Input::InvalidProposalAndPolkaPrevious(proposal),
Input::InvalidProposalAndPolkaPrevious(other_proposal),
) => proposal == other_proposal,
(Input::PolkaValue(value_id), Input::PolkaValue(other_value_id)) => {
value_id == other_value_id
}
(Input::PolkaAny, Input::PolkaAny) => true,
(Input::PolkaNil, Input::PolkaNil) => true,
(
Input::ProposalAndPolkaCurrent(proposal),
Input::ProposalAndPolkaCurrent(other_proposal),
) => proposal == other_proposal,
(Input::PrecommitAny, Input::PrecommitAny) => true,
(
Input::ProposalAndPrecommitValue(proposal),
Input::ProposalAndPrecommitValue(other_proposal),
) => proposal == other_proposal,
(Input::PrecommitValue(value_id), Input::PrecommitValue(other_value_id)) => {
value_id == other_value_id
}
(Input::SkipRound(round), Input::SkipRound(other_round)) => round == other_round,
(Input::TimeoutPropose, Input::TimeoutPropose) => true,
(Input::TimeoutPrevote, Input::TimeoutPrevote) => true,
(Input::TimeoutPrecommit, Input::TimeoutPrecommit) => true,
_ => false,
}
}
}

impl<Ctx: Context> Eq for Input<Ctx> {}

impl<Ctx> fmt::Debug for Input<Ctx>
where
Ctx: Context,
Ctx::Value: fmt::Debug,
Ctx::Proposal: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Input::NewRound => write!(f, "NewRound"),
Input::ProposeValue(value) => write!(f, "ProposeValue({:?})", value),
Input::Proposal(proposal) => write!(f, "Proposal({:?})", proposal),
Input::InvalidProposal => write!(f, "InvalidProposal"),
Input::ProposalAndPolkaPrevious(proposal) => {
write!(f, "ProposalAndPolkaPrevious({:?})", proposal)
}
Input::InvalidProposalAndPolkaPrevious(proposal) => {
write!(f, "InvalidProposalAndPolkaPrevious({:?})", proposal)
}
Input::PolkaValue(value_id) => write!(f, "PolkaValue({:?})", value_id),
Input::PolkaAny => write!(f, "PolkaAny"),
Input::PolkaNil => write!(f, "PolkaNil"),
Input::ProposalAndPolkaCurrent(proposal) => {
write!(f, "ProposalAndPolkaCurrent({:?})", proposal)
}
Input::PrecommitAny => write!(f, "PrecommitAny"),
Input::ProposalAndPrecommitValue(proposal) => {
write!(f, "ProposalAndPrecommitValue({:?})", proposal)
}
Input::PrecommitValue(value_id) => write!(f, "PrecommitValue({:?})", value_id),
Input::SkipRound(round) => write!(f, "SkipRound({:?})", round),
Input::TimeoutPropose => write!(f, "TimeoutPropose"),
Input::TimeoutPrevote => write!(f, "TimeoutPrevote"),
Input::TimeoutPrecommit => write!(f, "TimeoutPrecommit"),
}
}
}

0 comments on commit e97227b

Please sign in to comment.