public void TestCalculationExpressionWithConstants() { var const1 = new ConstantExpression("1"); var const2 = new ConstantExpression("-1"); var ce = new CalculationExpression("+", const1, const2); Assert.AreEqual(0, ce.GetExpected()); Assert.AreEqual(0, ce.GetMin()); Assert.AreEqual(0, ce.GetMax()); Assert.AreEqual(0, ce.Roll()); ce = new CalculationExpression("-", const1, const2); Assert.AreEqual(2, ce.GetExpected()); Assert.AreEqual(2, ce.GetMin()); Assert.AreEqual(2, ce.GetMax()); Assert.AreEqual(2, ce.Roll()); ce = new CalculationExpression("*", const1, const2); Assert.AreEqual(-1, ce.GetExpected()); Assert.AreEqual(-1, ce.GetMin()); Assert.AreEqual(-1, ce.GetMax()); Assert.AreEqual(-1, ce.Roll()); ce = new CalculationExpression("/", const1, const2); Assert.AreEqual(-1, ce.GetExpected()); Assert.AreEqual(-1, ce.GetMin()); Assert.AreEqual(-1, ce.GetMax()); Assert.AreEqual(-1, ce.Roll()); }
public void TestCalculationExpressionWithDies() { var d1 = new DiceExpression("1d6"); var d2 = new DiceExpression("1d8"); var ce = new CalculationExpression("+", d1, d2); Assert.AreEqual(8, ce.GetExpected()); Assert.AreEqual(2, ce.GetMin()); Assert.AreEqual(14, ce.GetMax()); ce = new CalculationExpression("-", d1, d2); Assert.AreEqual(-1, ce.GetExpected()); Assert.AreEqual(-7, ce.GetMin()); Assert.AreEqual(5, ce.GetMax()); ce = new CalculationExpression("*", d1, d2); Assert.AreEqual(3.5 * 4.5, ce.GetExpected()); Assert.AreEqual(1, ce.GetMin()); Assert.AreEqual(48, ce.GetMax()); ce = new CalculationExpression("/", d1, d2); Assert.AreEqual(3.5 / 4.5, ce.GetExpected()); Assert.AreEqual(0.125, ce.GetMin()); Assert.AreEqual(6, ce.GetMax()); }
public void TestCalculationExpressionWithCalculations() { var const1 = new ConstantExpression("1"); var const2 = new ConstantExpression("-1"); var d1 = new DiceExpression("1d6"); var d2 = new DiceExpression("1d8"); var ce = new CalculationExpression("+", new CalculationExpression("+", d1, d2), new CalculationExpression("+", const1, const2)); Assert.AreEqual(8, ce.GetExpected()); Assert.AreEqual(2, ce.GetMin()); Assert.AreEqual(14, ce.GetMax()); }