Skip to content

Commit 324a5e2

Browse files
committed
Fix tests
1 parent 7e67e44 commit 324a5e2

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

tests/kernel_tests.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
import networkx as nx
99
import numpy as np
1010

11-
from diffupy.kernels import commute_time_kernel, p_step_kernel, inverse_cosine_kernel, diffusion_kernel, \
12-
regularised_laplacian_kernel
11+
from diffupy.kernels import (
12+
commute_time_kernel,
13+
p_step_kernel,
14+
inverse_cosine_kernel,
15+
diffusion_kernel,
16+
regularised_laplacian_kernel,
17+
)
1318
from diffupy.matrix import Matrix
1419
from .constants import *
1520

@@ -19,24 +24,26 @@
1924

2025

2126
def _run_kernel_test(kernel_func, G, validate_matrix_path):
22-
M = kernel_func(G)
23-
V = Matrix.from_csv(validate_matrix_path)
27+
"""Run kernel test."""
28+
matrix = kernel_func(G)
29+
v = Matrix.from_csv(validate_matrix_path)
2430

25-
logging.info(' %s \n %s\n', 'Computed matrix', M)
26-
logging.info(' %s \n %s\n', 'Test matrix', V)
31+
logging.info(' %s \n %s\n', 'Computed matrix', matrix)
32+
logging.info(' %s \n %s\n', 'Test matrix', v)
2733
# Assert rounded similarity (floating comma)
28-
assert np.allclose(M, V)
34+
assert np.allclose(matrix, v)
2935
logging.info(' Test ' + kernel_func.__name__ + ' passed')
3036

3137

3238
"""Tests"""
3339

3440

3541
class KernelsTest(unittest.TestCase):
36-
G = nx.read_gml(GML_FILE_EXAMPLE, label='id')
37-
38-
_run_kernel_test(commute_time_kernel, G, COMMUTE_TIME_KERNEL)
39-
_run_kernel_test(diffusion_kernel, G, DIFFUSION_KERNEL)
40-
_run_kernel_test(p_step_kernel, G, P_STEP_KERNEL)
41-
_run_kernel_test(inverse_cosine_kernel, G, INVERSE_COSINE_KERNEL)
42-
_run_kernel_test(regularised_laplacian_kernel, G, REGULARISED_LAPLACIAN_KERNEL)
42+
"""Kernel test."""
43+
graph = nx.read_gml(GML_FILE_EXAMPLE, label='id')
44+
45+
_run_kernel_test(commute_time_kernel, graph, COMMUTE_TIME_KERNEL)
46+
_run_kernel_test(diffusion_kernel, graph, DIFFUSION_KERNEL)
47+
_run_kernel_test(p_step_kernel, graph, P_STEP_KERNEL)
48+
_run_kernel_test(inverse_cosine_kernel, graph, INVERSE_COSINE_KERNEL)
49+
_run_kernel_test(regularised_laplacian_kernel, graph, REGULARISED_LAPLACIAN_KERNEL)

0 commit comments

Comments
 (0)