use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum JudgeVerdict {
Accepted,
WrongAnswer,
TimeLimitExceeded,
MemoryLimitExceeded,
RuntimeError,
CompilationError,
InternalError,
}
impl JudgeVerdict {
#[must_use]
pub const fn as_code(self) -> &'static str {
match self {
Self::Accepted => "AC",
Self::WrongAnswer => "WA",
Self::TimeLimitExceeded => "TLE",
Self::MemoryLimitExceeded => "MLE",
Self::RuntimeError => "RE",
Self::CompilationError => "CE",
Self::InternalError => "IE",
}
}
#[must_use]
pub fn from_code(code: &str) -> Option<Self> {
match code {
"AC" => Some(Self::Accepted),
"WA" => Some(Self::WrongAnswer),
"TLE" => Some(Self::TimeLimitExceeded),
"MLE" => Some(Self::MemoryLimitExceeded),
"RE" => Some(Self::RuntimeError),
"CE" => Some(Self::CompilationError),
"IE" => Some(Self::InternalError),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum LocalFailure {
Compile,
Runtime,
TimeLimit,
MemoryLimit,
OutputLimit,
Cancelled,
Harness,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum LocalVerdict {
CasePass,
ExecutionPass,
CaseFail,
Error,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn judge_verdict_codes_roundtrip() {
for verdict in [
JudgeVerdict::Accepted,
JudgeVerdict::WrongAnswer,
JudgeVerdict::TimeLimitExceeded,
JudgeVerdict::MemoryLimitExceeded,
JudgeVerdict::RuntimeError,
JudgeVerdict::CompilationError,
JudgeVerdict::InternalError,
] {
assert_eq!(JudgeVerdict::from_code(verdict.as_code()), Some(verdict));
}
}
#[test]
fn judge_verdict_rejects_unknown_codes() {
assert_eq!(JudgeVerdict::from_code(""), None);
assert_eq!(JudgeVerdict::from_code("AC "), None);
assert_eq!(JudgeVerdict::from_code("OK"), None);
}
}