1 // Copyright (c) 2007, 2008 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #include "libmv/image/tuple.h"
22 #include "testing/testing.h"
23 
24 #include <algorithm>
25 
26 using libmv::Tuple;
27 
28 namespace {
29 
TEST(Tuple,InitConstantValue)30 TEST(Tuple, InitConstantValue) {
31   Tuple<int, 3> t(5);
32   EXPECT_EQ(t(0), 5);
33   EXPECT_EQ(t(0), 5);
34   EXPECT_EQ(t(0), 5);
35 }
36 
TEST(Tuple,InitFromPointer)37 TEST(Tuple, InitFromPointer) {
38   float vals[3] = {1.0f, 2.0f, 3.0f};
39 
40   Tuple<float, 3> t(vals);
41   for (int i = 0; i < 3; i++)
42     EXPECT_EQ(t(i), vals[i]);
43 
44   Tuple<int, 3> b(t);
45   EXPECT_EQ(b(0), int(vals[0]));
46   EXPECT_EQ(b(1), int(vals[1]));
47   EXPECT_EQ(b(2), int(vals[2]));
48 }
49 
TEST(Tuple,Swap)50 TEST(Tuple, Swap) {
51   unsigned char vala[3] = {1, 2, 3};
52   unsigned char valb[3] = {4, 5, 6};
53 
54   Tuple<unsigned char, 3> a(vala);
55   Tuple<unsigned char, 3> b(valb);
56 
57   std::swap(a, b);
58 
59   EXPECT_EQ(a(0), int(valb[0]));
60   EXPECT_EQ(a(1), int(valb[1]));
61   EXPECT_EQ(a(2), int(valb[2]));
62   EXPECT_EQ(b(0), int(vala[0]));
63   EXPECT_EQ(b(1), int(vala[1]));
64   EXPECT_EQ(b(2), int(vala[2]));
65 }
66 
TEST(Tuple,IsEqualOperator)67 TEST(Tuple, IsEqualOperator) {
68   Tuple<int, 3> a;
69   a(0) = 1;
70   a(1) = 2;
71   a(2) = 3;
72   Tuple<int, 3> b;
73   b(0) = 1;
74   b(1) = 2;
75   b(2) = 3;
76   EXPECT_TRUE(a == b);
77   EXPECT_FALSE(a != b);
78   b(1) = 5;
79   EXPECT_TRUE(a != b);
80   EXPECT_FALSE(a == b);
81 }
82 
83 }  // namespace
84