Adding logger support, and other things.

This commit is contained in:
Peter Goodman
2017-10-29 18:54:41 -04:00
parent 7c9710cd05
commit e0f104aaef
9 changed files with 494 additions and 60 deletions
+23 -6
View File
@@ -14,20 +14,37 @@
* limitations under the License.
*/
#include <mctest/McUnit.hpp>
#include <mctest/Quantified.hpp>
using namespace mctest;
MCTEST_NOINLINE int add(int x, int y) {
return x + y;
}
// MCTEST_NOINLINE int add(int x, int y) {
// return x + y;
// }
McTest_EntryPoint(AdditionIsCommutative) {
// TEST(Arithmetic, AdditionIsCommutative) {
// ForAll<int, int>([] (int x, int y) {
// ASSERT_EQ(add(x, y), add(y, x))
// << "Addition of signed integers must commute.";
// });
// }
// TEST(Arithmetic, AdditionIsAssociative) {
// ForAll<int, int, int>([] (int x, int y, int z) {
// ASSERT_EQ(add(x, add(y, z)), add(add(x, y), z))
// << "Addition of signed integers must associate.";
// });
// }
TEST(Arithmetic, InvertibleMultiplication_CanFail) {
ForAll<int, int>([] (int x, int y) {
McTest_Assert(add(x, y) == add(y, x));
ASSUME_NE(y, 0);
ASSERT_EQ(x, (x / y) * y)
<< x << " != (" << x << " / " << y << ") * " << y;
});
}
int main(int argc, char *argv[]) {
int main(void) {
return McTest_Run();
}
+4
View File
@@ -17,3 +17,7 @@ target_link_libraries(OutOfBoundsInt mctest)
add_executable(ArithmeticProperties ArithmeticProperties.cpp)
target_link_libraries(ArithmeticProperties mctest)
add_executable(Lists Lists.cpp)
target_link_libraries(Lists mctest)
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017 Trail of Bits, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <mctest/McUnit.hpp>
#include <mctest/Quantified.hpp>
#include <algorithm>
#include <vector>
using namespace mctest;
TEST(Vector, DoubleReversal) {
ForAll<std::vector<int>>([] (const std::vector<int> &vec1) {
std::vector<int> vec2 = vec1;
std::reverse(vec2.begin(), vec2.end());
std::reverse(vec2.begin(), vec2.end());
ASSERT_EQ(vec1, vec2)
<< "Double reverse of vectors must be equal.";
});
}
int main(void) {
McTest_Run();
}