Skip to main content

aj_models/
verdicts.rs

1//! Testing verdicts
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6/// Subgroup's verdict
7#[derive(Clone, Default, PartialEq, Eq, Debug, Serialize, Deserialize)]
8#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
9#[cfg_attr(
10    feature = "sqlx",
11    sqlx(type_name = "subgroup_verdict", rename_all = "snake_case")
12)]
13#[serde(rename_all = "snake_case")]
14pub enum SubgroupVerdict {
15    /// Ok, full score
16    #[default]
17    Ok,
18    /// Solution panicked
19    RuntimeError,
20    /// Solution is too slow
21    TimeLimitExceeded,
22    /// Solution uses too much memory
23    MemoryLimitExceeded,
24    /// Solution violates security (e.g. tries to access the Internet)
25    SecurityError,
26    /// Solution gives the wrong answer
27    WrongAnswer,
28    /// Solution prints answer incorrectly
29    PresentationError,
30    /// Skipped testing for this subgroup because some of it's dependencies' verdicts' aren't `Ok`
31    Skipped,
32    /// Testing on this subgroup now
33    Testing,
34}
35
36impl fmt::Display for SubgroupVerdict {
37    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38        let converted = match self {
39            Self::Ok => "Ok",
40            Self::RuntimeError => "RuntimeError",
41            Self::TimeLimitExceeded => "TimeLimitExceeded",
42            Self::MemoryLimitExceeded => "MemoryLimitExceeded",
43            Self::SecurityError => "SecurityError",
44            Self::WrongAnswer => "WrongAnswer",
45            Self::PresentationError => "PresentationError",
46            Self::Skipped => "Skipped",
47            Self::Testing => "Testing",
48        };
49        write!(f, "{converted}")
50    }
51}
52
53impl std::error::Error for SubgroupVerdict {}
54
55/// Total testing verdict
56#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
57#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
58#[cfg_attr(
59    feature = "sqlx",
60    sqlx(type_name = "total_verdict", rename_all = "snake_case")
61)]
62#[serde(rename_all = "snake_case")]
63pub enum TotalVerdict {
64    /// Ok, full score
65    Ok,
66    /// Not full score (may be zero)
67    PartialSolution,
68    /// In testing queue now
69    Pending,
70    /// Compiling solution now
71    Compiling,
72    /// Compilation error
73    CompilationError,
74    /// Testing this submission now
75    Testing,
76    /// Invalid problem (e.g. invalid config)
77    InvalidProblem,
78    /// Invalid request (e.g. problem not exist)
79    InvalidRequest,
80    /// Internal error
81    Bug,
82}
83
84impl fmt::Display for TotalVerdict {
85    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86        let converted = match self {
87            Self::Ok => "Ok",
88            Self::PartialSolution => "PartialSolution",
89            Self::Pending => "Pending",
90            Self::Compiling => "Compiling",
91            Self::CompilationError => "CompilationError",
92            Self::Testing => "Testing",
93            Self::InvalidProblem => "InvalidProblem",
94            Self::InvalidRequest => "InvalidRequest",
95            Self::Bug => "Bug",
96        };
97        write!(f, "{converted}")
98    }
99}
100
101impl std::error::Error for TotalVerdict {}