Skip to content

Commit

Permalink
Merge pull request #7 from mogproject/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mogproject committed Feb 8, 2023
2 parents b837a85 + 2069829 commit b989f09
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ jobs:
run: pip install numpy
- name: Install testing dependencies
run: pip install pytest pytest-cov mypy coveralls
- name: Run unit tests
run: make test
- name: Install lcov
run: sudo apt-get install -y lcov
- name: Run unit tests with coverage
run: make coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
56 changes: 46 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
RM = /bin/rm
PYTHON=python3
MKDIR=mkdir
GCOV=gcov
LCOV=lcov
GENHTML=genhtml

ifneq ("$(wildcard /opt/homebrew/bin/g++-12)","")
export CC=/opt/homebrew/bin/gcc-12
export CXX=/opt/homebrew/bin/g++-12
GCOV=/opt/homebrew/bin/gcov-12
else
ifneq ("$(wildcard /opt/homebrew/bin/g++-11)","")
export CC=/opt/homebrew/bin/gcc-11
export CXX=/opt/homebrew/bin/g++-11
GCOV=/opt/homebrew/bin/gcov-11
endif
endif

CMAKE=cmake
CMAKE_OPTS=-DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)

SRC_CPP=src/main/cpp
BUILD_DIR=$(PWD)/build
TEST_BIN_DIR=$(BUILD_DIR)/test
TEST_EXEC=$(TEST_BIN_DIR)/modular_test
COV_CPP_DIR=coverage/cpp
COV_CPP=$(COV_CPP_DIR)/lcov.info
COV_PY_DIR=coverage/py
COV_PY=$(COV_PY_DIR)/lcov.info
COV_HTML=coverage/html
COV_MERGED=coverage/lcov.info

SRC_PY=src/main/python
TEST_PY=src/test/python
Expand All @@ -19,27 +44,38 @@ PROFILE_ON ?= false
TRACE_ON ?= false

build:
cd $(SRC_CPP) && cmake -S . -B $(BUILD_DIR)/Release -DCMAKE_BUILD_TYPE=Release -DPROFILE_ON=$(PROFILE_ON) -DTRACE_ON=$(TRACE_ON)
cd $(SRC_CPP) && cmake --build $(BUILD_DIR)/Release
cd $(SRC_CPP) && $(CMAKE) -S . -B $(BUILD_DIR)/Release $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Release -DPROFILE_ON=$(PROFILE_ON) -DTRACE_ON=$(TRACE_ON)
cd $(SRC_CPP) && $(CMAKE) --build $(BUILD_DIR)/Release

test: test-cpp test-py

test-py:
mypy $(SRC_PY)
$(PYTHON) -m pytest -x --cov=$(SRC_PY) --cov-report=lcov:./coverage/lcov.info $(PYTEST_OPTS) $(TEST_PY)

test-cpp:
@echo "GTEST_FILTER: $(GTEST_FILTER)"
cd $(SRC_CPP) && cmake -DBUILD_TESTS=ON -S . -B $(BUILD_DIR)/Debug
cd $(SRC_CPP) && cmake --build $(BUILD_DIR)/Debug
cd $(SRC_CPP) && $(CMAKE) -DBUILD_TESTS=ON -S . -B $(BUILD_DIR)/Debug $(CMAKE_OPTS)
cd $(SRC_CPP) && $(CMAKE) --build $(BUILD_DIR)/Debug
$(TEST_EXEC) --output-on-failure $(GTEST_OPTS)
$(MKDIR) -p $(COV_CPP_DIR)
$(LCOV) --gcov-tool $(GCOV) -d $(TEST_BIN_DIR) -c -o "$(COV_CPP)"
$(LCOV) -r "${COV_CPP}" "*/include/*" "*.h" "*/test/*" "*/build*/*" -o "${COV_CPP}"

test-py:
mypy $(SRC_PY)
$(MKDIR) -p $(COV_PY_DIR)
$(PYTHON) -m pytest -x --cov=$(SRC_PY) --cov-report=lcov:$(COV_PY) $(PYTEST_OPTS) $(TEST_PY)

coverage: test
$(LCOV) --add-tracefile $(COV_PY) -a $(COV_CPP) -o $(COV_MERGED)

coverage-html: coverage
$(GENHTML) -o $(COV_HTML) $(COV_MERGED)
open $(COV_HTML)/index.html

clean:
@echo "Cleaning..."
@$(RM) -rf build/*
@$(RM) -rf build/* coverage/*
@echo "Cleaning done."

lab:
jupyter-lab

.PHONY: build test test-cpp clean lab
.PHONY: build test test-py test-cpp coverage coverage-html clean lab
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The code implements the algorithm described in *Simpler, Linear-Time Modular Dec
## Dependencies

- C++
- gcc version 11 or 12
- CMake
- gcc version 11 or 12 (Mac: `brew install gcc@12`)
- CMake (Mac: `brew install cmake`)
- Python
- NetworkX (`pip install networkx`)
- NumPy (`pip install numpy`)
Expand All @@ -19,6 +19,7 @@ The code implements the algorithm described in *Simpler, Linear-Time Modular Dec

- C++
- GoogleTest (automatically installed during the build process)
- lcov (Mac: `brew install lcov`)
- Python
- pytest (`pip install pytest`)
- pytest-cov (`pip install pytest-cov`)
Expand Down
9 changes: 0 additions & 9 deletions src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ option(BUILD_TESTS "Build test programs" OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# specify compilers on local machine (Mac)
if (EXISTS /opt/homebrew/bin/g++-12)
set(CMAKE_C_COMPILER /opt/homebrew/bin/gcc-12)
set(CMAKE_CXX_COMPILER /opt/homebrew/bin/g++-12)
elseif(EXISTS /opt/homebrew/bin/gcc-11)
set(CMAKE_C_COMPILER /opt/homebrew/bin/gcc-11)
set(CMAKE_CXX_COMPILER /opt/homebrew/bin/g++-11)
endif ()

message("Compiler: ${CMAKE_CXX_COMPILER}")

# source files
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/modular/MDTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MDTree:
Modular decomposition tree for undirected graphs.
"""

def __init__(self, G: nx.Graph, solver: str = 'naive') -> None:
def __init__(self, G: nx.Graph, solver: str = 'linear') -> None:
assert len(G) > 0, 'graph cannot be empty'

if solver == 'linear':
Expand Down Expand Up @@ -73,7 +73,7 @@ def __repr__(self) -> str:
return repr(self.root)


def modular_decomposition(G: nx.Graph, sorted: bool = False, solver: str = 'naive') -> Optional[MDTree]:
def modular_decomposition(G: nx.Graph, sorted: bool = False, solver: str = 'linear') -> Optional[MDTree]:
"""Alias to the constructor."""

if len(G) == 0:
Expand Down
13 changes: 13 additions & 0 deletions src/test/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()

# Code coverage
function(add_code_coverage)
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-fprofile-arcs -ftest-coverage)
link_libraries(gcov)
endif()
endfunction()

add_code_coverage()

# source files
file(GLOB_RECURSE TEST_SRC
LIST_DIRECTORIES false
Expand Down

0 comments on commit b989f09

Please sign in to comment.