UnBCIC-TP2/Oberon-Scala

ForEach giving error when dealing with REAL values

Closed this issue · 1 comments

This test will crash when added to the InterpreterTest.scala:

test("BeeCrowd test of REAL banknotes") {
	val module = ScalaParser.parseResource("stmts/BeeBanknoteReal.oberon")

	assert(module.stmt.isDefined)

	assert(module.name == "BeeBanknoteReal")

	module.accept(interpreter)

	assert(interpreter.env.lookup("i") == Some(IntValue(12)))

	assert(evalArraySubscript("banknotesNeeded", 0) == IntValue(5))
	assert(evalArraySubscript("banknotesNeeded", 1) == IntValue(1))
	assert(evalArraySubscript("banknotesNeeded", 2) == IntValue(1))
	assert(evalArraySubscript("banknotesNeeded", 3) == IntValue(0))
	assert(evalArraySubscript("banknotesNeeded", 4) == IntValue(1))
	assert(evalArraySubscript("banknotesNeeded", 5) == IntValue(0))
	assert(evalArraySubscript("banknotesNeeded", 6) == IntValue(1))
	assert(evalArraySubscript("banknotesNeeded", 7) == IntValue(1))
	assert(evalArraySubscript("banknotesNeeded", 8) == IntValue(0))
	assert(evalArraySubscript("banknotesNeeded", 9) == IntValue(2))
	assert(evalArraySubscript("banknotesNeeded", 10) == IntValue(0))
	assert(evalArraySubscript("banknotesNeeded", 11) == IntValue(3))
}

Content of BeeBanknoteReal.oberon file:

MODULE BeeBanknoteReal;

TYPE
	realArray = ARRAY 12 OF REAL
	intArray = ARRAY 12 OF INTEGER

VAR
	banknotesValues: realArray;
	banknotesNeeded: intArray;
	value: REAL;
	i: INTEGER;
	v: REAL;

BEGIN
	value := 576.73;
	i := 0;

	banknotesValues[0] := 100.0;
	banknotesValues[1] := 50.0;
	banknotesValues[2] := 20.0;
	banknotesValues[3] := 10.0;
	banknotesValues[4] := 5.0;
	banknotesValues[5] := 2.0;
	banknotesValues[6] := 1.0;
	banknotesValues[7] := 0.5;
	banknotesValues[8] := 0.25;
	banknotesValues[9] := 0.1;
	banknotesValues[10] := 0.05;
	banknotesValues[11] := 0.01;

	FOREACH v IN banknotesValues
		banknotesNeeded[i] := FLOOR(value/v);
		value := value - v*banknotesNeeded[i];
		INC(i)
	END;
END

END BeeBanknoteReal.

A very similar test was implemented using only INTEGER values, so the issue is probably related to ForEach not being able to deal with REAL values. Also, the only implemented test to ForEach uses only INTEGER values.

Syntax errors found, code will be re-written.