Exemple #1
0
 def test_tclobj_arithmetic4(self, x, y):
     """test tclobj <<="""
     tx = tohil.tclobj(x)
     ty = tohil.tclobj(y)
     assert tx << y == x << y
     assert tx << ty == x << y
     assert x << ty == x << y
    def test_tclobj_math10(self, i, j):
        """exercise tohil.tclobj "and" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti & j == i & j)
        assert (ti & tj == i & j)
        assert (i & tj == i & j)
    def test_tclobj_math9(self, i, j):
        """exercise tohil.tclobj right shift math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti >> j == i >> j)
        assert (ti >> tj == i >> j)
        assert (i >> tj == i >> j)
    def test_tclobj_math12(self, i, j):
        """exercise tohil.tclobj "xor" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti ^ j == i ^ j)
        assert (ti ^ tj == i ^ j)
        assert (i ^ tj == i ^ j)
    def test_tclobj_math11(self, i, j):
        """exercise tohil.tclobj "or" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti | j == i | j)
        assert (ti | tj == i | j)
        assert (i | tj == i | j)
    def test_tclobj_math21(self, i, j):
        """exercise tohil.tclobj "true divide" math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (abs(ti / j - i / j) < 1e-6)
        assert (abs(ti / tj - i / j) < 1e-6)
        assert (abs(i / tj - i / j) < 1e-6)
    def test_tclobj_math22(self, i, j):
        """exercise tohil.tclobj "floor divide" math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti // j == i // j)
        assert (ti // tj == i // j)
        assert (i // tj == i // j)
Exemple #8
0
 def test_tclobj_arithmetic3(self, x, y):
     """test tclobj *="""
     tx = tohil.tclobj(x)
     ty = tohil.tclobj(y)
     tx *= y
     assert tx == x * y
     tx = tohil.tclobj(x)
     tx *= ty
     assert tx == x * ty
Exemple #9
0
 def test_tclobj_arithmetic2(self, x, y):
     """test tclobj +="""
     tx = tohil.tclobj(x)
     ty = tohil.tclobj(y)
     tx += y
     assert tx == x + y
     tx.set(x)
     tx += ty
     assert tx == x + y
Exemple #10
0
    def test_tclobj_math18(self, i, j):
        """exercise tohil.tclobj "true divide" math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti / j == i / j)
        assert (ti / tj == i / j)
        assert (i / tj == i / j)
Exemple #11
0
 def test_tclobj_arithmetic1(self, x, y):
     """test tclobj +"""
     tx = tohil.tclobj(x)
     ty = tohil.tclobj(y)
     assert tx + y == x + y
     assert x + ty == x + y
     assert tx + ty == x + y
     assert tx - y == x - y
     assert x - ty == x - y
     assert tx - ty == x - y
Exemple #12
0
 def test_tclobj25(self):
     """tohil.tclobj dict wrapping tests"""
     # This isn't recommended (you should use the to= kwarg), but it works
     self.assertEqual(dict(tohil.tclobj()), {})
     # And here's why it's not recommended
     with self.assertRaises(ValueError):
         dict(tohil.tclobj("1 2"))
     with self.assertRaises(TypeError):
         # iterating on the tclobj gives us more tclobjs, which aren't
         # hashable and so cannot be keys
         dict(tohil.tclobj("{1 2}"))
Exemple #13
0
    def test_tclobj_math20(self, i, j):
        """exercise tohil.tclobj "inplace bitwise xor" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti ^= j
        assert (ti == i ^ j)

        ti = tohil.tclobj(i)
        ti ^= tj
        assert (ti == i ^ j)
Exemple #14
0
    def test_tclobj_math19(self, i, j):
        """exercise tohil.tclobj "inplace bitwise and" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti &= j
        assert (ti == i & j)

        ti = tohil.tclobj(i)
        ti &= tj
        assert (ti == i & j)
Exemple #15
0
    def test_tclobj_math18(self, i, j):
        """exercise tohil.tclobj "inplace bitwise or" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti |= j
        assert (ti == i | j)

        ti = tohil.tclobj(i)
        ti |= tj
        assert (ti == i | j)
Exemple #16
0
    def test_tclobj_math17(self, i, j):
        """exercise tohil.tclobj right shift math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti >>= j
        assert (ti == i >> j)

        ti = tohil.tclobj(i)
        ti >>= tj
        assert (ti == i >> j)
Exemple #17
0
    def test_tclobj_math15(self, i, j):
        """exercise tohil.tclobj "inplace multiply" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti *= j
        assert (ti == i * j)

        ti = tohil.tclobj(i)
        ti *= tj
        assert (ti == i * j)
Exemple #18
0
    def test_tclobj_math14(self, i, j):
        """exercise tohil.tclobj "inplace subtract" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti -= j
        assert (ti == i - j)

        ti = tohil.tclobj(i)
        ti -= tj
        assert (ti == i - j)
Exemple #19
0
    def test_tclobj_math8(self, i, j):
        """exercise tohil.tclobj left shift math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti << j == i << j)
        assert (ti << tj == i << j)
        assert (i << tj == i << j)

        assert (ti << 4 == i << 4)
        assert (4 << tj == 4 << j)
Exemple #20
0
    def test_tclobj_math26(self, u, v):
        """exercise tohil.tclobj "inplace remainder" float math ops"""
        assume(v != 0)
        tu = tohil.tclobj(u)
        tv = tohil.tclobj(v)

        tu %= v
        assert (abs(tu - u % v) < 0.000001)

        tu = tohil.tclobj(u)
        tu %= tv
        assert (abs(tu - u % v) < 0.000001)
Exemple #21
0
    def test_tclobj_math23(self, i, j):
        """exercise tohil.tclobj "inplace floor divide" integer math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti //= j
        assert (ti == i // j)

        ti = tohil.tclobj(i)
        ti //= tj
        assert (ti == i // j)
Exemple #22
0
    def test_tclobj_math19(self, i, j):
        """exercise tohil.tclobj "inplace true divide" math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti /= j
        assert (abs(ti - i / j) < 1e-6)

        ti = tohil.tclobj(i)
        ti /= tj
        assert (abs(ti - i / j) < 1e-6)
Exemple #23
0
    def test_tclobj_math5(self, u, v):
        """exercise tohil.tclobj multiply float math ops"""
        t6 = tohil.tclobj('6.')
        tu = tohil.tclobj(u)
        tv = tohil.tclobj(v)

        assert (tu * 6 == u * 6)
        assert (tu * 6. == u * 6.)
        assert (tu * t6 == u * 6.)
        assert (tu * tu == u * u)

        assert (tu * tv == u * v)
Exemple #24
0
    def test_tclobj_math25(self, i, j):
        """exercise tohil.tclobj "inplace remainder" integer math ops"""
        assume(j != 0)
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti %= j
        assert (ti == i % j)

        ti = tohil.tclobj(i)
        ti %= tj
        assert (ti == i % j)
Exemple #25
0
    def test_tclobj_math24(self, u, v):
        """exercise tohil.tclobj "inplace floor divide" float math ops"""
        assume(v < -0.1 or v > 0.1)
        tu = tohil.tclobj(u)
        tv = tohil.tclobj(v)

        tu //= v
        assert (tu == u // v)

        tu = tohil.tclobj(u)
        tu //= tv
        assert (tu == u // v)
Exemple #26
0
    def test_tclobj_math30(self):
        """exercise tohil.tclobj integer remainder of by zero exceptions"""
        t5 = tohil.tclobj(5)
        t0 = tohil.tclobj(0)

        with self.assertRaises(ZeroDivisionError):
            t5 % 0

        with self.assertRaises(ZeroDivisionError):
            t5 % t0

        with self.assertRaises(ZeroDivisionError):
            5 % t0
Exemple #27
0
    def test_tclobj_math29(self):
        """exercise tohil.tclobj integer division by zero exceptions"""
        t5 = tohil.tclobj(5)
        t0 = tohil.tclobj(0)

        with self.assertRaises(ZeroDivisionError):
            t5 // 0

        with self.assertRaises(ZeroDivisionError):
            t5 // t0

        with self.assertRaises(ZeroDivisionError):
            5 // t0
Exemple #28
0
    def test_tclobj_math28(self):
        """exercise tohil.tclobj float division by zero exceptions"""
        t5 = tohil.tclobj(5.)
        t0 = tohil.tclobj(0.)

        with self.assertRaises(ZeroDivisionError):
            t5 / 0.

        with self.assertRaises(ZeroDivisionError):
            t5 / t0

        with self.assertRaises(ZeroDivisionError):
            5 / t0
Exemple #29
0
    def test_tclobj_math2(self, i, j):
        """exercise tohil.tclobj 'minus' math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        assert (ti - 3 == i - 3)
        assert (ti - ti == 0)
        assert (6 - ti == 6 - i)

        assert (tj - 4. == j - 4.)
        assert (tj - float(tj) == 0.)
        assert (6. - ti == 6. - i)

        assert (tj - ti == j - i)
Exemple #30
0
    def test_tclobj_math13(self, i, j):
        """exercise tohil.tclobj "inplace add" math ops"""
        ti = tohil.tclobj(i)
        tj = tohil.tclobj(j)

        ti += j
        assert (ti == i + j)

        ti = tohil.tclobj(i)
        ti += ti
        assert (ti == i + i)

        ti = tohil.tclobj(i)
        ti += tj
        assert (ti == i + j)