-
-
Notifications
You must be signed in to change notification settings - Fork 443
Backout 'smart' digit separation & Fix Mages functions for Calculator plugin #3971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e107939
backout 'smart' digit grouping, mages fixes + workaround
dcog989 103d383
dead code, improve messages, group separator fix?
dcog989 190e0e1
Fix 'German' number formatting
dcog989 bd186e7
correct + extend description
dcog989 110f571
Rework solution for nested Mages
dcog989 6462023
Merge branch 'dev' into calculator-min-fix
dcog989 11f5ea5
Improve code quality
Jack251970 495ace1
Improve plugin description
Jack251970 daf35a4
Do not check bracket complete
Jack251970 c79e483
Merge branch 'Flow-Launcher:dev' into calculator-min-fix
dcog989 336e51d
IcoPath to const string
dcog989 e990e0f
Handle misplaced separators, Mages edge cases
dcog989 edc76fa
Review feedback, case insensitive, consistent separators
dcog989 9be8b71
review feedback, CultureInvariant, mild refactor
dcog989 b07420a
Use EmptyResults to improve code quality
Jack251970 cea1402
Improve code quality
Jack251970 1906d68
Add ShowErrorMessage setting
Jack251970 f9facda
Improve code quality
Jack251970 684fafd
Improve code quality
Jack251970 6841ad5
Add calculator unit testing
Jack251970 e10b925
Add workaround for log & ln function
Jack251970 552b654
Fix unit test result issue
Jack251970 8321e40
Fix test setting & Add instances to private fields
Jack251970 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Flow.Launcher.Plugin.Calculator; | ||
using Mages.Core; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
|
||
namespace Flow.Launcher.Test.Plugins | ||
{ | ||
[TestFixture] | ||
public class CalculatorPluginTest | ||
{ | ||
private readonly Main _plugin; | ||
|
||
public CalculatorPluginTest() | ||
{ | ||
_plugin = new Main(); | ||
|
||
var settingField = typeof(Main).GetField("_settings", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (settingField == null) | ||
Assert.Fail("Could not find field '_settings' on Flow.Launcher.Plugin.Calculator.Main"); | ||
settingField.SetValue(_plugin, new Settings | ||
{ | ||
ShowErrorMessage = false // Make sure we return the empty results when error occurs | ||
}); | ||
|
||
var engineField = typeof(Main).GetField("MagesEngine", BindingFlags.NonPublic | BindingFlags.Static); | ||
if (engineField == null) | ||
Assert.Fail("Could not find static field 'MagesEngine' on Flow.Launcher.Plugin.Calculator.Main"); | ||
engineField.SetValue(null, new Engine(new Configuration | ||
{ | ||
Scope = new Dictionary<string, object> | ||
{ | ||
{ "e", Math.E }, // e is not contained in the default mages engine | ||
} | ||
})); | ||
} | ||
|
||
// Basic operations | ||
[TestCase(@"1+1", "2")] | ||
[TestCase(@"2-1", "1")] | ||
[TestCase(@"2*2", "4")] | ||
[TestCase(@"4/2", "2")] | ||
[TestCase(@"2^3", "8")] | ||
// Decimal places | ||
[TestCase(@"10/3", "3.3333333333")] | ||
// Parentheses | ||
[TestCase(@"(1+2)*3", "9")] | ||
[TestCase(@"2^(1+2)", "8")] | ||
// Functions | ||
[TestCase(@"pow(2,3)", "8")] | ||
[TestCase(@"min(1,-1,-2)", "-2")] | ||
[TestCase(@"max(1,-1,-2)", "1")] | ||
[TestCase(@"sqrt(16)", "4")] | ||
[TestCase(@"sin(pi)", "0.0000000000")] | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[TestCase(@"cos(0)", "1")] | ||
[TestCase(@"tan(0)", "0")] | ||
[TestCase(@"log10(100)", "2")] | ||
[TestCase(@"log(100)", "2")] | ||
[TestCase(@"log2(8)", "3")] | ||
[TestCase(@"ln(e)", "1")] | ||
[TestCase(@"abs(-5)", "5")] | ||
// Constants | ||
[TestCase(@"pi", "3.1415926536")] | ||
// Complex expressions | ||
[TestCase(@"(2+3)*sqrt(16)-log(100)/ln(e)", "19")] | ||
[TestCase(@"sin(pi/2)+cos(0)+tan(0)", "2")] | ||
// Error handling (should return empty result) | ||
[TestCase(@"10/0", "")] | ||
[TestCase(@"sqrt(-1)", "")] | ||
[TestCase(@"log(0)", "")] | ||
[TestCase(@"invalid_expression", "")] | ||
public void CalculatorTest(string expression, string result) | ||
{ | ||
ClassicAssert.AreEqual(GetCalculationResult(expression), result); | ||
} | ||
|
||
private string GetCalculationResult(string expression) | ||
{ | ||
var results = _plugin.Query(new Plugin.Query() | ||
{ | ||
Search = expression | ||
}); | ||
return results.Count > 0 ? results[0].Title : string.Empty; | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.