Skip to content

Commit b2e6700

Browse files
Merge pull request #14 from powercoderlol/feature/conan-gtest
resolve #13: Add gtest from conan * Add one test for long string * Remove osx build
2 parents 2ad0207 + 0c4b63c commit b2e6700

14 files changed

Lines changed: 178 additions & 144 deletions

.travis.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
11
dist: xenial
2-
sudo: required
32

43
language: cpp
54

65
os:
76
- linux
87
- osx
9-
# - windows
108

119
compiler:
1210
- gcc
1311
- clang
1412

1513
env:
16-
- TARGET_CPU=amd64 BUILD_CONFIGURATION=Debug
14+
# - TARGET_CPU=amd64 BUILD_CONFIGURATION=Debug
1715
- TARGET_CPU=amd64 BUILD_CONFIGURATION=Release
18-
- TARGET_CPU=x86 BUILD_CONFIGURATION=Debug
16+
# - TARGET_CPU=x86 BUILD_CONFIGURATION=Debug
1917
- TARGET_CPU=x86 BUILD_CONFIGURATION=Release
2018

2119
matrix:
2220
exclude:
2321
- os: osx
2422
compiler: gcc
2523

26-
# - os: windows
27-
# compiler: gcc
28-
2924
- os: osx
30-
env: TARGET_CPU=x86 BUILD_CONFIGURATION=Debug
25+
env: TARGET_CPU=amd64 BUILD_CONFIGURATION=Release
3126

3227
- os: osx
3328
env: TARGET_CPU=x86 BUILD_CONFIGURATION=Release
3429

30+
linux: &linux
31+
os: linux
32+
sudo: required
33+
language: python
34+
python: "3.7"
35+
36+
install:
37+
- sudo apt-get update -qq
38+
- sudo apt-get install python3-pip -y
39+
- sudo apt-get install python3-setuptools -y
40+
- sudo python3 -m pip install --upgrade pip
41+
- sudo python3 -m pip install conan
42+
- conan user
43+
- conan --version
44+
- conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
3545

3646
script:
37-
- cmake --version
3847
- mkdir build
3948
- cd build
49+
- conan install .. -s compiler.libcxx=libstdc++11 --build=missing
4050
- cmake .. -DCMAKE_BUILD_TYPE=$BUILD_CONFIGURATION -DTARGET_CPU=$TARGET_CPU
41-
- cmake --build .
42-
- ctest -C Debug
51+
- cmake --build . --config Release
52+
# - ctest -C Debug
4353
- ctest -C Release

CMakeLists.txt

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,24 @@
11
project(algorithms)
2-
cmake_minimum_required(VERSION 2.8.11)
2+
cmake_minimum_required(VERSION 3.10)
33

44
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
55

6-
set(CMAKE_CXX_STANDARD 11)
7-
8-
message(STATUS "cmake module path: ${CMAKE_MODULE_PATH}")
9-
10-
# download and unpack googletest at configure time
11-
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
12-
13-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
14-
RESULT_VARIABLE result
15-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
16-
17-
if(result)
18-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
19-
endif()
20-
21-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
22-
RESULT_VARIABLE result
23-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
24-
if(result)
25-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
26-
endif()
6+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
7+
conan_basic_setup(TARGETS)
278

28-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
9+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2910

30-
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")
11+
message(STATUS "cmake module path: ${CMAKE_MODULE_PATH}")
3112

32-
if (CMAKE_VERSION VERSION_LESS 2.8.11)
33-
include_directories("${gtest_SOURCE_DIR}/include")
34-
endif()
13+
set(CMAKE_CXX_STANDARD 11)
14+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
15+
set(CMAKE_CXX_EXTENSIONS OFF)
3516

3617
enable_testing()
3718

38-
include(Sources)
39-
40-
add_library(algorithms_on_strings STATIC ${ALGORITHMS_ON_STRINGS_LIB_SRC})
41-
target_include_directories(algorithms_on_strings
42-
PUBLIC
43-
algorithms_on_strings/longest_common_substring)
44-
45-
SET(GTEST_LIBS gtest gtest_main)
46-
SET(STRING_ALGO_LIBS algorithms_on_strings)
47-
48-
add_library(sorting_algorithms STATIC ${SORTING_ALGORITHMS_LIB_SRC})
49-
target_include_directories(sorting_algorithms
50-
PUBLIC
51-
sorting_algorithms/quick_sort)
52-
set_property(TARGET sorting_algorithms PROPERTY LINKER_LANGUAGE CXX)
53-
54-
SET(SORTING_ALGO_LIBS sorting_algorithms)
55-
56-
add_executable(smoke-test-longest-substring tests/smoke-test-longest-substring.cpp)
57-
target_link_libraries(smoke-test-longest-substring ${GTEST_LIBS} ${STRING_ALGO_LIBS} ${SORTING_ALGO_LIBS})
19+
add_subdirectory(algorithms_on_strings)
20+
add_subdirectory(sorting_algorithms)
21+
add_subdirectory(tests)
5822

59-
add_test(NAME longest-substring-test COMMAND smoke-test-longest-substring)
6023

6124

CMakeLists.txt.in

Lines changed: 0 additions & 15 deletions
This file was deleted.

Sources.cmake

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
project(strings-lib)
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
set(ALGORITHMS_ON_STRINGS_LIB_SRC
5+
longest_common_substring/LongestSubstring.h
6+
longest_common_substring/LongestSubstring.cpp
7+
)
8+
9+
add_library(${PROJECT_NAME} STATIC ${ALGORITHMS_ON_STRINGS_LIB_SRC})
10+
target_include_directories(${PROJECT_NAME}
11+
PUBLIC
12+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/longest_common_substring>)
13+
14+
set_property(TARGET ${PROJECT_NAME} PROPERTY LINKER_LANGUAGE CXX)
Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
11
#include "LongestSubstring.h"
22

3-
int main() {
4-
char str[30], str1[30], str2[30];
5-
scanf("%s", str);
6-
scanf("%s", str1);
3+
void findLongestSubstring(const char a[], const char b[], char res[]) {
4+
size_t i, j, k, len_a, len_b, substr_i, max_substr;
5+
size_t** matrix;
76

8-
findLongestSubstring(str, str1, str2);
9-
printf("%s\n", str2);
7+
for(i = 0; a[i] != '\0'; i++);
8+
len_a = i;
109

11-
return 0;
10+
for(j = 0; b[j] != '\0'; j++);
11+
len_b = j;
12+
13+
matrix = (size_t**)malloc((len_a + 1) * sizeof(size_t*));
14+
15+
for(i = 0; i < len_a; i++) {
16+
matrix[i] = (size_t*)malloc((len_b + 1) * sizeof(size_t));
17+
for(j = 0; j < len_b; j++) {
18+
matrix[i][j] = 0;
19+
}
20+
}
21+
printf("\n");
22+
23+
max_substr = 0;
24+
substr_i = 0;
25+
26+
for(i = 0; i < len_a; i++) {
27+
for(j = 0; j < len_b; j++) {
28+
if(a[i] == b[j]) {
29+
if((0 == i) || (0 == j))
30+
matrix[i][j] = 1;
31+
else
32+
matrix[i][j] = matrix[i - 1][j - 1] + 1;
33+
if(matrix[i][j] > max_substr) {
34+
max_substr = matrix[i][j];
35+
substr_i = i;
36+
}
37+
else if(matrix[i][j] == max_substr)
38+
substr_i = i;
39+
}
40+
else
41+
matrix[i][j] = 0;
42+
}
43+
}
44+
45+
k = 0;
46+
for(i = (substr_i - max_substr + 1); i <= substr_i; i++) {
47+
res[k] = a[i];
48+
k++;
49+
}
50+
res[k] = '\0';
1251
}

algorithms_on_strings/longest_common_substring/LongestSubstring.h

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,4 @@
22
#include <stdio.h>
33
#include <stdlib.h>
44

5-
void findLongestSubstring(const char a[], const char b[], char res[]) {
6-
size_t i, j, k, len_a, len_b, substr_i, max_substr;
7-
size_t** matrix;
8-
9-
for(i = 0; a[i] != '\0'; i++);
10-
len_a = i;
11-
12-
for(j = 0; b[j] != '\0'; j++);
13-
len_b = j;
14-
15-
matrix = (size_t**)malloc((len_a + 1) * sizeof(size_t*));
16-
17-
for(i = 0; i < len_a; i++) {
18-
matrix[i] = (size_t*)malloc((len_b + 1) * sizeof(size_t));
19-
for(j = 0; j < len_b; j++) {
20-
matrix[i][j] = 0;
21-
}
22-
}
23-
printf("\n");
24-
25-
max_substr = 0;
26-
substr_i = 0;
27-
28-
for(i = 0; i < len_a; i++) {
29-
for(j = 0; j < len_b; j++) {
30-
if(a[i] == b[j]) {
31-
if((0 == i) || (0 == j))
32-
matrix[i][j] = 1;
33-
else
34-
matrix[i][j] = matrix[i - 1][j - 1] + 1;
35-
if(matrix[i][j] > max_substr) {
36-
max_substr = matrix[i][j];
37-
substr_i = i;
38-
}
39-
else if(matrix[i][j] == max_substr)
40-
substr_i = i;
41-
}
42-
else
43-
matrix[i][j] = 0;
44-
}
45-
}
46-
47-
k = 0;
48-
for(i = (substr_i - max_substr + 1); i <= substr_i; i++) {
49-
res[k] = a[i];
50-
k++;
51-
}
52-
res[k] = '\0';
53-
}
5+
void findLongestSubstring(const char a[], const char b[], char res[]);

appveyor.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@ platform:
44
- x64
55

66
environment:
7+
PYTHON: "C:\\Python37-x64"
8+
PYTHON_VERSION: "3.7.2"
9+
PYTHON_ARCH: "64"
10+
711
matrix:
812
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
913
CMAKE_GENERATOR: -G"Visual Studio 14 2015 Win64"
1014
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
1115
CMAKE_GENERATOR: -G"Visual Studio 15 2017 Win64"
1216

17+
install:
18+
- echo "Downloading conan..."
19+
- set PATH=%PATH%;%PYTHON%/Scripts/
20+
- python -m pip install --upgrade pip
21+
- pip3.exe install conan
22+
- conan user
23+
- conan --version
24+
- conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
25+
1326
build_script:
1427
- mkdir build
1528
- cd build
29+
- conan install ..
1630
- cmake %CMAKE_GENERATOR% ../
1731
- cmake --build . --config Release
1832
- ctest -C Release

conanfile.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[requires]
2+
gtest/1.8.1@bincrafters/stable
3+
4+
[options]
5+
gtest:shared=False
6+
7+
[generators]
8+
cmake

sorting_algorithms/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project(sorting-algo-lib)
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
set(SORTING_ALGORITHMS_LIB_SRC
5+
quick_sort/parallel_and_sequential_quick_sort.cpp
6+
quick_sort/qsort_test.cpp
7+
quick_sort/template_qsort.h
8+
)
9+
10+
add_library(sorting_algorithms STATIC ${SORTING_ALGORITHMS_LIB_SRC})
11+
target_include_directories(sorting_algorithms
12+
PRIVATE
13+
sorting_algorithms/quick_sort)
14+
set_property(TARGET sorting_algorithms PROPERTY LINKER_LANGUAGE CXX)
15+
16+
SET(SORTING_ALGO_LIBS sorting_algorithms)

0 commit comments

Comments
 (0)