Esempio n. 1
0
 def test_happiness(self):
   lines = ['Alice would gain 54 happiness units by sitting next to Bob.',
            'Alice would lose 79 happiness units by sitting next to Carol.',
            'Alice would lose 2 happiness units by sitting next to David.',
            'Bob would gain 83 happiness units by sitting next to Alice.',
            'Bob would lose 7 happiness units by sitting next to Carol.',
            'Bob would lose 63 happiness units by sitting next to David.',
            'Carol would lose 62 happiness units by sitting next to Alice.',
            'Carol would gain 60 happiness units by sitting next to Bob.',
            'Carol would gain 55 happiness units by sitting next to David.',
            'David would gain 46 happiness units by sitting next to Alice.',
            'David would lose 7 happiness units by sitting next to Bob.',
            'David would gain 41 happiness units by sitting next to Carol.']
   day13.parse_input(lines)
   self.assertEqual(day13.calc_happiness(), 330)
    def test_get_happiness_delta_for_person(self):
        example = """Alice would lose 79 happiness units by sitting next to Carol.
Alice would lose 2 happiness units by sitting next to Bob.
Carol would lose 62 happiness units by sitting next to Alice."""
        parsed = day13.parse_input(example)
        order = ['Alice', 'Bob', 'Carol']
        expect = -79 + -2
        self.assertEqual(expect, day13.get_happiness_delta_for_person('Alice', parsed, order))
 def test_input(self):
     graph = day13.parse_input(day13.INPUT_STRING)
     best = None
     for path in [p for p in day9.get_all_paths(graph) if all([loc in p for loc in graph.keys()])]:
         total = 0
         for person in path:
             h = day13.get_happiness_delta_for_person(person, graph, path)
             total += h
         if total > best:
             best = total
     self.assertEqual(0, best)
Esempio n. 4
0
 def test_finds_best_arrangement_with_noncommittal_guest(self):
     guests = parse_input(self.data)
     guests['Me'] = {}
     arrangement, happiness = find_best_arrangement(guests)
     self.assertEquals(len(arrangement), 5)
     self.assertEquals(happiness, 286)
Esempio n. 5
0
 def test_finds_best_arrangement(self):
     guests = parse_input(self.data)
     arrangement, happiness = find_best_arrangement(guests)
     self.assertEquals(len(arrangement), 4)
     self.assertEquals(happiness, 330)
Esempio n. 6
0
 def test_makes_guest_dict(self):
     guests = parse_input(self.data)
     self.assertEquals(guests['Alice']['Bob'], 54)
     self.assertEquals(guests['Alice']['Carol'], -79)
     self.assertEquals(guests['David']['Alice'], 46)
 def test_parse_input(self):
     result = day13.parse_input(self.input_string)
     self.assertEqual(-2, result['Alice']['David'])
     self.assertEqual(54, result['Alice']['Bob'])
     self.assertEqual(-63, result['Bob']['David'])
Esempio n. 8
0
 def test_finds_best_arrangement_with_noncommittal_guest(self):
     guests = parse_input(self.data)
     guests['Me'] = {}
     arrangement, happiness = find_best_arrangement(guests)
     self.assertEquals(len(arrangement), 5)
     self.assertEquals(happiness, 286)
Esempio n. 9
0
 def test_finds_best_arrangement(self):
     guests = parse_input(self.data)
     arrangement, happiness = find_best_arrangement(guests)
     self.assertEquals(len(arrangement), 4)
     self.assertEquals(happiness, 330)
Esempio n. 10
0
 def test_makes_guest_dict(self):
     guests = parse_input(self.data)
     self.assertEquals(guests['Alice']['Bob'], 54)
     self.assertEquals(guests['Alice']['Carol'], -79)
     self.assertEquals(guests['David']['Alice'], 46)