test_capabilities.py :  » Project-Management » Jest » jest-2.0.0b8 » libjest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Project Management » Jest 
Jest » jest 2.0.0b8 » libjest » test_capabilities.py
"""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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.