summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaidong Ji2020-05-09 15:32:19 -0500
committerHaidong Ji2020-05-09 15:32:19 -0500
commitf13dfb8c438c3c565ed4ede430e6046f54e5c9d5 (patch)
tree22c056ca5fec003a2f4fc09bdf0c1faccdf0b3da
parent570b84f60a05be1f765e15207b8a437610dc8893 (diff)
Machine rebuilt so I had to reconfig Eclipse and googletest for C++ dev
work on Linux
-rw-r--r--.cproject12
-rw-r--r--.gitignore1
-rw-r--r--.settings/org.eclipse.cdt.core.prefs6
-rw-r--r--Sources/GraphAlgo.cpp47
4 files changed, 66 insertions, 0 deletions
diff --git a/.cproject b/.cproject
index 373a354..cde89d2 100644
--- a/.cproject
+++ b/.cproject
@@ -23,6 +23,9 @@
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1431040230" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.2141303895" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option defaultValue="gnu.cpp.compiler.debugging.level.max" id="gnu.cpp.compiler.exe.debug.option.debugging.level.1202600613" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.1128524278" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+ <listOptionValue builtIn="false" value="/home/haidong/messAround/googletest/googletest/include/gtest"/>
+ </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.51594479" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.869290367" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
@@ -32,6 +35,13 @@
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.642571755" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.803564522" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.paths.1874108310" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
+ <listOptionValue builtIn="false" value="/home/haidong/messAround/googletest/build/lib"/>
+ </option>
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.403224170" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="gtest"/>
+ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="gtest_main"/>
+ </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.75394371" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@@ -120,4 +130,6 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+ <storageModule moduleId="refreshScope"/>
+ <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3df573f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/Debug/
diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs
new file mode 100644
index 0000000..c8ec5df
--- /dev/null
+++ b/.settings/org.eclipse.cdt.core.prefs
@@ -0,0 +1,6 @@
+doxygen/doxygen_new_line_after_brief=true
+doxygen/doxygen_use_brief_tag=false
+doxygen/doxygen_use_javadoc_tags=true
+doxygen/doxygen_use_pre_tag=false
+doxygen/doxygen_use_structural_commands=false
+eclipse.preferences.version=1
diff --git a/Sources/GraphAlgo.cpp b/Sources/GraphAlgo.cpp
new file mode 100644
index 0000000..d04987f
--- /dev/null
+++ b/Sources/GraphAlgo.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <gtest/gtest.h>
+
+using std::vector;
+
+static long getMaxDotProduct(vector<int> a, vector<int> b) {
+ std::sort(a.begin(), a.end());
+ std::sort(b.begin(), b.end());
+ long result = 0;
+ for (int i = 0; i < b.size(); i++) {
+ result = (long) a[i]*b[i]+result;
+ }
+ return result;
+}
+
+TEST(MaxDotProduct, Max1) {
+ vector<int> a = { 60, 100, 120 };
+ vector<int> b = { 20, 50, 30 };
+ ASSERT_EQ(getMaxDotProduct(a, b), 10200);
+}
+
+//TEST(MaxDotProduct, Max2) {
+// vector<int> a = { 23 };
+// vector<int> b = { 39 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 897);
+//}
+//
+//TEST(MaxDotProduct, Max3) {
+// vector<int> a = { 1,3,-5 };
+// vector<int> b = { -2,4,1 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 23);
+//}
+
+//int main() {
+// size_t n;
+// std::cin >> n;
+// vector<int> a(n), b(n);
+// for (size_t i = 0; i < n; i++) {
+// std::cin >> a[i];
+// }
+// for (size_t i = 0; i < n; i++) {
+// std::cin >> b[i];
+// }
+// std::cout << getMaxDotProduct(a, b) << std::endl;
+//}