示例#1
0
    def test_length(self):
        one = [4, [1, 1, 1, 1]]
        two = [3, [9, 9, 9]]

        result = natural.COM_NN_D(one, two)
        self.assertEqual(result, 2)

        result = natural.COM_NN_D(two, one)
        self.assertEqual(result, 1)
示例#2
0
    def test_simple(self):
        one = [3, [2, 4, 3]]
        two = [3, [3, 2, 4]]

        result = natural.COM_NN_D(one, two)
        self.assertEqual(result, 1)

        result = natural.COM_NN_D(two, one)
        self.assertEqual(result, 2)
def SUB_ZZ_Z(list1, list2):
    # Семёнов Михаил
    # Вычитание целых чисел
    if POZ_Z_D(list1) == '+' and POZ_Z_D(list2) == '-':
        return f1.ADD_NN_N(list1, ABS_Z_N(list2))
    elif POZ_Z_D(list1) == '-' and POZ_Z_D(list2) != '-':
        if POZ_Z_D(list2) == '+':
            return ['-'] + f1.ADD_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return list1

    elif f1.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 2:
        if list2 != 0:
            return f1.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return list1
    elif POZ_Z_D(list1) == 0:
        if POZ_Z_D(list2) == '-':
            return list2[1:]
        elif list2 == [0]:
            return list2
        else:
            return ['-'] + list2

    else:
        if POZ_Z_D(list1) == '+':
            return ['-'] + f1.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
        else:
            return f1.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
示例#4
0
def ADD_ZZ_Z(list1, list2):
    # Дашкин Дамир
    # Сложение целых чисел
    if POZ_Z_D(list1) == '+' and POZ_Z_D(list2) == '+':
        return nat.ADD_NN_N(list1, list2)
    elif POZ_Z_D(list1) == '-' and POZ_Z_D(list2) == '-':
        return ['-'] + nat.ADD_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 2:
        if POZ_Z_D(list1) == '-':
            return ['-'] + nat.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return nat.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 1:
        if POZ_Z_D(list2) == '-':
            return ['-'] + nat.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
        else:
            return nat.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 0:
        return [0]
def ADD_ZZ_Z(b1, n1, list1, b2, n2, list2):
    #Дашкин Дамир
    #Сложение целых чисел
    str1 = ""
    str2 = ""
    for i in range(len(list1)):
        str1 = str1 + str(list1[i])
    for j in range(len(list2)):
        str2 = str2 + str(list2[j])
    if b1 == 1:
        str1 = "-" + str1
    num1 = int(str1)
    if b2 == 1:
        str2 = "-" + str2
    num2 = int(str2)
    if f1.POZ_Z_D(num1) == 2 and f1.POZ_Z_D(num2) == 2:
        res = f1.ADD_NN_N(num1, num2)
    if f1.POZ_Z_D(num1) == 1 and f1.POZ_Z_D(num2) == 1:
        mod1 = f1.ABS_Z_N(num1)
        mod2 = f1.ABS_Z_N(num2)
        res = f1.ADD_NN_N(mod1, mod2)
        res = f1.MUL_ZM_Z(res)
    else:
        mod1 = f1.ABS_Z_N(num1)
        mod2 = f1.ABS_Z_N(num2)
        if f1.COM_NN_D(mod1, mod2) == 2:
            if f1.POZ_Z_D(num1) == 1:
                res = f1.SUB_NN_N(mod1, mod2)
                res = f1.MUL_ZM_Z(res)
            else:
                res = f1.SUB_NN_N(mod1, mod2)
        if f1.COM_NN_D(mod1, mod2) == 1:
            if f1.POZ_Z_D(num2) == 1:
                res = f1.SUB_NN_N(mod2, mod1)
                res = MUL_ZM_Z(res)
            else:
                res = f1.SUB_NN_N(mod2, mod1)
        else:
            res = 0
    return res
示例#6
0
    def on_btn_n_com_released(self):
        try:
            n1 = self.get_n_n(1)
            n2 = self.get_n_n(2)
            result = natural.COM_NN_D(n1, n2)
            if result == 0:
                sign = '='
            elif result == 1:
                sign = '<'
            else:
                sign = '>'

            self.add_history_record('%d %s %d' % (
                common.N_to_num(n1),
                sign,
                common.N_to_num(n2),
                ))
        except Exception as e:
            self.on_exception(e)
示例#7
0
 def test_equal(self):
     one = [3, [2, 7, 4]]
     two = one
     expect = 0
     result = natural.COM_NN_D(one, two)
     self.assertEqual(result, expect)
示例#8
0
 def test_zeros(self):
     one = [1, [0]]
     two = one
     expect = 0
     result = natural.COM_NN_D(one, two)
     self.assertEqual(result, expect)