示例#1
0
 def getNumberOfOnesAndTwos(self, messageDictionary, numberOfOnes, numberOfTwos):
     for i in range(64):
         outputDictionary = json.loads(IndigoGirls.dispatch(messageDictionary))
         grid = outputDictionary[self.board][self.grid]
         newList = grid
         del newList[8]
         del newList[11]
         numberOfOnes += newList.count(1)
         numberOfTwos += newList.count(2)
     return numberOfOnes, numberOfTwos
示例#2
0
 def test_300__1005_ShouldReturnErrorOnMissingGridInBoard(self):
     msg = {
         self.op: self.swipe,
         self.direction: self.left,
         self.board: {
             self.column: 4,
             self.row: 4
         }
     }
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
示例#3
0
 def test_600ForValidation(self):
     messageDictionary = {
         'op': 'recommend',
         'moves': '1',
         'board': {
             'columnCount': 4,
             'rowCount': 4,
             'grid': [0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2]
         }
     }
     self.assertTrue('error' in json.loads(
         IndigoGirls.dispatch(messageDictionary))['gameStatus'])
示例#4
0
 def test_300__1000_ShouldReturnErrorOnEmptyColumnCountInBoard(self):
     msg = {
         self.op: self.swipe,
         self.direction: self.left,
         self.board: {
             self.column: "",
             self.row: 4,
             self.grid: self.list
         }
     }
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
示例#5
0
 def test_300_960_ShouldReturnErrorOnRowCountInBoardLE1(self):
     msg = {
         self.op: self.swipe,
         self.direction: self.right,
         self.board: {
             self.column: 4,
             self.row: 1,
             self.grid: [1, 0, 2, 0]
         }
     }
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
示例#6
0
 def test_300_910_ShouldReturnErrorOnInvalidDirection(self):
     msg = {
         self.op: self.swipe,
         self.direction: "out",
         self.board: {
             self.column: 4,
             self.row: 4,
             self.grid: self.list
         }
     }
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
示例#7
0
 def test_300_975_ShouldReturnErrorOnColumnCountInBoardGT100(self):
     grid = [0] * (1200 * 4)
     msg = {
         self.op: self.swipe,
         self.direction: self.left,
         self.board: {
             self.column: 1200,
             self.row: 4,
             self.grid: grid
         }
     }
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
    def test_statusIntegration01(self):
        columnCount = 2
        rowCount = 2
        grid = [4, 0, 1, 0]
        board = {
            "columnCount": columnCount,
            "rowCount": rowCount,
            "grid": grid
        }

        message = {"board": board, "op": "status"}

        jInput = json.dumps(message, ensure_ascii=True)
        joutput = dispatch(jInput)

        output = json.loads(joutput)

        self.assertIn("win", output["gameStatus"])
    def test_swipeIntegration01(self):
        columnCount = 2
        rowCount = 2
        grid = [0] * 4
        direction = 3

        board = {
            "columnCount": columnCount,
            "rowCount": rowCount,
            "grid": grid
        }
        message = {"board": board, "direction": direction, "op": "swipe"}

        jInput = json.dumps(message)

        joutput = dispatch(jInput)

        output = json.loads(joutput)

        self.assertTrue("error" in output["gameStatus"])
    def test_recommendIntegration01(self):
        columnCount = 2
        rowCount = 2
        grid = [1, 0, 1, 0]
        moves = 1

        board = {
            "columnCount": columnCount,
            "rowCount": rowCount,
            "grid": grid
        }
        message = {"board": board, "op": "recommend", "moves": moves}

        jInput = json.dumps(message, ensure_ascii=True)

        joutput = dispatch(jInput)

        output = json.loads(joutput)

        score = output["score"]

        self.assertEquals(score, 2**2)
    def test_predictIntegration01(self):
        columnCount = 2
        rowCount = 2
        grid = [1, 0, 1, 0]
        direction = "up"

        board = {
            "columnCount": columnCount,
            "rowCount": rowCount,
            "grid": grid
        }
        message = {"board": board, "op": "predict", "direction": direction}

        jInput = json.dumps(message, ensure_ascii=True)

        joutput = dispatch(jInput)

        output = json.loads(joutput)

        score = output["highScore"]

        self.assertEquals(score, 2**2)
    def test_swipeIntegration02(self):
        columnCount = 2
        rowCount = 2
        grid = [0, 0, 1, 1]
        direction = "up"

        board = {
            "columnCount": columnCount,
            "rowCount": rowCount,
            "grid": grid
        }
        message = {"board": board, "direction": direction, "op": "swipe"}

        jInput = json.dumps(message, ensure_ascii=True)

        joutput = dispatch(jInput)

        output = json.loads(joutput)

        grid = output["board"]["grid"]

        self.assertEquals(grid[0], 1)
        self.assertEquals(grid[1], 1)
示例#13
0
import IndigoGirls.dispatch as dispatch

validJson = '{"op": "status", "tile": 2048, " ": {"columnCount": 4, "rowCount": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))

validJson = '{"op": "status", "tile": 2048, "board": {" ": 4, "rowCount": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))

validJson = '{"op": "status", "tile": 2048, "board": {"columnCount": "4", "rowCount": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))

validJson = '{"op": "status", "tile": 2048, "board": {"columnCount": 0, "rowCount": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))

validJson = '{"op": "status", "tile": 2048, "board": {"columnCount": 1000, "rowCount": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))

validJson = '{"op": "status", "tile": 2048, "board": {"columnCount": 4, " ": 4, "grid": [0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0]}}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(
    validJson, validResult))
示例#14
0
 def test_300_925_ShouldReturnErrorOnMissingBoard(self):
     msg = {self.op: self.swipe, self.direction: self.left}
     messageDictionary = json.dumps(msg)
     self.assertTrue(self.errorValue in json.loads(
         IndigoGirls.dispatch(messageDictionary))[self.errorKey])
示例#15
0
 def test_300ForValidation(self):
     messageDictionary = {'op': 'predict', 'moves': 1,
                          'board': {'columnCount': 4, 'rowCount': 4,
                                    'grid': [1, 2, 3, 4, 4, 3, 2, 1, 1, 2, 3, 4, 4, 3, 2, 1]}}
     self.assertTrue('error' in json.loads(IndigoGirls.dispatch(messageDictionary))['gameStatus'])
示例#16
0
import IndigoGirls.dispatch as dispatch

errorJson = '{"op": "unknown"}'
errorResult = dispatch.dispatch(errorJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n\n").format(errorJson, errorResult))

errorJson = ''
errorResult = dispatch.dispatch(errorJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n\n").format(errorJson, errorResult))

errorJson = '{}'
errorResult = dispatch.dispatch(errorJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n\n").format(errorJson, errorResult))

validJson = '{"op": "initializeGame"}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(validJson, validResult))

validJson = '{"op": "initializeGame", "rowCount":3}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(validJson, validResult))

validJson = '{"op": "initializeGame", "rowCount":3, "columnCount":5}'
validResult = dispatch.dispatch(validJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n").format(validJson, validResult))

errorJson = '{"op": "initializeGame", "rowCount":"two"}'
errorResult = dispatch.dispatch(errorJson)
print(("Input string:\t{0}\nOutput string:\t{1}\n\n").format(errorJson, errorResult))

errorJson = '{"op": "initializeGame", "columnCount":"9"}'
示例#17
0
 def test_904Validation(self):
     messageDictionary = {'op': 'swipe', 'direction' : 'right',
                       'board': {'columnCount': 4, 'rowCount': 4,
                                 'grid': [0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0,0,0,1]}}
     self.assertTrue('error' in json.loads(IndigoGirls.dispatch(messageDictionary))['gameStatus'])
示例#18
0
 def getOutputDictionay(self, msg):
     messageDictionary = json.dumps(msg)
     outputDictionary = json.loads(IndigoGirls.dispatch(messageDictionary))
     return outputDictionary