"""Unit tests for the capabilities module.
"""
from unittest import TestCase,main
from random import randint
from libjest.capabilities import Capabilities,AREA_TABLE
class HappyPathTestCase(TestCase):
"""More of an example than a rigorous test.
This gently tests the behavior on easy, expected input.
The results compared against in these tests come from an older
version of the same program.
"""
def __init__(self, *args):
"""Initialize with defaults."""
TestCase.__init__(self, *args)
self.cap = Capabilities()
def test_lines_to_time(self):
"""The traditional sort of estimation."""
self.assertAlmostEqual(2.3117123676601046,
self.cap.lines_to_time(100))
def test_time_to_lines(self):
"""The default sort of estimation."""
self.assertAlmostEqual(210.73030338974195,
self.cap.time_to_lines(3))
def test_people(self):
"""Both ways of estimating staff."""
self.assertAlmostEqual(0.10109124238169297,
self.cap.lines_to_people(100))
self.assertAlmostEqual(0.17681888565885381,
self.cap.time_to_people(3))
class ConsistencyTestCase(TestCase):
"""Check that answers are consistent.
"""
def __init__(self, *args):
"""Initialize with defaults."""
TestCase.__init__(self, *args)
self.cap = Capabilities()
def test_lines_through_time(self):
"""Randomized round trip test."""
for _ in xrange(1000):
lines = randint(1, 10**7)
self.assertAlmostEqual(lines,
self.cap.time_to_lines(self.cap.lines_to_time(lines)))
def test_time_through_lines(self):
"""Randomized round trip test."""
for _ in xrange(1000):
time = randint(1, 10**2)
self.assertAlmostEqual(time,
self.cap.lines_to_time(self.cap.time_to_lines(time)))
def test_same_people(self):
"""Randomized test that lines -> people is the same as lines ->
time -> people.
"""
for _ in xrange(1000):
lines = randint(1, 10**7)
self.assertAlmostEqual(
self.cap.lines_to_people(lines),
self.cap.time_to_people((self.cap.lines_to_time(lines))))
class SpotCheckTestCase(TestCase):
"""Spot check particular known cases.
"""
def test_same_levels(self):
"""Test each area rating."""
def set_all(rating):
"""Set every area to the same rating."""
return dict((area, rating) for area in AREA_TABLE.keys())
self.assertAlmostEqual(0.68803771182821283,
Capabilities(**set_all('extra-easy')).lines_to_time(10))
self.assertAlmostEqual(1.1528953327971505,
Capabilities(**set_all('very-easy')).lines_to_time(10**2))
self.assertAlmostEqual(3.2238415454165787,
Capabilities(**set_all('easy')).lines_to_time(10**3))
self.assertAlmostEqual(11.566741570539959,
Capabilities(**set_all('normal')).lines_to_time(10**4))
self.assertAlmostEqual(54.261008069641228,
Capabilities(**set_all('hard')).lines_to_time(10**5))
self.assertAlmostEqual(334.78230079964277,
Capabilities(**set_all('very-hard')).lines_to_time(10**6))
self.assertAlmostEqual(1157.9638550275956,
Capabilities(**set_all('extra-hard')).lines_to_time(10**7))
def test_outside_comparison(self):
"""Compare to someone else's implementation.
Based on http://sunset.usc.edu/research/COCOMOII/expert_cocomo/
"""
cap = Capabilities(
precedent='very-hard',
flexibility='hard',
risk='easy',
team='extra-easy',
process='easy')
self.assertAlmostEqual(11.1, cap.lines_to_time(10**4), places=1)
self.assertAlmostEqual(34.7/11.1, cap.lines_to_people(10**4), places=1)
cap = Capabilities(
precedent='extra-easy',
flexibility='very-hard',
risk='very-hard',
team='hard',
process='hard')
self.assertAlmostEqual(28.7, cap.lines_to_time(10**5), places=1)
self.assertAlmostEqual(554/28.7, cap.lines_to_people(10**5), places=1)
cap = Capabilities(
precedent='hard',
flexibility='easy',
risk='normal',
team='easy',
process='very-hard')
self.assertAlmostEqual(5.2, cap.lines_to_time(10**3), places=1)
self.assertAlmostEqual(2.9/5.2, cap.lines_to_people(10**3), places=1)
class EdgeCasesTestCase(TestCase):
"""Test edge and special cases."""
def __init__(self, *args):
"""Initialize with defaults."""
TestCase.__init__(self, *args)
self.cap = Capabilities()
def test_zeroes(self):
"""Every conversion should turn 0 into 0."""
self.assertEqual(0, self.cap.time_to_lines(0))
self.assertEqual(0, self.cap.time_to_people(0))
self.assertEqual(0, self.cap.lines_to_time(0))
self.assertEqual(0, self.cap.lines_to_people(0))
if __name__ == '__main__':
main()
|