Ejemplo n.º 1
0
    def getSudokuString(self):
        """
        This method asks to the user for the Sudoku game to be solved.

        If the option selected is Console, the input expected is a string with
        the matrix unsolved:
        '001093000000100004020060370700000005080504060400000008092080010100009000000340600'

        If the option selected is File, the input expected is the filename
        which contains the matrix unsolved in .txt or .csv format.
        i.e: 'SodukuGame.txt'
        """
        option = self.settingsSudoku.getSudokuOutputFormat()
        if option == "Console":
            return self.getUserInput("Enter the SUDOKU to be solved in a string line")
        if option == "File":
            fileNameFull = self.getUserInput("Please enter file name with extension")
            if os.path.exists(fileNameFull):
                fileName, fileExtension = os.path.splitext(fileNameFull)
                if fileExtension == ".txt":
                    txtFile = SudokuTXTReader(fileNameFull, self.settingsSudoku.getSudokuMatrixDimension())
                    return txtFile.readSudokuFromTXTFile()
                if fileExtension == ".csv":
                    csvFile = SudokuCSVReader(fileNameFull, self.settingsSudoku.getSudokuMatrixDimension())
                    return csvFile.getSudokuString()
Ejemplo n.º 2
0
 def setUp(self):
     self.csvObject = SudokuCSVReader("requiredtestfiles/SudokuTest.csv", 9)
Ejemplo n.º 3
0
class TestSudokuCSVReader(unittest.TestCase):
    def setUp(self):
        self.csvObject = SudokuCSVReader("requiredtestfiles/SudokuTest.csv", 9)

    def testGetSudokuStringFromCSVFile(self):
        expected =  "001700600090043000007000810003050900002" + \
                    "600075080000020040009002605021008000800040"
        review = self.csvObject.getSudokuString()
        self.assertEquals(expected, review)

    def testSizeOfRowStringFromCSVFile(self):
        expected = self.csvObject._countRowsSizeEntries()
        self.assertTrue(expected)

    def testSetTXTFileName(self):
        expected = "NewTXTFile.txt"
        self.csvObject.setFileName(expected)
        self.assertEqual(expected, self.csvObject._csvFileName)

    def testAreOnlyAllowedNumbers(self):
        expected = self.csvObject.areOnlyAllowedNumbers()
        self.assertTrue(expected)

    def testIsDimensionAccurate(self):
        expected = self.csvObject.isDimensionAccurate()
        self.assertTrue(expected)

    def testIsCSVContentValid(self):
        expected = self.csvObject.isCSVContentValid()
        self.assertTrue(expected)

    def testIsSizeAccurate(self):
        expected = self.csvObject.isSizeAccurate()
        self.assertTrue(expected)

    def testProvideWrongValuesUsingAlphanumericCharsInsteadOfDigits(self):
        self.csvObject.__init__("requiredtestfiles/SudokuWrong.csv", 9)
        expected = self.csvObject.areOnlyAllowedNumbers()
        self.assertFalse(expected)
        self.csvObject.__init__("requiredtestfiles/SudokuTest.csv", 9)

    def testIsCSVContentValidWhenProvideAlphanumericCharsInsteadOfDigits(self):
        self.csvObject.__init__("requiredtestfiles/SudokuWrong.csv", 9)
        expected = self.csvObject.isCSVContentValid()
        self.assertFalse(expected)
        self.csvObject.__init__("requiredtestfiles/SudokuTest.csv", 9)