#include "gtest/gtest.h" #include "type.h" #include "operation/math.h" #include "conditional/if.h" #include "list/cons.h" #include "list/list.h" class TypeAsValueTest : public ::testing::Test { }; TEST_F(TypeAsValueTest, BasicMath) { // (+ 1 2) EXPECT_EQ(3, ( tav::Add, tav::Int<2>>::value )); // (- 10 6) EXPECT_EQ(4, ( tav::Substract, tav::Int<6>>::value )); // (* 2 21) EXPECT_EQ(42, ( tav::Multiply, tav::Int<21>>::value )); // (/ 10 2) EXPECT_EQ(5, ( tav::Divide, tav::Int<2>>::value )); } TEST_F(TypeAsValueTest, Conditional) { // (if #t 1 2) EXPECT_EQ(1, ( tav::If, tav::Int<2>>::type::value )); // (if #f 1 2) EXPECT_EQ(2, ( tav::If, tav::Int<2>>::type::value )); } TEST_F(TypeAsValueTest, Cons) { // (car (cons 1 void)) EXPECT_EQ(1, ( tav::Car, void>>::value )); // (car (cons 1 2)) EXPECT_EQ(1, ( tav::Car, tav::Int<2>>>::value )); // (cdr (cons 1 2)) EXPECT_EQ(2, ( tav::Cdr, tav::Int<2>>>::value )); // (car (cdr (cons 1 (cons 2 3)))) EXPECT_EQ(2, ( tav::Car, tav::Cons, tav::Int<3>>>>>::value )); } TEST_F(TypeAsValueTest, List) { // (length (list 1)) EXPECT_EQ(1, ( tav::Length>::type>::type::value )); // (length (list 1 2)) EXPECT_EQ(2, ( tav::Length, tav::Int<2>>::type>::type::value )); // (head (list 1)) EXPECT_EQ(1, ( tav::Head>::type>::value )); // (head (list 1 2)) EXPECT_EQ(1, ( tav::Head, tav::Int<2>>::type>::value )); // (head (tail (list 1 2))) EXPECT_EQ(2, ( tav::Head, tav::Int<2>>::type>>::value )); // (head (tail (list 1 2 3))) EXPECT_EQ(2, ( tav::Head, tav::Int<2>, tav::Int<3>>::type>>::value )); } TEST_F(TypeAsValueTest, ListNth) { // (nth 0 (list 1)) EXPECT_EQ(1, ( tav::Nth, tav::List>::type>::type::value )); // (nth 0 (list 1 2)) EXPECT_EQ(1, ( tav::Nth, tav::List, tav::Int<2>>::type>::type::value )); // (nth 1 (list 1 2)) EXPECT_EQ(2, ( tav::Nth, tav::List, tav::Int<2>>::type>::type::value )); } TEST_F(TypeAsValueTest, ListConcatenate) { // (length (concatenate (list 1) (list 2))) EXPECT_EQ(2, ( tav::Length>::type, tav::List>::type>::type>::type::value )); // (length (concatenate (list 1 2) (list 3 4))) EXPECT_EQ(4, ( tav::Length, tav::Int<2>>::type, tav::List, tav::Int<4>>::type>::type>::type::value )); // (head (concatenate (list 1) (list 2))) EXPECT_EQ(1, ( tav::Head>::type, tav::List>::type>::type>::value )); // (head (tail (concatenate (list 1) (list 2)))) EXPECT_EQ(2, ( tav::Head>::type, tav::List>::type>::type>>::value )); } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }