1.0.9 • Published 4 years ago

envoijs v1.0.9

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

ENVOI LOGO

PR's Welcome

Envoi is a lightweight and robust code execution system capable of executing or judging test cases from source code across multiple languages that are easily extensible/integrated in your usage pattern

Currently Envoi supports: C++, Java, Python 3, Go, JavaScript (Node).

Envoi is fully compatible with TypeScript but can also be used seamlessly with JavaScript

 

Installation

Envoi requires the respective compile/run tools for each language intended to be used installed on the host system and added to PATH. These include | Langauge | Tool | | ------------- |:-------------:| | C++ | g++ | | Java | java jdk | | Python | Python | | Go | go | | JavaScript | node |

Npm installation

$ npm install envoijs

Basic Usage - JavaScript

const { Envoi, Languages, Verdict } = require('envoijs');
const runCodeExample = async () => {
  const sourceCode = `print("Hello",input())`;
  const result = await Envoi({
    input: 'From Envoi',
    sourceCode: sourceCode,
    language: Languages.PYTHON
  });
  console.log(result); //{ verdict: 'AC', output: 'Hello From Envoi' }
  if (result.verdict === Verdict.AC)
    //check verdict if accepted (indicating success)
    console.log('success');
};
runCodeExample();

API

Envoi(submission) : Promise<SubmissionVerdict>

Returns a promise resolving to a SubmissionVerdict

Parameters

submission

Type: Submission

Submission

An object type representing a submission

properties

sourceCode and language are required | Property | Type | description |default | | ------------- |:-------------:|-------------|--------------| | sourceCode |string | the source code to execute | - | | language | string | the programming language, can use the helper enum Languages |- | | input? | string | input fed into the program (stdin) | null| | testCases? | TestCase[] | test cases to run against the program | | | timeout? | number |milliseconds before timing out the program (TLE) | 5000 |

SubmissionVerdict

An object type representing the submission result

properties

PropertyTypedescription
verdictVerdictthe verdict of the submission -
outputstringthe output of the program, can also be a description of the compilation error/runtime error or a simple message. i.e "passed test cases"-

Verdict

An enum representing the verdict of a submission as strings

properties

PropertyValuedescription
AC'AC'The source code executed successfully/passed all test cases-
COMPILATION'COMPILATION'Compilation error-
ERROR'ERROR'An error during the whole execution process
MLE'MLE'Memory limit exceeded (NOT YET IMPLEMENTED)
PENDING'PENDING'Submission is pending
RUNTIME'RUNTIME'Runtime error
TLE'TLE'Time limit exceeded (timedout)
WA'WA'Wrong answer (Failed test cases)

Languages

An enum representing all the supported languages as string

properties

PropertyValue
CPP'c++'-
GO'go'
JAVA'java'
JAVASCRIPT'javascript'
PYTHON'python'

TestCase

An object type representing a submission testcase

properties

both properties are required | Property | Type | description | | ------------- |:-------------:|-------------| | input |string | input for the test case (stdin) |
| expectedOutput | string |expected output for the test case|-

Running against test cases - JavaScript

const { Envoi, Languages, Verdict } = require('envoijs');
const runCodeExample = async () => {
  const sourceCode = `
  #include <iostream>
  using namespace std;
  int main(){
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
    return 0;
  }`;
  const result = await Envoi({
    sourceCode: sourceCode,
    language: Languages.CPP,
    testCases: [
      {
        input: '2 3',
        expectedOutput: '5'
      },
      {
        input: '21 4',
        expectedOutput: '27' //fail this test case
      }
    ]
  });
  console.log(result); //{ output: 'For input: 21 4\nFound: 25\nExpected:27', verdict: 'WA' }
  if (result.verdict === Verdict.WA) console.log('WRONG ANSWER');
};
runCodeExample();

Running against test cases - TypeScript

import { Envoi, Languages, Verdict, SubmissionVerdict, TestCase } from 'envoijs';
const runCodeExample = async () => {
  const sourceCode = `
    #include <iostream>
    using namespace std;
    int main(){
      int a,b;
      cin>>a>>b;
      cout<<a+b<<endl;
      return 0;
    }`;
  const testCases: TestCase[] = [
    {
      input: '2 3',
      expectedOutput: '5'
    },
    {
      input: '21 4',
      expectedOutput: '27' //fail this test case
    }
  ];
  const result: SubmissionVerdict = await Envoi({
    sourceCode: sourceCode,
    language: Languages.CPP,
    testCases: testCases
  });
  console.log(result); //{ output: 'For input: 21 4\nFound: 25\nExpected:27', verdict: 'WA' }
  if (result.verdict === Verdict.WA) console.log('WRONG ANSWER');
};
runCodeExample();
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago