Skip to content

Commit 755b067

Browse files
committed
MathematicaEvaluator should get immutable and convert it to mutable to avoid out-side interference.
1 parent 91247e9 commit 755b067

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/scala/com/github/tomerghelber/mathematica/eval/MathematicaEvaluator.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import scala.collection.mutable
99
* @author user
1010
* @since 01-Nov-19
1111
*/
12-
class MathematicaEvaluator(globalEnvironment: mutable.Map[String, ASTNode]= mutable.Map.empty[String, ASTNode])
12+
class MathematicaEvaluator private (globalEnvironment: mutable.Map[String, ASTNode])
1313
extends LazyLogging {
1414

15+
/* --- constructors --- */
16+
17+
def this(startEnvironment: Map[String, ASTNode]=Map.empty) = {
18+
this(mutable.Map[String, ASTNode](startEnvironment.toSeq:_*))
19+
}
20+
1521
/* --- publics --- */
1622

1723
def eval(node: ASTNode): ASTNode = {

src/test/scala/com/github/tomerghelber/mathematica/eval/MathematicaEvaluatorSpec.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
77
import com.github.tomerghelber.mathematica.ast.{FunctionNode, NumberNode, SymbolNode}
88
import com.github.tomerghelber.mathematica.parser.MathematicaParser
99

10-
import scala.collection.mutable
11-
1210
/**
1311
* @author user
1412
* @since 01-Nov-19
@@ -35,7 +33,7 @@ class MathematicaEvaluatorSpec extends FunSpec with Matchers with ScalaCheckProp
3533

3634
it("symbol evaluated") {
3735
forAll { (symbol: SymbolNode, expected: NumberNode) =>
38-
val eval = new MathematicaEvaluator(mutable.Map((symbol.value, expected)))
36+
val eval = new MathematicaEvaluator(Map((symbol.value, expected)))
3937
val actual = eval.eval(symbol)
4038
actual shouldBe expected
4139
}

0 commit comments

Comments
 (0)