use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CorpusFormat {
Bash,
Makefile,
Dockerfile,
}
impl std::fmt::Display for CorpusFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bash => write!(f, "bash"),
Self::Makefile => write!(f, "makefile"),
Self::Dockerfile => write!(f, "dockerfile"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum CorpusTier {
Trivial = 1,
Standard = 2,
Complex = 3,
Adversarial = 4,
Production = 5,
}
impl CorpusTier {
pub fn weight(&self) -> f64 {
match self {
Self::Trivial => 1.0,
Self::Standard => 1.5,
Self::Complex => 2.0,
Self::Adversarial => 2.5,
Self::Production => 3.0,
}
}
pub fn target_rate(&self) -> f64 {
match self {
Self::Trivial => 1.0,
Self::Standard => 0.99,
Self::Complex => 0.98,
Self::Adversarial => 0.95,
Self::Production => 0.95,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Grade {
APlus,
A,
B,
C,
D,
F,
}
impl Grade {
pub fn from_score(score: f64) -> Self {
if score >= 97.0 {
Self::APlus
} else if score >= 90.0 {
Self::A
} else if score >= 80.0 {
Self::B
} else if score >= 70.0 {
Self::C
} else if score >= 60.0 {
Self::D
} else {
Self::F
}
}
}
impl std::fmt::Display for Grade {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::APlus => write!(f, "A+"),
Self::A => write!(f, "A"),
Self::B => write!(f, "B"),
Self::C => write!(f, "C"),
Self::D => write!(f, "D"),
Self::F => write!(f, "F"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CorpusEntry {
pub id: String,
pub name: String,
pub description: String,
pub format: CorpusFormat,
pub tier: CorpusTier,
pub input: String,
pub expected_output: String,
pub shellcheck: bool,
pub deterministic: bool,
pub idempotent: bool,
}
include!("mod_corpusentry.rs");