1 /*
2  * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #define BOOST_TEST_MAIN
19 
20 #define BOOST_TEST_MODULE graphnode_test
21 
22 // Standard includes
23 #include <cmath>
24 #include <exception>
25 #include <iostream>
26 
27 // Third party includes
28 #include <boost/test/unit_test.hpp>
29 
30 // Local VOTCA includes
31 #include "votca/tools/graphnode.h"
32 
33 using namespace std;
34 using namespace votca::tools;
35 
36 BOOST_AUTO_TEST_SUITE(graphnode_test)
37 
38 BOOST_AUTO_TEST_CASE(constructors_test) { GraphNode gn; }
39 
40 BOOST_AUTO_TEST_CASE(accessors_test) {
41   GraphNode gn;
42 
43   BOOST_CHECK_EQUAL(gn == gn, true);
44   BOOST_CHECK_EQUAL(gn.getStringId(), "");
45 
46   unordered_map<string, votca::Index> int_vals = {{"Num", 134}};
47   unordered_map<string, double> double_vals = {{"Height", 159.32}};
48   unordered_map<string, string> str_vals = {{"Name", "George"}};
49   GraphNode gn2(int_vals, double_vals, str_vals);
50   GraphNode gn3(int_vals, double_vals, str_vals);
51   BOOST_CHECK_EQUAL(gn != gn2, true);
52   BOOST_CHECK_EQUAL(gn2 == gn2, true);
53   BOOST_CHECK_EQUAL(gn3 == gn2, true);
54 }
55 
56 BOOST_AUTO_TEST_CASE(setters_test) {
57   unordered_map<string, votca::Index> int_vals = {{"Num", 134}};
58   unordered_map<string, double> double_vals = {{"Height", 159.32}};
59   unordered_map<string, string> str_vals = {{"Name", "George"}};
60   GraphNode gn2(int_vals, double_vals, str_vals);
write_file(filename, content)61 
62   string str{"Num134Height159.32NameGeorge"};
63   BOOST_CHECK_EQUAL(gn2.getStringId(), str);
64 
65   unordered_map<string, votca::Index> int_vals2 = {{"Second", 2}, {"First", 1}};
66   gn2.setInt(int_vals2);
67   str = "First1Second2Height159.32NameGeorge";
68   BOOST_CHECK_EQUAL(gn2.getStringId(), str);
69 
70   unordered_map<string, double> double_vals2 = {{"Height", 159.32},
71                                                 {"Weight", 101.43}};
72   gn2.setDouble(double_vals2);
73   str = "First1Second2Height159.32Weight101.43NameGeorge";
74   BOOST_CHECK_EQUAL(gn2.getStringId(), str);
75 
76   unordered_map<string, string> str_vals2 = {{"Name", "George"},
77                                              {"Address", "Koogler St"}};
78   gn2.setStr(str_vals2);
79   str = "First1Second2Height159.32Weight101.43AddressKoogler StNameGeorge";
80   BOOST_CHECK_EQUAL(gn2.getStringId(), str);
81 }
82 
83 BOOST_AUTO_TEST_CASE(comparisontest) {
84   unordered_map<string, votca::Index> int_vals1 = {{"a", 134}};
85   unordered_map<string, votca::Index> int_vals2 = {{"b", 134}};
86 
87   unordered_map<string, double> double_vals;
88   unordered_map<string, string> str_vals;
89 
90   GraphNode gn1(int_vals1, double_vals, str_vals);
91   GraphNode gn2(int_vals2, double_vals, str_vals);
92 
93   BOOST_CHECK_EQUAL(cmpNode(gn1, gn2), true);
94   BOOST_CHECK_EQUAL(cmpNode(gn2, gn1), false);
95 
96   vector<GraphNode> vec_gn = {gn1, gn2};
97   sort(vec_gn.begin(), vec_gn.end(), cmpNode);
98 
99   string str1{"a134"};
100   string str2{"b134"};
101 
102   BOOST_CHECK_EQUAL(vec_gn.at(0).getStringId(), str1);
103   BOOST_CHECK_EQUAL(vec_gn.at(1).getStringId(), str2);
104 
105   vector<GraphNode> vec_gn2 = {gn2, gn1};
106   sort(vec_gn2.begin(), vec_gn2.end(), cmpNode);
107 
108   BOOST_CHECK_EQUAL(vec_gn2.at(0).getStringId(), str1);
109   BOOST_CHECK_EQUAL(vec_gn2.at(1).getStringId(), str2);
110 }
111 
112 BOOST_AUTO_TEST_SUITE_END()
113