Merging unit tests, language switching and mps export #48

Closed
SinusFox wants to merge 56 commits from adding-unit-tests-and-language-switching into export-mps
2 changed files with 54 additions and 5 deletions
Showing only changes of commit 00d72a1560 - Show all commits
+5 -5
View File
@@ -19,19 +19,19 @@ export default function Home() {
</header> </header>
<Box <Box
title={"Objective"} title={"Objective"}
placeholder={"Objective"} placeholder={"Insert your objective here. One objective is allowed. Use one line for it (no \"enter\"!) Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx + y\n-786433 x1 + 655361 x2"}
id="objective"/> id="objective"/>
<Box <Box
title={"Subject"} title={"Subject"}
placeholder={"Subject"} placeholder={"Insert your subject here. One per line (divide by 'enter' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\n+1 x + 2 y <= 15\n524321 x14 + 524305 x15 <= 4194303.5"}
id="subject"/> id="subject"/>
<Box <Box
title={"Bounds"} title={"Bounds"}
placeholder={"Bounds"} placeholder={"Insert your bounds here. One per line (divide by 'enter' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx >= 0\nx > 0\n0 <= x1 <= 1"}
id="bounds"/> id="bounds"/>
<Box <Box
title={"Variables"} title={"Variables"}
placeholder={"Your Variables here"} placeholder={"List all your variables. One per line (divide by 'enter' button). Allowed symbols are a-z, A-Z.\nExample:\nx\ny"}
id="vars" /> id="vars" />
<Button <Button
title={"Calculate"} title={"Calculate"}
@@ -47,7 +47,7 @@ export default function Home() {
<br></br> <br></br>
<Output <Output
id="out" id="out"
text={"Ergebnis"}/> text={"Input a problem and an action button to display output..."}/>
{/* <Popup_Button {/* <Popup_Button
title="Popup" title="Popup"
className="button" className="button"
+49
View File
@@ -46,6 +46,52 @@ function walltimeStart() {
return Date.now(); return Date.now();
} }
function isInputValidRegex(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined): boolean {
customLog("Staring input checks...");
// standard case: input is undefined - invalid
if (obj === undefined || obj === null || subj === undefined || subj === null || bounds === undefined || bounds === null || vars === undefined || vars === null) {
customLog("Error: Function isInputValidRegex received undefined or null input.");
return false;
}
// RegEx check for objective
let regex = /^[ (\n)]*[\+-]? *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)( *[\+-] *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*))*[ (\n)]*$/g;
let isValid = regex.test(obj);
if (!isValid) {
customLog("Error: Invalid or missing character in object box.");
return false;
}
// RegEx check for subject
regex = /^([ (\n)]*[\+-]* *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*( *[\+-] *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)* *((<=?)|(>=?)|=) *[\+-]? *\d+(.\d+)?[ (\n)]*)+$/g;
isValid = regex.test(subj);
if (!isValid) {
customLog("Error: Invalid or missing character in subject box.");
return false;
}
// RegEx check for subject
regex = /[ (\n)]*(([a-zA-Z][a-zA-Z0-9]* *((<=?)|(>=?)|=) *\d(.\d+)?)|((\d(.\d+)?) *<=? *[a-zA-Z][a-zA-Z0-9]* *<= *(\d(.\d+)?)))[ (\n)]*/g;
isValid = regex.test(bounds);
if (!isValid) {
customLog("Error: Invalid or missing character in bounds box.");
return false;
}
// RegEx check for variables
regex = /^ *([a-zA-Z][a-zA-Z0-9]*(\n)* *)+$/g;
isValid = regex.test(vars);
if (!isValid) {
customLog("Error: Invalid or missing character in variables box.");
return false;
}
customLog("All input checks successful.");
customLog("");
return true;
}
function isInputFilled(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined) { function isInputFilled(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined) {
if (obj == "" || obj == null || obj == undefined) { if (obj == "" || obj == null || obj == undefined) {
customLog("Error: Empty input field."); customLog("Error: Empty input field.");
@@ -148,6 +194,9 @@ export function calculate_click() {
// catch error: empty input field(s) // catch error: empty input field(s)
if (!isInputFilled(objective, subject, bounds, variables)) return; if (!isInputFilled(objective, subject, bounds, variables)) return;
// catch error: variables field has invalid characters
if (!isInputValidRegex(objective, subject, bounds, variables)) return;
let wholeText: string = "Maximize\n obj: " + objective let wholeText: string = "Maximize\n obj: " + objective
+ "\nSubject To \n" + subject + "\nSubject To \n" + subject
+ "\nBounds \n" + bounds + "\nBounds \n" + bounds