-
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.
Added initial support for C++ while keeping changes to a minimum. Some caveats: - Comparisons rely on '==' operator of operands. - Compiler will signal errors if operand does not have '<<' implemented. - Currently mixing cerr with fprintf to take advantage of '<<'.
- Loading branch information
1 parent
570c4ac
commit 7485a81
Showing
4 changed files
with
92 additions
and
12 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* vector.cpp - Test C++ using vector type | ||
* | ||
* Copyright (c) 2022 Luiz Henrique Suraty Filho <[email protected]> | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include <vector> | ||
#include "unitctest/unitctest.h" | ||
|
||
template <typename T> | ||
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) | ||
{ | ||
out << "["; | ||
for (std::vector<int>::size_type i = 0; i < v.size(); ++i) { | ||
out << v[i]; | ||
if (i != v.size() - 1) | ||
out << ", "; | ||
} | ||
out << "]"; | ||
return out; | ||
} | ||
|
||
/* Note that we rely on '==' operator for comparisons */ | ||
TEST(vector, "Check if two vectors are equal (a == b)") | ||
{ | ||
std::vector<int> a = { 0, 0, 1, 0 }; | ||
std::vector<int> b = { 0, 0, 1, 0 }; | ||
EXPECT_EQ(a, b, "Both vectors should be '=='"); | ||
|
||
a.push_back(0); | ||
EXPECT_NEQ(a, b, "a added 0, vectors should NOT be '=='"); | ||
|
||
b.push_back(0); | ||
EXPECT_EQ(a, b, "Both vectors should be '==' again"); | ||
} | ||
|
||
TEST_MAIN() |