Commits

Matt Oswald committed e04789f

originally failed to implement NotEqual for strings, added unit tests for Equal, NotEqual for strings

Comments (0)

Files changed (4)

Tests/UnitTests/Assert.Equal.cpp

     Assert.Contains(assert.what(), "at location 0");
 }
 
+FACT(EqualForStrings)
+{
+    std::string expected = "abcd";
+    std::string actual = "abc";
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.Equal(expected.c_str(), actual.c_str()); });
+    Assert.Throws<xUnitAssert>([=]() { Assert.Equal(expected.c_str(), actual); });
+    Assert.Throws<xUnitAssert>([=]() { Assert.Equal(expected, actual.c_str()); });
+    Assert.Throws<xUnitAssert>([=]() { Assert.Equal(expected, actual); });
 }
+
+
+}

Tests/UnitTests/Assert.NotEqual.cpp

     Assert.Throws<xUnitAssert>([&]() { Assert.NotEqual(v0.begin(), v0.end(), v1.begin(), v1.end(), [](int, long long) { return true; }); });
 }
 
+FACT(NotEqualForStrings)
+{
+    std::string expected = "abcd";
+    std::string actual = "abcd";
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotEqual(expected.c_str(), actual.c_str()); }, LI);
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotEqual(expected.c_str(), actual); }, LI);
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotEqual(expected, actual.c_str()); }, LI);
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotEqual(expected, actual); }, LI);
 }
+
+}

xUnit++/src/xUnitAssert.cpp

     return Equal(er, ar, [](double er, double ar) { return er == ar; }, lineInfo);
 }
 
+xUnitFailure Assert::NotEqual(const std::string &expected, const std::string &actual, const LineInfo &lineInfo) const
+{
+    if (expected == actual)
+    {
+        return OnFailure(xUnitAssert(callPrefix + "NotEqual", lineInfo)
+            .Expected(expected)
+            .Actual(actual));
+    }
+
+    return OnSuccess();
+}
+
+xUnitFailure Assert::NotEqual(const char *expected, const char *actual, const LineInfo &lineInfo) const
+{
+    return NotEqual(std::string(expected), std::string(actual), lineInfo);
+}
+
+xUnitFailure Assert::NotEqual(const char *expected, const std::string &actual, const LineInfo &lineInfo) const
+{
+    return NotEqual(std::string(expected), actual, lineInfo);
+}
+
+xUnitFailure Assert::NotEqual(const std::string &expected, const char *actual, const LineInfo &lineInfo) const
+{
+    return NotEqual(expected, std::string(actual), lineInfo);
+}
+
 xUnitFailure Assert::Fail(const LineInfo &lineInfo) const
 {
     return OnFailure(xUnitAssert(callPrefix + "Fail", lineInfo));

xUnit++/xUnit++/xUnitAssert.h

         return NotEqual(expected, actual, [](TExpected expected, TActual actual) { return expected == actual; }, lineInfo);
     }
 
+    xUnitFailure NotEqual(const char *expected, const char *actual, const LineInfo &lineInfo = LineInfo::empty()) const;
+    xUnitFailure NotEqual(const char *expected, const std::string &actual, const LineInfo &lineInfo = LineInfo::empty()) const;
+    xUnitFailure NotEqual(const std::string &expected, const char *actual, const LineInfo &lineInfo = LineInfo::empty()) const;
+    xUnitFailure NotEqual(const std::string &expected, const std::string &actual, const LineInfo &lineInfo = LineInfo::empty()) const;
+
     template<typename TExpected, typename TActual, typename TComparer>
     xUnitFailure NotEqual(const TExpected &expectedBegin, const TExpected &expectedEnd, const TActual &actualBegin, const TActual &actualEnd, TComparer comparer, const LineInfo &lineInfo = LineInfo::empty()) const
     {
         return OnSuccess();
     }
 
+    template<typename TSequence>
+    typename std::enable_if<has_empty<TSequence>::value, xUnitFailure>::type NotEmpty(const TSequence &sequence, const LineInfo &lineInfo = LineInfo::empty()) const
+    {
+        if (sequence.empty())
+        {
+            return OnFailure(xUnitAssert(callPrefix + "NotEmpty", lineInfo));
+        }
+
+        return OnSuccess();
+    }
+
+    template<typename TSequence>
+    typename std::enable_if<!has_empty<TSequence>::value, xUnitFailure>::type NotEmpty(const TSequence &sequence, const LineInfo &lineInfo = LineInfo::empty()) const
+    {
+        using namespace std;
+
+        if (begin(sequence) == end(sequence))
+        {
+            return OnFailure(xUnitAssert(callPrefix + "NotEmpty", lineInfo));
+        }
+
+        return OnSuccess();
+    }
+
     template<typename TSequence, typename TPredicate>
     xUnitFailure DoesNotContainPred(const TSequence &sequence, TPredicate &&predicate, const LineInfo &lineInfo = LineInfo::empty()) const
     {