From 10ae9430a049af1d0dec24ed8e6ffdc8c82a2f23 Mon Sep 17 00:00:00 2001 From: Tian L <60599517+tian-lt@users.noreply.github.com> Date: Thu, 26 Aug 2021 10:58:36 +0800 Subject: [PATCH] Simple fix for the omitted multiplication sign before a left parenthesis (#1661) * simple fix for the omitted multiplication sign * accepts unary-op-code --- src/CalcManager/CEngine/scicomm.cpp | 6 ++++++ src/CalculatorUnitTests/CalculatorManagerTest.cpp | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 72d9206..42b70ba 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -519,6 +519,12 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) if (wParam == IDC_OPENP) { + // if there's an omitted multiplication sign + if (IsDigitOpCode(m_nLastCom) || IsUnaryOpCode(m_nLastCom) || m_nLastCom == IDC_PNT || m_nLastCom == IDC_CLOSEP) + { + ProcessCommand(IDC_MUL); + } + CheckAndAddLastBinOpToHistory(); m_HistoryCollector.AddOpenBraceToHistory(); diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp index 4837e3f..e123389 100644 --- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp +++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp @@ -633,16 +633,16 @@ namespace CalculatorManagerTest Command commands3[] = { Command::Command1, Command::Command2, Command::CommandCLOSEP, Command::CommandCLOSEP, Command::CommandOPENP, Command::CommandNULL }; - TestDriver::Test(L"12", L"(", commands3, true, true); + TestDriver::Test(L"12", L"12 \x00D7 (", commands3, true, true); Command commands4[] = { Command::Command2, Command::CommandOPENP, Command::Command2, Command::CommandCLOSEP, Command::CommandADD, Command::CommandNULL }; - TestDriver::Test(L"2", L"(2) + ", commands4, true, true); + TestDriver::Test(L"4", L"2 \x00D7 (2) + ", commands4, true, true); Command commands5[] = { Command::Command2, Command::CommandOPENP, Command::Command2, Command::CommandCLOSEP, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"(2) + 2=", commands5, true, true); + TestDriver::Test(L"8", L"2 \x00D7 (2) + 4=", commands5, true, true); } void CalculatorManagerTest::CalculatorManagerTestScientificError()