Решение на BiDict от Дин Анх

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

Към профила на Дин Анх

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 9 успешни тест(а)
  • 7 неуспешни тест(а)

Код

class BiDict:
def __init__(self, dict1):
self.d = dict1
def __getitem__(self, key):
return self.d[key]
def __delitem__(self, key):
del self.d[key]
def __setitem__(self, key, value):
self.d[key] = value
def __contains__(self, key):
return key in self.d
def keys(self):
return self.d.keys()
def update(self):
raise TypeError
def pop(self, *args):
return self.d.pop(*args)
def copy():
return self.d.copy()
def inverse(self):
list_of_keys = [key for key in self.d]
for key in list_of_keys:
self.d[self.d[key]] = key
del self.d[key]
def man_print(self):
print(self.d)

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

..EE..F.EEEE....
======================================================================
ERROR: test_circular_values (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", 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-1t2sw9z", line 56, in test_copied_circular_values
    inversed_circular = circular.copy()
TypeError: copy() takes no arguments (1 given)

======================================================================
ERROR: test_insert_existing_key_with_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", line 74, in test_insert_existing_key_with_existing_value
    new_person = self.person.copy()
TypeError: copy() takes no arguments (1 given)

======================================================================
ERROR: test_insert_existing_key_with_none_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", line 81, in test_insert_existing_key_with_none_existing_value
    new_person = self.person.copy()
TypeError: copy() takes no arguments (1 given)

======================================================================
ERROR: test_insert_none_existing_key_with_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", line 88, in test_insert_none_existing_key_with_existing_value
    new_person = self.person.copy()
TypeError: copy() takes no arguments (1 given)

======================================================================
ERROR: test_insert_none_existing_key_with_none_existing_value (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", line 95, in test_insert_none_existing_key_with_none_existing_value
    new_person = self.person.copy()
TypeError: copy() takes no arguments (1 given)

======================================================================
FAIL: test_has_dict_attrs (__main__.BiDictTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120627-22085-1t2sw9z", line 71, in test_has_dict_attrs
    self.assertIn('items', dir(self.person))
AssertionError: 'items' not found in ['__class__', '__contains__', '__delattr__', '__delitem__', '__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', 'd', 'inverse', 'keys', 'man_print', 'pop', 'update']

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

FAILED (failures=1, errors=6)

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

Дин обнови решението на 19.04.2012 15:04 (преди над 8 години)

+class BiDict:
+
+ def __init__(self, dict1):
+ self.d = dict1
+
+ def __getitem__(self, key):
+ return self.d[key]
+
+ def __delitem__(self, key):
+ del self.d[key]
+
+ def __setitem__(self, key, value):
+ self.d[key] = value
+
+ def __contains__(self, key):
+ return key in self.d
+
+ def keys(self):
+ return self.d.keys()
+
+ def update(self):
+ raise TypeError
+
+ def pop(self, *args):
+ return self.d.pop(*args)
+
+ def copy():
+ return self.d.copy()
+
+ def inverse(self):
+ list_of_keys = [key for key in self.d]
+ for key in list_of_keys:
+ self.d[self.d[key]] = key
+ del self.d[key]
+
+ def man_print(self):
+ print(self.d)