Permalink
Browse files

wrote tests for rotation and reflection.

implemented rotate90 and reflect.
  • Loading branch information...
uberj
uberj committed Nov 17, 2011
1 parent b984b41 commit a0e2e179a7e426a95a2550acdd6777e384db876a
Showing with 56 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +18 −0 rr.py
  3. +37 −0 test_rr.py
View
@@ -0,0 +1 @@
+*.pyc
View
18 rr.py
@@ -0,0 +1,18 @@
+# Rotation and Reflections functions
+import copy
+from nqueens import *
+
+def rotate90(matrix, n):
+ # OH GOD THIS IS TERRIBLE.
+ rotated_matrix = copy.deepcopy(matrix)
+ for i in range(n):
+ for j in range(n):
+ rotated_matrix[n-1-j][i] = matrix[i][j]
+ return rotated_matrix
+
+def reflect(matrix,n):
+ reflected_matrix = []
+ for i in range(n):
+ reflected_matrix.append(copy.deepcopy(matrix[n-1-i]))
+
+ return reflected_matrix
View
@@ -0,0 +1,37 @@
+from rr import *
+import unittest
+
+class TestnQueens(unittest.TestCase):
+ def setUp(self):
+ self.n = 11
+ self.two = [[1,2],[3,4]]
+ self.two_reflect = [[3,4],[1,2]]
+ self.r_90two = [[2,4],[1,3]]
+ self.three = [[1,2,3],[4,5,6],[7,8,9]]
+ self.three_reflect = [[7,8,9],[4,5,6],[1,2,3]]
+ self.r_90three = [[3,6,9],[2,5,8],[1,4,7]]
+ self.four =[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
+ self.four_reflect = [[13,14,15,16],[9,10,11,12],[5,6,7,8],[1,2,3,4]]
+ self.r_90four = [[4,8,12,16],[3,7,11,15],[2,6,10,14],[1,5,9,13]]
+
+ def test_rotate901(self):
+ self.assertEqual(rotate90(self.two,2),self.r_90two)
+
+ def test_rotate902(self):
+ self.assertEqual(rotate90(self.three,3),self.r_90three)
+
+ def test_rotate903(self):
+ self.assertEqual(rotate90(self.four,4),self.r_90four)
+
+ def test_reflect1(self):
+ self.assertEqual(reflect(self.two,2),self.two_reflect)
+
+ def test_reflect2(self):
+ self.assertEqual(reflect(self.three,3),self.three_reflect)
+
+ def test_reflect3(self):
+ self.assertEqual(reflect(self.four,4),self.four_reflect)
+
+if __name__ == "__main__":
+ unittest.main()
+

0 comments on commit a0e2e17

Please sign in to comment.