forked from selforgmap/som-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_test.cpp
More file actions
56 lines (46 loc) · 1.17 KB
/
Copy pathgrid_test.cpp
File metadata and controls
56 lines (46 loc) · 1.17 KB
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
53
54
55
56
//
// Created by Sumedhe Dissanayake on 10/6/18.
//
#include "gtest/gtest.h"
#include "core/grid.h"
#include "grids/rectangular.h"
#include "core/som.h"
#include "struct/node.h"
/**
* Test Get Position of Rectangular Grid
*/
TEST(RectangularGrid, GetPosition){
Grid* grid = new Rectangular(10, 10, 3);
grid->InitializeNodes();
Node node = grid->nodes[25];
ASSERT_EQ(node.x_pos, 5);
ASSERT_EQ(node.y_pos, 2);
}
/**
* Test Find BMU
*/
TEST(FindBMU, Manual){
Grid* grid = new Rectangular(2, 2, 3, false);
grid->InitializeNodes();
grid->nodes[0].features = vector<double>{10, 20, 30};
grid->nodes[1].features = vector<double>{-10, 2, 7};
grid->nodes[2].features = vector<double>{1, 2, 5};
grid->nodes[3].features = vector<double>{-5, -4, -3};
vector<double>vec = {3, 4, 5};
int bmu = grid->FindBMU(vec);
ASSERT_EQ(bmu, 2);
}
/**
* Test Calculate Distance
*/
TEST(CalculateDistance, TwoPointers){
Node n1;
Node n2;
n1.x_pos = 6;
n1.y_pos = 11;
n2.x_pos = 3;
n2.y_pos = 7;
Rectangular grid = Rectangular(10, 10, 3);
float dist = grid.CalculateDistance(n1, n2);
ASSERT_NEAR(dist, 5.0, 1.0e-5);
}