From db781b9026e5b7b021611428b7128e84a8b9c06e Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Mon, 11 Mar 2019 20:47:16 -0700 Subject: [PATCH] Add unit tests --- src/CalculatorUnitTests/CopyPasteManagerTest.cpp | 7 +++---- .../StandardViewModelUnitTests.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp index fa595cd4..7a33fa32 100644 --- a/src/CalculatorUnitTests/CopyPasteManagerTest.cpp +++ b/src/CalculatorUnitTests/CopyPasteManagerTest.cpp @@ -148,9 +148,8 @@ namespace CalculatorUnitTests VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ 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{ 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{ 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{ 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{ L"12323e456" }, ViewMode::Scientific, CategoryGroupType::Calculator, -1, -1), L"Verify operand only needs to match one pattern."); - VERIFY_IS_TRUE(m_CopyPasteManager.ExpressionRegExMatch(vector{ 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{ 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{ L"123", L"9223372036854775808" }, ViewMode::Programmer, CategoryGroupType::Calculator, DecBase, QwordType), L"Verify all operand must be within max value."); @@ -477,8 +476,8 @@ namespace CalculatorUnitTests void CopyPasteManagerTest::ValidateScientificPasteExpressionTest() { - String^ positiveInput[] = { L"123", L"+123", L"-133", L"123+456", L"12345e+023", L"1,234", L"1.23", L"-.123", L".1234", L"012.012", L"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"1 2 3", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ", L"1\"2", L"1.2e+023", L"12345e-23", L"(123)+(456)", L"12345678912345678123456789012345", L"(123)+(456)=", L"2+2= " }; - String^ negativeInput[] = { L"1.2e23"/*unsigned exponent*/, L"abcdef", L"xyz", L"ABab", L"e+234", L"123456789123456781234567890123456"/*boundary condition: greater than 32 digits*/, L"SIN(2)", L"2+2==", L"2=+2" }; + String^ positiveInput[] = { L"123", L"+123", L"-133", L"123+456", L"12345e+023", L"1,234", L"1.23", L"-.123", L".1234", L"012.012", L"123+-234", L"123*-345", L"123*4*-3", L"123*+4*-3", L"1 2 3", L"\n\r1,234\n", L"\f\n1+2\t\r\v\x85", L"\n 1+\n2 ", L"1\"2", L"1.2e+023", L"12345e-23", L"(123)+(456)", L"12345678912345678123456789012345", L"(123)+(456)=", L"2+2= ", L"1.2e23"/*unsigned exponent*/}; + String^ negativeInput[] = { L"abcdef", L"xyz", L"ABab", L"e+234", L"123456789123456781234567890123456"/*boundary condition: greater than 32 digits*/, L"SIN(2)", L"2+2==", L"2=+2" }; ASSERT_POSITIVE_TESTCASES(ValidateScientificPasteExpression, positiveInput); ASSERT_NEGATIVE_TESTCASES(ValidateScientificPasteExpression, negativeInput); diff --git a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp index 214c612f..b0e2cef4 100644 --- a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp +++ b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" @@ -462,6 +462,12 @@ namespace CalculatorUnitTests m_viewModel->OnPaste("1.23e+10", ViewMode::Scientific); ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e+10", ""); + m_viewModel->OnPaste("1.23e10", ViewMode::Scientific); + ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e+10", ""); + + m_viewModel->OnPaste("135e10", ViewMode::Scientific); + ValidateViewModelValueAndExpression("135" + m_decimalSeparator + "e+10", ""); + //// Negative exponent m_viewModel->OnPaste("1.23e-10", ViewMode::Scientific); ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e-10", ""); @@ -469,6 +475,9 @@ namespace CalculatorUnitTests //// Uppercase E (for exponent) m_viewModel->OnPaste("1.23E-10", ViewMode::Scientific); ValidateViewModelValueAndExpression("1" + m_decimalSeparator + "23e-10", ""); + + m_viewModel->OnPaste("135E10", ViewMode::Scientific); + ValidateViewModelValueAndExpression("135" + m_decimalSeparator + "e+10", ""); } // Verify Calculator CalculationResultAutomationName is set correctly