[kupfer] relevance: Add more doctests, put doctest run in if __name__
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] relevance: Add more doctests, put doctest run in if __name__
- Date: Fri, 11 Sep 2009 16:10:59 +0000 (UTC)
commit 8931d9b5f83da6d07e249fff96097aab9ab3ba99
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Sep 11 15:00:26 2009 +0200
relevance: Add more doctests, put doctest run in if __name__
kupfer/relevance.py | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/relevance.py b/kupfer/relevance.py
index 3c70a4e..d367e42 100644
--- a/kupfer/relevance.py
+++ b/kupfer/relevance.py
@@ -96,6 +96,14 @@ def score(s, query):
0.735098684211
>>> print score('terminal', 'term')
0.992302631579
+ >>> print score('terminal', 'try')
+ 0.0
+ >>> print score('terminal', '')
+ 1.0
+ >>> print score('terminal', 'yl')
+ 0.0
+ >>> print score('terminal', 'tlm')
+ 0.0
"""
if len(query) == 0:
return 1
@@ -170,6 +178,12 @@ def _findBestMatch(s, query):
Returns: a two-item tuple containing the start and end indicies of
the match. No match returns (-1,-1).
+ >>> _findBestMatch('terminal', 'yl')
+ (-1, -1)
+ >>> _findBestMatch('terminal', 'trml')
+ (0, 8)
+ >>> _findBestMatch('teerminal', 'erml')
+ (2, 9)
"""
if len(query) == 0:
return 0, 0
@@ -233,3 +247,7 @@ def _index(s, char, index = 0, count = -1):
return index + s.index(char)
except ValueError:
return -1
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]