Skip to content

Commit

Permalink
Additional tests and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Feb 24, 2015
1 parent 46ef6c2 commit b53d90d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
16 changes: 13 additions & 3 deletions khmer/_khmermodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4472,13 +4472,23 @@ hllcounter_set_ksize(khmer_KHLLCounter_Object * me, PyObject *value,
return -1;
}

if (!PyLong_Check(value) && !PyInt_Check(value)) {
long ksize = 0;
if (PyLong_Check(value)) {
ksize = PyLong_AsLong(value);
} else if (PyInt_Check(value)) {
ksize = PyInt_AsLong(value);
} else {
PyErr_SetString(PyExc_TypeError,
"Please use an int value for k-mer size");
"Please use an integer value for k-mer size");
return -1;
}

if (ksize <= 0) {
PyErr_SetString(PyExc_ValueError, "Please set k-mer size to a value "
"greater than zero");
return -1;
}

WordLength ksize = PyLong_AsLong(value);
try {
me->hllcounter->set_ksize(ksize);
} catch (InvalidValue &e) {
Expand Down
4 changes: 0 additions & 4 deletions lib/hllcounter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,6 @@ void HLLCounter::set_ksize(WordLength new_ksize)
"first counting");
}

if (new_ksize <= 0) {
throw InvalidValue("Please set k-mer size to a value "
"greater than zero");
}
this->init(this->p, new_ksize);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_hll.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ def test_hll_change_error_rate():
hllcpp.error_rate = 0.01
assert hllcpp.error_rate == 0.008125

with assert_raises(TypeError):
del hllcpp.error_rate

with assert_raises(TypeError):
hllcpp.error_rate = 5

with assert_raises(ValueError):
hllcpp.error_rate = 2.5

# error rate can only be changed prior to first counting,
hllcpp.consume_string('AAACCACTTGTGCATGTCAGTGCAGTCAGT')
with assert_raises(AttributeError):
Expand All @@ -213,6 +222,15 @@ def test_hll_change_ksize():
hllcpp.ksize = 12
assert hllcpp.ksize == 12

with assert_raises(ValueError):
hllcpp.ksize = -20

with assert_raises(TypeError):
del hllcpp.ksize

with assert_raises(TypeError):
hllcpp.ksize = 33.4

# error rate can only be changed prior to first counting,
hllcpp.consume_string('AAACCACTTGTGCATGTCAGTGCAGTCAGT')
with assert_raises(AttributeError):
Expand Down

0 comments on commit b53d90d

Please sign in to comment.