Sha256: 066aa92f62d34d67f98be91f53ec1414ad1aec95c388ee626b775f4edaa42cc0

Contents?: true

Size: 1.2 KB

Versions: 118

Compression:

Stored size: 1.2 KB

Contents

import unittest

from robot_name import Robot
import random


class RobotTest(unittest.TestCase):
    # assertRegex() alias to adress DeprecationWarning
    # assertRegexpMatches got renamed in version 3.2
    if not hasattr(unittest.TestCase, "assertRegex"):
        assertRegex = unittest.TestCase.assertRegexpMatches

    name_re = r'^[A-Z]{2}\d{3}$'

    def test_has_name(self):
        self.assertRegex(Robot().name, self.name_re)

    def test_name_sticks(self):
        robot = Robot()
        robot.name
        self.assertEqual(robot.name, robot.name)

    def test_different_robots_have_different_names(self):
        self.assertNotEqual(
            Robot().name,
            Robot().name
        )

    def test_reset_name(self):
        # Set a seed
        seed = "Totally random."

        # Initialize RNG using the seed
        random.seed(seed)

        # Call the generator
        robot = Robot()
        name = robot.name

        # Reinitialize RNG using seed
        random.seed(seed)

        # Call the generator again
        robot.reset()
        name2 = robot.name
        self.assertNotEqual(name, name2)
        self.assertRegex(name2, self.name_re)


if __name__ == '__main__':
    unittest.main()

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
trackler-2.0.8.27 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.26 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.24 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.23 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.22 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.21 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.20 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.19 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.18 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.17 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.16 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.15 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.14 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.13 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.12 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.11 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.10 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.9 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.8 tracks/python/exercises/robot-name/robot_name_test.py
trackler-2.0.8.7 tracks/python/exercises/robot-name/robot_name_test.py