Ваша задача - написать тело функции которая будет вычислять формулы.
Формула передаётся через параметр forlmula
. Формулы могут содержать в себе все значения, но также можно передать переменные вида $1
, $2
, $3
и т.д.
Значения переменных передаются вторым параметром в неограниченном кол-ве.
Посмотрите тесты что бы понять что от вас требуется.
Удачи! Она вам потребуется ;)
======
Your task is to write the body of a function that will calculate formulas.
The formula is passed through the forlmula
parameter. Formulas can contain all values, but you can also pass variables like $1
, $2
, $3
, etc.
Variable values are passed as the second parameter in an unlimited number.
Look at the tests to understand what is required of you.
Good luck! You will need it;)
using System;
public class Calculator
{
public static float Calculate(string forlmula, params float[] values)
{
// your code
}
}
using System;
using NUnit.Framework;
[TestFixture]
public class KataTests {
[Test]
public static void MyTest()
{
Assert.AreEqual(10, Calculator.Calculate("(2 + 3) * 4 / 2"));
Assert.AreEqual(25, Calculator.Calculate("50 - 10 * 2.5"));
Assert.AreEqual(3, Calculator.Calculate("2 ^ 3 - 1 * 5"));
Assert.AreEqual(5, Calculator.Calculate("2 + |-(-20 + 50)| / (5 * 2)"));
Assert.AreEqual(40, Calculator.Calculate("$1 * $2 - $1", 5, 9));
}
}