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
3 changed files with 52 additions and 29 deletions
Showing only changes of commit 62c3f7c55c - Show all commits
+10
View File
@@ -172,3 +172,13 @@ body {
.dropdown-custom:hover {
background-color: #444;
}
.dropdown-custom-maxmin {
width: 150px;
background-color: black;
color: white;
border: none;
padding: 10px;
font-size: 16px;
cursor: pointer;
}
+32 -17
View File
@@ -2,11 +2,13 @@
import React, { useState } from 'react';
import { Box, Button, Output } from "./modules";
import { calculate_clickMaximize, calculate_clickMinimize, downloadLP, import_click } from "./scripts"
import text from "./lang"
import { calculate_click, downloadLP, import_click } from "./scripts";
import text from "./lang";
export default function Home() {
const [language, setLanguage] = useState('eng');
const [maxminOption, setMaxminOption] = useState('maximize'); // Zustand für den MaxMin-Switch
const tr_hTitle = text(language, 'header_title');
const tr_hSubtitle = text(language, 'header_subtitle');
const tr_boxObjTitle = text(language, 'boxObjTitle');
@@ -21,21 +23,27 @@ export default function Home() {
const tr_boxExportLP = text(language, "boxExportLP");
const tr_calc_max = text(language, "maximize");
const tr_calc_min = text(language, "minimize");
const tr_calcButton = text(language, "buttonCalc");
const handleLanguageChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setLanguage(event.target.value);
};
const handleMaxMinChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setMaxminOption(event.target.value); // Update den Zustand basierend auf dem Wert des Selects
};
return (
<>
<header className="header">
<div className="title">
<main className="header_box">
{tr_hTitle}
<br></br>
<br />
<span className="header_copyright">
<i>{tr_hSubtitle}</i>
</span><br></br>
</span>
<br />
<select id="language_current" value={language} onChange={handleLanguageChange} className="dropdown-custom">
<option value="ger">Deutsch</option>
<option value="eng">English</option>
@@ -46,35 +54,42 @@ export default function Home() {
<Box
title={tr_boxObjTitle}
placeholder={tr_boxObjDesc}
id="objective" />
id="objective"
/>
<Box
title={tr_boxSubjTitle}
placeholder={tr_boxSubjDesc}
id="subject" />
id="subject"
/>
<Box
title={tr_boxBoundsTitle}
placeholder={tr_boxBoundsDesc}
id="bounds" />
id="bounds"
/>
<Box
title={tr_boxVarsTitle}
placeholder={tr_boxVarsDesc}
id="vars" />
id="vars"
/>
<select id="maxminswitch" value={maxminOption} onChange={handleMaxMinChange} className="dropdown-custom-maxmin">
<option value="maximize">{tr_calc_max}</option>
<option value="minimize">{tr_calc_min}</option>
</select>
<Button
title={tr_calc_max}
title={tr_calcButton}
className={"button_green"}
onClickFunc={calculate_clickMaximize} />
<Button
title={tr_calc_min}
className={"button_green"}
onClickFunc={calculate_clickMinimize} />
onClickFunc={calculate_click}
/>
<Button
title={tr_boxExportLP}
className={"button"}
onClickFunc={downloadLP} />
<br></br>
onClickFunc={downloadLP}
/>
<br />
<Output
id="out"
text={tr_boxOut} />
text={tr_boxOut}
/>
</>
);
}
+10 -12
View File
@@ -128,7 +128,7 @@ function isInputFilled(obj: string | undefined, subj: string | undefined, bounds
return true;
}
function calculate_click(maximize: boolean) {
export function calculate_click() {
customLogClear();
const timer = walltimeStart();
customLog("calculating");
@@ -215,8 +215,9 @@ function calculate_click(maximize: boolean) {
if (!isInputValidRegex(objective, subject, bounds, variables)) return;
// fetch operator
const maxmin = (document.getElementById('maxminswitch') as HTMLSelectElement)?.value;
let operator = "Minimize";
if (maximize) operator = "Maximize";
if (maxmin == "maximize") operator = "Maximize";
let wholeText: string = operator + "\n obj: " + objective
+ "\nSubject To \n" + subject
@@ -284,11 +285,17 @@ function downloadLPFormatting(objective: any, subject: any, bounds: any) {
const formattedSubject = typeof subject === 'string' ? subject : '';
const formattedBounds = typeof bounds === 'string' ? bounds : '';
// fetch operator
const maxmin = (document.getElementById('maxminswitch') as HTMLSelectElement)?.value;
let operator = "Minimize";
if (maxmin == "maximize") operator = "Maximize";
// Header mit Problemname
const header = "\\ Your problem\n";
// format objective
const objectiveFunction = `Maximize\n obj: ${formattedObjective}\n`;
const objectiveFunction = operator + `\n obj: ${formattedObjective}\n`;
// turn each subject into a single line
const constraints = `Subject To\n${formattedSubject.split("\n").filter(line => line.trim() !== "").map(line => ` ${line}`).join("\n")}\n`;
@@ -302,15 +309,6 @@ function downloadLPFormatting(objective: any, subject: any, bounds: any) {
return lpFormat;
}
export function calculate_clickMaximize() {
calculate_click(true);
}
export function calculate_clickMinimize() {
calculate_click(false);
}
function downloadProblemDownload(content: string) {
customLog("downloadPrepFile");
customLog("");