Fixed a bug in CorrectMaps.get_npoints(), which would return 1

when npoints=0.
This commit is contained in:
Will Daly
2013-03-01 16:40:54 -05:00
parent d6df7e2d96
commit 28a502ea97
2 changed files with 7 additions and 1 deletions

View File

@@ -117,7 +117,7 @@ class CorrectMap(object):
Otherwise, return 0 points """
if self.is_correct(answer_id):
npoints = self.get_property(answer_id, 'npoints')
return npoints if npoints else 1
return npoints if npoints is not None else 1
else:
return 0

View File

@@ -69,6 +69,7 @@ class CorrectMapTest(unittest.TestCase):
# 2) correct, None points
# 3) incorrect, 5 points
# 4) incorrect, None points
# 5) correct, 0 points
self.cmap.set(answer_id='1_2_1',
correctness='correct',
npoints=5)
@@ -85,6 +86,10 @@ class CorrectMapTest(unittest.TestCase):
correctness='incorrect',
npoints=None)
self.cmap.set(answer_id='5_2_1',
correctness='correct',
npoints=0)
# Assert that we get the expected points
# If points assigned and correct --> npoints
# If no points assigned and correct --> 1 point
@@ -93,6 +98,7 @@ class CorrectMapTest(unittest.TestCase):
self.assertEqual(self.cmap.get_npoints('2_2_1'), 1)
self.assertEqual(self.cmap.get_npoints('3_2_1'), 0)
self.assertEqual(self.cmap.get_npoints('4_2_1'), 0)
self.assertEqual(self.cmap.get_npoints('5_2_1'), 0)
def test_set_overall_message(self):