Skip to content

Commit

Permalink
CopyPasteManagerTest fails to test all values (microsoft#269)
Browse files Browse the repository at this point in the history
CopyPasteManager unit tests were not fully run, the first item of arrays were never tested. (Luckily, the not-tested values were ok).

Updated from using a pre-decrement while loop to using a standard for loop with an iterator.
  • Loading branch information
rudyhuyn authored and HowardWolosky committed Mar 12, 2019
1 parent 67fa228 commit a80d082
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/CalculatorUnitTests/CopyPasteManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,17 @@ namespace CalculatorUnitTests

#define ASSERT_POSITIVE_TESTCASES(func, dataSet) \
{\
int size = sizeof(dataSet)/sizeof(*dataSet);\
while(--size)\
for(auto data : dataSet)\
{\
VERIFY_ARE_EQUAL(func(dataSet[size]), dataSet[size]);\
VERIFY_ARE_EQUAL(func(data), data);\
}\
}

#define ASSERT_NEGATIVE_TESTCASES(func, dataSet) \
{\
int size = sizeof(dataSet)/sizeof(*dataSet);\
while(--size)\
for(auto data : dataSet)\
{\
VERIFY_ARE_EQUAL(func(dataSet[size]), StringReference(L"NoOp"));\
}\
}

// returns a iterator from end
#define START_LOOP(dataSet)\
{\
int size = sizeof(dataSet)/sizeof(*dataSet);\
while(--size)\
{

#define END_LOOP\
VERIFY_ARE_EQUAL(func(data), StringReference(L"NoOp"));\
}\
}

Expand Down Expand Up @@ -450,15 +437,16 @@ namespace CalculatorUnitTests
// Doesn't have test where converter is involved. Will add such a test later.
StandardCalculatorViewModel^ scvm = ref new StandardCalculatorViewModel();
scvm->IsStandard = true;
String^ input[] = { L"123", L"12345", L"123+456", L"1,234", L"1 2 3", L"\n\r1,234\n", L"\n 1+\n2 ", L"1\"2" };
String^ inputs[] = { L"123", L"12345", L"123+456", L"1,234", L"1 2 3", L"\n\r1,234\n", L"\n 1+\n2 ", L"1\"2" };

START_LOOP(input)
for (String^ &input : inputs)
{
// paste number in standard mode and then validate the pastability of displayed number for other modes
scvm->OnPaste(input[size], ViewMode::Standard);
scvm->OnPaste(input, ViewMode::Standard);
VERIFY_ARE_EQUAL(ValidateStandardPasteExpression(scvm->DisplayValue), scvm->DisplayValue);
VERIFY_ARE_EQUAL(ValidateScientificPasteExpression(scvm->DisplayValue), scvm->DisplayValue);
VERIFY_ARE_EQUAL(ValidateProgrammerHexQwordPasteExpression(scvm->DisplayValue), scvm->DisplayValue);
END_LOOP
}
}


Expand Down

0 comments on commit a80d082

Please sign in to comment.