Fixed an additional "decimal place" defect, in scope of issue #2326

This commit is contained in:
Jordan Sinclair 2025-05-18 00:40:35 -05:00
commit 424275ee8f
3 changed files with 76 additions and 0 deletions

View file

@ -832,6 +832,40 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
break; break;
case IDC_PNT: 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()) if (m_bRecord && !m_fIntegerMode && m_input.TryAddDecimalPt())
{ {
DisplayNum(); DisplayNum();

View file

@ -173,6 +173,40 @@ namespace CalculatorUITests
var historyItems1 = page.HistoryPanel.GetAllHistoryListViewItems(); var historyItems1 = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyItems1[0].GetValue().Equals("28", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(historyItems1[0].GetValue().Equals("28", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems1[0].GetExpression().Equals("(7 \x00D7 2) \x00D7 2=", 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] [TestMethod]

View file

@ -655,6 +655,14 @@ namespace CalculatorManagerTest
Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandCLOSEP, Command::Command2, Command::CommandEQU,
Command::CommandOPENP, Command::Command1, Command::Command4, Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandNULL}; 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); 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() void CalculatorManagerTest::CalculatorManagerTestScientificError()