Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4f546d

Browse files
Merge pull request clearloop#10 from Raees678/master
Display stdout for test and execute commands, fix minor spacing in results displayed
2 parents 15a444f + 24e1714 commit d4f546d

File tree

2 files changed

+68
-39
lines changed

2 files changed

+68
-39
lines changed

β€Žsrc/cache/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ pub fn conn(p: String) -> SqliteConnection {
1818
}
1919

2020
/// Condition submit or test
21-
#[derive(Clone)]
21+
#[derive(Clone,Debug)]
2222
pub enum Run {
2323
Test,
2424
Submit,
2525
}
2626

27+
impl std::default::Default for Run {
28+
fn default() -> Self { Run::Submit }
29+
}
30+
31+
2732
/// Requests if data not download
2833
#[derive(Clone)]
2934
pub struct Cache(pub LeetCode);
@@ -285,6 +290,7 @@ impl Cache {
285290

286291
res.name = json.get("name")?.to_string();
287292
res.data_input = json.get("data_input")?.to_string();
293+
res.result_type = run;
288294
Ok(res)
289295
}
290296

β€Žsrc/cache/models.rs

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ pub struct RunCode {
196196
}
197197

198198
use super::parser::ssr;
199+
use crate::cache::Run;
200+
199201
/// verify result model
200202
#[derive(Debug, Deserialize)]
201203
pub struct VerifyResult {
@@ -204,6 +206,8 @@ pub struct VerifyResult {
204206
pub name: String,
205207
#[serde(skip)]
206208
pub data_input: String,
209+
#[serde(skip)]
210+
pub result_type: Run,
207211
#[serde(default)]
208212
lang: String,
209213
#[serde(default)]
@@ -256,17 +260,17 @@ impl std::fmt::Display for VerifyResult {
256260
// Pass Test
257261
write!(
258262
f,
259-
"\n{}{}{}\n{}{}{}{}{}{}\n",
263+
"\n{}{}{}\n{}{}{}{}{}{}\n",
260264
&self.status.status_msg.green().bold(),
261265
" Runtime: ".dimmed(),
262266
&self.status.status_runtime.dimmed(),
263-
"\n Your input: ",
267+
"\nYour input: ",
264268
&self.data_input.replace("\n", "↩"),
265-
"\n Output: ",
269+
"\nOutput: ",
266270
ca,
267-
"\n Expected: ",
271+
"\nExpected: ",
268272
eca,
269-
)
273+
)?
270274
} else if !self.submit.compare_result.is_empty() {
271275
// Submit Successfully
272276
// TODO: result shoule be all 1;
@@ -300,9 +304,9 @@ impl std::fmt::Display for VerifyResult {
300304
}
301305
write!(
302306
f,
303-
"\n{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}.\n",
304-
"Success\n\n".green().bold(),
305-
"Runtime: ".dimmed(),
307+
"\n{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}.\n\n",
308+
"Success\n\n".green().bold(),
309+
"Runtime: ".dimmed(),
306310
&self.status.status_runtime.bold(),
307311
", faster than ",
308312
rp.to_string().bold(),
@@ -312,7 +316,7 @@ impl std::fmt::Display for VerifyResult {
312316
" online submissions for ",
313317
&self.name,
314318
".\n\n",
315-
"Memory Usage: ".dimmed(),
319+
"Memory Usage: ".dimmed(),
316320
&self.status.status_memory.bold(),
317321
", less than ",
318322
mp.to_string().bold(),
@@ -321,38 +325,38 @@ impl std::fmt::Display for VerifyResult {
321325
&self.pretty_lang,
322326
" online submissions for ",
323327
&self.name,
324-
)
328+
)?
325329
} else {
326-
// Wrong Answer
330+
// Wrong Answer during testing
327331
write!(
328332
f,
329333
"\n{}{}{}\n{}{}{}{}{}{}\n",
330-
"Wrong Answer".red().bold(),
334+
"Wrong Answer".red().bold(),
331335
" Runtime: ".dimmed(),
332336
&self.status.status_runtime.dimmed(),
333-
"\n Your input: ",
337+
"\nYour input: ",
334338
&self.data_input.replace("\n", "↩"),
335-
"\n Output: ",
339+
"\nOutput: ",
336340
ca,
337-
"\n Expected: ",
341+
"\nExpected: ",
338342
eca,
339-
)
343+
)?
340344
}
341-
}
342-
// Failed some tests
345+
},
346+
// Failed some tests during submission
343347
11 => write!(
344348
f,
345-
"\n{}:\n\n{}{}\n{}{}\n{}{}\n",
349+
"\n{}\n\n{}{}\n{}{}\n{}{}\n",
346350
&self.status.status_msg.red().bold(),
347-
"Total Correct: ".green(),
351+
"Cases passed: ".green(),
348352
&self
349353
.analyse
350354
.total_correct
351355
.as_ref()
352356
.unwrap_or(&Number::from(0))
353357
.to_string()
354358
.green(),
355-
"Total Testcases: ".yellow(),
359+
"Total cases: ".yellow(),
356360
&self
357361
.analyse
358362
.total_testcases
@@ -361,38 +365,57 @@ impl std::fmt::Display for VerifyResult {
361365
.to_string()
362366
.bold()
363367
.yellow(),
364-
"Last TestCase: ".dimmed(),
365-
&self.submit.last_testcase.dimmed()
366-
),
367-
// Output Timeout Exceeded
368-
13 => write!(
369-
f,
370-
"\n{}:\n\n{:?}\n",
371-
&self.status.status_msg.yellow().bold(),
372-
&self.code_output,
373-
),
368+
"Last case: ".dimmed(),
369+
&self.submit.last_testcase.dimmed().replace("\n", "↩")
370+
)?,
374371
// Output Timeout Exceeded
375-
14 => write!(
372+
13 | 14 => write!(
376373
f,
377-
"\n{}:\n\n{:?}\n",
374+
"\n{}\n",
378375
&self.status.status_msg.yellow().bold(),
379-
&self.code_output,
380-
),
376+
)?,
381377
// Runtime error
382-
15 => write!(f, "\n{}\n", &self.status.status_msg.red().bold()),
378+
15 => write!(f, "\n{}\n", &self.status.status_msg.red().bold())?,
383379
// Compile Error
384380
20 => write!(
385381
f,
386382
"\n{}:\n\n{}\n",
387383
&self.status.status_msg.red().bold(),
388384
&self.error.full_compile_error
389-
),
390-
_ => write!(f, "{}", "\nUnknown Error...\n".red().bold()),
385+
)?,
386+
_ => write!(f, "{}", "\nUnknown Error...\n".red().bold())?,
387+
};
388+
389+
match &self.result_type {
390+
Run::Test => {
391+
if &self.code_output.len() > &0 {
392+
write!(
393+
f,
394+
"{}{}",
395+
"Stdout: ".purple(),
396+
&self.code_output.join("\n ")
397+
)
398+
} else {
399+
write!(f, "")
400+
}},
401+
_ => {
402+
if &self.std_output.len() > &0 {
403+
write!(
404+
f,
405+
"{}{}",
406+
"Stdout: ".purple(),
407+
&self.std_output.replace("\n", "\n ")
408+
)
409+
} else {
410+
write!(f, "")
411+
}
412+
},
391413
}
392414
}
393415
}
394416

395417
use verify::*;
418+
396419
mod verify {
397420
use super::super::parser::ssr;
398421
use serde::Deserialize;

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /