add exponential without sign support

This commit is contained in:
Rudy Huyn 2019-03-11 19:59:35 -07:00
commit 3654ccd95b
3 changed files with 45 additions and 30 deletions

View file

@ -45,7 +45,7 @@ static const array<wregex, 1> standardModePatterns =
static const array<wregex, 2> scientificModePatterns = static const array<wregex, 2> scientificModePatterns =
{ {
wregex(c_wspcLParens + c_signedDecFloat + c_wspcRParens), wregex(c_wspcLParens + c_signedDecFloat + c_wspcRParens),
wregex(c_wspcLParens + c_signedDecFloat + L"[e]([+]|[-])+\\d+" + c_wspcRParens) wregex(c_wspcLParens + c_signedDecFloat + L"e[+-]?\\d+" + c_wspcRParens)
}; };
static const array<array<wregex, 5>, 4> programmerModePatterns = static const array<array<wregex, 5>, 4> programmerModePatterns =
{ { { {

View file

@ -504,7 +504,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{ {
if (commandIndex == 0) if (commandIndex == 0)
{ {
delete [] temp; delete[] temp;
return; return;
} }
@ -855,14 +855,25 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
} }
} }
// Handle exponent and exponent sign (...e+... or ...e-...) // Handle exponent and exponent sign (...e+... or ...e-... or ...e...)
if (mappedNumOp == NumbersAndOperatorsEnum::Exp) if (mappedNumOp == NumbersAndOperatorsEnum::Exp)
{ {
++it; //Check the following item
if (!(MapCharacterToButtonId(*it, canSendNegate) == NumbersAndOperatorsEnum::Add)) switch (MapCharacterToButtonId(*(it + 1), canSendNegate))
{
case NumbersAndOperatorsEnum::Subtract:
{ {
Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate); Command cmdNegate = ConvertToOperatorsEnum(NumbersAndOperatorsEnum::Negate);
m_standardCalculatorManager.SendCommand(cmdNegate); m_standardCalculatorManager.SendCommand(cmdNegate);
++it;
}
break;
case NumbersAndOperatorsEnum::Add:
{
//Nothing to do, skip to the next item
++it;
}
break;
} }
} }

View file

@ -147,6 +147,10 @@ namespace CalculatorUnitTests
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1)); VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"1e23" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1));
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"1.23e+456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern."); VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"1.23e+456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern.");
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123e-456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern.");
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123e -456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern.");
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"12323e456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern.");
VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"12323 e 456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern.");
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), L"Verify all operands must be within maxlength"); VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"12345678901234567" }, ViewMode::Standard, CategoryGroupType::Calculator, -1, -1), L"Verify all operands must be within maxlength");
VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify all operand must be within max value."); VERIFY_IS_FALSE(m_CopyPasteManager.ExpressionRegExMatch(vector<wstring>{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify all operand must be within max value.");