- enhancement: 3 compare mode for problem cases.

This commit is contained in:
Roy Qu 2023-08-19 18:01:16 +08:00
parent c63d0e7187
commit 4be629727d
16 changed files with 828 additions and 723 deletions

View File

@ -34,6 +34,7 @@ Red Panda C++ Version 2.24
- enhancement: Better layout for compiler options page.
- enhancement: False branches are displayed as comments.
- enhancement: Support SDCC Project.
- enhancement: 3 compare mode for problem cases.
Red Panda C++ Version 2.23

View File

@ -130,6 +130,11 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
ui->cbProblemCaseValidateType->blockSignals(true);
ui->cbProblemCaseValidateType->addItem(tr("Exact"));
ui->cbProblemCaseValidateType->addItem(tr("Ignore leading/trailing spaces"));
ui->cbProblemCaseValidateType->addItem(tr("Ignore spaces"));
ui->cbProblemCaseValidateType->blockSignals(false);
addActions( this->findChildren<QAction *>(QString(), Qt::FindChildrenRecursively));
//custom actions
@ -968,7 +973,7 @@ void MainWindow::applySettings()
showHideMessagesTab(ui->tabProblem, pSettings->ui().showProblem()
&& pSettings->executor().enableProblemSet());
ui->chkIgnoreSpaces->setChecked(pSettings->executor().ignoreSpacesWhenValidatingCases());
ui->cbProblemCaseValidateType->setCurrentIndex((int)(pSettings->executor().problemCaseValidateType()));
ui->actionInterrupt->setVisible(pSettings->debugger().useGDBServer());
//icon sets for editors
updateEditorSettings();
@ -6057,7 +6062,7 @@ void MainWindow::onOJProblemCaseFinished(const QString& id, int current, int tot
if (row>=0) {
POJProblemCase problemCase = mOJProblemModel.getCase(row);
ProblemCaseValidator validator;
problemCase->testState = validator.validate(problemCase,pSettings->executor().ignoreSpacesWhenValidatingCases())?
problemCase->testState = validator.validate(problemCase,pSettings->executor().problemCaseValidateType())?
ProblemCaseTestState::Passed:
ProblemCaseTestState::Failed;
mOJProblemModel.update(row);
@ -9623,14 +9628,6 @@ void MainWindow::on_actionToggle_Messages_Panel_triggered()
stretchMessagesPanel(ui->tabMessages->isShrinked());
}
void MainWindow::on_chkIgnoreSpaces_stateChanged(int /*arg1*/)
{
pSettings->executor().setIgnoreSpacesWhenValidatingCases(ui->chkIgnoreSpaces->isChecked());
}
void MainWindow::on_actionRaylib_Manual_triggered()
{
if (pSettings->environment().language()=="zh_CN") {
@ -10087,3 +10084,10 @@ bool MainWindow::openingFiles() const
return mOpeningFiles;
}
void MainWindow::on_cbProblemCaseValidateType_currentIndexChanged(int index)
{
pSettings->executor().setProblemCaseValidateType((ProblemCaseValidateType)index);
pSettings->executor().save();
}

View File

@ -767,8 +767,6 @@ private slots:
void on_actionToggle_Messages_Panel_triggered();
void on_chkIgnoreSpaces_stateChanged(int arg1);
void on_actionRaylib_Manual_triggered();
void on_actionSelect_Word_triggered();
@ -850,6 +848,8 @@ private slots:
void on_actionTurtle_Graphics_Manual_triggered();
void on_cbProblemCaseValidateType_currentIndexChanged(int index);
private:
Ui::MainWindow *ui;
bool mFullInitialized;

View File

@ -965,7 +965,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>6</number>
</property>
<property name="iconSize">
<size>
@ -2060,11 +2060,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="chkIgnoreSpaces">
<property name="text">
<string>Ignore Spaces</string>
</property>
</widget>
<widget class="QComboBox" name="cbProblemCaseValidateType"/>
</item>
</layout>
</widget>

View File

@ -15,14 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "problemcasevalidator.h"
#include "../utils.h"
ProblemCaseValidator::ProblemCaseValidator()
{
}
bool ProblemCaseValidator::validate(POJProblemCase problemCase, bool ignoreSpaces)
bool ProblemCaseValidator::validate(POJProblemCase problemCase, ProblemCaseValidateType type)
{
if (!problemCase)
return false;
@ -44,18 +43,31 @@ bool ProblemCaseValidator::validate(POJProblemCase problemCase, bool ignoreSpace
}
}
int count=std::min(output.count(), expected.count());
switch(type) {
case ProblemCaseValidateType::Exact:
for (int i=0;i<count;i++) {
if (ignoreSpaces) {
if (!equalIgnoringSpaces(output[i],expected[i])) {
problemCase->firstDiffLine = i;
return false;
}
} else {
if (output[i]!=expected[i]) {
problemCase->firstDiffLine = i;
return false;
}
}
break;
case ProblemCaseValidateType::IgnoreLeadingTrailingSpaces:
for (int i=0;i<count;i++) {
if (output[i].trimmed()!=expected[i].trimmed()) {
problemCase->firstDiffLine = i;
return false;
}
}
break;
case ProblemCaseValidateType::IgnoreSpaces:
for (int i=0;i<count;i++) {
if (!equalIgnoringSpaces(output[i],expected[i])) {
problemCase->firstDiffLine = i;
return false;
}
}
break;
}
if (output.count()<expected.count()) {
problemCase->firstDiffLine=output.count();

View File

@ -18,12 +18,13 @@
#define PROBLEMCASEVALIDATOR_H
#include "ojproblemset.h"
#include "../utils.h"
class ProblemCaseValidator
{
public:
ProblemCaseValidator();
bool validate(POJProblemCase problemCase,bool ignoreSpaces);
bool validate(POJProblemCase problemCase, ProblemCaseValidateType type);
private:
bool equalIgnoringSpaces(const QString& s1, const QString& s2);
QStringList split(const QString& s);

View File

@ -2458,31 +2458,6 @@ void Settings::CompilerSet::setExecutables()
mMake = findProgramInBinDirs(MAKE_PROGRAM);
#ifdef Q_OS_WIN
mResourceCompiler = findProgramInBinDirs(WINDRES_PROGRAM);
if (mMake.isEmpty()) {
mMake = findProgramInBinDirs(MAKE2_PROGRAM);
}
if (mMake.isEmpty()) {
QSet<QString> searched;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH");
QStringList pathList = path.split(PATH_SEPARATOR);
QString folder;
for (int i=pathList.count()-1;i>=0;i--) {
folder = pathList[i];
if (searched.contains(folder))
continue;
searched.insert(folder);
QDir dir(folder);
if (dir.exists(MAKE_PROGRAM)) {
mMake = dir.absoluteFilePath(MAKE_PROGRAM);
break;
} else if (dir.exists(MAKE2_PROGRAM)) {
mMake = dir.absoluteFilePath(MAKE2_PROGRAM);
break;
}
}
}
#endif
}
@ -3962,16 +3937,6 @@ void Settings::Executor::setCompetivieCompanionPort(int newCompetivieCompanionPo
mCompetivieCompanionPort = newCompetivieCompanionPort;
}
bool Settings::Executor::ignoreSpacesWhenValidatingCases() const
{
return mIgnoreSpacesWhenValidatingCases;
}
void Settings::Executor::setIgnoreSpacesWhenValidatingCases(bool newIgnoreSpacesWhenValidatingCases)
{
mIgnoreSpacesWhenValidatingCases = newIgnoreSpacesWhenValidatingCases;
}
bool Settings::Executor::caseEditorFontOnlyMonospaced() const
{
return mCaseEditorFontOnlyMonospaced;
@ -4022,6 +3987,16 @@ void Settings::Executor::setRedirectStderrToToolLog(bool newRedirectStderrToTool
mRedirectStderrToToolLog = newRedirectStderrToToolLog;
}
ProblemCaseValidateType Settings::Executor::problemCaseValidateType() const
{
return mProblemCaseValidateType;
}
void Settings::Executor::setProblemCaseValidateType(ProblemCaseValidateType newProblemCaseValidateType)
{
mProblemCaseValidateType = newProblemCaseValidateType;
}
bool Settings::Executor::convertHTMLToTextForInput() const
{
return mConvertHTMLToTextForInput;
@ -4096,7 +4071,7 @@ void Settings::Executor::doSave()
saveValue("competitive_companion_port", mCompetivieCompanionPort);
saveValue("input_convert_html", mConvertHTMLToTextForInput);
saveValue("expected_convert_html", mConvertHTMLToTextForExpected);
saveValue("ignore_spaces_when_validating_cases", mIgnoreSpacesWhenValidatingCases);
saveValue("problem_case_validate_type", (int)mProblemCaseValidateType);
saveValue("redirect_stderr_to_toollog", mRedirectStderrToToolLog);
saveValue("case_editor_font_name",mCaseEditorFontName);
saveValue("case_editor_font_size",mCaseEditorFontSize);
@ -4131,7 +4106,7 @@ void Settings::Executor::doLoad()
mCompetivieCompanionPort = intValue("competitive_companion_port",10045);
mConvertHTMLToTextForInput = boolValue("input_convert_html", false);
mConvertHTMLToTextForExpected = boolValue("expected_convert_html", false);
mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false);
mProblemCaseValidateType =(ProblemCaseValidateType)intValue("problem_case_validate_type", (int)ProblemCaseValidateType::Exact);
mRedirectStderrToToolLog = boolValue("redirect_stderr_to_toollog", false);
#ifdef Q_OS_WIN

View File

@ -904,9 +904,6 @@ public:
int competivieCompanionPort() const;
void setCompetivieCompanionPort(int newCompetivieCompanionPort);
bool ignoreSpacesWhenValidatingCases() const;
void setIgnoreSpacesWhenValidatingCases(bool newIgnoreSpacesWhenValidatingCases);
const QString &caseEditorFontName() const;
void setCaseEditorFontName(const QString &newCaseEditorFontName);
@ -934,6 +931,9 @@ public:
bool redirectStderrToToolLog() const;
void setRedirectStderrToToolLog(bool newRedirectStderrToToolLog);
ProblemCaseValidateType problemCaseValidateType() const;
void setProblemCaseValidateType(ProblemCaseValidateType newProblemCaseValidateType);
private:
// general
bool mPauseConsole;
@ -950,6 +950,7 @@ public:
bool mConvertHTMLToTextForInput;
bool mConvertHTMLToTextForExpected;
bool mIgnoreSpacesWhenValidatingCases;
ProblemCaseValidateType mProblemCaseValidateType;
bool mRedirectStderrToToolLog;
QString mCaseEditorFontName;
int mCaseEditorFontSize;

View File

@ -24,6 +24,10 @@ ExecutorProblemSetWidget::ExecutorProblemSetWidget(const QString& name, const QS
ui(new Ui::ExecutorProblemSetWidget)
{
ui->setupUi(this);
ui->cbProblemCaseValidateType->addItem(tr("Exact"));
ui->cbProblemCaseValidateType->addItem(tr("Ignore leading/trailing spaces"));
ui->cbProblemCaseValidateType->addItem(tr("Ignore spaces"));
}
ExecutorProblemSetWidget::~ExecutorProblemSetWidget()
@ -39,7 +43,7 @@ void ExecutorProblemSetWidget::doLoad()
ui->chkConvertInputHTML->setChecked(pSettings->executor().convertHTMLToTextForInput());
ui->chkConvertExpectedHTML->setChecked(pSettings->executor().convertHTMLToTextForExpected());
ui->chkIgnoreSpacesWhenValidatingCases->setChecked(pSettings->executor().ignoreSpacesWhenValidatingCases());
ui->cbProblemCaseValidateType->setCurrentIndex((int)(pSettings->executor().problemCaseValidateType()));
ui->chkRedirectStderr->setChecked(pSettings->executor().redirectStderrToToolLog());
ui->cbFont->setCurrentFont(QFont(pSettings->executor().caseEditorFontName()));
@ -58,7 +62,7 @@ void ExecutorProblemSetWidget::doSave()
pSettings->executor().setCompetivieCompanionPort(ui->spinPortNumber->value());
pSettings->executor().setConvertHTMLToTextForInput(ui->chkConvertInputHTML->isChecked());
pSettings->executor().setConvertHTMLToTextForExpected(ui->chkConvertExpectedHTML->isChecked());
pSettings->executor().setIgnoreSpacesWhenValidatingCases(ui->chkIgnoreSpacesWhenValidatingCases->isChecked());
pSettings->executor().setProblemCaseValidateType((ProblemCaseValidateType)(ui->cbProblemCaseValidateType->currentIndex()));
pSettings->executor().setRedirectStderrToToolLog(ui->chkRedirectStderr->isChecked());
pSettings->executor().setCaseEditorFontName(ui->cbFont->currentFont().family());
pSettings->executor().setCaseEditorFontOnlyMonospaced(ui->chkOnlyMonospaced->isChecked());
@ -79,4 +83,3 @@ void ExecutorProblemSetWidget::on_chkOnlyMonospaced_stateChanged(int )
ui->cbFont->setFontFilters(QFontComboBox::FontFilter::AllFonts);
}
}

View File

@ -39,6 +39,7 @@ protected:
void doSave() override;
private slots:
void on_chkOnlyMonospaced_stateChanged(int arg1);
};
#endif // EXECUTORPROBLEMSETWIDGET_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>545</width>
<height>503</height>
<height>516</height>
</rect>
</property>
<property name="windowTitle">
@ -125,10 +125,44 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkIgnoreSpacesWhenValidatingCases">
<property name="text">
<string>Ignore spaces when validating problem cases</string>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Problem Case Validate type</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbProblemCaseValidateType"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -40,7 +40,6 @@
#define SDCC_PROGRAM "sdcc.exe"
#define PACKIHX_PROGRAM "packihx.exe"
#define MAKEBIN_PROGRAM "makebin.exe"
#define MAKE2_PROGRAM "make.exe"
#elif defined(Q_OS_LINUX)
#define CONSOLE_PAUSER "consolepauser"
#define ASSEMBLER "nasm"

View File

@ -2079,7 +2079,7 @@
</message>
<message>
<source>Ignore spaces when validating problem cases</source>
<translation>Ignorar espaços ao validar casos de problemas</translation>
<translation type="vanished">Ignorar espaços ao validar casos de problemas</translation>
</message>
<message>
<source>Timeout for Case Valdation</source>
@ -2137,6 +2137,22 @@
<source>Redirect STDERR to Tools output panel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Problem Case Validate type</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Exact</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore leading/trailing spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore spaces</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FileAssociationModel</name>
@ -4925,7 +4941,7 @@
</message>
<message>
<source>Ignore Spaces</source>
<translation>Ignorar espaços</translation>
<translation type="vanished">Ignorar espaços</translation>
</message>
<message>
<source>Raylib Manual</source>
@ -5319,6 +5335,18 @@
<source>Turtle Graphics Tutorial</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Exact</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore leading/trailing spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore spaces</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MemoryModel</name>
@ -5467,10 +5495,6 @@
<source>Icon Info:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TextLabel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NewProjectUnitDialog</name>

File diff suppressed because it is too large Load Diff

View File

@ -1910,10 +1910,6 @@
<source>Port Number</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore spaces when validating problem cases</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Case Editor Font</source>
<translation type="unfinished"></translation>
@ -1966,6 +1962,22 @@
<source>Redirect STDERR to Tools output panel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Problem Case Validate type</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Exact</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore leading/trailing spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore spaces</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FileAssociationModel</name>
@ -4660,10 +4672,6 @@
<source>Rename</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore Spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Raylib Manual</source>
<translation type="unfinished"></translation>
@ -5048,6 +5056,18 @@
<source>Turtle Graphics Tutorial</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Exact</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore leading/trailing spaces</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ignore spaces</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MemoryModel</name>
@ -5192,10 +5212,6 @@
<source>Icon Info:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TextLabel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NewProjectUnitDialog</name>

View File

@ -107,6 +107,12 @@ enum class SplitProcessCommandQuoteType {
Double
};
enum class ProblemCaseValidateType {
Exact,
IgnoreLeadingTrailingSpaces,
IgnoreSpaces
};
FileType getFileType(const QString& filename);
QStringList splitProcessCommand(const QString& cmd);