Example #1
0
 def test_division_by_integer(self):
     a = EisensteinFraction(four=(1, 1, -3, 2)) / 2
     self.assertEqual(a, EisensteinFraction(four=(1, 2, -3, 4)))
     b = Eisenstein(2, 0) // 2
     self.assertEqual(b, EisensteinFraction(four=(1, 1, 0, 1)))
     c = Eisenstein(4, 0) // 2
     self.assertEqual(c, EisensteinFraction(four=(2, 1, 0, 1)))
Example #2
0
    def test_comparison(self):
        a = EisensteinFraction(Eisenstein(1, 2))
        b = EisensteinFraction(1, 2)
        self.assertEqual(a == b, True)

        a = Eisenstein(1, 2)
        b = EisensteinFraction(1, 2)
        self.assertEqual(a == b, True)
        self.assertEqual(b == a, True)
Example #3
0
    def test_another_substract_values(self):
        a = EisensteinFraction(four=(1, 2, 3, 4))
        b = EisensteinFraction(four=(1, 3, 3, 4))
        c = a - b
        self.assertEqual(str(c), "EisensteinFraction(four=(1, 6, 0, 1))")

        a = EisensteinFraction(four=(1, 1, 3, 4))
        c = a - 1
        self.assertEqual(str(c), "EisensteinFraction(four=(0, 1, 3, 4))")
 def test_hash_one(self):
     deltaA = EisensteinFraction(1, 0)
     deltaB = EisensteinFraction(1, 0)
     if get_dot_product(deltaA, deltaB) > 0:
         hash_result, delta_hash = hash_Eisenstein_Fraction(
             data_sets.A, deltaA, data_sets.B, deltaB)
         check_result_hash(hash_result)
     else:
         SystemExit("dot product =< 0")
Example #5
0
    def test_another_add_values(self):
        a = EisensteinFraction(four=(1, 2, 3, 4))
        b = EisensteinFraction(four=(1, 3, 3, 4))
        c = a + b
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 6, 3, 2))")

        a = EisensteinFraction(four=(1, 2, 3, 4))
        c = a + 2
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 2, 3, 4))")

        a = EisensteinFraction(four=(1, 2, 3, 4))
        c = a + Eisenstein(2)
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 2, 3, 4))")
Example #6
0
    def test_floor_and_ceil(self):
        a = EisensteinFraction(Fraction(1, 2), 2)

        self.assertEqual(Eisenstein(0, 2), a.floor)
        self.assertEqual(Eisenstein(1, 2), a.ceil)

        a = EisensteinFraction(Fraction(1, 3), 2)
        self.assertEqual(Eisenstein(0, 2), a.floor)
        self.assertEqual(Eisenstein(1, 2), a.ceil)

        a = EisensteinFraction(Fraction(3, 4), Fraction(3, 4))

        self.assertEqual(Eisenstein(0, 0), a.floor)
        self.assertEqual(Eisenstein(1, 1), a.ceil)
    def test_add_matrix(self):
        TestRange = parameters.cfg_prm.test_range

        for l in range(TestRange):
            for k in range(TestRange):
                for j in range(TestRange):
                    for i in range(TestRange):
                        deltaA = EisensteinFraction(i + 1, l)
                        deltaB = EisensteinFraction(j + 1, k)

                        add_result, delta_add = add_Eisenstein_Fraction(
                            data_sets.A, deltaA, data_sets.B, deltaB)
                        if check_result_add(add_result):
                            raise SystemExit("Add algorithm fails")
    def test_hash_matrix(self):
        TestRange = parameters.cfg_prm.test_range

        for l in range(TestRange):
            for k in range(TestRange):
                for j in range(TestRange):
                    for i in range(TestRange):
                        deltaA = EisensteinFraction(i + 1, l)
                        deltaB = EisensteinFraction(j + 1, k)
                        if get_dot_product(deltaA, deltaB) > 0:
                            hash_result, delta_hash = hash_Eisenstein_Fraction(
                                data_sets.A, deltaA, data_sets.B, deltaB)
                            check_result_hash(hash_result)
                        else:
                            pass
Example #9
0
    def test_multiplication(self):
        """
        TestEisensteinFractionNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; c = ( 1 + 2 w ) * ( 2 + 4 w )
        answer: c = -6
        """
        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(2)
        c = a * b
        self.assertEqual(c, Eisenstein(1))

        a = EisensteinFraction(Eisenstein(2, 1))
        b = EisensteinFraction(Fraction(1, 2))
        c = a * b
        self.assertEqual(c, EisensteinFraction(1, Fraction(1, 2)))
Example #10
0
    def test_add_values(self):
        # 2 + 2 = 4
        a = EisensteinFraction(Fraction(4, 2))
        b = EisensteinFraction(Fraction(6, 3))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(4, 1, 0, 1)))

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(1, 4))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(3, 4, 0, 1)))

        a = EisensteinFraction(Eisenstein(1, 1))
        b = EisensteinFraction(Eisenstein(1, -1))
        c = a + b
        self.assertEqual(c, EisensteinFraction(Eisenstein(2, 0)))
Example #11
0
 def test_multiplication_by_integer(self):
     a = 2 * EisensteinFraction(four=(1, 1, -3, 2))
     self.assertEqual(a, EisensteinFraction(four=(2, 1, -6, 2)))
     b = 2 * Eisenstein(2, 0)
     self.assertEqual(b, EisensteinFraction(four=(4, 1, 0, 1)))
     a = EisensteinFraction(four=(1, 1, -3, 2)) * 2
     self.assertEqual(a, EisensteinFraction(four=(2, 1, -6, 2)))
     b = Eisenstein(2, 0) * 2
     self.assertEqual(b, EisensteinFraction(four=(4, 1, 0, 1)))
    def test_add_diff_matrix(self):
        TestRange = parameters.cfg_prm.test_range

        for l in range(TestRange):
            for k in range(TestRange):
                for j in range(TestRange):
                    for i in range(TestRange):
                        deltaA = EisensteinFraction(i + 1, l)
                        deltaB = EisensteinFraction(j + 1, k)

                        add_result, delta_add = add_Eisenstein_Fraction(
                            data_sets.A, deltaA, data_sets.B, deltaB)

                        if check_result_add(add_result):
                            raise SystemExit("Add algorithm fails")

                        diff_result, delta_diff = diff_Eisenstein_Fraction(
                            add_result, deltaA, deltaB)

                        if check_result_is_number_sequence(diff_result):
                            print()
                            print(deltaA)
                            print(deltaA)
                            print("argument:", add_result)
                            print("result: ", diff_result)
                            raise SystemExit("Diff algorithm fails")

                        diff_result, delta_diff = diff_Eisenstein_Fraction(
                            add_result, deltaB, deltaA)

                        if check_result_is_alpha_sequence(diff_result):
                            print()
                            print(deltaA)
                            print(deltaA)
                            print("argument:", add_result)
                            print("result: ", diff_result)
                            raise SystemExit("Diff algorithm fails")
Example #13
0
    def test_types_mix(self):
        """
        TestEisensteinFractionNumbers:
        """

        # 2 + 2 = 4
        a = EisensteinFraction(Fraction(4, 2))
        b = EisensteinFraction(Fraction(6, 3))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(4, 1, 0, 1)))

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(1, 4))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(3, 4, 0, 1)))

        a = EisensteinFraction(Eisenstein(1, 1))
        b = EisensteinFraction(Fraction(1, 2))
        c = a + b
        self.assertEqual(c, EisensteinFraction(Fraction(3, 2), 1))
Example #14
0
    def test_div_mod(self):
        obj_a = EisensteinFraction(four=(2, 1, 3, 1))
        obj_b = EisensteinFraction(four=(1, 1, 0, 1))
        obj_c = obj_a / obj_b
        self.assertEqual(obj_c, EisensteinFraction(four=(2, 1, 3, 1)))

        obj_a = EisensteinFraction(four=(4, 1, 6, 1))
        obj_b = EisensteinFraction(four=(1, 1, 0, 1))
        obj_c = obj_a / 2
        self.assertEqual(obj_c, EisensteinFraction(four=(2, 1, 3, 1)))
Example #15
0
    def test_substract_values(self):
        """
        TestEisensteinFractionNumbers:
        """

        # 2 - 2 = 0
        a = EisensteinFraction(Fraction(4, 2))
        b = EisensteinFraction(Fraction(6, 3))
        c = a - b
        self.assertEqual(c, EisensteinFraction(four=(0, 1, 0, 1)))

        # 3/1 - 1/1 = 2/1
        a = EisensteinFraction(Fraction(3, 1))
        b = EisensteinFraction(Fraction(1, 1))
        c = a - b
        self.assertEqual(c, EisensteinFraction(four=(2, 1, 0, 1)))

        a = EisensteinFraction(3, 1)
        b = EisensteinFraction(1, 1)
        c = a - b
        self.assertEqual(c, EisensteinFraction(2, 0))
Example #16
0
    def test_abs(self):
        """
        Hint:
        abs(1+1i) = sqrt(2)
        abs(1+1w) = 1

        Beware: if you make computations via complex form you will hit 0.999 as answer
        and then you need to use self.assertAlmostEqual(1, eisensteinAbs(a), 10)
        """
        a = EisensteinFraction(1, 1)
        self.assertEqual(1, abs(a))
        a = EisensteinFraction(2, 2)
        self.assertEqual(2, abs(a))

        a = EisensteinFraction(2, 2)
        self.assertAlmostEqual(abs(a.get_complex_form), abs(a), 10)
        a = EisensteinFraction(1, 1)
        self.assertAlmostEqual(abs(a.get_complex_form), abs(a), 10)

        a = EisensteinFraction(-2, 3)
        self.assertAlmostEqual(abs(a.get_complex_form), abs(a), 10)
        a = EisensteinFraction(4, 5)
        self.assertAlmostEqual(abs(a.get_complex_form), abs(a), 10)
Example #17
0
 def test_fraction_as_integer(self):
     a = EisensteinFraction(four=(2, 1, -3, 1))
     self.assertEqual(str(a), "Eisenstein(2, -3)")
Example #18
0
 def test_presentation(self):
     a = Eisenstein(2, 2)
     self.assertEqual(str(a), "Eisenstein(2, 2)")
     a = EisensteinFraction(Fraction(1, 2), 2)
     self.assertEqual(str(a), "EisensteinFraction(four=(1, 2, 2, 1))")
Example #19
0
    def test_round(self):
        a = EisensteinFraction(Fraction(1, 2), Fraction(3, 4))
        self.assertEqual(Eisenstein(0, 1), a.round)

        a = EisensteinFraction(Fraction(-3, 4), Fraction(1, 2))
        self.assertEqual(Eisenstein(-1, 0), a.round)
Example #20
0
 def test_four_parts(self):
     obj = EisensteinFraction(four=(1, 2, 3, 4))
     self.assertEqual(str(obj), "EisensteinFraction(four=(1, 2, 3, 4))")
     obj = EisensteinFraction(four=(5, 6, 7, 11))
     self.assertEqual(str(obj), "EisensteinFraction(four=(5, 6, 7, 11))")
Example #21
0
 def test_inverse(self):
     a = EisensteinFraction(Fraction(1, 2), Fraction(1, 2))
     c = EisensteinFraction(1) / a
     self.assertEqual(c, EisensteinFraction(0, -2))
Example #22
0
 def test_alternation(self):
     # covering issue __rmul__ = __mul__ ,  __radd__ = __add__
     a = EisensteinFraction(Fraction(1, 2))
     b = EisensteinFraction(2)
     c = a * b
     self.assertEqual(c, EisensteinFraction(four=(1, 1, 0, 1)))
Example #23
0
    def test_division(self):
        """
        TestEisensteinFractionNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; a = ( 2 + 4 w ); b = ( 2 + 4 w ) ; c = a / b
        answer: c = 1
        """

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(4, 2))
        c = a / b
        self.assertEqual(c, EisensteinFraction(four=(1, 4, 0, 1)))

        a = EisensteinFraction(4)
        b = EisensteinFraction(2)
        c = a / b
        self.assertEqual(c, EisensteinFraction(2))

        a = EisensteinFraction(0, 2)
        b = EisensteinFraction(0, 4)
        self.assertEqual(a, EisensteinFraction(Eisenstein(0, 2)))
        self.assertEqual(b, EisensteinFraction(Eisenstein(0, 4)))
        c = a / b
        self.assertEqual(c, EisensteinFraction(four=(1, 2, 0, 1)))
Example #24
0
 def test_integer_isequal_eisensteinFraction(self):
     a = 1 == EisensteinFraction(four=(1, 1, 0, 1))
     self.assertEqual(a, True)
     b = EisensteinFraction(four=(1, 1, 0, 1)) == 1
     self.assertEqual(b, True)
Example #25
0
 def test_integer_add_eisensteinFraction(self):
     a = 1 + EisensteinFraction(four=(1, 1, -3, 2))
     self.assertEqual(a, EisensteinFraction(four=(2, 1, -3, 2)))
     b = EisensteinFraction(four=(1, 1, -3, 2)) + 1
     self.assertEqual(b, EisensteinFraction(four=(2, 1, -3, 2)))
Example #26
0
 def test_multiply_values(self):
     a = EisensteinFraction(four=(1, 2, 3, 5))
     b = EisensteinFraction(four=(7, 11, 13, 17))
     c = a * b
     self.assertEqual(str(c), "EisensteinFraction(four=(-263, 1870, 571, 1870))")
     self.assertEqual(repr(c), "EisensteinFraction(four=(-263, 1870, 571, 1870))")
Example #27
0
 def test_norm(self):
     obj_a = EisensteinFraction(four=(1, 1, 1, 1))
     self.assertEqual(obj_a.get_norm, 1)
     obj_a = EisensteinFraction(four=(1, 1, 1, 2))
     self.assertEqual(obj_a.get_norm, Fraction(3, 4))
Example #28
0
 def test_compare_values(self):
     obj_a = EisensteinFraction(four=(2, 4, 2, 3))
     obj_b = EisensteinFraction(four=(1, 2, 6, 9))
     self.assertEqual(obj_a == obj_b, True)
    def test_dehash_matrix(self):
        TestRange = parameters.cfg_prm.test_range

        callCount = 0
        for l in range(TestRange):
            for k in range(TestRange):
                for j in range(TestRange):
                    for i in range(TestRange):
                        deltaA = EisensteinFraction(i + 1, l)
                        deltaB = EisensteinFraction(j + 1, k)
                        if get_dot_product(deltaA, deltaB) > 0:
                            hash_result, delta_hash = hash_Eisenstein_Fraction(
                                data_sets.A, deltaA, data_sets.B, deltaB)
                            # check_result_hash(hash_result) Already checked
                            callCount += 1
                            dehashOdd_result, delta_dehashOdd = dehashodd_Eisenstein_Fraction(
                                hash_result, delta_hash, deltaB)

                            assert delta_dehashOdd == deltaA

                            if not check_result_is_only_alpha_sequence(
                                    dehashOdd_result):
                                print()
                                print("!! CALL COUNT:", callCount)
                                print()
                                print(i + 1, l, j + 1, k)
                                print(
                                    "deltaA=",
                                    deltaA,
                                    " deltaB=",
                                    deltaB,
                                    " dot=",
                                    get_dot_product(deltaA, deltaB),
                                )
                                print(
                                    ("a/b=", deltaA / deltaB),
                                    " b/a=",
                                    (deltaB / deltaA),
                                )

                                print("*", dehashOdd_result)
                                print("!",
                                      data_sets.B[0:len(dehashOdd_result)])

                                print(dehashOdd_result ==
                                      data_sets.B[0:len(dehashOdd_result)])

                                print(hash_result)

                                for i in dehashOdd_result:
                                    print("%3s" % str(i), end="")
                                print()
                                for i in data_sets.B[0:len(dehashOdd_result)]:
                                    print("%3s" % str(i), end="")
                                print()
                                raise SystemExit(
                                    "dehasodd_Eisenstein_Fraction algorithm fails"
                                )
                                # input("Press Enter to continue...")

                            dehashEven_result, delta_dehashEven = dehasheven_Eisenstein_Fraction(
                                hash_result, delta_hash, deltaA)
                            if not check_result_is_only_number_sequence(
                                    dehashEven_result):

                                print()

                                print("*", dehashEven_result)
                                print(data_sets.A[0:2])
                                print("!",
                                      data_sets.A[0:len(dehashEven_result)])

                                print()

                                for i in dehashEven_result:
                                    print("%3s" % str(i), end="")
                                print()
                                for i in data_sets.A[0:len(dehashEven_result)]:
                                    print("%3s" % str(i), end="")
                                print()
                                raise SystemExit(
                                    "dehasheven_Eisenstein_Fraction algorithm fails"
                                )

                        else:
                            pass
Example #30
0
 def test_division_by_eisenstein(self):
     a = EisensteinFraction(four=(1, 1, -3, 2))
     b = a / Eisenstein(2, 0)
     self.assertEqual(b, EisensteinFraction(four=(1, 2, -3, 4)))
     c = a / Eisenstein(3, 0)
     self.assertEqual(c, EisensteinFraction(four=(1, 3, -1, 2)))