Fix prefix 0s after deleting decimal point (#825)

This commit is contained in:
dovisutu 2020-01-03 18:21:12 +08:00 committed by Rudy Huyn
parent a21b4a2d1a
commit 9e52256196
3 changed files with 25 additions and 0 deletions

View File

@ -231,6 +231,10 @@ void CalcInput::Backspace()
if (!m_base.IsEmpty()) if (!m_base.IsEmpty())
{ {
m_base.value.pop_back(); m_base.value.pop_back();
if (m_base.value == L"0")
{
m_base.value.pop_back();
}
} }
if (m_base.value.size() <= m_decPtIndex) if (m_base.value.size() <= m_decPtIndex)

View File

@ -184,6 +184,17 @@ public void Operator_Delete()
Assert.AreEqual("-1,234", page.GetCalculatorResultText()); Assert.AreEqual("-1,234", page.GetCalculatorResultText());
} }
// Issue #817: Prefixed multiple zeros
[TestMethod]
public void Operator_Delete_Prefix_Zeros()
{
page.StandardOperators.NumberPad.Input(0.1); // To enter decimal point
page.StandardOperators.BackSpaceButton.Click();
page.StandardOperators.BackSpaceButton.Click();
page.StandardOperators.NumberPad.Input(0);
Assert.AreEqual("0", page.GetCalculatorResultText());
}
[TestMethod] [TestMethod]
public void Operator_ClearAll() public void Operator_ClearAll()
{ {

View File

@ -252,6 +252,16 @@ namespace CalculatorEngineTests
m_calcInput.Backspace(); m_calcInput.Backspace();
VERIFY_ARE_EQUAL(L"1.2", m_calcInput.ToString(10), L"Verify input after backspace."); VERIFY_ARE_EQUAL(L"1.2", m_calcInput.ToString(10), L"Verify input after backspace.");
} }
// Issue #817: Prefixed multiple zeros
TEST_METHOD(BackspaceZeroDecimalWithoutPrefixZeros)
{
m_calcInput.TryAddDigit(0, 10, false, L"999", 64, 32);
m_calcInput.TryAddDecimalPt();
VERIFY_ARE_EQUAL(L"0.", m_calcInput.ToString(10), L"Verify input before backspace.")
m_calcInput.Backspace();
m_calcInput.TryAddDigit(0, 10, false, L"999", 64, 32);
VERIFY_ARE_EQUAL(L"0", m_calcInput.ToString(10), L"Verify input after backspace.")
}
TEST_METHOD(SetDecimalSymbol) TEST_METHOD(SetDecimalSymbol)
{ {