diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
commit | 6249432407af8730c10bccc7894c0725fcaf5e47 (patch) | |
tree | 3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /moses/FeatureVectorTest.cpp | |
parent | 59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff) |
beautify
Diffstat (limited to 'moses/FeatureVectorTest.cpp')
-rw-r--r-- | moses/FeatureVectorTest.cpp | 107 |
1 files changed, 73 insertions, 34 deletions
diff --git a/moses/FeatureVectorTest.cpp b/moses/FeatureVectorTest.cpp index af1829e62..2e00b276e 100644 --- a/moses/FeatureVectorTest.cpp +++ b/moses/FeatureVectorTest.cpp @@ -28,41 +28,49 @@ static const float TOL = 0.00001; BOOST_AUTO_TEST_SUITE(fv) -BOOST_AUTO_TEST_CASE(vector_sum_diff) +BOOST_AUTO_TEST_CASE(vector_sum_diff) { FVector f1,f2,f3; FName n1("a"); FName n2("b"); FName n3("c"); FName n4("d"); - f1[n1] = 1.2; f1[n2] = 1.4; f1[n3] = -0.1; - f2[n1] = 0.01; f2[n3] = 5.6; f2[n4] = 0.6; + f1[n1] = 1.2; + f1[n2] = 1.4; + f1[n3] = -0.1; + f2[n1] = 0.01; + f2[n3] = 5.6; + f2[n4] = 0.6; f3[n1] =1.2; FVector sum = f1 + f2; FVector diff = f1 - f2; - BOOST_CHECK_CLOSE((FValue)sum[n1], 1.21, TOL); - BOOST_CHECK_CLOSE((FValue)sum[n2], 1.4, TOL); - BOOST_CHECK_CLOSE((FValue)sum[n3], 5.5, TOL); - BOOST_CHECK_CLOSE((FValue)sum[n4], 0.6, TOL); - BOOST_CHECK_CLOSE((FValue)diff[n1], 1.19, TOL); - BOOST_CHECK_CLOSE((FValue)diff[n2], 1.4, TOL); - BOOST_CHECK_CLOSE((FValue)diff[n3], -5.7, TOL); - BOOST_CHECK_CLOSE((FValue)diff[n4], -0.6, TOL); + BOOST_CHECK_CLOSE((FValue)sum[n1], 1.21, TOL); + BOOST_CHECK_CLOSE((FValue)sum[n2], 1.4, TOL); + BOOST_CHECK_CLOSE((FValue)sum[n3], 5.5, TOL); + BOOST_CHECK_CLOSE((FValue)sum[n4], 0.6, TOL); + BOOST_CHECK_CLOSE((FValue)diff[n1], 1.19, TOL); + BOOST_CHECK_CLOSE((FValue)diff[n2], 1.4, TOL); + BOOST_CHECK_CLOSE((FValue)diff[n3], -5.7, TOL); + BOOST_CHECK_CLOSE((FValue)diff[n4], -0.6, TOL); f1 -= f3; cerr << f1 << endl << f3 << endl ; BOOST_CHECK_CLOSE((FValue)f1[n1],0,TOL); } -BOOST_AUTO_TEST_CASE(scalar) +BOOST_AUTO_TEST_CASE(scalar) { FVector f1,f2; FName n1("a"); FName n2("b"); FName n3("c"); FName n4("d"); - f1[n1] = 0.2; f1[n2] = 9.178; f1[n3] = -0.1; - f2[n1] = 0.01; f2[n3] = 5.6; f2[n4] = 0.6; + f1[n1] = 0.2; + f1[n2] = 9.178; + f1[n3] = -0.1; + f2[n1] = 0.01; + f2[n3] = 5.6; + f2[n4] = 0.6; FVector prod1 = f1 * 2; FVector prod2 = f1 * -0.1; FVector quot = f2 / 2; @@ -80,12 +88,13 @@ BOOST_AUTO_TEST_CASE(scalar) BOOST_CHECK_CLOSE((FValue)quot[n4], 0.3, TOL); } -BOOST_AUTO_TEST_CASE(inc) +BOOST_AUTO_TEST_CASE(inc) { FVector f1; FName n1("a"); FName n2("b"); - f1[n1] = 2.3; f1[n2] = -0.4; + f1[n1] = 2.3; + f1[n2] = -0.4; f1[n1]+=2; BOOST_CHECK_CLOSE((FValue)f1[n1], 4.3, TOL); BOOST_CHECK_CLOSE((FValue)f1[n2], -0.4, TOL); @@ -103,8 +112,13 @@ BOOST_AUTO_TEST_CASE(vector_mult) FName n2("b"); FName n3("c"); FName n4("d"); - f1[n1] = 0.2; f1[n2] = 9.178; f1[n3] = -0.1; - f2[n1] = 0.01; f2[n2] = 5.6; f2[n3] = 1; f2[n4] = 0.6; + f1[n1] = 0.2; + f1[n2] = 9.178; + f1[n3] = -0.1; + f2[n1] = 0.01; + f2[n2] = 5.6; + f2[n3] = 1; + f2[n4] = 0.6; FVector prod = f1 * f2; FVector quot = f1/f2; BOOST_CHECK_CLOSE((FValue)prod[n1], 0.002, TOL); @@ -118,7 +132,7 @@ BOOST_AUTO_TEST_CASE(vector_mult) BOOST_CHECK_CLOSE((FValue)quot[n4], 0, TOL); } -BOOST_AUTO_TEST_CASE(core) +BOOST_AUTO_TEST_CASE(core) { FVector f1(2); f1[0] = 1.3; @@ -127,7 +141,7 @@ BOOST_AUTO_TEST_CASE(core) BOOST_CHECK_CLOSE(f1[1],-1.9,TOL); f1[1] = 0.1; BOOST_CHECK_CLOSE(f1[1],0.1,TOL); - + BOOST_CHECK_EQUAL(f1.size(),2); f1[FName("a")] = 1.2; @@ -140,8 +154,13 @@ BOOST_AUTO_TEST_CASE(core_arith) FVector f2(2); FName n1("a"); FName n2("b"); - f1[0] = 1.1; f1[1] = 0.25; f1[n1] = 3.6; f1[n2] = -1.5; - f2[0] = 0.5; f2[1] = -0.1; f2[n1] = 1; + f1[0] = 1.1; + f1[1] = 0.25; + f1[n1] = 3.6; + f1[n2] = -1.5; + f2[0] = 0.5; + f2[1] = -0.1; + f2[n1] = 1; //vector ops FVector sum = f1+f2; @@ -172,9 +191,10 @@ BOOST_AUTO_TEST_CASE(core_arith) //with different length vectors FVector f3(2); FVector f4(1); - f3[0] = 2; f3[1] = -1; + f3[0] = 2; + f3[1] = -1; f4[0] = 5; - + FVector sum1 = f3 + f4; FVector sum2 = f4 + f3; BOOST_CHECK_EQUAL(sum1,sum2); @@ -200,14 +220,17 @@ BOOST_AUTO_TEST_CASE(core_arith) BOOST_CHECK_EQUAL(quot1[1], -numeric_limits<float>::infinity()); BOOST_CHECK_CLOSE(quot2[0], 2.5, TOL); BOOST_CHECK_CLOSE(quot2[1], 0, TOL); - + } BOOST_AUTO_TEST_CASE(core_scalar) { FVector f1(3); FName n1("a"); - f1[0] = 1.5; f1[1] = 2.1; f1[2] = 4; f1[n1] = -0.5; + f1[0] = 1.5; + f1[1] = 2.1; + f1[2] = 4; + f1[n1] = -0.5; FVector prod = f1*2; FVector quot = f1/5; @@ -224,31 +247,41 @@ BOOST_AUTO_TEST_CASE(core_scalar) } -BOOST_AUTO_TEST_CASE(l1norm) +BOOST_AUTO_TEST_CASE(l1norm) { FVector f1(3); FName n1("a"); - f1[0] = 1.5; f1[1] = 2.1; f1[2] = 4; f1[n1] = -0.5; + f1[0] = 1.5; + f1[1] = 2.1; + f1[2] = 4; + f1[n1] = -0.5; FValue n = f1.l1norm(); BOOST_CHECK_CLOSE((FValue)n, abs(1.5)+abs(2.1)+abs(4)+abs(-0.5), TOL); } -BOOST_AUTO_TEST_CASE(sum) +BOOST_AUTO_TEST_CASE(sum) { FVector f1(3); FName n1("a"); FName n2("b"); - f1[0] = 1.5; f1[1] = 2.1; f1[2] = 4; f1[n1] = -0.5; f1[n2] = 2.7; + f1[0] = 1.5; + f1[1] = 2.1; + f1[2] = 4; + f1[n1] = -0.5; + f1[n2] = 2.7; FValue n = f1.sum(); BOOST_CHECK_CLOSE((FValue)n, 1.5+2.1+4-0.5+2.7, TOL); } -BOOST_AUTO_TEST_CASE(l2norm) +BOOST_AUTO_TEST_CASE(l2norm) { FVector f1(3); FName n1("a"); - f1[0] = 1.5; f1[1] = 2.1; f1[2] = 4; f1[n1] = -0.5; + f1[0] = 1.5; + f1[1] = 2.1; + f1[2] = 4; + f1[n1] = -0.5; FValue n = f1.l2norm(); BOOST_CHECK_CLOSE((FValue)n, sqrt((1.5*1.5)+(2.1*2.1)+(4*4)+(-0.5*-0.5)), TOL); } @@ -260,8 +293,14 @@ BOOST_AUTO_TEST_CASE(ip) FName n1("a"); FName n2("b"); FName n3("c"); - f1[0] = 1.1; f1[1] = -0.1; ; f1[n2] = -1.5; f1[n3] = 2.2; - f2[0] = 0.5; f2[1] = 0.25; f2[n1] = 1; f2[n3] = 2.4; + f1[0] = 1.1; + f1[1] = -0.1; ; + f1[n2] = -1.5; + f1[n3] = 2.2; + f2[0] = 0.5; + f2[1] = 0.25; + f2[n1] = 1; + f2[n3] = 2.4; FValue p1 = inner_product(f1,f2); FValue p2 = inner_product(f2,f1); BOOST_CHECK_CLOSE(p1,p2,TOL); |