Skip to content

Commit

Permalink
SanityCheck for deprecated spaces in subtask name
Browse files Browse the repository at this point in the history
  • Loading branch information
dp1 committed Dec 6, 2023
1 parent cbd2f24 commit 49503f7
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/tools/find_bad_case/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ pub fn patch_task_for_batch(
name: Some(format!("batch-{}", batch_index)),
max_score: 100.0,
testcases,
span: None,
is_default: false,
..Default::default()
};
task.subtasks.insert(0, subtask);
}
Expand Down
42 changes: 24 additions & 18 deletions task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,28 +520,34 @@ where
self.subtask_id, score
)
})?;
let name = if line.len() >= 2 {
// Remove whitespaces for retrocompatibility with descriptions
let s = line[1].as_str();
Some(s.chars().filter(|&c| c != ' ' && c != '\t').collect())
let description = if line.len() >= 2 {
Some(line[1].as_str().to_string())
} else {
None
};
// Remove whitespaces for retrocompatibility with descriptions
let name = description
.as_deref()
.map(|s| s.chars().filter(|&c| c != ' ' && c != '\t').collect());
self.subtask_name = name.clone();
self.result.push(TaskInputEntry::Subtask(SubtaskInfo {
id: self.subtask_id,
name,
max_score: score,
testcases: HashMap::new(),
span: CodeSpan::from_str(
&self.file_path,
&self.file_content,
span.start(),
span.end() - span.start(),
)
.ok(),
is_default: false,
}));
self.result.push(TaskInputEntry::Subtask(
#[allow(deprecated)]
SubtaskInfo {
id: self.subtask_id,
name,
description,
max_score: score,
span: CodeSpan::from_str(
&self.file_path,
&self.file_content,
span.start(),
span.end() - span.start(),
)
.ok(),
is_default: false,
..Default::default()
},
));
self.subtask_id += 1;
Ok(())
}
Expand Down
8 changes: 2 additions & 6 deletions task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::path::Path;
use std::sync::Arc;

Expand Down Expand Up @@ -51,11 +50,9 @@ where

let mut default_subtask = Some(SubtaskInfo {
id: 0,
name: None,
max_score: 100.0,
testcases: HashMap::new(),
span: None,
is_default: true,
..Default::default()
});

let mut generators = find_source_file(
Expand Down Expand Up @@ -99,9 +96,7 @@ where
let path = path.strip_prefix(task_dir).unwrap_or(path);
entries.push(TaskInputEntry::Subtask(SubtaskInfo {
id: subtask_id,
name: None,
max_score: score.parse::<f64>().context("Invalid subtask score")?,
testcases: HashMap::new(),
span: CodeSpan::from_str(
path,
&content,
Expand All @@ -110,6 +105,7 @@ where
)
.ok(),
is_default: false,
..Default::default()
}));
subtask_id += 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::path::PathBuf;

use crate::ioi::format::italian_yaml::TaskInputEntry;
Expand Down Expand Up @@ -40,9 +39,8 @@ where
id: 0,
name: Some("static-testcases".into()),
max_score: 100.0,
testcases: HashMap::new(),
span: None,
is_default: true,
..Default::default()
}));
}
let id = self.index - 1; // offset caused by the first iteration
Expand Down
5 changes: 4 additions & 1 deletion task-maker-format/src/ioi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,17 @@ pub struct IOITask {
}

/// A subtask of a IOI task.
#[derive(Debug, Clone, Serialize, Deserialize, TypeScriptify)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeScriptify, Default)]
pub struct SubtaskInfo {
/// The id of the subtask.
pub id: SubtaskId,
/// The name of the subtask.
///
/// This is what is used for running the solutions' checks.
pub name: Option<String>,
/// Textual description of the subtask. (deprecated)
#[deprecated(note = "Use the `name` field instead")]
pub description: Option<String>,
/// The maximum score of the subtask, must be >= 0.
pub max_score: f64,
/// The testcases inside this subtask.
Expand Down
39 changes: 39 additions & 0 deletions task-maker-format/src/ioi/sanity_checks/subtasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,42 @@ impl SanityCheck for AllOutputsEqual {
Ok(())
}
}

/// Check if any subtask uses the deprecated `description` field.
#[derive(Debug, Default)]
pub struct DeprecatedDescriptionInSubtask;
make_sanity_check!(DeprecatedDescriptionInSubtask);

impl SanityCheck for DeprecatedDescriptionInSubtask {
type Task = IOITask;

fn name(&self) -> &'static str {
"DeprecatedDescriptionInSubtask"
}

fn category(&self) -> SanityCheckCategory {
SanityCheckCategory::Task
}

fn pre_hook(&self, task: &IOITask, eval: &mut EvaluationData) -> Result<(), Error> {
for subtask in task.subtasks.values() {
#[allow(deprecated)]
let description = subtask.description.as_deref();
match (subtask.name.as_deref(), description) {
(Some(a), Some(b)) if a != b => {
let mut diagnostic = Diagnostic::warning(format!(
"Subtask {} uses spaces and/or tabs in its name, which are now deprecated",
subtask.id
));
if let Some(span) = subtask.span.clone() {
diagnostic = diagnostic.with_code_span(span);
}
eval.add_diagnostic(diagnostic)?;
}
_ => {}
}
}

Ok(())
}
}
8 changes: 2 additions & 6 deletions task-maker-format/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ pub fn new_task_with_context(path: &Path) -> IOITask {
};
let st0 = task.subtasks.entry(0).or_insert(SubtaskInfo {
id: 0,
name: None,
max_score: 10.0,
testcases: HashMap::default(),
span: None,
is_default: false,
..Default::default()
});
st0.testcases.entry(0).or_insert_with(|| {
TestcaseInfo::new(
Expand All @@ -58,11 +56,9 @@ pub fn new_task_with_context(path: &Path) -> IOITask {
});
let st1 = task.subtasks.entry(1).or_insert(SubtaskInfo {
id: 1,
name: None,
max_score: 90.0,
testcases: HashMap::default(),
span: None,
is_default: false,
..Default::default()
});
st1.testcases.entry(1).or_insert_with(|| {
TestcaseInfo::new(
Expand Down

0 comments on commit 49503f7

Please sign in to comment.