aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/computations/slink.py12
-rw-r--r--tests/unit/computations/test_slink.py6
2 files changed, 18 insertions, 0 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index c29ddb0..103a853 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -6,6 +6,7 @@ FUNCTIONS:
slink:
TODO: Describe what the function does...
"""
+import logging
from functools import partial
class LengthError(BaseException):
@@ -116,3 +117,14 @@ def nearest(lists, i, j):
return min(ns)
else:
raise ValueError("member values (i or j) should be lists/tuples of integers or integers")
+
+def slink(lists):
+ """
+ """
+ try:
+ nearest(lists, 1, 2)
+ except Exception as e:
+ # TODO: Look into making the logging log output to the system's
+ # configured logger(s)
+ logging.warning("Exception: {}, {}".format(type(e), e))
+ return []
diff --git a/tests/unit/computations/test_slink.py b/tests/unit/computations/test_slink.py
index dd42d5d..bdfaf6d 100644
--- a/tests/unit/computations/test_slink.py
+++ b/tests/unit/computations/test_slink.py
@@ -2,6 +2,7 @@
import unittest
from unittest import TestCase
+from gn3.computations.slink import slink
from gn3.computations.slink import nearest
from gn3.computations.slink import LengthError
from gn3.computations.slink import MirrorError
@@ -200,3 +201,8 @@ class TestSlink(TestCase):
expected_distance=ed):
self.assertEqual(nearest(md, ml, mc), ed)
self.assertEqual(nearest(md, mc, ml), ed)
+
+ def test_slink_wrong_data_returns_empty_list(self):
+ for data in [1, "test", [], 2.945, nearest]:
+ with self.subTest(data=data):
+ self.assertEqual(slink(data), [])