Skip to content
Snippets Groups Projects
Commit d40eb112 authored by srosse's avatar srosse
Browse files

OO-685: accept comma as separator for float in QTI <=, >=, <, and > test, and...

OO-685: accept comma as separator for float in QTI <=, >=, <, and > test, and prevent red screen if the format of the float cannot be parsed
parent 254574a2
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,6 @@ public class QTI_vargt implements BooleanEvaluable { ...@@ -44,7 +44,6 @@ public class QTI_vargt implements BooleanEvaluable {
* @return * @return
*/ */
public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) { public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
boolean ok = false;
ItemInput iinp = userContext.getItemInput(); ItemInput iinp = userContext.getItemInput();
if (iinp.isEmpty()) return false; // user has given no answer if (iinp.isEmpty()) return false; // user has given no answer
String respident = boolElement.attributeValue("respident"); String respident = boolElement.attributeValue("respident");
...@@ -56,13 +55,21 @@ public class QTI_vargt implements BooleanEvaluable { ...@@ -56,13 +55,21 @@ public class QTI_vargt implements BooleanEvaluable {
// Integer // Integer
shouldVal = shouldVal.trim(); shouldVal = shouldVal.trim();
isVal = isVal.trim(); isVal = isVal.trim();
float fs = Float.parseFloat(shouldVal);
float fi;
try { try {
Float fs = new Float(shouldVal); fi = Float.parseFloat(isVal);
Float fi = new Float(isVal); } catch (NumberFormatException e) {
ok = (fi.floatValue() > fs.floatValue()); //try to replace , -> .
} catch (NumberFormatException nfe) { isVal = isVal.replace(',', '.');
// try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e1) {
//we try all what we can to understand the input value -> false
return false;
}
} }
boolean ok = (fi > fs);
return ok; return ok;
} }
......
...@@ -51,10 +51,21 @@ public class QTI_vargte implements BooleanEvaluable { ...@@ -51,10 +51,21 @@ public class QTI_vargte implements BooleanEvaluable {
// we use Float so we are on the safe side, even if comparison was only Integer // we use Float so we are on the safe side, even if comparison was only Integer
shouldVal = shouldVal.trim(); shouldVal = shouldVal.trim();
isVal = isVal.trim(); isVal = isVal.trim();
Float fs = new Float(shouldVal); float fs = Float.parseFloat(shouldVal);
Float fi = new Float(isVal); float fi;
boolean ok = (fi.floatValue() >= fs.floatValue()); try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e) {
//try to replace , -> .
isVal = isVal.replace(',', '.');
try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e1) {
//we try all what we can to understand the input value -> false
return false;
}
}
boolean ok = (fi >= fs);
return ok; return ok;
} }
} }
...@@ -52,9 +52,22 @@ public class QTI_varlt implements BooleanEvaluable { ...@@ -52,9 +52,22 @@ public class QTI_varlt implements BooleanEvaluable {
// we use Float so we are on the safe side, even if comparison was only Integer // we use Float so we are on the safe side, even if comparison was only Integer
shouldVal = shouldVal.trim(); shouldVal = shouldVal.trim();
isVal = isVal.trim(); isVal = isVal.trim();
Float fs = new Float(shouldVal); float fs = Float.parseFloat(shouldVal);
Float fi = new Float(isVal); float fi;
boolean ok = (fi.floatValue() < fs.floatValue()); try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e) {
//try to replace , -> .
isVal = isVal.replace(',', '.');
try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e1) {
//we try all what we can to understand the input value -> false
return false;
}
}
boolean ok = (fi < fs);
return ok; return ok;
} }
......
...@@ -52,9 +52,21 @@ public class QTI_varlte implements BooleanEvaluable { ...@@ -52,9 +52,21 @@ public class QTI_varlte implements BooleanEvaluable {
// we use Float so we are on the safe side, even if comparison was only Integer // we use Float so we are on the safe side, even if comparison was only Integer
shouldVal = shouldVal.trim(); shouldVal = shouldVal.trim();
isVal = isVal.trim(); isVal = isVal.trim();
Float fs = new Float(shouldVal); float fs = Float.parseFloat(shouldVal);
Float fi = new Float(isVal); float fi;
boolean ok = (fi.floatValue() <= fs.floatValue()); try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e) {
//try to replace , -> .
isVal = isVal.replace(',', '.');
try {
fi = Float.parseFloat(isVal);
} catch (NumberFormatException e1) {
//we try all what we can to understand the input value -> false
return false;
}
}
boolean ok = (fi <= fs);
return ok; return ok;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment