Exemplo n.º 1
0
    def test_square_within_beam_distance(self):
        # arrange
        s = SpaceMap([1101, 100, -1, 4, 0])

        m = [
            '#.......................................',
            '.#......................................',
            '..##....................................',
            '...###..................................',
            '....###.................................',
            '.....####...............................',
            '......#####.............................',
            '......######............................',
            '.......#######..........................',
            '........########........................',
            '.........#########......................',
            '..........#########.....................',
            '...........##########...................',
            '...........############.................',
            '............############................',
            '.............#############..............',
            '..............##############............',
            '...............###############..........',
            '................###############.........',
            '................#################.......',
            '.................########OOOOOOOOOO.....',
            '..................#######OOOOOOOOOO#....',
            '...................######OOOOOOOOOO###..',
            '....................#####OOOOOOOOOO#####',
            '.....................####OOOOOOOOOO#####',
            '.....................####OOOOOOOOOO#####',
            '......................###OOOOOOOOOO#####',
            '.......................##OOOOOOOOOO#####',
            '........................#OOOOOOOOOO#####',
            '.........................OOOOOOOOOO#####',
            '..........................##############',
            '..........................##############',
            '...........................#############',
            '............................############',
            '.............................###########'
        ]
        testPoints = [(25, 20), (20, 19), (26, 20), (26, 22)]
        testResult = [True, False, False, True]
        result = []

        # act
        points = s.LoadMap(m)
        for p in testPoints:
            x, y = p
            result.append(s.SquareWithinBeam(x, y, 10))

        # assert
        self.assertEquals(result, testResult)
Exemplo n.º 2
0
    def test_print_map(self):
        # arrange
        s = SpaceMap([1101, 100, -1, 4, 0])
        m = [
            '#.........', '.#........', '..##......', '...###....',
            '....###...', '.....#O##.', '......####', '......####',
            '.......###', '........##'
        ]

        # act
        points = s.LoadMap(m)
        lines = s.PrintSpaceMap()

        # assert
        self.assertEqual(lines, 10)
Exemplo n.º 3
0
    def test_find_square_distance(self):
        # arrange
        s = SpaceMap([1101, 100, -1, 4, 0])

        m = [
            '#.......................................',
            '.#......................................',
            '..##....................................',
            '...###..................................',
            '....###.................................',
            '.....####...............................',
            '......#####.............................',
            '......######............................',
            '.......#######..........................',
            '........########........................',
            '.........#########......................',
            '..........#########.....................',
            '...........##########...................',
            '...........############.................',
            '............############................',
            '.............#############..............',
            '..............##############............',
            '...............###############..........',
            '................###############.........',
            '................#################.......',
            '.................########OOOOOOOOOO.....',
            '..................#######OOOOOOOOOO#....',
            '...................######OOOOOOOOOO###..',
            '....................#####OOOOOOOOOO#####',
            '.....................####OOOOOOOOOO#####',
            '.....................####OOOOOOOOOO#####',
            '......................###OOOOOOOOOO#####',
            '.......................##OOOOOOOOOO#####',
            '........................#OOOOOOOOOO#####',
            '.........................OOOOOOOOOO#####',
            '..........................##############',
            '..........................##############',
            '...........................#############',
            '............................############',
            '.............................###########'
        ]

        # act
        points = s.LoadMap(m)
        result = s.FindSquareDistance()

        # assert
        self.assertEqual(result, 250020)
Exemplo n.º 4
0
    def test_write_beam_map(self):
        # arrange
        infile = open('data/input_19.txt', 'r')
        program = infile.readline().strip().split(',')
        # program[0] = 2
        a = SpaceMap(program)
        result = []

        # act
        print()
        result = a.WriteBeamMap()
        a.PrintSpaceMap()
        print(a.GetAffectedCells())

        # assert
        self.assertEqual(result, 2500)
Exemplo n.º 5
0
    def test_load_map(self):
        # arrange
        s = SpaceMap([1101, 100, -1, 4, 0])
        m = [
            '#.........', '.#........', '..##......', '...###....',
            '....###...', '.....####.', '......####', '......####',
            '.......###', '........##'
        ]

        # act
        points = s.LoadMap(m)
        print(points)
        result = s.GetAffectedCells()

        # assert
        self.assertEqual(result, 27)
Exemplo n.º 6
0
# Advent of Code 2019: https://adventofcode.com/2019/day/11
#
#

from AoC19_classes import SpaceMap

infile = open('data/input_19.txt', 'r')
inputData1 = infile.readline().strip().split(',')

# Part 1
e = SpaceMap(inputData1)
e.WriteTractorMap()

print("Part 1: ", e.GetAffectedCells())

# Part 2
# result = w.RunAgain()
result = e.FindSquareDistance(100)
print("Part 2: ", result)