def testFlip(self): tile = Tile(101, DATA[1:11]) tile.flip() self.assertEqual(4, tile.rotation) self.assertEqual('..##.#..#.'[::-1], tile.borders['n']) self.assertEqual('...#.##..#'[::-1], tile.borders['w']) self.assertEqual('###..###..'[::-1], tile.borders['s']) self.assertEqual('.#..#####.'[::-1], tile.borders['e'])
def testImage(self): tile = Tile(101, get_image(DATA)) success = False for rotation in range(8): tile.set_rotation(rotation) if (tile.image == IMAGE): success = True self.assertTrue(success)
def test_compute_image(self): # input = read_inputfile("input20.txt") input = read_inputfile("example20.txt") tiles = parse_tiles(input) image = compute_image(tiles) #print(image) solution = read_inputfile("example20solution.txt") expected = Tile(0, solution) self.assertIn(image, expected.get_variants())
def test_tile_pair(self): inputdata1=['abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890'] inputdata2=['zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','abcdefghij'] testtile1=Tile(1234, inputdata1, verbose=True) testtile2=Tile(3141, inputdata2, verbose=True) testtile1.pair(testtile2) testtile2.pair(testtile1) assert 3141 in testtile1.pairs assert 1234 in testtile2.pairs
def test_build_tile(self): inputdata=['abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890','abcdefghij','1234567890'] testtile=Tile(1234, inputdata, verbose=True) assert 'abcdefghij' in testtile.borders assert '1234567890' in testtile.borders assert 'j0j0j0j0j0' in testtile.borders assert 'a1a1a1a1a1' in testtile.borders assert 'jihgfedcba' in testtile.borders assert '0987654321' in testtile.borders assert '0j0j0j0j0j' in testtile.borders assert '1a1a1a1a1a' in testtile.borders
def testRotate(self): tile = Tile(101, DATA[1:11]) tile.rotate() self.assertEqual(1, tile.rotation) self.assertEqual('.#..#####.', tile.borders['n']) self.assertEqual('..##.#..#.', tile.borders['e']) self.assertEqual('...#.##..#', tile.borders['s']) self.assertEqual('###..###..', tile.borders['w']) tile.rotate() self.assertEqual(2, tile.rotation) self.assertEqual('###..###..', tile.borders['n']) self.assertEqual('.#..#####.', tile.borders['e']) self.assertEqual('..##.#..#.', tile.borders['s']) self.assertEqual('...#.##..#', tile.borders['w']) tile.rotate() tile.rotate() self.assertEqual(0, tile.rotation) self.assertEqual('###..###..', tile.borders['s']) self.assertEqual('..##.#..#.', tile.borders['n']) self.assertEqual('...#.##..#', tile.borders['e']) self.assertEqual('.#..#####.', tile.borders['w'])
def test_find_sea_monsters(self): input = read_inputfile("example20b.txt") sea = Tile(0, input) self.assertEqual(sea.find_sea_monsters(), 2) self.assertEqual(sea.count_hashes(), 273)
def test_flip_horiz(self): tile = Tile(0, ["123", "456", "789"]) flipped_tile = tile.flip_horiz() print(flipped_tile.cells) self.assertEqual(flipped_tile.cells, ['789', '456', '123']) self.assertEqual(flipped_tile.flip_horiz(), tile)
def test_flip_vert(self): tile = Tile(0, ["123", "456", "789"]) flipped_tile = tile.flip_vert() print(flipped_tile.cells) self.assertEqual(flipped_tile.cells, ['321', '654', '987']) self.assertEqual(flipped_tile.flip_vert(), tile)
def test_rotate(self): tile = Tile(0, ["123", "456", "789"]) rotated_tile = tile.rotate() # print(rotated_tile) self.assertEqual(rotated_tile.cells, ['741', '852', '963'])
def testSetRotate(self): tile1 = Tile(101, DATA[1:11]) tile2 = Tile(101, DATA[1:11]) tile3 = Tile(101, DATA[1:11]) tile2.flip() tile2.rotate() tile2.rotate() tile1.set_rotation(6) self.assertEqual(tile1.rotation, tile2.rotation) self.assertEqual(tile1.image, tile2.image) self.assertEqual(tile1.borders, tile2.borders) tile1.set_rotation(1) tile3.rotate() self.assertEqual(tile1.image, tile3.image)
def testTile(self): tile = Tile(101, DATA[1:11]) self.assertEqual('..##.#..#.', tile.borders['n']) self.assertEqual('...#.##..#', tile.borders['e']) self.assertEqual('###..###..', tile.borders['s']) self.assertEqual('.#..#####.', tile.borders['w'])
def test_find_2_monsters2(self): inputdata=[' # # ','# ## ## #### ## ## ###',' # # # # # # # # # # # # '] testtile=Tile(1234, inputdata) result = testtile.find_monsters() assert result == 2
def test_tile_flip(self): inputdata2=['zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','zzzzzzzzzz','abcdefghij'] testtile2=Tile(3141, inputdata2, verbose=True) testtile2.flip() print(testtile2)