def test_cube_neq(self): c = Cube(debug_cube_str) c.L() self.assertNotEqual(c, self.debug_cube) self.assertNotEqual(self.debug_cube, c) self.assertFalse(c == self.debug_cube) self.assertTrue(c != self.debug_cube)
class TestCube(unittest.TestCase): def setUp(self): self.solved_cube = Cube(solved_cube_str) self.debug_cube = Cube(debug_cube_str) def test_cube_constructor_solved_cube(self): self.assertEqual(solved_cube_str, str(self.solved_cube)) def test_cube_constructor_unique_stickers(self): self.assertEqual(debug_cube_str, str(self.debug_cube)) def test_cube_constructor_additional_whitespace(self): cube = Cube(" ".join(x for x in debug_cube_str)) self.assertEqual(debug_cube_str, str(cube)) def test_cube_copy_constructor(self): c = Cube(self.debug_cube) self.assertEqual(debug_cube_str, str(c)) self.assertEqual(self.debug_cube, c) def test_cube_eq(self): c = Cube(debug_cube_str) self.assertEqual(c, self.debug_cube) self.assertEqual(self.debug_cube, c) def test_cube_neq(self): c = Cube(debug_cube_str) c.L() self.assertNotEqual(c, self.debug_cube) self.assertNotEqual(self.debug_cube, c) self.assertFalse(c == self.debug_cube) self.assertTrue(c != self.debug_cube) def test_cube_constructor_no_whitespace(self): cube = Cube("".join(x for x in debug_cube_str if x not in string.whitespace)) self.assertEqual(debug_cube_str, str(cube)) def test_cube_L(self): self.debug_cube.L() self.assertEqual( " I12\n" " w45\n" " k78\n" "xl9 0de fgh ijP\n" "yma 3pq rst uvM\n" "znb 6BC DEF GHJ\n" " cKL\n" " oNO\n" " AQR", str(self.debug_cube)) def test_cube_Li(self): self.debug_cube.Li() self.assertEqual( " c12\n" " o45\n" " A78\n" "bnz Jde fgh ij6\n" "amy Mpq rst uv3\n" "9lx PBC DEF GH0\n" " IKL\n" " wNO\n" " kQR", str(self.debug_cube)) def test_cube_R(self): self.debug_cube.R() self.assertEqual( " 01e\n" " 34q\n" " 67C\n" "9ab cdL Drf 8jk\n" "lmn opO Esg 5vw\n" "xyz ABR Fth 2HI\n" " JKG\n" " MNu\n" " PQi", str(self.debug_cube)) def test_cube_Ri(self): self.debug_cube.Ri() self.assertEqual( " 01G\n" " 34u\n" " 67i\n" "9ab cd2 htF Rjk\n" "lmn op5 gsE Ovw\n" "xyz AB8 frD LHI\n" " JKe\n" " MNq\n" " PQC", str(self.debug_cube)) def test_cube_U(self): self.debug_cube.U() self.assertEqual( " 630\n" " 741\n" " 852\n" "cde fgh ijk 9ab\n" "lmn opq rst uvw\n" "xyz ABC DEF GHI\n" " JKL\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_Ui(self): self.debug_cube.Ui() self.assertEqual( " 258\n" " 147\n" " 036\n" "ijk 9ab cde fgh\n" "lmn opq rst uvw\n" "xyz ABC DEF GHI\n" " JKL\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_D(self): self.debug_cube.D() self.assertEqual( " 012\n" " 345\n" " 678\n" "9ab cde fgh ijk\n" "lmn opq rst uvw\n" "GHI xyz ABC DEF\n" " PMJ\n" " QNK\n" " ROL", str(self.debug_cube)) def test_cube_Di(self): self.debug_cube.Di() self.assertEqual( " 012\n" " 345\n" " 678\n" "9ab cde fgh ijk\n" "lmn opq rst uvw\n" "ABC DEF GHI xyz\n" " LOR\n" " KNQ\n" " JMP", str(self.debug_cube)) def test_cube_F(self): self.debug_cube.F() self.assertEqual( " 012\n" " 345\n" " znb\n" "9aJ Aoc 6gh ijk\n" "lmK Bpd 7st uvw\n" "xyL Cqe 8EF GHI\n" " Drf\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_Fi(self): self.debug_cube.Fi() self.assertEqual( " 012\n" " 345\n" " frD\n" "9a8 eqC Lgh ijk\n" "lm7 dpB Kst uvw\n" "xy6 coA JEF GHI\n" " bnz\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_B(self): self.debug_cube.B() self.assertEqual( " htF\n" " 345\n" " 678\n" "2ab cde fgR Gui\n" "1mn opq rsQ Hvj\n" "0yz ABC DEP Iwk\n" " JKL\n" " MNO\n" " 9lx", str(self.debug_cube)) def test_cube_Bi(self): self.debug_cube.Bi() self.assertEqual( " xl9\n" " 345\n" " 678\n" "Pab cde fg0 kwI\n" "Qmn opq rs1 jvH\n" "Ryz ABC DE2 iuG\n" " JKL\n" " MNO\n" " Fth", str(self.debug_cube)) def test_cube_M(self): self.debug_cube.M() self.assertEqual( " 0H2\n" " 3v5\n" " 6j8\n" "9ab c1e fgh iQk\n" "lmn o4q rst uNw\n" "xyz A7C DEF GKI\n" " JdL\n" " MpO\n" " PBR", str(self.debug_cube)) def test_cube_Mi(self): self.debug_cube.Mi() self.assertEqual( " 0d2\n" " 3p5\n" " 6B8\n" "9ab cKe fgh i7k\n" "lmn oNq rst u4w\n" "xyz AQC DEF G1I\n" " JHL\n" " MvO\n" " PjR", str(self.debug_cube)) def test_cube_E(self): self.debug_cube.E() self.assertEqual( " 012\n" " 345\n" " 678\n" "9ab cde fgh ijk\n" "uvw lmn opq rst\n" "xyz ABC DEF GHI\n" " JKL\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_Ei(self): self.debug_cube.Ei() self.assertEqual( " 012\n" " 345\n" " 678\n" "9ab cde fgh ijk\n" "opq rst uvw lmn\n" "xyz ABC DEF GHI\n" " JKL\n" " MNO\n" " PQR", str(self.debug_cube)) def test_cube_S(self): self.debug_cube.S() self.assertEqual( " 012\n" " yma\n" " 678\n" "9Mb cde f3h ijk\n" "lNn opq r4t uvw\n" "xOz ABC D5F GHI\n" " JKL\n" " Esg\n" " PQR", str(self.debug_cube)) def test_cube_Si(self): self.debug_cube.Si() self.assertEqual( " 012\n" " gsE\n" " 678\n" "95b cde fOh ijk\n" "l4n opq rNt uvw\n" "x3z ABC DMF GHI\n" " JKL\n" " amy\n" " PQR", str(self.debug_cube)) def test_cube_X(self): self.debug_cube.X() self.assertEqual( " cde\n" " opq\n" " ABC\n" "bnz JKL Drf 876\n" "amy MNO Esg 543\n" "9lx PQR Fth 210\n" " IHG\n" " wvu\n" " kji", str(self.debug_cube)) def test_cube_Xi(self): self.debug_cube.Xi() self.assertEqual( " IHG\n" " wvu\n" " kji\n" "xl9 012 htF RQP\n" "yma 345 gsE ONM\n" "znb 678 frD LKJ\n" " cde\n" " opq\n" " ABC", str(self.debug_cube)) def test_cube_Y(self): self.debug_cube.Y() self.assertEqual( " 630\n" " 741\n" " 852\n" "cde fgh ijk 9ab\n" "opq rst uvw lmn\n" "ABC DEF GHI xyz\n" " LOR\n" " KNQ\n" " JMP", str(self.debug_cube)) def test_cube_Yi(self): self.debug_cube.Yi() self.assertEqual( " 258\n" " 147\n" " 036\n" "ijk 9ab cde fgh\n" "uvw lmn opq rst\n" "GHI xyz ABC DEF\n" " PMJ\n" " QNK\n" " ROL", str(self.debug_cube)) def test_cube_Z(self): self.debug_cube.Z() self.assertEqual( " xl9\n" " yma\n" " znb\n" "PMJ Aoc 630 kwI\n" "QNK Bpd 741 jvH\n" "ROL Cqe 852 iuG\n" " Drf\n" " Esg\n" " Fth", str(self.debug_cube)) def test_cube_Zi(self): self.debug_cube.Zi() self.assertEqual( " htF\n" " gsE\n" " frD\n" "258 eqC LOR Gui\n" "147 dpB KNQ Hvj\n" "036 coA JMP Iwk\n" " bnz\n" " amy\n" " 9lx", str(self.debug_cube)) def test_cube_find_face_piece(self): piece = self.debug_cube.find_piece('p') self.assertEqual(cube.FACE, piece.type) self.assertEqual(cube.FRONT, piece.pos) self.assertEqual([None, None, 'p'], piece.colors) def test_cube_find_edge_piece(self): def _check_piece(piece): self.assertEqual(cube.EDGE, piece.type) self.assertEqual(cube.FRONT + cube.UP, piece.pos) self.assertEqual([None, '7', 'd'], piece.colors) _check_piece(self.debug_cube.find_piece('d', '7')) _check_piece(self.debug_cube.find_piece('7', 'd')) def test_cube_find_corner_piece(self): def _check_piece(piece): self.assertEqual(cube.CORNER, piece.type) self.assertEqual(cube.FRONT + cube.UP + cube.LEFT, piece.pos) self.assertEqual(['b', '6', 'c'], piece.colors) for colors in itertools.permutations(('b', '6', 'c')): _check_piece(self.debug_cube.find_piece(*colors)) def test_cube_find_face_piece_negative(self): self.assertIsNone(self.debug_cube.find_piece('7')) def test_cube_find_edge_piece_negative(self): self.assertIsNone(self.debug_cube.find_piece('o', 'q')) def test_cube_find_corner_piece_negative(self): self.assertIsNone(self.debug_cube.find_piece('c', '6', '9')) def test_cube_is_solved(self): self.assertTrue(self.solved_cube.is_solved()) def test_cube_is_solved_negative(self): self.solved_cube.L() self.assertFalse(self.solved_cube.is_solved()) self.assertFalse(self.debug_cube.is_solved()) def test_cube_sequence(self): self.solved_cube.sequence("L U M Ri X E Xi Ri D D F F Bi") self.assertEqual( " DLU\n" " RRD\n" " FFU\n" "BBL DDR BRB LDL\n" "RBF RUU LFB DDU\n" "FBR BBR FUD FLU\n" " DLU\n" " ULF\n" " LFR", str(self.solved_cube)) def test_cube_colors(self): self.assertEqual({'U', 'D', 'F', 'B', 'L', 'R'}, self.solved_cube.colors()) debug_colors = set() debug_colors.update(c for c in debug_cube_str if c not in string.whitespace) self.assertEqual(debug_colors, self.debug_cube.colors()) def test_cube_get_piece(self): piece = self.debug_cube.get_piece(0, 0, 1) self.assertEqual(cube.FACE, piece.type) self.assertEqual(cube.FRONT, piece.pos) def test_cube_getitem(self): piece = self.debug_cube[0, 0, 1] self.assertEqual(cube.FACE, piece.type) self.assertEqual(cube.FRONT, piece.pos) def test_cube_getitem_from_tuple(self): piece = self.debug_cube[(0, 0, 1)] self.assertEqual(cube.FACE, piece.type) self.assertEqual(cube.FRONT, piece.pos) def test_move_and_inverse(self): for name in ('R', 'L', 'U', 'D', 'F', 'B', 'M', 'E', 'S', 'X', 'Y', 'Z'): move, unmove = getattr(Cube, name), getattr(Cube, name + 'i') self._check_move_and_inverse(move, unmove, self.debug_cube) def _check_move_and_inverse(self, move, inverse, cube): check_str = str(cube) move(cube) self.assertNotEqual(check_str, str(cube)) inverse(cube) self.assertEqual(check_str, str(cube)) inverse(cube) self.assertNotEqual(check_str, str(cube)) move(cube) self.assertEqual(check_str, str(cube))