Домашни > Великденско домашно > Решения > Решението на Милка Кръстева

Резултати
1 точки от тестове
1 точки от учител

2 точки общо

4 успешни теста
42 неуспешни теста
Код (Съжалявам, не е пълно, но нямам много време. :))
Скрий всички коментари

  1class Egg:
  2
  3    def __init__(self):
  4        self.painted_percentage = 0
  5        self.painted_data = {}
  6        self.top_strength = 0
  7        self.bottom_strength = 0
  8        self.broken_parts = []
  9        self.tourment = None
 10
 11    def paint(self, *args):
 12        for hex_color, percentage in args:
 13            try:
 14                if self.painted_percentage + percentage > 100:
 15                    raise ValueError('The eggs is painted that 100 %')
 16            except ValueError:
 17                print('The eggs is painted that 100 %')
 18            else:
 19                self._add_strengt(hex_color, percentage)
 20                self.painted_percentage += percentage
 21                if hex_color.upper() in self.painted_data:
 22                    self.painted_data[hex_color.upper()] += percentage
 23                else:
 24                    self.painted_data[hex_color.upper()] = percentage
 25
 26    def _add_strengt(self, hex_color, percentage):
 27        hex_color_count = sum(
 28            int(hex_color.upper()[i:i+2], 16) for i in (0, 2, 4))
 29        if self.painted_percentage + percentage <= 50:
 30            self.top_strength += hex_color_count * percentage/50
 31        if self.painted_percentage < 50 and self.painted_percentage + percentage > 50:
 32            self.top_strength += hex_color_count * \
 33                (50-self.painted_percentage)/50
 34            self.bottom_strength += hex_color_count * \
 35                (self.painted_percentage + percentage - 50)/50
 36        if self.painted_percentage >= 50:
 37            self.bottom_strength += hex_color_count * percentage/50
 38
 39    def __mul__(self, other):
 40        if isinstance(other, Egg):
 41            return self._compare_eggs(other, 'top')
 42
 43    def __matmul__(self, other):
 44        if isinstance(other, Egg):
 45            return self._compare_eggs(other, 'bottom')
 46
 47    def _compare_eggs(self, other, part):
 48        if (part in self.broken_parts or part in other.broken_parts):
 49            raise TypeError(f'There is a egg with broken {part} part.')
 50        winner = self if getattr(
 51            self, part + '_strength') > getattr(self, part + '_strength') else other
 52        looser = self if winner == other else other
 53        looser.broken_parts.append(part)
 54        self.tourment.add_to_history(self, other, part, winner)
 55        return winner
 56
 57    def set_tournament(self, tournament):
 58        self.tourment = tournament
 59
 60
 61class EggTournament:
 62
 63    tourment_instances = {}
 64    history = []
 65
 66    def __init__(self):
 67        self.register_eggs = {}
 68        self.tourment_instances[hash(self)] = []
 69        self.history = []
 70
 71    def register(self, egg, name):
 72        try:
 73            self.validate_register_name(name)
 74        except ValueError as e:
 75            print(e)
 76        else:
 77            self.register_eggs[name] = egg
 78            self.tourment_instances[hash(self)].append(name)
 79            egg.set_tournament(self)
 80
 81    def validate_register_name(self, name):
 82        if name in self.register_eggs:
 83            raise ValueError(
 84                f'Egg with name {name} has already been registered')
 85        if any(name in d for d in
 86               [items for key, items in self.tourment_instances.items()
 87                if key is not hash(self)]
 88               ):
 89            raise ValueError(
 90                'An egg cannot be registered in multiple tournaments')
 91        if name.isidentifier() is False:
 92            raise ValueError('Invalid registration name')
 93
 94    def add_to_history(self, egg1, egg2, part, winner):
 95        self.history.append((egg1, egg2, part, winner))
 96
 97    def __getitem__(self, key):
 98        if isinstance(key, tuple) and len(key) == 3:
 99            egg1, egg2, part = key
100        elif isinstance(key, slice):
101            egg1, egg2, part = key.start, key.stop, key.step
102        else:
103            raise KeyError(
104                "Use tournament[egg1, egg2, 'top'|'bottom'] or tournament[egg1:egg2:'top']")
105
106        element = [item for item in self.history if item[:3] == (
107            egg1, egg2, part) or item[:3] == (egg2, egg1, part)]
108        if not element:
109            raise KeyError("There is no pair like this.")
110
111        return element.pop()[3]
112
113    def __contains__(self, egg):
114        return egg in self.register_eggs.values()

EEEEEF
Stdout:
The eggs is painted that 100 %
EEEEEEEEF
Stdout:
The eggs is painted that 100 %
F
Stdout:
The eggs is painted that 100 %
F
Stdout:
The eggs is painted that 100 %
F
Stdout:
The eggs is painted that 100 %
EEEEEFFE...FF
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
.E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
FFE
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
F
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
F
Stdout:
Invalid registration name
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
E
Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_bottom_collision_returns_egg_with_greater_bottom_strength (test.TestEgg.test_bottom_collision_returns_egg_with_greater_bottom_strength)
A bottom collision should return the egg with the greater bottom strength.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 177, in test_bottom_collision_returns_egg_with_greater_bottom_strength
self.assertIs(stronger_egg @ weaker_egg, stronger_egg)
~~~~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 45, in __matmul__
return self._compare_eggs(other, 'bottom')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_breaking_one_side_does_not_prevent_using_the_other_side (test.TestEgg.test_breaking_one_side_does_not_prevent_using_the_other_side)
Breaking one side of an egg should not prevent using the other side.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 287, in test_breaking_one_side_does_not_prevent_using_the_other_side
self.assertIs(first_egg * second_egg, second_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_broken_side_raises_type_error_regardless_of_operand_position (test.TestEgg.test_broken_side_raises_type_error_regardless_of_operand_position)
Using a broken side in a collision should raise a TypeError regardless of operand position.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 257, in test_broken_side_raises_type_error_regardless_of_operand_position
self.assertIs(broken_top_egg * top_winner, top_winner)
~~~~~~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_collision_result_is_independent_of_operand_order (test.TestEgg.test_collision_result_is_independent_of_operand_order)
Swapping the egg operands should not change the collision winner.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 212, in test_collision_result_is_independent_of_operand_order
self.assertIs(top_first_egg * top_second_egg, top_first_egg)
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_collision_with_partially_painted_eggs (test.TestEgg.test_collision_with_partially_painted_eggs)
Partially painted eggs should collide correctly from both sides.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 192, in test_collision_with_partially_painted_eggs
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_losing_side_becomes_unusable (test.TestEgg.test_losing_side_becomes_unusable)
Losing a collision should make the losing side unusable.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 238, in test_losing_side_becomes_unusable
self.assertIs(top_loser * top_winner, top_winner)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_boundary_exactly_at_50_percent (test.TestEgg.test_paint_boundary_exactly_at_50_percent)
Painting an egg exactly to the half boundary should keep the two halves separate.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 130, in test_paint_boundary_exactly_at_50_percent
self.assertIs(egg * opponent, egg)
~~~~^~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_can_be_called_multiple_times (test.TestEgg.test_paint_can_be_called_multiple_times)
Painting an egg in multiple calls should preserve the full painting order.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 54, in test_paint_can_be_called_multiple_times
self.assertIs(egg * top_opponent, egg)
~~~~^~~~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_chunk_crossing_50_percent_boundary_is_split_correctly (test.TestEgg.test_paint_chunk_crossing_50_percent_boundary_is_split_correctly)
Painting a chunk across the half boundary should split it correctly between the two halves.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 138, in test_paint_chunk_crossing_50_percent_boundary_is_split_correctly
self.assertIs(egg * opponent, egg)
~~~~^~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_exactly_to_100_percent_is_allowed (test.TestEgg.test_paint_exactly_to_100_percent_is_allowed)
Painting an egg exactly to 100 percent should not raise an error.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 41, in test_paint_exactly_to_100_percent_is_allowed
self.assertIs(egg @ opponent, egg)
~~~~^~~~~~~~~~
File "/tmp/solution.py", line 45, in __matmul__
return self._compare_eggs(other, 'bottom')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_is_case_insensitive_for_hex_colors (test.TestEgg.test_paint_is_case_insensitive_for_hex_colors)
Painting an egg with lowercase and uppercase hex colors should produce the same behavior.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 111, in test_paint_is_case_insensitive_for_hex_colors
self.assertIs(lower_case_egg * lower_case_top_opponent, lower_case_egg)
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_multiple_calls_can_cross_50_percent_boundary (test.TestEgg.test_paint_multiple_calls_can_cross_50_percent_boundary)
Painting an egg across the half boundary in multiple calls should split the halves correctly.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 150, in test_paint_multiple_calls_can_cross_50_percent_boundary
self.assertIs(egg * opponent, egg)
~~~~^~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_order_of_color_chunks_matters (test.TestEgg.test_paint_order_of_color_chunks_matters)
Painting the same colors in different orders should change the collision result.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 122, in test_paint_order_of_color_chunks_matters
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_paint_single_color_full_egg (test.TestEgg.test_paint_single_color_full_egg)
A fully painted single-color egg should win collisions against a weaker egg from both sides.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 30, in test_paint_single_color_full_egg
self.assertIs(egg * opponent, egg)
~~~~^~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_same_two_eggs_can_have_different_winners_for_top_and_bottom (test.TestEgg.test_same_two_eggs_can_have_different_winners_for_top_and_bottom)
The same two eggs should be able to have different winners for top and bottom collisions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 184, in test_same_two_eggs_can_have_different_winners_for_top_and_bottom
self.assertIs(first_egg * second_egg, second_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_top_collision_returns_egg_with_greater_top_strength (test.TestEgg.test_top_collision_returns_egg_with_greater_top_strength)
A top collision should return the egg with the greater top strength.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 170, in test_top_collision_returns_egg_with_greater_top_strength
self.assertIs(stronger_egg * weaker_egg, stronger_egg)
~~~~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_unpainted_half_loses_to_half_painted_black (test.TestEgg.test_unpainted_half_loses_to_half_painted_black)
An unpainted half should lose to a half painted in black.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 200, in test_unpainted_half_loses_to_half_painted_black
self.assertIs(unpainted_egg * black_egg, black_egg)
~~~~~~~~~~~~~~^~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_winner_side_does_not_become_broken (test.TestEgg.test_winner_side_does_not_become_broken)
Winning a collision should not break the winning side.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 302, in test_winner_side_does_not_become_broken
self.assertIs(winner_egg * first_loser, winner_egg)
~~~~~~~~~~~^~~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_collision_between_unregistered_eggs_is_not_recorded (test.TestEggTournament.test_collision_between_unregistered_eggs_is_not_recorded)
A collision between unregistered eggs should not be recorded in the tournament.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 381, in test_collision_between_unregistered_eggs_is_not_recorded
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

======================================================================
ERROR: test_history_lookup_is_symmetric_with_respect_to_egg_order (test.TestEggTournament.test_history_lookup_is_symmetric_with_respect_to_egg_order)
Looking up a recorded collision in reversed egg order should return the same winner.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 445, in test_history_lookup_is_symmetric_with_respect_to_egg_order
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_history_lookup_returns_winner_for_top_and_bottom (test.TestEggTournament.test_history_lookup_returns_winner_for_top_and_bottom)
Looking up recorded top and bottom collisions should return the correct winners.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 415, in test_history_lookup_returns_winner_for_top_and_bottom
self.assertIs(first_egg * second_egg, second_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_history_lookup_top_and_bottom_are_distinct (test.TestEggTournament.test_history_lookup_top_and_bottom_are_distinct)
Looking up top and bottom collisions should treat them as distinct entries.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 456, in test_history_lookup_top_and_bottom_are_distinct
self.assertIs(first_egg * second_egg, second_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_history_lookup_with_slice_key (test.TestEggTournament.test_history_lookup_with_slice_key)
Looking up a recorded collision with a slice key should return the winner.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 436, in test_history_lookup_with_slice_key
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_history_lookup_with_tuple_key (test.TestEggTournament.test_history_lookup_with_tuple_key)
Looking up a recorded collision with a tuple key should return the winner.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 427, in test_history_lookup_with_tuple_key
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~^~~~~~~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_ranking_tied_position_returns_set_of_eggs (test.TestEggTournament.test_ranking_tied_position_returns_set_of_eggs)
Looking up a tied ranking position should return a set of eggs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 489, in test_ranking_tied_position_returns_set_of_eggs
self.assertIs(alpha * gamma, alpha)
~~~~~~^~~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_ranking_unique_position_returns_single_egg (test.TestEggTournament.test_ranking_unique_position_returns_single_egg)
Looking up a unique ranking position should return a single egg.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 477, in test_ranking_unique_position_returns_single_egg
self.assertIs(alpha * beta, alpha)
~~~~~~^~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_ranking_uses_dense_ranking_without_skipping_places (test.TestEggTournament.test_ranking_uses_dense_ranking_without_skipping_places)
Looking up ranking positions should use dense ranking without skipping places.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 509, in test_ranking_uses_dense_ranking_without_skipping_places
self.assertIs(alpha * beta, alpha)
~~~~~~^~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_registered_egg_attribute_returns_position_and_victories (test.TestEggTournament.test_registered_egg_attribute_returns_position_and_victories)
Accessing a registered egg as an attribute should return its position and victories.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 556, in test_registered_egg_attribute_returns_position_and_victories
self.assertIs(alpha * beta, alpha)
~~~~~~^~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
ERROR: test_registered_egg_attribute_with_zero_victories_is_accessible (test.TestEggTournament.test_registered_egg_attribute_with_zero_victories_is_accessible)
Accessing a registered egg with zero victories should return its position and victories.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 572, in test_registered_egg_attribute_with_zero_victories_is_accessible
self.assertIs(alpha * beta, alpha)
~~~~~~^~~~~~
File "/tmp/solution.py", line 41, in __mul__
return self._compare_eggs(other, 'top')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/tmp/solution.py", line 54, in _compare_eggs
self.tourment.add_to_history(self, other, part, winner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'add_to_history'

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
FAIL: test_failed_paint_overflow_does_not_change_egg_state (test.TestEgg.test_failed_paint_overflow_does_not_change_egg_state)
Failing to paint an egg because of overflow should not change its state.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 85, in test_failed_paint_overflow_does_not_change_egg_state
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
The eggs is painted that 100 %

======================================================================
FAIL: test_paint_overflow_above_100_raises_value_error (test.TestEgg.test_paint_overflow_above_100_raises_value_error)
Painting an egg above 100 percent should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 61, in test_paint_overflow_above_100_raises_value_error
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
The eggs is painted that 100 %

======================================================================
FAIL: test_paint_overflow_from_existing_fill_raises_value_error (test.TestEgg.test_paint_overflow_from_existing_fill_raises_value_error)
Painting an already partially painted egg above 100 percent should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 69, in test_paint_overflow_from_existing_fill_raises_value_error
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
The eggs is painted that 100 %

======================================================================
FAIL: test_paint_overflow_with_multiple_colors_raises_value_error (test.TestEgg.test_paint_overflow_with_multiple_colors_raises_value_error)
Painting an egg with multiple new colors whose total overflows 100 percent should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 77, in test_paint_overflow_with_multiple_colors_raises_value_error
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
The eggs is painted that 100 %

======================================================================
FAIL: test_paint_overflow_with_multiple_colors_should_not_change_the_egg (test.TestEgg.test_paint_overflow_with_multiple_colors_should_not_change_the_egg)
Failing to overpaint an egg with multiple colors should not change the egg.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 158, in test_paint_overflow_with_multiple_colors_should_not_change_the_egg
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
The eggs is painted that 100 %

======================================================================
FAIL: test_collision_between_registered_and_unregistered_egg_is_not_recorded (test.TestEggTournament.test_collision_between_registered_and_unregistered_egg_is_not_recorded)
A collision between a registered and an unregistered egg should not be recorded in the tournament.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 392, in test_collision_between_registered_and_unregistered_egg_is_not_recorded
self.assertIs(registered_egg * unregistered_egg, registered_egg)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <solution.Egg object at 0x7c9b437687d0> is not <solution.Egg object at 0x7c9b437689d0>

======================================================================
FAIL: test_collision_between_two_registered_eggs_is_recorded (test.TestEggTournament.test_collision_between_two_registered_eggs_is_recorded)
A collision between two registered eggs should be recorded in the tournament.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 371, in test_collision_between_two_registered_eggs_is_recorded
self.assertIs(first_egg * second_egg, first_egg)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: <solution.Egg object at 0x7c9b43768750> is not <solution.Egg object at 0x7c9b43768950>

======================================================================
FAIL: test_egg_cannot_be_registered_in_second_tournament (test.TestEggTournament.test_egg_cannot_be_registered_in_second_tournament)
Registering an egg in a second tournament should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 341, in test_egg_cannot_be_registered_in_second_tournament
with self.assertRaises(ValueError) as context:
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

======================================================================
FAIL: test_failed_registration_in_second_tournament_does_not_remove_first_registration (test.TestEggTournament.test_failed_registration_in_second_tournament_does_not_remove_first_registration)
Failing to register an egg in a second tournament should not remove its first registration.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 359, in test_failed_registration_in_second_tournament_does_not_remove_first_registration
with self.assertRaises(ValueError):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
FAIL: test_missing_egg_attribute_raises_attribute_error (test.TestEggTournament.test_missing_egg_attribute_raises_attribute_error)
Accessing an unregistered egg as an attribute should raise an AttributeError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 586, in test_missing_egg_attribute_raises_attribute_error
self.assertEqual(
~~~~~~~~~~~~~~~~^
str(context.exception),
^^^^^^^^^^^^^^^^^^^^^^^
"Apologies, there is no such egg registered",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: "'EggTournament' object has no attribute 'the_monster'" != 'Apologies, there is no such egg registered'
- 'EggTournament' object has no attribute 'the_monster'
+ Apologies, there is no such egg registered

======================================================================
FAIL: test_ranking_missing_position_raises_index_error (test.TestEggTournament.test_ranking_missing_position_raises_index_error)
Looking up a missing ranking position should raise an IndexError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 533, in test_ranking_missing_position_raises_index_error
self.assertIs(alpha * beta, alpha)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
AssertionError: <solution.Egg object at 0x7c9b43768bd0> is not <solution.Egg object at 0x7c9b43768cd0>

======================================================================
FAIL: test_register_duplicate_name_raises_value_error (test.TestEggTournament.test_register_duplicate_name_raises_value_error)
Registering an egg with a duplicate name should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 325, in test_register_duplicate_name_raises_value_error
with self.assertRaises(ValueError) as context:
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
An egg cannot be registered in multiple tournaments
An egg cannot be registered in multiple tournaments

======================================================================
FAIL: test_register_invalid_name_raises_value_error (test.TestEggTournament.test_register_invalid_name_raises_value_error)
Registering an egg with an invalid name should raise a ValueError.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 312, in test_register_invalid_name_raises_value_error
with self.assertRaises(ValueError) as context:
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: ValueError not raised

Stdout:
Invalid registration name

----------------------------------------------------------------------
Ran 46 tests in 0.013s

FAILED (failures=13, errors=29)

Дискусия
Виктор Бечев
15.04.2026 15:46

Като цяло - доста добре си тръгнала. С малко повече време щеше да се получи супер.
Виктор Бечев
15.04.2026 15:41

Вероятно ще видиш, че на други колеги сме "възстановили" някоя друга точка, защото тестовете ни много разчитат на това, че яйца ще могат да се сблъскват без да са регистрирани в турнир. Това неспазване на условието го има и в твоето решение. И понеже би било прекалено строго това изискване да коства на някого 2-3 точки - пробваме кода как работи с дребен fix и корегираме точките с лека такса. И ако броят тестове, които минават, би бил значително по-различен - и на теб щяхме да ти върнем някоя точка. Уви, при теб разликата в минаващите тестове е 2 повече, т.е. не достатъчно за да ти дадем точката.
История
Това решение има само една версия.