Решение на BiDict от Недислав Стойчев

Обратно към всички решения

Към профила на Недислав Стойчев

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 11 успешни тест(а)
  • 5 неуспешни тест(а)

Код

class BiDict:
def __init__(self, dict):
self.dict = dict
def __getitem__(self, item):
return self.dict[item]
def __setitem__(self, key, value):
hash(value)
self.dict[key] = value
def update(self, key, value):
self.dict.update(key, value)
def inverse(self):
new_dict = dict()
for key, value in self.dict.items():
new_dict[value] = key
self.dict = new_dict
def keys(self):
return self.dict.keys()
def pop(self, key):
return self.dict.pop(key)
def copy(self):
return self.dict.copy()

Лог от изпълнението

..EE..F.F.F.....
======================================================================
ERROR: test_circular_values (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1f2shfc", line 49, in test_circular_values
    circular = self.solutions.BiDict({1: 2, 2: 3, 3: 1})
AttributeError: 'BiDictTestCase' object has no attribute 'solutions'

======================================================================
ERROR: test_copied_circular_values (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1f2shfc", line 57, in test_copied_circular_values
    inversed_circular.inverse()
AttributeError: 'dict' object has no attribute 'inverse'

======================================================================
FAIL: test_has_dict_attrs (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1f2shfc", line 71, in test_has_dict_attrs
    self.assertIn('items', dir(self.person))
AssertionError: 'items' not found in ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'copy', 'dict', 'inverse', 'keys', 'pop', 'update']

======================================================================
FAIL: test_insert_existing_key_with_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1f2shfc", line 78, in test_insert_existing_key_with_existing_value
    self.assertNotIn('age', new_person.keys())
AssertionError: 'age' unexpectedly found in dict_keys(['age', 'name', 'sex'])

======================================================================
FAIL: test_insert_none_existing_key_with_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1f2shfc", line 92, in test_insert_none_existing_key_with_existing_value
    self.assertNotIn('age', new_person.keys())
AssertionError: 'age' unexpectedly found in dict_keys(['age', 'name', 'none', 'sex'])

----------------------------------------------------------------------
Ran 16 tests in 0.003s

FAILED (failures=3, errors=2)

История (1 версия и 0 коментара)

Недислав обнови решението на 11.04.2012 17:26 (преди над 8 години)

+class BiDict:
+ def __init__(self, dict):
+ self.dict = dict
+
+ def __getitem__(self, item):
+ return self.dict[item]
+
+ def __setitem__(self, key, value):
+ hash(value)
+ self.dict[key] = value
+
+ def update(self, key, value):
+ self.dict.update(key, value)
+
+ def inverse(self):
+ new_dict = dict()
+ for key, value in self.dict.items():
+ new_dict[value] = key
+
+ self.dict = new_dict
+
+ def keys(self):
+ return self.dict.keys()
+
+ def pop(self, key):
+ return self.dict.pop(key)
+
+ def copy(self):
+ return self.dict.copy()