1 package org.simantics.modeling.tests.commands;
3 import junit.framework.Assert;
4 import junit.framework.AssertionFailedError;
6 import org.simantics.db.layer0.util.EvaluatingListener;
7 import org.simantics.db.layer0.util.EvaluatingListener.Criterion;
8 import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;
9 import org.simantics.db.testing.common.Command;
10 import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
11 import org.simantics.modeling.tests.traits.SingleResourceTrait;
13 public class AssertStateValue extends Command<ModelingCommandSequenceTest> {
16 private transient final SingleResourceTrait run;
17 private transient final String rvi;
18 private transient final Number expectedValue;
19 private transient final double tolerance;
21 public AssertStateValue(SingleResourceTrait run, String rvi, Number expectedValue, double tolerance) {
24 this.expectedValue = expectedValue;
25 this.tolerance = tolerance;
28 public void run(ModelingCommandSequenceTest environment) throws Exception {
30 //final double tolerance = 0.0001;
32 Criterion<Number> criterion = new EvaluatingListener.Criterion<Number>() {
34 public Evaluation evaluate(Number result) {
36 return Evaluation.IGNORE;
39 double resultDouble = result.doubleValue();
40 double expectedDouble = expectedValue.doubleValue();
41 if (Math.abs(expectedDouble - resultDouble) <= tolerance){
42 return Evaluation.ACCEPT;
45 return Evaluation.IGNORE;
50 Number result = Utils.readValue(run, rvi, criterion);
52 double resultDouble = result.doubleValue();
53 double expectedDouble = expectedValue.doubleValue();
55 Assert.assertEquals(expectedDouble, resultDouble, tolerance);
58 throw new AssertionFailedError();