def test_apply_5(self): ex = {'foo': 0} def f(x): # nonlocal ex (can't do this, for Python 2 compatibility) ex['foo'] += 1 # Any call to apply calls the function exactly once zz.range(10).apply(f) zz.of([1, 2, 3]).apply(f) zz.empty().apply(f) self.assertEqual(ex['foo'], 3)
async def ducksay(self, ctx: Context, message: str) -> None: """Duck says what?""" MAX_LEN = 50 data = message.split(' ') res = [] curr = "" for val in data: new = curr + ' ' + val if curr else curr + val if len(new) >= MAX_LEN: res.append(curr) curr = "" new = curr + val curr = new if curr: res.append(curr) max_len = len(zz.of(res).max(len)) if len(res) > 1: delim = zz.empty().chain(zz.of(["/\\"]), zz.repeat("||", n=len(res) - 2), zz.of(["\\/"])) else: delim = zz.repeat("<>") final = '' final += "```\n" final += " " + "_" * (max_len + 2) + " \n" for d, elem in zip(delim, res): elem += " " * (max_len - len(elem)) final += d[0] + " " + elem + " " + d[1] + "\n" final += " " + "-" * (max_len + 2) + " \n" final += " \\\n" final += " \\\n" final += " \\ >()_\n" final += " (__)__ _\n" final += "```" await ctx.send(final)
def test_null_1(self): self.assertTrue(zz.empty().null())
def test_any_6(self): self.assertEqual(zz.empty().any(default=-1), -1)
def test_all_4(self): self.assertTrue(zz.empty().all())
def test_intersperse_2(self): self.assertEqual(zz.empty().intersperse(0).list(), [])
def test_foldr_3(self): # Error if empty and no init func = lambda x, y: zz.raise_(Exception("This should not be called")) with self.assertRaises(zz.AlakazamError): zz.empty().foldr(func)
def test_each_1(self): def f(x): raise SampleError("This error should not be raised") zz.empty().each(f)
def test_sum_2(self): # Defaults to 0 self.assertEqual(zz.empty().sum(), 0)
def test_absorb_7(self): def f(x, y): raise Exception("This exception should never be raised") self.assertEqual(zz.empty().absorb(f, "lorem ipsum"), "lorem ipsum")
def test_foldr_lazy_2(self): func = lambda x, y: zz.raise_(Exception("This should not be called")) self.assertEqual(zz.empty().foldr_lazy(func, init=1), 1)
def test_accumulate_5(self): self.assertTrue(zz.empty().accumulate().null())
def test_accumulate_4(self): self.assertEqual(zz.empty().accumulate(init = None).list(), [None])
def test_length_1(self): self.assertEqual(zz.empty().length(), 0)
def test_product_2(self): self.assertEqual(zz.empty().product(), 1)
def test_string_3(self): self.assertEqual(zz.empty().string(), '')
def test_max_3(self): self.assertEqual(zz.empty().max(default=999), 999)
def test_apply_6(self): def f(x): raise SampleError("This function raises an error") with self.assertRaises(SampleError): zz.empty().apply(f)
def test_min_3(self): self.assertEqual(zz.empty().min(default=999), 999)
def test_foldr_2(self): # Doesn't call the function on an empty sequence func = lambda x, y: zz.raise_(Exception("This should not be called")) self.assertEqual(zz.empty().foldr(func, init=1), 1)
def test_min_6(self): with self.assertRaises(zz.AlakazamError): zz.empty().min()
def test_empty(self): self.assertEqual(list(zz.empty()), [])
def test_cycle_2(self): self.assertTrue(zz.empty().cycle().null())