-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8c890f
commit 1a84923
Showing
3 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
ZenUnitUtilsAndAssertionTests/Assertions/SPANS_ARE_EQUALTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#include "pch.h" | ||
|
||
namespace ZenUnit | ||
{ | ||
template<typename T> | ||
TEMPLATE_TESTS(SPANS_ARE_EQUALTests, T) | ||
AFACT(ConstEmptySpans_DoesNothing) | ||
AFACT(NonConstEmptySpans_DoesNothing) | ||
AFACT(ConstNonEmptySpans_AllElementsEqual_DoesNothing) | ||
AFACT(ConstNonEmptySpans_SizesAreNotEqual_ThrowsAnomaly) | ||
AFACT(ConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly__TestCase1) | ||
AFACT(ConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly__TestCase2) | ||
AFACT(NonConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly) | ||
EVIDENCE | ||
|
||
const string TypeName = *Type::GetName<T>(); | ||
const string _constSpanTypeName = *Type::GetName<span<const T>>(); | ||
const string _nonConstSpanTypeName = *Type::GetName<span<T>>(); | ||
|
||
TEST(ConstEmptySpans_DoesNothing) | ||
{ | ||
const span<const T> expectedSpan; | ||
const span<const T> actualSpan; | ||
SPANS_ARE_EQUAL(expectedSpan, actualSpan); | ||
} | ||
|
||
TEST(NonConstEmptySpans_DoesNothing) | ||
{ | ||
const span<T> expectedSpan; | ||
const span<T> actualSpan; | ||
SPANS_ARE_EQUAL(expectedSpan, actualSpan); | ||
} | ||
|
||
TEST(ConstNonEmptySpans_AllElementsEqual_DoesNothing) | ||
{ | ||
const vector<T> expectedElements{ 1, 2, 3 }; | ||
const vector<T> actualElements{ 1, 2, 3 }; | ||
|
||
const span<const T> expectedSpan = expectedElements; | ||
const span<const T> actualSpan = actualElements; | ||
SPANS_ARE_EQUAL(expectedSpan, actualSpan); | ||
} | ||
|
||
TEST(ConstNonEmptySpans_SizesAreNotEqual_ThrowsAnomaly) | ||
{ | ||
const vector<T> expectedElements; | ||
const vector<T> actualElements{ 1 }; | ||
|
||
const span<const T> expectedSpan = expectedElements; | ||
const span<const T> actualSpan = actualElements; | ||
|
||
THROWS_EXCEPTION(SPANS_ARE_EQUAL(expectedSpan, actualSpan), | ||
Anomaly, TestUtil::NewlineConcat("", | ||
" Failed: SPANS_ARE_EQUAL(expectedSpan, actualSpan)", | ||
"Expected: " + _constSpanTypeName + " (size 0):", | ||
"{", | ||
"}", | ||
" Actual: " + _constSpanTypeName + " (size 1):", | ||
"{", | ||
" 1", | ||
"}", | ||
" Because: ARE_EQUAL(expectedSpan.size(), actualSpan.size()) failed", | ||
"Expected: 0", | ||
" Actual: 1", | ||
"File.cpp(1)", | ||
"File.cpp(1)")); | ||
} | ||
|
||
TEST(ConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly__TestCase1) | ||
{ | ||
const vector<T> expectedElements{ 0 }; | ||
const vector<T> actualElements{ 1 }; | ||
|
||
const span<const T> expectedSpan = expectedElements; | ||
const span<const T> actualSpan = actualElements; | ||
|
||
THROWS_EXCEPTION(SPANS_ARE_EQUAL(expectedSpan, actualSpan), | ||
Anomaly, TestUtil::NewlineConcat("", | ||
" Failed: SPANS_ARE_EQUAL(expectedSpan, actualSpan)", | ||
"Expected: " + _constSpanTypeName + " (size 1):", | ||
"{", | ||
" 0", | ||
"}", | ||
" Actual: " + _constSpanTypeName + " (size 1):", | ||
"{", | ||
" 1", | ||
"}", | ||
" Because: ARE_EQUAL(ithExpectedElement, ithActualElement, indexMessage) failed", | ||
"Expected: 0", | ||
" Actual: 1", | ||
" Message: \"i=0\"", | ||
"File.cpp(1)", | ||
"File.cpp(1)")); | ||
} | ||
|
||
TEST(ConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly__TestCase2) | ||
{ | ||
const vector<T> expectedElements{ 0, 1, 20 }; | ||
const vector<T> actualElements{ 0, 1, 30 }; | ||
|
||
const span<const T> expectedSpan = expectedElements; | ||
const span<const T> actualSpan = actualElements; | ||
|
||
THROWS_EXCEPTION(SPANS_ARE_EQUAL(expectedSpan, actualSpan), | ||
Anomaly, TestUtil::NewlineConcat("", | ||
" Failed: SPANS_ARE_EQUAL(expectedSpan, actualSpan)", | ||
"Expected: " + _constSpanTypeName + " (size 3):", | ||
"{", | ||
" 0,", | ||
" 1,", | ||
" 20", | ||
"}", | ||
" Actual: " + _constSpanTypeName + " (size 3):", | ||
"{", | ||
" 0,", | ||
" 1,", | ||
" 30", | ||
"}", | ||
" Because: ARE_EQUAL(ithExpectedElement, ithActualElement, indexMessage) failed", | ||
"Expected: 20", | ||
" Actual: 30", | ||
" Message: \"i=2\"", | ||
"File.cpp(1)", | ||
"File.cpp(1)")); | ||
} | ||
|
||
TEST(NonConstNonEmptySpans_SizesAreEqual_ElementsAreNotEqual_ThrowsAnomaly) | ||
{ | ||
vector<T> expectedElements{ 0 }; | ||
vector<T> actualElements{ 1 }; | ||
|
||
const span<T> expectedSpan = expectedElements; | ||
const span<T> actualSpan = actualElements; | ||
|
||
THROWS_EXCEPTION(SPANS_ARE_EQUAL(expectedSpan, actualSpan), | ||
Anomaly, TestUtil::NewlineConcat("", | ||
" Failed: SPANS_ARE_EQUAL(expectedSpan, actualSpan)", | ||
"Expected: " + _nonConstSpanTypeName + " (size 1):", | ||
"{", | ||
" 0", | ||
"}", | ||
" Actual: " + _nonConstSpanTypeName + " (size 1):", | ||
"{", | ||
" 1", | ||
"}", | ||
" Because: ARE_EQUAL(ithExpectedElement, ithActualElement, indexMessage) failed", | ||
"Expected: 0", | ||
" Actual: 1", | ||
" Message: \"i=0\"", | ||
"File.cpp(1)", | ||
"File.cpp(1)")); | ||
} | ||
|
||
RUN_TEMPLATE_TESTS(SPANS_ARE_EQUALTests, int) | ||
THEN_RUN_TEMPLATE_TESTS(SPANS_ARE_EQUALTests, unsigned long long) | ||
} |