summaryrefslogtreecommitdiff
path: root/utils/logval_test.cc
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:37:10 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 02:37:10 +0000
commit80686d4e567bae579ea39e009826a2de92cd4ace (patch)
treec3c35fcba57dde423a248f38aa121ad197c79734 /utils/logval_test.cc
parent3c85c407c333899f6b4bc26632d312b8e568b638 (diff)
major refactor, break bad circular deps
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@509 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/logval_test.cc')
-rw-r--r--utils/logval_test.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/logval_test.cc b/utils/logval_test.cc
new file mode 100644
index 00000000..1a23177d
--- /dev/null
+++ b/utils/logval_test.cc
@@ -0,0 +1,73 @@
+#include "logval.h"
+
+#include <gtest/gtest.h>
+#include <iostream>
+
+class LogValTest : public testing::Test {
+ protected:
+ virtual void SetUp() { }
+ virtual void TearDown() { }
+};
+
+using namespace std;
+
+TEST_F(LogValTest,Order) {
+ LogVal<double> a(-0.3);
+ LogVal<double> b(0.3);
+ LogVal<double> c(2.4);
+ EXPECT_LT(a,b);
+ EXPECT_LT(b,c);
+ EXPECT_LT(a,c);
+ EXPECT_FALSE(b < a);
+ EXPECT_FALSE(c < a);
+ EXPECT_FALSE(c < b);
+ EXPECT_FALSE(c < c);
+ EXPECT_FALSE(b < b);
+ EXPECT_FALSE(a < a);
+}
+
+TEST_F(LogValTest,Invert) {
+ LogVal<double> x(-2.4);
+ LogVal<double> y(2.4);
+ y.invert();
+ EXPECT_FLOAT_EQ(x,y);
+}
+
+TEST_F(LogValTest,Minus) {
+ LogVal<double> x(12);
+ LogVal<double> y(2);
+ LogVal<double> z1 = x - y;
+ LogVal<double> z2 = x;
+ z2 -= y;
+ EXPECT_FLOAT_EQ(z1, z2);
+ EXPECT_FLOAT_EQ(z1, 10.0);
+ EXPECT_FLOAT_EQ(y - x, -10.0);
+}
+
+TEST_F(LogValTest,TestOps) {
+ LogVal<double> x(-12.12);
+ LogVal<double> y(x);
+ cerr << x << endl;
+ cerr << (x*y) << endl;
+ cerr << (x*y + x) << endl;
+ cerr << (x + x*y) << endl;
+ cerr << log1p(-0.5) << endl;
+ LogVal<double> aa(0.2);
+ LogVal<double> bb(-0.3);
+ cerr << (aa + bb) << endl;
+ cerr << (bb + aa) << endl;
+ EXPECT_FLOAT_EQ((aa + bb), (bb + aa));
+ EXPECT_FLOAT_EQ((aa + bb), -0.1);
+}
+
+TEST_F(LogValTest,TestSizes) {
+ cerr << sizeof(LogVal<double>) << endl;
+ cerr << sizeof(LogVal<float>) << endl;
+ cerr << sizeof(void*) << endl;
+}
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+