File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212} from './models' ;
1313import getOutput from './utils/getOutput' ;
1414import saveCode from './utils/saveCode' ;
15+ import matchLines from './utils/matchLines' ;
1516
1617interface RunnerOpts {
1718 id : string ;
@@ -93,7 +94,7 @@ export default class Runner {
9394 if ( exitCode === 124 ) {
9495 remarks = 'Time limit exceeded' ;
9596 } else if ( exitCode === 0 ) {
96- remarks = expectedOutput . trim ( ) === obtainedOutput . trim ( ) ? 'Pass' : 'Fail' ;
97+ remarks = matchLines ( expectedOutput , obtainedOutput ) ;
9798 } else {
9899 remarks = 'Error' ;
99100 }
Original file line number Diff line number Diff line change 1+ export default function matchLines ( expected : string , obtained : string ) : 'Pass' | 'Fail' {
2+ function splitAndTrim ( code : string ) {
3+ return code . split ( '\n' ) . map ( ( sentence ) => sentence . trim ( ) ) ;
4+ }
5+
6+ const expectedArray = splitAndTrim ( expected ) ;
7+ const obtainedArray = splitAndTrim ( obtained ) ;
8+
9+ const minLength = Math . min ( expectedArray . length , obtainedArray . length ) ;
10+
11+ for ( let i = 0 ; i < minLength ; i += 1 ) {
12+ if ( expectedArray [ i ] !== obtainedArray [ i ] ) {
13+ return 'Fail' ;
14+ }
15+ }
16+
17+ return 'Pass' ;
18+ }
You can’t perform that action at this time.
0 commit comments