mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-05 20:51:09 -07:00
Fixes issue #2326 (#2327)
Some checks are pending
Windows Calculator Continuous Integration Pipeline / Define builds (push) Waiting to run
Windows Calculator Continuous Integration Pipeline / Build (push) Blocked by required conditions
Windows Calculator Continuous Integration Pipeline / Run unit tests (push) Blocked by required conditions
Windows Calculator Continuous Integration Pipeline / Run UI tests (x64) (push) Blocked by required conditions
Some checks are pending
Windows Calculator Continuous Integration Pipeline / Define builds (push) Waiting to run
Windows Calculator Continuous Integration Pipeline / Build (push) Blocked by required conditions
Windows Calculator Continuous Integration Pipeline / Run unit tests (push) Blocked by required conditions
Windows Calculator Continuous Integration Pipeline / Run UI tests (x64) (push) Blocked by required conditions
* Fixes issue #2326 * Fixed an additional "decimal place" defect, in scope of issue #2326
This commit is contained in:
parent
be6eee0328
commit
0e6d669352
3 changed files with 175 additions and 3 deletions
|
@ -163,8 +163,16 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||
{
|
||||
m_bRecord = true;
|
||||
m_input.Clear();
|
||||
|
||||
/*
|
||||
* Account for scenarios where an equation includes any input after closing parenthesis - i.e. "(8)2=16".
|
||||
* This prevents the calculator from ending an equation and adding to history prematurely.
|
||||
*/
|
||||
if (m_nLastCom != IDC_CLOSEP)
|
||||
{
|
||||
CheckAndAddLastBinOpToHistory();
|
||||
}
|
||||
}
|
||||
|
||||
// Interpret digit keys.
|
||||
if (IsDigitOpCode(wParam))
|
||||
|
@ -185,6 +193,38 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||
return;
|
||||
}
|
||||
|
||||
// Check if the last command was a closing parenthesis
|
||||
if (m_nLastCom == IDC_CLOSEP)
|
||||
{
|
||||
// Treat this as an implicit multiplication
|
||||
m_nOpCode = IDC_MUL;
|
||||
m_lastVal = m_currentVal;
|
||||
|
||||
// We need to clear any previous state from last calculation
|
||||
m_holdVal = Rational(0);
|
||||
m_bNoPrevEqu = true;
|
||||
|
||||
// Add the operand to history before adding the implicit multiplication
|
||||
if (!m_HistoryCollector.FOpndAddedToHistory())
|
||||
{
|
||||
m_HistoryCollector.AddOpenBraceToHistory();
|
||||
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal);
|
||||
m_HistoryCollector.AddCloseBraceToHistory();
|
||||
}
|
||||
|
||||
// Add the implicit multiplication to history
|
||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, m_fIntegerMode);
|
||||
|
||||
m_bChangeOp = true;
|
||||
m_nPrevOpCode = 0;
|
||||
|
||||
// Clear any pending operations in the precedence stack
|
||||
while (m_precedenceOpCount > 0)
|
||||
{
|
||||
m_precedenceOpCount--;
|
||||
m_nPrecOp[m_precedenceOpCount] = 0;
|
||||
}
|
||||
}
|
||||
DisplayNum();
|
||||
|
||||
return;
|
||||
|
@ -504,11 +544,13 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||
{
|
||||
wstring groupedString = GroupDigitsPerRadix(m_numberString, m_radix);
|
||||
m_HistoryCollector.CompleteEquation(groupedString);
|
||||
|
||||
m_lastVal = m_currentVal;
|
||||
m_nPrevOpCode = 0;
|
||||
m_precedenceOpCount = 0;
|
||||
}
|
||||
|
||||
m_bChangeOp = false;
|
||||
m_nPrevOpCode = 0;
|
||||
|
||||
break;
|
||||
|
||||
case IDC_OPENP:
|
||||
|
@ -790,6 +832,40 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||
break;
|
||||
|
||||
case IDC_PNT:
|
||||
|
||||
// Check if the last command was a closing parenthesis
|
||||
if (m_nLastCom == IDC_CLOSEP)
|
||||
{
|
||||
// Treat this as an implicit multiplication
|
||||
m_nOpCode = IDC_MUL;
|
||||
m_lastVal = m_currentVal;
|
||||
|
||||
// We need to clear any previous state from last calculation
|
||||
m_holdVal = Rational(0);
|
||||
m_bNoPrevEqu = true;
|
||||
|
||||
// Add the operand to history before adding the implicit multiplication
|
||||
if (!m_HistoryCollector.FOpndAddedToHistory())
|
||||
{
|
||||
m_HistoryCollector.AddOpenBraceToHistory();
|
||||
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal);
|
||||
m_HistoryCollector.AddCloseBraceToHistory();
|
||||
}
|
||||
|
||||
// Add the implicit multiplication to history
|
||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, m_fIntegerMode);
|
||||
|
||||
m_bChangeOp = true;
|
||||
m_nPrevOpCode = 0;
|
||||
|
||||
// Clear any pending operations in the precedence stack
|
||||
while (m_precedenceOpCount > 0)
|
||||
{
|
||||
m_precedenceOpCount--;
|
||||
m_nPrecOp[m_precedenceOpCount] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bRecord && !m_fIntegerMode && m_input.TryAddDecimalPt())
|
||||
{
|
||||
DisplayNum();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using CalculatorUITestFramework;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace CalculatorUITests
|
||||
{
|
||||
|
@ -133,6 +134,81 @@ namespace CalculatorUITests
|
|||
Assert.AreEqual("12", page.CalculatorResults.GetCalculatorResultText());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Priority(0)]
|
||||
public void SmokeTest_CloseParenthesis()
|
||||
{
|
||||
/*
|
||||
* TEST #1
|
||||
*/
|
||||
page.ScientificOperators.ParenthesisLeftButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(8);
|
||||
page.ScientificOperators.ParenthesisRightButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(2);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
|
||||
// Assert calculator & history results
|
||||
Assert.AreEqual("16", page.CalculatorResults.GetCalculatorResultText());
|
||||
Assert.AreEqual("(8) \x00D7 2=", page.CalculatorResults.GetCalculatorExpressionText());
|
||||
|
||||
var historyItems0 = page.HistoryPanel.GetAllHistoryListViewItems();
|
||||
Assert.IsTrue(historyItems0[0].GetValue().Equals("16", StringComparison.InvariantCultureIgnoreCase));
|
||||
Assert.IsTrue(historyItems0[0].GetExpression().Equals("(8) \x00D7 2=", StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
/*
|
||||
* TEST #2
|
||||
*/
|
||||
page.ScientificOperators.ParenthesisLeftButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(7);
|
||||
page.StandardOperators.MultiplyButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(2);
|
||||
page.ScientificOperators.ParenthesisRightButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(2);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
|
||||
// Assert calculator & history results
|
||||
Assert.AreEqual("28", page.CalculatorResults.GetCalculatorResultText());
|
||||
Assert.AreEqual("(7 \x00D7 2) \x00D7 2=", page.CalculatorResults.GetCalculatorExpressionText());
|
||||
|
||||
var historyItems1 = page.HistoryPanel.GetAllHistoryListViewItems();
|
||||
Assert.IsTrue(historyItems1[0].GetValue().Equals("28", StringComparison.InvariantCultureIgnoreCase));
|
||||
Assert.IsTrue(historyItems1[0].GetExpression().Equals("(7 \x00D7 2) \x00D7 2=", StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
/*
|
||||
* TEST #3
|
||||
*/
|
||||
page.ScientificOperators.ParenthesisLeftButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(8);
|
||||
page.ScientificOperators.ParenthesisRightButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(0.5);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
|
||||
// Assert calculator & history results
|
||||
Assert.AreEqual("4", page.CalculatorResults.GetCalculatorResultText());
|
||||
Assert.AreEqual("(8) \x00D7 0.5=", page.CalculatorResults.GetCalculatorExpressionText());
|
||||
|
||||
var historyItems2 = page.HistoryPanel.GetAllHistoryListViewItems();
|
||||
Assert.IsTrue(historyItems2[0].GetValue().Equals("4", StringComparison.InvariantCultureIgnoreCase));
|
||||
Assert.IsTrue(historyItems2[0].GetExpression().Equals("(8) \x00D7 0.5=", StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
/*
|
||||
* TEST #4
|
||||
*/
|
||||
page.ScientificOperators.ParenthesisLeftButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(8);
|
||||
page.ScientificOperators.ParenthesisRightButton.Click();
|
||||
page.StandardOperators.NumberPad.Input(.5);
|
||||
page.StandardOperators.EqualButton.Click();
|
||||
|
||||
// Assert calculator & history results
|
||||
Assert.AreEqual("4", page.CalculatorResults.GetCalculatorResultText());
|
||||
Assert.AreEqual("(8) \x00D7 0.5=", page.CalculatorResults.GetCalculatorExpressionText());
|
||||
|
||||
var historyItems3 = page.HistoryPanel.GetAllHistoryListViewItems();
|
||||
Assert.IsTrue(historyItems3[0].GetValue().Equals("4", StringComparison.InvariantCultureIgnoreCase));
|
||||
Assert.IsTrue(historyItems3[0].GetExpression().Equals("(8) \x00D7 0.5=", StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Priority(0)]
|
||||
public void SmokeTest_RadianAngleOperator()
|
||||
|
|
|
@ -643,6 +643,26 @@ namespace CalculatorManagerTest
|
|||
Command commands5[] = { Command::Command2, Command::CommandOPENP, Command::Command2, Command::CommandCLOSEP,
|
||||
Command::CommandADD, Command::CommandEQU, Command::CommandNULL };
|
||||
TestDriver::Test(L"8", L"2 \x00D7 (2) + 4=", commands5, true, true);
|
||||
|
||||
Command commands6[] = { Command::CommandOPENP, Command::Command8, Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandNULL };
|
||||
TestDriver::Test(L"16", L"(8) \x00D7 2=", commands6, true, true);
|
||||
|
||||
Command commands7[] = { Command::CommandOPENP, Command::Command7, Command::CommandMUL, Command::Command2,
|
||||
Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandNULL };
|
||||
TestDriver::Test(L"28", L"(7 \x00D7 2) \x00D7 2=", commands7, true, true);
|
||||
|
||||
Command commands8[] = { Command::CommandOPENP, Command::Command7, Command::CommandMUL, Command::Command2,
|
||||
Command::CommandCLOSEP, Command::Command2, Command::CommandEQU,
|
||||
Command::CommandOPENP, Command::Command1, Command::Command4, Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandNULL};
|
||||
TestDriver::Test(L"28", L"(14) \x00D7 2=", commands8, true, true);
|
||||
|
||||
Command commands9[] = { Command::CommandOPENP, Command::Command8, Command::CommandCLOSEP,
|
||||
Command::Command0, Command::CommandPNT, Command::Command5, Command::CommandEQU, Command::CommandNULL };
|
||||
TestDriver::Test(L"4", L"(8) \x00D7 0.5=", commands9, true, true);
|
||||
|
||||
Command commands10[] = { Command::CommandOPENP, Command::Command8, Command::CommandCLOSEP,
|
||||
Command::CommandPNT, Command::Command5, Command::CommandEQU, Command::CommandNULL };
|
||||
TestDriver::Test(L"4", L"(8) \x00D7 0.5=", commands10, true, true);
|
||||
}
|
||||
|
||||
void CalculatorManagerTest::CalculatorManagerTestScientificError()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue