Esempio n. 1
0
    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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 def test_null_1(self):
     self.assertTrue(zz.empty().null())
Esempio n. 4
0
 def test_any_6(self):
     self.assertEqual(zz.empty().any(default=-1), -1)
Esempio n. 5
0
 def test_all_4(self):
     self.assertTrue(zz.empty().all())
Esempio n. 6
0
 def test_intersperse_2(self):
     self.assertEqual(zz.empty().intersperse(0).list(), [])
Esempio n. 7
0
 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)
Esempio n. 8
0
    def test_each_1(self):
        def f(x):
            raise SampleError("This error should not be raised")

        zz.empty().each(f)
Esempio n. 9
0
 def test_sum_2(self):
     # Defaults to 0
     self.assertEqual(zz.empty().sum(), 0)
Esempio n. 10
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")
Esempio n. 11
0
 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)
Esempio n. 12
0
 def test_accumulate_5(self):
     self.assertTrue(zz.empty().accumulate().null())
Esempio n. 13
0
 def test_accumulate_4(self):
     self.assertEqual(zz.empty().accumulate(init = None).list(), [None])
Esempio n. 14
0
 def test_length_1(self):
     self.assertEqual(zz.empty().length(), 0)
Esempio n. 15
0
 def test_product_2(self):
     self.assertEqual(zz.empty().product(), 1)
Esempio n. 16
0
 def test_string_3(self):
     self.assertEqual(zz.empty().string(), '')
Esempio n. 17
0
 def test_max_3(self):
     self.assertEqual(zz.empty().max(default=999), 999)
Esempio n. 18
0
    def test_apply_6(self):
        def f(x):
            raise SampleError("This function raises an error")

        with self.assertRaises(SampleError):
            zz.empty().apply(f)
Esempio n. 19
0
 def test_min_3(self):
     self.assertEqual(zz.empty().min(default=999), 999)
Esempio n. 20
0
 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)
Esempio n. 21
0
 def test_min_6(self):
     with self.assertRaises(zz.AlakazamError):
         zz.empty().min()
Esempio n. 22
0
 def test_empty(self):
     self.assertEqual(list(zz.empty()), [])
Esempio n. 23
0
 def test_cycle_2(self):
     self.assertTrue(zz.empty().cycle().null())