コード例 #1
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldFailSinceIncorrectFace(self):
        cube = Cube()
        cubeCollection = collections.OrderedDict((('f', [
            'green', 'green', 'green', 'green', 'green', 'green', 'green',
            'green', 'green'
        ]), ('r', [
            'yellow', 'yellow', 'yellow', 'yellow', 'yellow', 'yellow',
            'yellow', 'yellow', 'yellow'
        ]), ('b', [
            'blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'blue', 'blue',
            'blue'
        ]), ('l', [
            'white', 'white', 'white', 'white', 'white', 'white', 'white',
            'white', 'white'
        ]), ('t',
             ['red', 'red', 'red', 'red', 'red', 'red', 'red', 'red',
              'red']), ('u', [
                  'orange', 'orange', 'orange', 'orange', 'orange', 'orange',
                  'orange', 'orange', 'orange'
              ])))
        cube.sides = cubeCollection
        faceBeingRotated = 'blah'
        cube.rotateCube(faceBeingRotated)

        self.assertEquals('face is unknown', cube.error)
コード例 #2
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldRotateFaceBeingRotatedCounterClockwise(self):
        cube = Cube()
        face = ['0', '1', '2', '3', '4', '5', '6', '7', '8']
        expectedRotatedFace = ['2', '5', '8', '1', '4', '7', '0', '3', '6']
        actualRotatedFace = cube._rotateCallingFace(face, COUNTER_CLOCKWISE)

        self.assertEquals(actualRotatedFace, expectedRotatedFace)
コード例 #3
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldFailSinceIllegalCubeIncorrectSize(self):
        cube = Cube()
        cubeCollection = collections.OrderedDict((('f', [
            'red', 'blue', 'blue', 'green', 'orange', 'blue', 'red', 'green'
        ]), ('r', [
            'yellow', 'orange', 'white', 'green', 'red', 'yellow', 'yellow',
            'red', 'yellow'
        ]), ('b', [
            'red', 'white', 'orange', 'blue', 'blue', 'green', 'green',
            'white', 'red'
        ]), ('l', [
            'green', 'green', 'green', 'red', 'orange', 'orange', 'blue',
            'white', 'orange'
        ]), ('t', [
            'white', 'green', 'blue', 'yellow', 'white', 'white', 'white',
            'orange', 'orange'
        ]), ('u', [
            'white', 'yellow', 'orange', 'red', 'yellow', 'blue', 'yellow',
            'blue', 'red'
        ])))
        cube.sides = cubeCollection
        faceBeingRotated = 'f'

        cube.checkCube(cube.getCubeString())
        if cube.status != 'error':
            cube.rotateCube(faceBeingRotated)

        self.assertEquals('cube is not sized properly', cube.error)
コード例 #4
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
 def testShouldTestRandomnessFidelity(self):
     cube = Cube()
     faces = collections.OrderedDict(
         (('f', ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g',
                 'g']), ('r', ['y', 'r', 'r', 'y', 'r', 'r', 'y', 'r',
                               'r']),
          ('b', ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
                 'b']), ('l', ['o', 'o', 'w', 'o', 'o', 'w', 'o', 'o',
                               'w']),
          ('t', ['w', 'w', 'w', 'w', 'w', 'w', 'r', 'r',
                 'r']), ('u', ['o', 'o', 'o', 'y', 'y', 'y', 'y', 'y',
                               'y'])))
     cube.sides = faces
     cube._randomness()
     self.assertEquals(cube.randomness, 67)
コード例 #5
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldRotateFront(self):
        cube = Cube()
        faceBeingRotated = 'f'
        cubeCollection = collections.OrderedDict((('f', [
            'red', 'yellow', 'blue', 'blue', 'green', 'orange', 'blue', 'red',
            'green'
        ]), ('r', [
            'yellow', 'orange', 'white', 'green', 'yellow', 'yellow', 'yellow',
            'red', 'yellow'
        ]), ('b', [
            'red', 'white', 'orange', 'blue', 'blue', 'green', 'green',
            'white', 'red'
        ]), ('l', [
            'green', 'green', 'green', 'red', 'white', 'orange', 'blue',
            'white', 'orange'
        ]), ('t', [
            'white', 'green', 'blue', 'yellow', 'red', 'white', 'white',
            'orange', 'orange'
        ]), ('u', [
            'white', 'yellow', 'orange', 'red', 'orange', 'blue', 'yellow',
            'blue', 'red'
        ])))
        cube.sides = cubeCollection

        expectedRotatedCube = collections.OrderedDict((('f', [
            'blue', 'blue', 'red', 'red', 'green', 'yellow', 'green', 'orange',
            'blue'
        ]), ('r', [
            'white', 'orange', 'white', 'orange', 'yellow', 'yellow', 'orange',
            'red', 'yellow'
        ]), ('b', [
            'red', 'white', 'orange', 'blue', 'blue', 'green', 'green',
            'white', 'red'
        ]), ('l', [
            'green', 'green', 'white', 'red', 'white', 'yellow', 'blue',
            'white', 'orange'
        ]), ('t', [
            'white', 'green', 'blue', 'yellow', 'red', 'white', 'orange',
            'orange', 'green'
        ]), ('u', [
            'yellow', 'green', 'yellow', 'red', 'orange', 'blue', 'yellow',
            'blue', 'red'
        ])))

        cube.rotateCube(faceBeingRotated)

        self.assertEquals(expectedRotatedCube, cube.sides)
コード例 #6
0
def dispatch(parm={}):
    '''Dispatch is passed parm by microservice.

    To be successful contains at least op : create, check, rotate, or scramble

    Parm can contain custom side values, must be under key's 'f', 'r', 'b', 'l', 't', or 'u'
    If custom values are not provided for the faces then they will be defaulted
    If faces are provided in parm but there are no values with them then an error will be returned

    For check a cube must be supplied as well as the face values in parm as well
    If the cube is not a legal cube an error will be returned, otherwise its type will be returned

    For rotate the face for the rotation must be supplied as well as the cube and the face values
    If any of those values are not suppleid an error will return
    Otherwise it will return the rotated cube

    For scramble the method is optional and is n but n will default to 0 if not
    provided and method will default to random

    '''

    dispatchStatus = ''
    op = ''
    cube = ''
    if 'op' in parm:  # if op is in the passed parameters
        colors = _setupColorsForCube(parm)
        if colors is not None:
            cube = Cube(colors)
            op = parm['op']
            if op == 'check':
                _checkCube(parm, cube)
            elif op == 'create':
                cube.createCube()
            elif op == 'rotate':
                _rotateCube(parm, cube)
            elif op == 'scramble':
                _scrambleCube(parm, cube)
            else:  # did not pass correct op
                dispatchStatus = 'error: missing op'
        else:  # Had a face key with missing value
            dispatchStatus = 'error: missing color'
    else:  # op not provided in parm
        dispatchStatus = 'error: missing op'

    httpResponse = _getHttpResponse(dispatchStatus, op, cube)
    return httpResponse
コード例 #7
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldFailSinceMethodIsIllegal(self):
        cube = Cube()
        numberOfRotations = '1'
        cube.scramble(numberOfRotations, 'test')

        self.assertEquals('unknown function for scramble', cube.error)
コード例 #8
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldFailSinceNIsIllegal3(self):
        cube = Cube()
        numberOfRotations = 'a'
        cube.scramble(numberOfRotations)

        self.assertEquals('n must be an integer between 0 to 99', cube.error)
コード例 #9
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldTestTransitionFidelity(self):
        cube = Cube()
        numberOfRotations = '1'
        cube.scramble(numberOfRotations, 'transition')

        self.assertEquals(cube.status, 'scrambled 67')
コード例 #10
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldTestScrambleNotBeing100Two(self):
        cube = Cube()
        numberOfRotations = '8'
        cube.scramble(numberOfRotations)

        self.assertNotEquals(cube.status, 'scrambled 100')
コード例 #11
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldTestPicking1Rotations(self):
        cube = Cube()
        numberOfRotations = '1'
        cube.scramble(numberOfRotations)

        self.assertEquals(len(cube.rotations), int(numberOfRotations))
コード例 #12
0
ファイル: CubeTest.py プロジェクト: nadrojisk/PyCube
    def testShouldRotatePartOfFaceBeingRotatedClockwise(self):
        cube = Cube()
        face = ['0', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g']
        newFace = cube._rotateCallingFace(face, CLOCKWISE)

        self.assertEquals(newFace[2], face[0])