Created
February 12, 2016 15:47
-
-
Save BeOleg/f93577b7c51a520ccc76 to your computer and use it in GitHub Desktop.
test suite for suduko.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from suduko import SodukuValidator | |
class TestSodukuValidator(unittest.TestCase): | |
def test_validate_rows_return_true_when_rows_not_contains_duplicates(self): | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
rows_validation = [] | |
for i in range(3): | |
rows_validation.append(validator.validate_rows(i)) | |
self.assertListEqual([True, True, True], rows_validation) | |
def test_validate_rows_return_false_when_rows_contains_duplicates(self): | |
# second row contains duplicates | |
test_input = '182543697' \ | |
'165178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
rows_validation = [] | |
for i in range(3): | |
rows_validation.append(validator.validate_rows(i)) | |
self.assertListEqual([True, False, True], rows_validation) | |
def test_validate_cols_return_true_when_cols_not_contains_duplicates(self): | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
cols_validation = [] | |
for i in range(3): | |
cols_validation.append(validator.validate_cols(i)) | |
self.assertListEqual([True, True, True], cols_validation) | |
def test_validate_cols_return_false_when_cols_contains_duplicates(self): | |
# first cols contains duplicates | |
test_input = '182543697' \ | |
'165178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
cols_validation = [] | |
for i in range(3): | |
cols_validation.append(validator.validate_cols(i)) | |
self.assertListEqual([False, True, True], cols_validation) | |
# ... | |
def test_validate_inner_return_false_when_prev_num_duplicate(self): | |
# first row 182 | |
# second 961^ not valid | |
test_input = '182543697' \ | |
'961578342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
inner_validation = validator.validate_inner(0) | |
self.assertFalse(inner_validation) | |
def test_validate_inner_return_true_when_prev_num_not_duplicate(self): | |
# 182 | |
# 965 | |
# 743 | |
# not duplicate, should be true | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
inner_validation = validator.validate_inner(0) | |
self.assertTrue(inner_validation) | |
def test_validate_return_false_when_any_row_not_valid(self): | |
# last row contains duplicate | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319244' | |
validator = SodukuValidator(3, test_input) | |
validate = validator.validate() | |
self.assertFalse(validate) | |
def test_validate_return_false_when_any_col_not_valid(self): | |
# last col contains duplicate | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319275' | |
validator = SodukuValidator(3, test_input) | |
validate = validator.validate() | |
self.assertFalse(validate) | |
def test_validate_return_false_when_any_inner_not_valid(self): | |
# first row 182 | |
# second 961^ not valid | |
test_input = '182543697' \ | |
'961578342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
validate = validator.validate() | |
self.assertFalse(validate) | |
def test_validate_return_true_when_input_valid(self): | |
test_input = '182543697' \ | |
'965178342' \ | |
'743962815' \ | |
'374896521' \ | |
'628451739' \ | |
'519237468' \ | |
'297684153' \ | |
'431725986' \ | |
'856319274' | |
validator = SodukuValidator(3, test_input) | |
validate = validator.validate() | |
self.assertTrue(validate) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment