1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
* This file is part of AtracDEnc.
*
* AtracDEnc is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* AtracDEnc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with AtracDEnc; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "util.h"
#include <gtest/gtest.h>
#include <vector>
TEST(Util, SwapArrayTest) {
TFloat arr[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
SwapArray(arr, 8);
for (size_t i = 0; i < 8; ++i) {
EXPECT_NEAR((TFloat)i, arr[7-i], 0.000000000001);
}
}
TEST(Util, GetFirstSetBitTest) {
EXPECT_EQ(1, GetFirstSetBit(2));
EXPECT_EQ(1, GetFirstSetBit(3));
EXPECT_EQ(2, GetFirstSetBit(4));
EXPECT_EQ(2, GetFirstSetBit(5));
EXPECT_EQ(2, GetFirstSetBit(6));
EXPECT_EQ(2, GetFirstSetBit(7));
EXPECT_EQ(3, GetFirstSetBit(8));
EXPECT_EQ(3, GetFirstSetBit(9));
EXPECT_EQ(3, GetFirstSetBit(10));
}
TEST(Util, CalcEnergy) {
EXPECT_NEAR((TFloat)0.0, CalcEnergy(std::vector<TFloat>{0.0}), 0.000000000001);
EXPECT_NEAR((TFloat)1.0, CalcEnergy(std::vector<TFloat>{1.0}), 0.000000000001);
EXPECT_NEAR((TFloat)2.0, CalcEnergy(std::vector<TFloat>{1.0, 1.0}), 0.000000000001);
EXPECT_NEAR((TFloat)5.0, CalcEnergy(std::vector<TFloat>{2.0, 1.0}), 0.000000000001);
EXPECT_NEAR((TFloat)5.0, CalcEnergy(std::vector<TFloat>{1.0, 2.0}), 0.000000000001);
EXPECT_NEAR((TFloat)8.0, CalcEnergy(std::vector<TFloat>{2.0, 2.0}), 0.000000000001);
}
|