Решение на Четири функции от Мария Станчева

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

Към профила на Мария Станчева

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 8 успешни тест(а)
  • 12 неуспешни тест(а)

Код

GROUPBY_DICT = {}
def groupby(func, seq):
key_groupby_dict = map(func, seq)
for item in seq:
GROUPBY_DICT.setdefault(next(key_groupby_dict), []).append(item)
return GROUPBY_DICT
def zip_with(func, *iterables):
zipped_iterables = zip(*iterables)
for i in zipped_iterables:
yield func(*i)
def iterate(func):
def identity(identical_func):
return identical_func
def composition(func_1, func_2):
compositional_func = (lambda x: func_1(func_2(x)))
return compositional_func
while True:
identity = composition(func, identity)
yield identity
def cache(funk, cache_size):
pass

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

EEEEE...FFFFFFF.....
======================================================================
ERROR: test_cache_cache_is_not_global (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 131, in test_cache_cache_is_not_global
    self.assertEqual(42 * 2, cached_double1(42))
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_cache_call_is_cached (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 117, in test_cache_call_is_cached
    self.assertEqual(256, cached_double(128))
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_cache_function_with_vargs (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 160, in test_cache_function_with_vargs
    self.assertEqual(6, cached_sum(1, 2, 3))
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_cache_no_cache (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 104, in test_cache_no_cache
    self.assertEqual(42 * 2, cached_double(42))
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_cache_size_is_respected (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 144, in test_cache_size_is_respected
    self.assertEqual(2, cached_double(1))
TypeError: 'NoneType' object is not callable

======================================================================
FAIL: test_groupby_simple_types (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 20, in test_groupby_simple_types
    self.assertEqual(expected, actual)
AssertionError: {'odd': [1, 3, 5, 9], 'even': [2, 8, 10, 12]} != {1: [1], 2: [2], 3: [3], 5: [5], 'odd': [1, 3, 1, 3, 5, 9], 'se7en': ['se7en'],  [truncated]...
- {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
+ {1: [1],
+  2: [2],
+  3: [3],
+  5: [5],
+  'even': [2, 4, 2, 8, 10, 12],
+  'odd': [1, 3, 1, 3, 5, 9],
+  'se7en': ['se7en']}

======================================================================
FAIL: test_groupby_with_generator (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 25, in test_groupby_with_generator
    self.assertEqual(expected, actual)
AssertionError: {'big': [35, 40, 45], 'small': [0, 5, 10, 15, 20, 25, 30]} != {1: [1], 2: [2], 3: [3], 5: [5], 'big': [35, 40, 45], 'odd': [1, 3, 1, 3, 5, 9], [truncated]...
+ {1: [1],
+  2: [2],
+  3: [3],
+  5: [5],
+  'big': [35, 40, 45],
+  'even': [2, 4, 2, 8, 10, 12],
+  'odd': [1, 3, 1, 3, 5, 9],
+  'se7en': ['se7en'],
- {'big': [35, 40, 45], 'small': [0, 5, 10, 15, 20, 25, 30]}
? ---------------------

+  'small': [0, 5, 10, 15, 20, 25, 30]}

======================================================================
FAIL: test_iterate_ordered_calls (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 39, in test_iterate_ordered_calls
    self.assertEqual(1 * 'eggs', f('eggs'))
AssertionError: 'eggs' != 'eggseggs'
- eggs
+ eggseggs


======================================================================
FAIL: test_iterate_out_of_order_calls (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 53, in test_iterate_out_of_order_calls
    self.assertEqual(1 * 'eggs', f0('eggs'))
AssertionError: 'eggs' != 'eggseggs'
- eggs
+ eggseggs


======================================================================
FAIL: test_iterate_out_of_order_calls_again (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 53, in test_iterate_out_of_order_calls
    self.assertEqual(1 * 'eggs', f0('eggs'))
AssertionError: 'eggs' != 'eggseggs'
- eggs
+ eggseggs


======================================================================
FAIL: test_iterate_out_of_order_calls_yet_again (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 53, in test_iterate_out_of_order_calls
    self.assertEqual(1 * 'eggs', f0('eggs'))
AssertionError: 'eggs' != 'eggseggs'
- eggs
+ eggseggs


======================================================================
FAIL: test_iterate_start_with_identity_function (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-dz90hq/test.py", line 34, in test_iterate_start_with_identity_function
    self.assertEqual('hello world', no_brackets('hello world'))
AssertionError: 'hello world' != '(hello world)'
- hello world
+ (hello world)
? +           +


----------------------------------------------------------------------
Ran 20 tests in 0.019s

FAILED (failures=7, errors=5)

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

Мария обнови решението на 15.03.2013 23:02 (преди над 11 години)

+GROUPBY_DICT = {}
+
+def groupby(func, seq):
+ key_groupby_dict = map(func, seq)
+ for item in seq:
+ GROUPBY_DICT.setdefault(next(key_groupby_dict), []).append(item)
+ return GROUPBY_DICT
+
+def zip_with(func, *iterables):
+ zipped_iterables = zip(*iterables)
+ for i in zipped_iterables:
+ yield func(*i)
+
+def iterate(func):
+ def identity(identical_func):
+ return identical_func
+ def composition(func_1, func_2):
+ compositional_func = (lambda x: func_1(func_2(x)))
+ return compositional_func
+ while True:
+ identity = composition(func, identity)
+ yield identity
+
+def cache(funk, cache_size):
+ pass
+
+