public void TestEquationSubtractionSolution() { Equation eq = new Equation (); eq.val1 = 5; eq.val2 = 5; eq.type = EquationType.SUBTRACTION; // 5 - 5 = 0 Assert.AreEqual(0, EquationTarget.CalcSolution(eq)); }
public void TestEquationDivisionSolution() { Equation eq = new Equation (); eq.val1 = 5; eq.val2 = 5; eq.type = EquationType.DIVISISON; // 5 / 5 = 1 Assert.AreEqual (1, EquationTarget.CalcSolution(eq)); }
public void TestEquationMultiplicationSolution() { Equation eq = new Equation (); eq.val1 = 5; eq.val2 = 5; eq.type = EquationType.MULTIPLICATION; // 5 x 5 = 25 Assert.AreEqual(25, EquationTarget.CalcSolution(eq)); }
public void TestEquationAdditionSolution() { Equation eq = new Equation (); eq.val1 = 5; eq.val2 = 5; eq.type = EquationType.ADDITION; // 5 + 5 = 10 Assert.AreEqual(10, EquationTarget.CalcSolution(eq)); }
public EquationTarget(float x, float y, EquationDifficulty diff, Random r) : base(x, y, Color.Red) { _eq = GenEquation(diff, r); }
public static float CalcSolution(Equation eq) { switch (eq.type) { case EquationType.ADDITION: return eq.val1 + eq.val2; case EquationType.SUBTRACTION: return eq.val1 - eq.val2; case EquationType.MULTIPLICATION: return eq.val1 * eq.val2; case EquationType.DIVISISON: return eq.val1 / eq.val2; } // it shouldn't reach this code return 0.0f; }
public EquationTarget(float x, float y, EquationDifficulty diff, Random r) : base(x, y, Color.Red) { _eq = GenEquation (diff, r); }
/// <summary> /// Generates a random equation. /// </summary> /// <returns>The equation.</returns> /// <param name="diff">Diff.</param> /// <param name="r">Random generator. This is needed to get unique rand values each time</param> public static Equation GenEquation(EquationDifficulty diff, Random r) { Equation eq = new Equation (); if (diff == EquationDifficulty.EASY) { eq.val1 = r.Next (0, 10); eq.val2 = r.Next (0, 10); eq.type = (EquationType)r.Next (0, 2); } else if (diff == EquationDifficulty.INTERMEDIATE) { eq.val1 = r.Next (0, 15); eq.val2 = r.Next (0, 15); eq.type = (EquationType)r.Next (0, 3); } else { // hard eq.val1 = r.Next (0, 50); eq.val2 = r.Next (0, 50); eq.type = (EquationType)r.Next (0, 4); } eq.solution = CalcSolution(eq); return eq; }