aboutsummaryrefslogtreecommitdiff
path: root/test.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-19 18:19:44 +0100
committerAdrian Kummerlaender2015-01-19 18:19:44 +0100
commit46e028017b34f43d7aa8004ccef5a56fccf2826c (patch)
treeaf754264e76348bc665478cb3881be3cc270960e /test.cc
parent17a62b7627551243419d0a85c611eec7e6581e7b (diff)
downloadTypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar.gz
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar.bz2
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar.lz
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar.xz
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.tar.zst
TypeAsValue-46e028017b34f43d7aa8004ccef5a56fccf2826c.zip
Replaced Google-Test with `static_assert` based test cases
* as everything this library does happens during compile time it can be checked using standard language features ** i.e. `static_assert` already offers everything needed for test cases in this situation
Diffstat (limited to 'test.cc')
-rw-r--r--test.cc257
1 files changed, 154 insertions, 103 deletions
diff --git a/test.cc b/test.cc
index aa98be9..5b4467a 100644
--- a/test.cc
+++ b/test.cc
@@ -1,5 +1,3 @@
-#include "gtest/gtest.h"
-
#include "type.h"
#include "operation/math.h"
#include "conditional/if.h"
@@ -9,108 +7,161 @@
#include "list/operation/higher/fold.h"
#include "list/operation/higher/misc.h"
-class TypeAsValueTest : public ::testing::Test { };
+int main(int, char **) { }
template <typename Element>
using quadruple = tav::Multiply<tav::Int<4>, Element>;
-TEST_F(TypeAsValueTest, BasicMath) {
- // (+ 1 2)
- EXPECT_EQ(3, ( tav::Add<tav::Int<1>, tav::Int<2>>::value ));
- // (- 10 6)
- EXPECT_EQ(4, ( tav::Substract<tav::Int<10>, tav::Int<6>>::value ));
- // (* 2 21)
- EXPECT_EQ(42, ( tav::Multiply<tav::Int<2>, tav::Int<21>>::value ));
- // (/ 10 2)
- EXPECT_EQ(5, ( tav::Divide<tav::Int<10>, tav::Int<2>>::value ));
-}
-
-TEST_F(TypeAsValueTest, Conditional) {
- // (if #t 1 2)
- EXPECT_EQ(1, ( tav::If<true, tav::Int<1>, tav::Int<2>>::type::value ));
- // (if #f 1 2)
- EXPECT_EQ(2, ( tav::If<false, tav::Int<1>, tav::Int<2>>::type::value ));
-}
-
-TEST_F(TypeAsValueTest, Cons) {
- // (car (cons 1 void))
- EXPECT_EQ(1, ( tav::Car<tav::Cons<tav::Int<1>, void>>::value ));
- // (car (cons 1 2))
- EXPECT_EQ(1, ( tav::Car<tav::Cons<tav::Int<1>, tav::Int<2>>>::value ));
- // (cdr (cons 1 2))
- EXPECT_EQ(2, ( tav::Cdr<tav::Cons<tav::Int<1>, tav::Int<2>>>::value ));
- // (car (cdr (cons 1 (cons 2 3))))
- EXPECT_EQ(2, ( tav::Car<tav::Cdr<tav::Cons<tav::Int<1>, tav::Cons<tav::Int<2>, tav::Int<3>>>>>::value ));
-}
-
-TEST_F(TypeAsValueTest, List) {
- // (length (list 1))
- EXPECT_EQ(1, ( tav::Length<tav::List<tav::Int<1>>::type>::type::value ));
- // (length (list 1 2))
- EXPECT_EQ(2, ( tav::Length<tav::List<tav::Int<1>, tav::Int<2>>::type>::type::value ));
-
- // (head (list 1))
- EXPECT_EQ(1, ( tav::Head<tav::List<tav::Int<1>>::type>::value ));
- // (head (list 1 2))
- EXPECT_EQ(1, ( tav::Head<tav::List<tav::Int<1>, tav::Int<2>>::type>::value ));
- // (head (tail (list 1 2)))
- EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::List<tav::Int<1>, tav::Int<2>>::type>>::value ));
- // (head (tail (list 1 2 3)))
- EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>>::value ));
-}
-
-TEST_F(TypeAsValueTest, ListNth) {
- // (nth 0 (list 1))
- EXPECT_EQ(1, ( tav::Nth<tav::Size<0>, tav::List<tav::Int<1>>::type>::type::value ));
- // (nth 0 (list 1 2))
- EXPECT_EQ(1, ( tav::Nth<tav::Size<0>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type::value ));
- // (nth 1 (list 1 2))
- EXPECT_EQ(2, ( tav::Nth<tav::Size<1>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type::value ));
-}
-
-TEST_F(TypeAsValueTest, ListTake) {
- // (length (take 1 (list 1 2)))
- EXPECT_EQ(1, ( tav::Length<tav::Take<tav::Size<1>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type::value ));
- // (length (take 2 (list 1 2)))
- EXPECT_EQ(2, ( tav::Length<tav::Take<tav::Size<2>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type::value ));
- // (length (take 3 (list 1 2)))
- EXPECT_EQ(2, ( tav::Length<tav::Take<tav::Size<3>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type::value ));
-}
-
-TEST_F(TypeAsValueTest, ListConcatenate) {
- // (length (concatenate (list 1) (list 2)))
- EXPECT_EQ(2, ( tav::Length<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>::type::value ));
- // (length (concatenate (list 1 2) (list 3 4)))
- EXPECT_EQ(4, ( tav::Length<tav::Concatenate<tav::List<tav::Int<1>, tav::Int<2>>::type, tav::List<tav::Int<3>, tav::Int<4>>::type>::type>::type::value ));
-
- // (head (concatenate (list 1) (list 2)))
- EXPECT_EQ(1, ( tav::Head<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>::value ));
- // (head (tail (concatenate (list 1) (list 2))))
- EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>>::value ));
-}
-
-TEST_F(TypeAsValueTest, ListFold) {
- // (fold + 0 (list 1 2 3))
- EXPECT_EQ(6, ( tav::Fold<tav::Add, tav::Int<0>, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type::value ));
-}
-
-TEST_F(TypeAsValueTest, ListMap) {
- // (map quadruple (list 1 2 3))
- EXPECT_TRUE(( std::is_same<tav::List<tav::Int<4>, tav::Int<8>, tav::Int<12>>::type, tav::Map<quadruple, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value ));
-}
-
-TEST_F(TypeAsValueTest, ListFilter) {
- // (filter odd (list 1 2 3))
- EXPECT_TRUE(( std::is_same<tav::List<tav::Int<1>, tav::Int<3>>::type, tav::Filter<tav::Odd, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value ));
-}
-
-TEST_F(TypeAsValueTest, ListReverse) {
- // (reverse (list 1 2 3))
- EXPECT_TRUE(( std::is_same<tav::List<tav::Int<3>, tav::Int<2>, tav::Int<1>>::type, tav::Reverse<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value ));
-}
-
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
-
- return RUN_ALL_TESTS();
-}
+// basic math operations
+
+static_assert(
+ std::is_same<tav::Int<3>, tav::Add<tav::Int<1>, tav::Int<2>>>::value,
+ "(+ 1 2) != 3"
+);
+
+static_assert(
+ std::is_same<tav::Int<4>, tav::Substract<tav::Int<10>, tav::Int<6>>>::value,
+ "(- 10 6) != 4"
+);
+
+static_assert(
+ std::is_same<tav::Int<42>, tav::Multiply<tav::Int<2>, tav::Int<21>>>::value,
+ "(* 2 21) != 42"
+);
+
+static_assert(
+ std::is_same<tav::Int<5>, tav::Divide<tav::Int<10>, tav::Int<2>>>::value,
+ "(/ 10 2) != 42"
+);
+
+// conditionals
+
+static_assert(
+ std::is_same<tav::Int<1>, tav::If<true, tav::Int<1>, tav::Int<2>>::type>::value,
+ "(if #t 1 2) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Int<2>, tav::If<false, tav::Int<1>, tav::Int<2>>::type>::value,
+ "(if #f 1 2) != 2"
+);
+
+// cons
+
+static_assert(
+ std::is_same<tav::Int<1>, tav::Car<tav::Cons<tav::Int<1>, void>>>::value,
+ "(car (cons 1 void)) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Int<1>, tav::Car<tav::Cons<tav::Int<1>, tav::Int<2>>>>::value,
+ "(car (cons 1 2)) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Int<2>, tav::Cdr<tav::Cons<tav::Int<1>, tav::Int<2>>>>::value,
+ "(cdr (cons 1 2)) != 2"
+);
+
+static_assert(
+ std::is_same<tav::Int<2>, tav::Car<tav::Cdr<tav::Cons<tav::Int<1>, tav::Cons<tav::Int<2>, tav::Int<3>>>>>>::value,
+ "(car (cdr (cons 1 (cons 2 3)))) != 2"
+);
+
+// list
+
+static_assert(
+ std::is_same<tav::Cons<tav::Int<1>, void>, tav::List<tav::Int<1>>::type>::value,
+ "(list 1) != (cons 1 void)"
+);
+
+static_assert(
+ std::is_same<tav::Cons<tav::Int<1>, tav::Cons<tav::Int<2>, void>>, tav::List<tav::Int<1>, tav::Int<2>>::type>::value,
+ "(list 1 2) != (cons 1 (cons 2 void))"
+);
+
+// list length
+
+static_assert(
+ std::is_same<tav::Size<1>, tav::Length<tav::List<tav::Int<1>>::type>::type>::value,
+ "(length (list 1)) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Size<2>, tav::Length<tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::value,
+ "(length (list 1 2)) != 2"
+);
+
+// list nth
+
+static_assert(
+ std::is_same<tav::Int<1>, tav::Nth<tav::Size<0>, tav::List<tav::Int<1>>::type>::type>::value,
+ "(nth 0 (list 1)) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Int<1>, tav::Nth<tav::Size<0>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::value,
+ "(nth 0 (list 1 2)) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Int<2>, tav::Nth<tav::Size<1>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::value,
+ "(nth 1 (list 1 2)) != 2"
+);
+
+// list take
+
+static_assert(
+ std::is_same<tav::Size<1>, tav::Length<tav::Take<tav::Size<1>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type>::value,
+ "(length (take 1 (list 1 2))) != 1"
+);
+
+static_assert(
+ std::is_same<tav::Size<2>, tav::Length<tav::Take<tav::Size<2>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type>::value,
+ "(length (take 2 (list 1 2))) != 2"
+);
+
+static_assert(
+ std::is_same<tav::Size<2>, tav::Length<tav::Take<tav::Size<3>, tav::List<tav::Int<1>, tav::Int<2>>::type>::type>::type>::value,
+ "(length (take 3 (list 1 2))) != 2"
+);
+
+// list concatenate
+
+static_assert(
+ std::is_same<tav::Size<2>, tav::Length<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>::type>::value,
+ "(length (concatenate (list 1) (list 2))) != 2"
+);
+
+static_assert(
+ std::is_same<tav::Size<4>, tav::Length<tav::Concatenate<tav::List<tav::Int<1>, tav::Int<2>>::type, tav::List<tav::Int<3>, tav::Int<4>>::type>::type>::type>::value,
+ "(length (concatenate (list 1 2) (list 3 4))) != 4"
+);
+
+// list fold
+
+static_assert(
+ std::is_same<tav::Int<6>, tav::Fold<tav::Add, tav::Int<0>, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value,
+ "(fold + 0 (list 1 2 3)) != 6"
+);
+
+// list map
+
+static_assert(
+ std::is_same<tav::List<tav::Int<4>, tav::Int<8>, tav::Int<12>>::type, tav::Map<quadruple, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value,
+ "(map quadruple (list 1 2 3)) != (list 4 8 12)"
+);
+
+// list filter
+
+static_assert(
+ std::is_same<tav::List<tav::Int<1>, tav::Int<3>>::type, tav::Filter<tav::Odd, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value,
+ "(filter odd (list 1 2 3)) != (list 1 3)"
+);
+
+// list reverse
+
+static_assert(
+ std::is_same<tav::List<tav::Int<3>, tav::Int<2>, tav::Int<1>>::type, tav::Reverse<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value,
+ "(reverse (list 1 2 3)) != (list 3 2 1)"
+);