mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-14 18:47:04 -07:00
Merge 8fb959e296
into 06eb235d48
This commit is contained in:
commit
fb7c584fd4
12 changed files with 140 additions and 32 deletions
|
@ -822,6 +822,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||
DisplayNum();
|
||||
break;
|
||||
|
||||
case IDC_ENG:
|
||||
m_nFE = NumberFormat::Engineering;
|
||||
DisplayNum();
|
||||
break;
|
||||
|
||||
case IDC_EXP:
|
||||
if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent())
|
||||
{
|
||||
|
|
|
@ -66,6 +66,7 @@ namespace CalculationManager
|
|||
CommandGRAD = 323,
|
||||
CommandDegrees = 324,
|
||||
CommandHYP = 325,
|
||||
CommandENG = 326,
|
||||
|
||||
CommandNULL = 0,
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#define IDM_RAD 322
|
||||
#define IDM_GRAD 323
|
||||
#define IDM_DEGREES 324
|
||||
#define IDC_ENG 326
|
||||
|
||||
#define IDC_HEX IDM_HEX
|
||||
#define IDC_DEC IDM_DEC
|
||||
|
|
|
@ -1171,7 +1171,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radi
|
|||
{
|
||||
if (format == NumberFormat::Engineering)
|
||||
{
|
||||
exponent = (eout % 3);
|
||||
exponent = (3 + (eout % 3)) % 3;
|
||||
eout -= exponent;
|
||||
exponent++;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace CalculatorApp::ViewModel::Common
|
|||
Radians = (int)CM::Command::CommandRAD,
|
||||
Grads = (int)CM::Command::CommandGRAD,
|
||||
Degrees = (int)CM::Command::CommandDegrees,
|
||||
Engineering = (int)CM::Command::CommandENG,
|
||||
OpenParenthesis = (int)CM::Command::CommandOPENP,
|
||||
CloseParenthesis = (int)CM::Command::CommandCLOSEP,
|
||||
Pi = (int)CM::Command::CommandPI,
|
||||
|
|
|
@ -499,6 +499,12 @@ void StandardCalculatorViewModel::FtoEButtonToggled()
|
|||
OnButtonPressed(NumbersAndOperatorsEnum::FToE);
|
||||
}
|
||||
|
||||
void StandardCalculatorViewModel::EngButton()
|
||||
{
|
||||
OnButtonPressed(NumbersAndOperatorsEnum::Engineering);
|
||||
}
|
||||
|
||||
|
||||
void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
|
||||
{
|
||||
DisplayExpressionToken ^ displayExpressionToken = ExpressionTokens->GetAt(m_TokenPosition);
|
||||
|
|
|
@ -266,6 +266,7 @@ namespace CalculatorApp
|
|||
void SetOpenParenthesisCountNarratorAnnouncement();
|
||||
void SwitchAngleType(CalculatorApp::ViewModel::Common::NumbersAndOperatorsEnum num);
|
||||
void FtoEButtonToggled();
|
||||
void EngButton();
|
||||
|
||||
internal : void OnPaste(Platform::String ^ pastedString);
|
||||
void OnCopyCommand(Platform::Object ^ parameter);
|
||||
|
|
|
@ -98,21 +98,32 @@
|
|||
CommandParameter="2"
|
||||
Content="GRAD"
|
||||
Visibility="Collapsed"/>
|
||||
<ToggleButton x:Name="FtoeButton"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource CaptionToggleButtonWithIndicatorStyle}"
|
||||
Background="{ThemeResource SystemControlBackgroundTransparentBrush}"
|
||||
common:KeyboardShortcutManager.VirtualKey="{utils:ResourceVirtualKey Name=ftoeButton/[using:CalculatorApp.Common]KeyboardShortcutManager/VirtualKey}"
|
||||
AutomationProperties.AutomationId="ftoeButton"
|
||||
AutomationProperties.Name="{utils:ResourceString Name=ftoeButton/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
|
||||
Checked="FToEButton_Toggled"
|
||||
Content="F-E"
|
||||
IsChecked="{x:Bind Model.IsFToEChecked, Mode=OneWay}"
|
||||
Unchecked="FToEButton_Toggled"
|
||||
IsEnabled="{x:Bind Model.IsFToEEnabled, Mode=OneWay}">
|
||||
<ToggleButton.CommandParameter>
|
||||
<local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum>
|
||||
</ToggleButton.CommandParameter>
|
||||
</ToggleButton>
|
||||
|
||||
<Button x:Name="AutoButton"
|
||||
x:Uid="AutoButton"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource CaptionButtonSmallStyle}"
|
||||
AutomationProperties.AutomationId="autoButton"
|
||||
Command="{x:Bind NotationPressed}"
|
||||
CommandParameter="0"
|
||||
Content="AUTO"/>
|
||||
<Button x:Name="SciButton"
|
||||
x:Uid="SciButton"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource CaptionButtonSmallStyle}"
|
||||
AutomationProperties.AutomationId="sciButton"
|
||||
Command="{x:Bind NotationPressed}"
|
||||
CommandParameter="1"
|
||||
Content="SCI"
|
||||
Visibility="Collapsed"/>
|
||||
<Button x:Name="EngButton"
|
||||
x:Uid="EngButton"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource CaptionButtonSmallStyle}"
|
||||
AutomationProperties.AutomationId="engButton"
|
||||
Command="{x:Bind NotationPressed}"
|
||||
CommandParameter="2"
|
||||
Content="ENG"
|
||||
Visibility="Collapsed"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
@ -17,10 +17,10 @@ namespace CalculatorApp
|
|||
[Windows.Foundation.Metadata.WebHostHidden]
|
||||
public sealed partial class CalculatorScientificAngleButtons
|
||||
{
|
||||
public CalculatorScientificAngleButtons()
|
||||
public CalculatorScientificAngleButtons()
|
||||
{
|
||||
m_isErrorVisualState = false;
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public StandardCalculatorViewModel Model => (StandardCalculatorViewModel)this.DataContext;
|
||||
|
@ -84,10 +84,49 @@ namespace CalculatorApp
|
|||
}
|
||||
}
|
||||
|
||||
private void FToEButton_Toggled(object sender, RoutedEventArgs e)
|
||||
public System.Windows.Input.ICommand NotationPressed
|
||||
{
|
||||
var viewModel = (StandardCalculatorViewModel)this.DataContext;
|
||||
viewModel.FtoEButtonToggled();
|
||||
get
|
||||
{
|
||||
if (donotuse_NotationPressed == null)
|
||||
{
|
||||
donotuse_NotationPressed = DelegateCommandUtils.MakeDelegateCommand(this,
|
||||
(that, param) =>
|
||||
{
|
||||
that.OnNotationButtonPressed(param);
|
||||
});
|
||||
}
|
||||
return donotuse_NotationPressed;
|
||||
}
|
||||
}
|
||||
private System.Windows.Input.ICommand donotuse_NotationPressed;
|
||||
|
||||
private void OnNotationButtonPressed(object commandParameter)
|
||||
{
|
||||
string buttonId = (string)commandParameter;
|
||||
|
||||
AutoButton.Visibility = Visibility.Collapsed;
|
||||
SciButton.Visibility = Visibility.Collapsed;
|
||||
EngButton.Visibility = Visibility.Collapsed;
|
||||
|
||||
if (buttonId == "0")
|
||||
{
|
||||
Model.FtoEButtonToggled();
|
||||
SciButton.Visibility = Visibility.Visible;
|
||||
SciButton.Focus(FocusState.Programmatic);
|
||||
}
|
||||
else if (buttonId == "1")
|
||||
{
|
||||
Model.EngButton();
|
||||
EngButton.Visibility = Visibility.Visible;
|
||||
EngButton.Focus(FocusState.Programmatic);
|
||||
}
|
||||
else if (buttonId == "2")
|
||||
{
|
||||
Model.FtoEButtonToggled();
|
||||
AutoButton.Visibility = Visibility.Visible;
|
||||
AutoButton.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
|
||||
private bool m_isErrorVisualState;
|
||||
|
|
|
@ -17,8 +17,9 @@ namespace CalculatorUITestFramework
|
|||
|
||||
public enum FEButtonState
|
||||
{
|
||||
Normal,
|
||||
Exponential
|
||||
Auto,
|
||||
Scientific,
|
||||
Engineering
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -78,11 +79,14 @@ namespace CalculatorUITestFramework
|
|||
public WindowsElement RandButton => this.session.TryFindElementByAccessibilityId("randButton");
|
||||
public WindowsElement DmsButton => this.session.TryFindElementByAccessibilityId("dmsButton");
|
||||
public WindowsElement DegreesButton => this.session.TryFindElementByAccessibilityId("degreesButton");
|
||||
public WindowsElement FixedToExponentialButton => this.session.TryFindElementByAccessibilityId("ftoeButton");
|
||||
public WindowsElement AutoButton => this.session.TryFindElementByAccessibilityId("autoButton");
|
||||
public WindowsElement SciButton => this.session.TryFindElementByAccessibilityId("sciButton");
|
||||
public WindowsElement EngButton => this.session.TryFindElementByAccessibilityId("engButton");
|
||||
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
|
||||
public WindowsElement ShiftButton => this.session.TryFindElementByAccessibilityId("shiftButton");
|
||||
public WindowsElement TrigFlyout => this.session.TryFindElementByAccessibilityId("Trigflyout");
|
||||
public WindowsElement LightDismiss => this.session.TryFindElementByAccessibilityId("Light Dismiss");
|
||||
private WindowsElement AutoSciEngButton => GetNumberFormatButton();
|
||||
private WindowsElement DegRadGradButton => GetAngleOperatorButton();
|
||||
private WindowsElement GetAngleOperatorButton()
|
||||
{
|
||||
|
@ -103,6 +107,25 @@ namespace CalculatorUITestFramework
|
|||
throw new NotFoundException("Could not find deg, rad or grad button in page source");
|
||||
}
|
||||
|
||||
private WindowsElement GetNumberFormatButton()
|
||||
{
|
||||
string source = this.session.PageSource;
|
||||
if (source.Contains("autoButton"))
|
||||
{
|
||||
return AutoButton;
|
||||
}
|
||||
else if (source.Contains("sciButton"))
|
||||
{
|
||||
return SciButton;
|
||||
}
|
||||
else if (source.Contains("engButton"))
|
||||
{
|
||||
return EngButton;
|
||||
}
|
||||
|
||||
throw new NotFoundException("Could not find auto, sci, or eng button in page source");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the state of the degrees, radians and gradians buttons.
|
||||
/// </summary>
|
||||
|
@ -122,11 +145,19 @@ namespace CalculatorUITestFramework
|
|||
}
|
||||
}
|
||||
|
||||
public void ResetFEButton(FEButtonState value)
|
||||
public void SetNumberFormat(FEButtonState value)
|
||||
{
|
||||
if (this.FixedToExponentialButton.GetAttribute("Toggle.ToggleState") != "0")
|
||||
//set the desired string value for the button
|
||||
string desiredId = value switch
|
||||
{
|
||||
FixedToExponentialButton.Click();
|
||||
FEButtonState.Auto => "autoButton",
|
||||
FEButtonState.Scientific => "sciButton",
|
||||
FEButtonState.Engineering => "engButton",
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
while (this.AutoSciEngButton.GetAttribute("AutomationId") != desiredId)
|
||||
{
|
||||
this.AutoSciEngButton.Click();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using CalculatorUITestFramework;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace CalculatorUITests
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace CalculatorUITests
|
|||
}
|
||||
CalculatorApp.EnsureCalculatorHasFocus();
|
||||
page.ScientificOperators.SetAngleOperator(AngleOperatorState.Degrees);
|
||||
page.ScientificOperators.ResetFEButton(FEButtonState.Normal);
|
||||
page.ScientificOperators.SetNumberFormat(FEButtonState.Auto);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
@ -237,11 +237,22 @@ namespace CalculatorUITests
|
|||
|
||||
[TestMethod]
|
||||
[Priority(0)]
|
||||
public void SmokeTest_FixedToExponential()
|
||||
public void SmokeTest_ScientificFormat()
|
||||
{
|
||||
page.ScientificOperators.FixedToExponentialButton.Click();
|
||||
page.ScientificOperators.SetNumberFormat(FEButtonState.Scientific);
|
||||
page.StandardOperators.NumberPad.Input(0.123);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
Assert.AreEqual("0.e+0", page.CalculatorResults.GetCalculatorResultText());
|
||||
Assert.AreEqual("1.23e-1", page.CalculatorResults.GetCalculatorResultText());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Priority(0)]
|
||||
public void SmokeTest_EngineeringFormat()
|
||||
{
|
||||
page.ScientificOperators.SetNumberFormat(FEButtonState.Engineering);
|
||||
page.StandardOperators.NumberPad.Input(0.123);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
Assert.AreEqual("123.e-3", page.CalculatorResults.GetCalculatorResultText());
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue