Beispiel #1
0
wbBool wbSolution(wbArg_t arg, void * data, int rows, int columns) {
    int ii;
    char * type;
    wbBool res;
    json_t * msg;
    char * expectedOutputFile;
    char * outputFile;
    json_t * inputFileArray;

    expectedOutputFile = wbArg_getExpectedOutputFile(arg);
    outputFile = wbArg_getOutputFile(arg);
    type = wbArg_getType(arg);

    wbAssert(type != NULL);
    wbAssert(expectedOutputFile != NULL);
    wbAssert(outputFile != NULL);

    res = wbSolution(expectedOutputFile, outputFile, type, data, rows, columns);

#if 1
    if (res) {
        _solution_correctQ = json_object();

        msg = json_string("Solution is correct.");

        json_object_set(_solution_correctQ, "CorrectQ", json_true());
        json_object_set(_solution_correctQ, "Message", msg);
    } else {
        msg = _solution_correctQ;
        _solution_correctQ = json_object();
        json_object_set(_solution_correctQ, "CorrectQ", json_false());
        json_object_set(_solution_correctQ, "Message", msg);
    }
#else
    if (res) {
        _solution_correctQ = json_true();
    } else {
        _solution_correctQ = json_false();
    }
#endif

    inputFileArray = json_array();

    for (ii = 0; ii < wbArg_getInputCount(arg); ii++) {
        char * file = wbArg_getInputFile(arg, ii);
        if (file != NULL) {
            json_array_append(inputFileArray, json_string(file));
        }
    }

    /*
    json_object_set(_solution_correctQ, "InputFiles", inputFileArray);
    json_object_set(_solution_correctQ, "ExpectedOutput", json_string(expectedOutputFile));
    json_object_set(_solution_correctQ, "OutputFile", json_string(outputFile));
    */

    return res;
}
Beispiel #2
0
wbBool wbSolution(wbArg_t arg, void *data, int rows, int columns,
                  int depth) {
  char *type;
  wbBool res;
  char *expectedOutputFile;
  char *outputFile;
  stringstream ss;

  expectedOutputFile = wbArg_getExpectedOutputFile(arg);
  outputFile         = wbArg_getOutputFile(arg);
  type               = wbArg_getType(arg);

  wbAssert(type != NULL);
  wbAssert(expectedOutputFile != NULL);
  wbAssert(outputFile != NULL);

  res = wbSolution(expectedOutputFile, outputFile, type, data, rows,
                   columns, depth);

  if (WB_USE_JSON11) {
    json11::Json json;
    if (res) {
      json = json11::Json::object{{"correctq", true},
                                  {"message", "The solution is correct"}};
    } else {
      json = json11::Json::object{{"correctq", false},
                                  {"message", _solution_correctQ}};
    }

#ifdef wbLogger_printOnLog
    if (wbLogger_printOnLog) {
      json11::Json e =
          json11::Json::object{{"type", "solution"}, {"data", json}};
      std::cout << e.dump() << std::endl;
    }
#endif /* wbLogger_printOnLog */

    solutionJSON = wbString_duplicate(json.string_value());
  } else {
    if (res) {
      ss << "{\n";
      ss << wbString_quote("correctq") << ": true,\n";
      ss << wbString_quote("message") << ": "
         << wbString_quote("Solution is correct.") << "\n";
      ss << "}";
    } else {
      ss << "{\n";
      ss << wbString_quote("correctq") << ": false,\n";
      ss << wbString_quote("message") << ": "
         << wbString_quote(_solution_correctQ) << "\n";
      ss << "}";
    }
    solutionJSON = wbString_duplicate(ss.str());
  }

  return res;
}
Beispiel #3
0
void wbArg_delete(wbArg_t arg) {
  if (wbArg_getInputCount(arg) > 0 && wbArg_getInputFiles(arg) != NULL) {
    int ii;
    for (ii = 0; ii < wbArg_getInputCount(arg); ii++) {
      wbDelete(wbArg_getInputFile(arg, ii));
    }
    wbDelete(wbArg_getInputFiles(arg));
    wbArg_setInputCount(arg, 0);
    wbArg_setInputFiles(arg, NULL);
  }
  if (wbArg_getOutputFile(arg)) {
    wbDelete(wbArg_getOutputFile(arg));
    wbArg_setOutputFile(arg, NULL);
  }
  if (wbArg_getExpectedOutputFile(arg)) {
    wbDelete(wbArg_getExpectedOutputFile(arg));
    wbArg_setExpectedOutputFile(arg, NULL);
  }
  if (wbArg_getType(arg)) {
    wbDelete(wbArg_getType(arg));
    wbArg_setType(arg, NULL);
  }
  return;
}