mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Add e to calculator (#9124)
* Add support for e * Add tests for e * Fix compiler complaints
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Microsoft.Plugin.Calculator.UnitTests
|
|||||||
[TestCase("42")]
|
[TestCase("42")]
|
||||||
[TestCase("test")]
|
[TestCase("test")]
|
||||||
[TestCase("pi(2)")] // Incorrect input, constant is being treated as a function.
|
[TestCase("pi(2)")] // Incorrect input, constant is being treated as a function.
|
||||||
|
[TestCase("e(2)")]
|
||||||
public void Interpret_NoResult_WhenCalled(string input)
|
public void Interpret_NoResult_WhenCalled(string input)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -62,6 +63,9 @@ namespace Microsoft.Plugin.Calculator.UnitTests
|
|||||||
[TestCase("8.43 + 4.43 - 12.86", 0D)]
|
[TestCase("8.43 + 4.43 - 12.86", 0D)]
|
||||||
[TestCase("8.43 + 4.43 - 12.8", 0.06D)]
|
[TestCase("8.43 + 4.43 - 12.8", 0.06D)]
|
||||||
[TestCase("exp(5)", 148.413159102577D)]
|
[TestCase("exp(5)", 148.413159102577D)]
|
||||||
|
[TestCase("e^5", 148.413159102577D)]
|
||||||
|
[TestCase("e*2", 5.43656365691809D)]
|
||||||
|
[TestCase("log(e)", 1D)]
|
||||||
[TestCase("cosh(0)", 1D)]
|
[TestCase("cosh(0)", 1D)]
|
||||||
public void Interpret_NoErrors_WhenCalledWithRounding(string input, decimal expectedResult)
|
public void Interpret_NoErrors_WhenCalledWithRounding(string input, decimal expectedResult)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Mages.Core;
|
using Mages.Core;
|
||||||
|
|
||||||
@@ -10,7 +11,14 @@ namespace Microsoft.Plugin.Calculator
|
|||||||
{
|
{
|
||||||
public class CalculateEngine
|
public class CalculateEngine
|
||||||
{
|
{
|
||||||
private readonly Engine _magesEngine = new Engine();
|
private readonly Engine _magesEngine = new Engine(new Configuration
|
||||||
|
{
|
||||||
|
Scope = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "e", Math.E }, // e is not contained in the default mages engine
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
public const int RoundingDigits = 10;
|
public const int RoundingDigits = 10;
|
||||||
|
|
||||||
public CalculateResult Interpret(string input)
|
public CalculateResult Interpret(string input)
|
||||||
|
|||||||
Reference in New Issue
Block a user