public static void Start() { MathClass math = new MathClass(); System.Console.WriteLine(math.Addition(2, 3)); TextClass text = new TextClass(); System.Console.WriteLine(@"Hello World"); }
public ActionResult Index(int?n1, int?n2) { if (n1.HasValue && n2.HasValue) { int sum = MathClass.Add(n1.Value, n2.Value); return(View(sum)); } return(View()); }
//Test method for inputting each individual value from a range private void SquareRootOneValue(MathClass mathClass, double expectedResult) { //ARRANGE double input = expectedResult * expectedResult; //ACT double actualResult = mathClass.SquareRoot(input); //ASSERT Assert.AreEqual(expectedResult, actualResult, delta: expectedResult / 1000); }
static void Main(string[] args) { Console.WriteLine("Enter number 1"); int n1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter number 2"); int n2 = int.Parse(Console.ReadLine()); int result = MathClass.Add(n1, n2); Console.WriteLine(result); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async(context) => { await context.Response.WriteAsync($"2 + 2 = {MathClass.Add(2, 2)}"); }); }
public void SubtractTest() { MathClass target = new MathClass(); int a = 10; int b = 5; int expected = 5; int actual = 0; actual = target.Subtract(a, b); Assert.Equal(expected, actual); }
public static void Main() { Console.WriteLine("Enter first number "); int firstno = int.Parse(Console.ReadLine()); Console.WriteLine("Enter ssecond number "); int secondno = int.Parse(Console.ReadLine()); int result = MathClass.Add(firstno, secondno); Console.WriteLine("Addition is:" + result); }
public void MultiplyTest() { MathClass target = new MathClass(); int a = 5; // TODO: Initialize to an appropriate value int b = 5; // TODO: Initialize to an appropriate value int expected = 25; // TODO: Initialize to an appropriate value int actual; actual = target.Multiply(a, b); Assert.Equal(expected, actual); }
public void DivideTest() { MathClass target = new MathClass(); int a = 25; int b = 0; int expected = 0; int actual = 0; actual = target.Divide(a, b); Assert.AreEqual(expected, actual); }
private Dictionary <string, decimal> GetCoefsFromApi2(OddEvent oddEvent) { var paramsToPythonApi = MathClass.GetCoefsToPythonApi(oddEvent); var task = this._pythonClient.GetDataFromPythonApiAsync2(paramsToPythonApi.k1, paramsToPythonApi.to, paramsToPythonApi.tu, paramsToPythonApi.k2, paramsToPythonApi.hdp1, paramsToPythonApi.hdp2); task.Wait(); Dictionary <string, decimal> dict = task.Result; return(dict); }
//[DeploymentItem("SimpleMathLib.dll")] public void MultiplyTest() { MathClass target = new MathClass(); int a = 5; int b = 5; int expected = 25; int actual = 0; actual = target.Multiply(a, b); Assert.AreEqual(expected, actual); }
public void AddTest() { MathClass target = new MathClass(); int a = 2; int b = 3; int expected = 5; int actual = 0; actual = target.Add(a, b); Assert.AreEqual(expected, actual, 1, "You are getting close!"); }
private (Point[], Point?, Point?) CheckIfExistsStraightPath(Planet originPlanet, Planet destinationPlanet) { double shortestDist = double.MaxValue; double shortestStraightPathDist = double.MaxValue; Point? bestOrigP = null; Point? bestDestP = null; Point[] straightPathPoints = new Point[2]; foreach (Point origP in originPlanet.ContactPoints) { foreach (Point destP in destinationPlanet.ContactPoints) { bool intersection = false; foreach (var item in gameObjects) { if (item is Planet planet) { int collision = FindCollision(originPlanet, planet, destinationPlanet, origP, destP); if (collision == -1) { continue; } else if (collision == 1) { intersection = true; break; } else { } } } double dist = MathClass.GetDistance(origP.X, destP.X, origP.Y, destP.Y); // gets points for straight path if (dist < shortestStraightPathDist) { shortestStraightPathDist = dist; straightPathPoints[0] = origP; straightPathPoints[1] = destP; } // gets the shortest path without collision if (dist < shortestDist && !intersection) { shortestDist = dist; bestOrigP = origP; bestDestP = destP; } } } return(straightPathPoints, bestOrigP, bestDestP); }
public void TestSumThrowExceptionWhenNegative() { MathClass objMath = new MathClass(); try { objMath.Sum(-123, -456); } catch (ArgumentException) { // logging code will go here } }
public void TestSumThrowExceptionWhenZero() { MathClass objMath = new MathClass(); try { objMath.Sum(0, 0); } catch (ArgumentException) { // logging code will go here } }
static void Main(String[] args) { MathClass myClass = new MathClass(); myClass.FirstNumber = 10; myClass.SecondNumber = 10; Console.WriteLine("Addition result :" + myClass.Addition()); Console.WriteLine("Substraction result :" + myClass.Substraction()); Console.WriteLine("Multiplication result :" + myClass.Multiplication()); Console.WriteLine("Division result :" + myClass.Division()); Console.ReadLine(); }
public void TestSumThrowExceptionWhenNegative() { MathLibrary.MathClass objMath = new MathClass(); try { objMath.Sum(-123, -456); } catch (ArgumentException ex) { // logging code will go here Assert.AreSame("No Zero or Negative are allowed", ex.Message); } }
public void SquareRootValueRange() { //ARRANGE // Create an instance to test. MathClass mathClass = new MathClass(); //ACT // Try a range of values. for (double expected = 1e-8; expected < 1e+8; expected *= 3.2) { //ARRANGE within method SquareRootOneValue(mathClass, expected); } }
private void Analysis(ushort[] data, int Loop) { int Index = 0; Rv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; RSv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; RA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kW[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kVAR[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kVA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_PF[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kWh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kVARh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; R_kVAh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; Sv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2;//20 STv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; SA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kW[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kVAR[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kVA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_PF[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kWh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kVARh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; S_kVAh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; Tv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; TRv[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; TA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kW[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kVAR[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kVA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_PF[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kWh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kVARh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; T_kVAh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; vn[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; v[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; A[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kW[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kVAR[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kVA[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; PF[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kWh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kVARh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; kVAh[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); Index += 2; HZ[Loop] = MathClass.work16to754(data[Index + 1], data[Index]); }
public override void ReadData(IModbusMaster master) { try { ushort[] HZ = master.ReadHoldingRegisters(ID, 304, 1); ushort[] V = master.ReadHoldingRegisters(ID, 305, 6); ushort[] A = master.ReadHoldingRegisters(ID, 312, 6); ushort[] data = master.ReadHoldingRegisters(ID, 318, 16); ushort[] KWH = master.ReadHoldingRegisters(ID, 40960, 2); ushort[] KVARH = master.ReadHoldingRegisters(ID, 40990, 2); int Index = 0; hz = Convert.ToDecimal(HZ[0] * 0.01); rsv = Convert.ToDecimal(MathClass.work16to10(V[Index], V[Index + 1]) * 0.01); Index += 2; stv = Convert.ToDecimal(MathClass.work16to10(V[Index], V[Index + 1]) * 0.01); Index += 2; trv = Convert.ToDecimal(MathClass.work16to10(V[Index], V[Index + 1]) * 0.01); Index = 0; ra = Convert.ToDecimal(MathClass.work16to10(A[Index], A[Index + 1]) * 0.01); Index += 2; sa = Convert.ToDecimal(MathClass.work16to10(A[Index], A[Index + 1]) * 0.01); Index += 2; ta = Convert.ToDecimal(MathClass.work16to10(A[Index], A[Index + 1]) * 0.01); Index = 0; _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //P1 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //P2 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //P3 kw = Convert.ToDecimal(data[Index] * 0.01 * (ReportConfig.Ratio)); Index++; _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //Q1 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //Q2 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //Q3 kvar = Convert.ToDecimal(data[Index] * 0.01); Index++; _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //A1 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //A2 _ = Convert.ToDecimal(data[Index] * 0.01); Index++; //A3 kva = Convert.ToDecimal(data[Index] * 0.01); Index++; _ = Convert.ToDecimal(data[Index] * 0.001); Index++; //PFE1 _ = Convert.ToDecimal(data[Index] * 0.001); Index++; //PFE2 _ = Convert.ToDecimal(data[Index] * 0.001); Index++; //PFE3 pfe = Convert.ToDecimal(data[Index] * 0.001); Index = 0; kwh = Convert.ToDecimal(MathClass.work16to10(KWH[Index], KWH[Index + 1]) * 0.01 * (ReportConfig.Ratio)); kvarh = Convert.ToDecimal(MathClass.work16to10(KVARH[Index], KVARH[Index + 1]) * 0.01); ConnectFlag = true; InsertSql(); } catch (ThreadAbortException) { } catch (Exception ex) { Log.Error(ex, $"BAW-4C電表通訊失敗 ID : {ID}"); ConnectFlag = false; } }
static void Main(string[] args) { Console.WriteLine("Enter the value for factorial:"); var fact = int.Parse(Console.ReadLine()); MathClass.Factorial(fact); Console.WriteLine("Enter the value for power:"); var valPow = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the power:"); var pow = int.Parse(Console.ReadLine()); MathClass.Power(valPow, pow); Console.ReadKey(); }
public override void DataReader(ModbusMaster master) { try { int Index = 0; ushort[] value = master.ReadHoldingRegisters(ID, 4096, 46); ushort[] value1 = master.ReadHoldingRegisters(ID, 4142, 20); _ = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; Rv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; Sv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; Tv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; RSv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; STv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; TRv = MathClass.work16to10(value[Index], value[Index + 1]); Index += 2; _ = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; RA = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; SA = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; TA = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; PF = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; PF_A = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //PFE L1 PF_B = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //PFE L2 PF_C = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //PFE L3 _ = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相相位角 RV_Angle = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相相位角 L1 SV_Angle = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相相位角 L2 TV_Angle = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相相位角 L3 kVA = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; kVA_A = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相視在功率 L1 kVA_B = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; Index += 2; //三相視在功率 L2 kVA_C = MathClass.work16to10(value[Index], value[Index + 1]) * 0.001F; //三相視在功率 L3 Index = 0; kW = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; kW_A = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //有效功率 L1 kW_B = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //有效功率 L2 kW_C = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //有效功率 L3 kVAR = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; kVAR_A = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //無效功率 L1 kVAR_B = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //無效功率 L2 kVAR_C = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; //無效功率 L3 kWh = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; Index += 2; kVARh = MathClass.work16to10(value1[Index], value1[Index + 1]) * 0.001F; } catch (Exception ex) { ConnectFlag = false; Log.Error(ex, $"ABBM2M解析異常、通訊編號: {GatewayIndex}、設備編號: {DeviceIndex}"); } }
private int FindCollision(Planet originPlanet, Planet collisionPlanet, Planet destinationPlanet, Point origP, Point destP) { Point midPoint = new Point((originPlanet.Position.X + destinationPlanet.Position.X) / 2, (originPlanet.Position.Y + destinationPlanet.Position.Y) / 2); // midpoint between origin and target double midPointTargetDist = MathClass.GetDistance(midPoint.X, destinationPlanet.Position.X, midPoint.Y, destinationPlanet.Position.Y); double midPointCollisionPlanetDist = MathClass.GetDistance(midPoint.X, collisionPlanet.Position.X, midPoint.Y, collisionPlanet.Position.Y); // find collision with other planets and check if the other planets aren't too far away if (collisionPlanet == originPlanet || collisionPlanet == destinationPlanet || midPointTargetDist < midPointCollisionPlanetDist) { return(-1); } if (MathClass.LineAndCircleIntersectionExists(collisionPlanet.Position.X, collisionPlanet.Position.Y, collisionPlanet.Size / 2.0 * Planet.dodgeRadiusMultiple, origP, destP)) { return(1); // intersection } return(0); // no collision }
public override void DataReader(ModbusMaster master) { try { int Index = 0; ushort[] kwhvalue = master.ReadHoldingRegisters(ID, 0, 2); //kwh ushort[] kwvalue = master.ReadHoldingRegisters(ID, 8, 2); //kw kWh = MathClass.work16to10(kwhvalue[Index + 1], kwhvalue[Index]) * 0.01; kW = MathClass.work16to10(kwvalue[Index + 1], kwvalue[Index]) * 0.001; ConnectFlag = true; } catch (Exception ex) { ConnectFlag = false; Log.Error(ex, $"PM200解析異常、通訊編號: {GatewayIndex}、設備編號: {DeviceIndex}"); } }
public void PythagorasTheoremCalculateSideNegativeValue() { //ARRANGE //Create an instance to test MathClass mathClass = new MathClass(); //Define test input and output values double a = -2.0; double b = -4.0; double expectedResult = mathClass.SquareRoot(a * a + b * b); //ACT double actualResult = mathClass.PythagorasTheoremCalculateSide(a, b); //ASSERT //Verify the Result Assert.AreEqual(expectedResult, actualResult); }
static void Main() { MathClass m = new MathClass(); // Delegate instantiation using "MultiplyNumbers" Del d = m.MultiplyNumbers; // Invoke the delegate object. System.Console.WriteLine("Invoking the delegate using 'MultiplyNumbers':"); for (int i = 1; i <= 5; i++) { d(i, 2); } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }
private void AnimateAIShips(Planet originPlanet, Planet targetPlanet) { if (currentAIPolyLine.Points.Count == 0) { return; } int unitCount = (int)Math.Round(originPlanet.UnitCount / 100.0 * 50); if (unitCount == 0) { return; } originPlanet.UnitCount -= unitCount; originPlanet.UnitCountChanged = true; SpaceShip spaceShip = new SpaceShip(originPlanet, targetPlanet, unitCount, currentAIPolyLine.Points.ToList(), npcColor); AnimateSpaceShipPath(spaceShip, MathClass.GetDistanceBetweenPointsInList(currentAIPolyLine.Points.ToList()), npcColor, currentAIPolyLine.Points); gameObjects.Add(spaceShip); }
/// <summary> /// Устанавливает вычисленные к-ты и расхождения для события на исходы:1X2 /// </summary> /// <param name="prices"></param> /// <param name="oddEvent"></param> private static void SetMoneyLineComputedPrices(Dictionary <string, decimal> prices, OddEvent oddEvent) { MoneyLine moneyLine = oddEvent.Periods[0].MoneyLine; if (moneyLine != null) { decimal?margin = MathClass.GetMargin3(moneyLine.Home, moneyLine.Draw, moneyLine.Away); moneyLine.FairHome = (moneyLine.Home / (1 - margin)); moneyLine.FairDraw = (moneyLine.Draw / (1 - margin)); moneyLine.FairAway = (moneyLine.Away / (1 - margin)); if (moneyLine != null) { foreach (KeyValuePair <string, decimal> keyValuePair in prices) { decimal?price; if (keyValuePair.Key.Equals("ML 1") == true) { price = keyValuePair.Value; moneyLine.HomeComputed = price; moneyLine.HomeDisc = GetDiscByCoefs(moneyLine.FairHome, moneyLine.HomeComputed); } if (keyValuePair.Key.Equals("ML X") == true) { price = keyValuePair.Value; moneyLine.DrawCompute = price; moneyLine.DrawDisc = GetDiscByCoefs(moneyLine.FairDraw, moneyLine.DrawCompute); } if (keyValuePair.Key.Equals("ML 2") == true) { price = keyValuePair.Value; moneyLine.AwayComputed = price; moneyLine.AwayDisc = GetDiscByCoefs(moneyLine.FairAway, moneyLine.AwayComputed); } } } } }
/// <summary> /// Устанавливает вычисленные к-ты и расхождения для события на исходы:Total /// </summary> /// <param name="prices"></param> /// <param name="oddEvent"></param> private static void SetTotalComputedPrices(Dictionary <string, decimal> prices, OddEvent oddEvent) { List <Total> _pinnacleTotals = oddEvent.Periods[0].Totals; for (int i = 0; i < _pinnacleTotals.Count; i++) { decimal points = _pinnacleTotals[i].Points; decimal?margin = MathClass.GetMargin2(_pinnacleTotals[i].Over, _pinnacleTotals[i].Under); _pinnacleTotals[i].FairOver = _pinnacleTotals[i].Over / (1 - margin); _pinnacleTotals[i].FairUnder = _pinnacleTotals[i].Under / (1 - margin); foreach (KeyValuePair <string, decimal> keyValuePair in prices) { if (keyValuePair.Key.StartsWith("T O") == true) { decimal resultOver = 0.0M; decimal resultUnder = 0.0M; string name = keyValuePair.Key.Replace("T O ", ""); resultOver = Decimal.Parse(name, CultureInfo.InvariantCulture); foreach (KeyValuePair <string, decimal> keyValuePair2 in prices) { if (keyValuePair2.Key.StartsWith("T U") == true) { string name2 = keyValuePair2.Key.Replace("T U ", ""); resultUnder = Decimal.Parse(name2, CultureInfo.InvariantCulture); if (resultOver == resultUnder && resultOver == points) { _pinnacleTotals[i].OverComputed = keyValuePair.Value; _pinnacleTotals[i].UnderComputed = keyValuePair2.Value; _pinnacleTotals[i].OverDisc = GetDiscByCoefs(_pinnacleTotals[i].FairOver, _pinnacleTotals[i].OverComputed); _pinnacleTotals[i].UnderDisc = GetDiscByCoefs(_pinnacleTotals[i].FairUnder, _pinnacleTotals[i].UnderComputed); } } } } } } }
public void SquareRootTestNegativeInput() { //ARRANGE MathClass mathClass = new MathClass(); //ACT try { mathClass.SquareRoot(-10); } catch (System.ArgumentOutOfRangeException) { return; } //ASSERT //Assert.Fail(); Assert.ThrowsException <ArgumentOutOfRangeException>(() => mathClass.SquareRoot(-10)); }