コード例 #1
0
 def test(self):
     self.assertEqual(
         arithmetic(1, 2, "add"), 3,
         "'add' should return the two numbers added together!")
     self.assertEqual(arithmetic(8, 2, "subtract"), 6,
                      "'subtract' should return a minus b!")
     self.assertEqual(arithmetic(5, 2, "multiply"), 10,
                      "'multiply' should return a multiplied by b!")
     self.assertEqual(arithmetic(8, 2, "divide"), 4,
                      "'divide' should return a divided by b!")
コード例 #2
0
def woe(t,
        label_col,
        order_col,
        partition_cols,
        label_delay,
        window_lens=[2592000],
        expr='{0}*1.0/{1}'):

    windows = []
    for index, window_len in enumerate(window_lens):
        windows.append({
            'name': 'w' + str(index),
            'range': (-label_delay - window_len, -label_delay),
            'row': (None, None)
        })
    aggregate_functions = ['existcount', 'fsum']
    target_cols = [label_col]
    extend_partition_cols = partition_cols[:]
    extend_partition_cols.append('1')
    t1 = window_aggregate_sql(t, windows, aggregate_functions,
                              extend_partition_cols, target_cols, order_col)

    cnt_cols = [
        utils.name_new_col(label_col, 'existcount', name, partition_col)
        for (name,
             partition_col) in zip([window['name']
                                    for window in windows], partition_cols)
    ]
    pos_cols = [
        utils.name_new_col(label_col, 'fsum', name, partition_col)
        for (name,
             partition_col) in zip([window['name']
                                    for window in windows], partition_cols)
    ]
    cnt_cols_total = [
        utils.name_new_col(label_col, 'existcount', name, '1')
        for (name,
             partition_col) in zip([window['name']
                                    for window in windows], partition_cols)
    ]
    pos_cols_total = [
        utils.name_new_col(label_col, 'fsum', name, '1')
        for (name,
             partition_col) in zip([window['name']
                                    for window in windows], partition_cols)
    ]

    # pos_rate_cols:adjust by prior positive rate
    t2 = arithmetic(t1, expr, 'pos_rate_', cnt_cols, pos_cols, cnt_cols_total,
                    pos_cols_total, partition_cols)

    return t2
コード例 #3
0
    def test_rand(self):
        from random import randint
        sol = lambda a, b, o: eval("".join([
            str(a), "+" if o == "add" else "-" if o == "subtract" else "*"
            if o == "multiply" else "/",
            str(b)
        ]))
        base = ["add", "subtract", "multiply", "divide"]

        for _ in range(40):
            a, b, o = randint(-10, 10), randint(1, 10), base[randint(0, 3)]
            self.assertEqual(arithmetic(a, b, o), sol(a, b, o),
                             "It should work for random inputs too")
コード例 #4
0
def test_arithmetic():
    assert arithmetic(1, 2, "add") == 3
    assert arithmetic(8, 2, "subtract") == 6
    assert arithmetic(5, 2, "multiply") == 10
    assert arithmetic(8, 2, "divide") == 4
コード例 #5
0
 def test_invalid_operand_type(self):
     """
     Тестовый случай с неверными типами операндов.
     """
     with self.assertRaises(TypeError):
         arithmetic('7', False, '*')
コード例 #6
0
 def test_undefined_operation(self):
     """
     Тестовый случай с неопределённой операцией.
     """
     with self.assertRaises(ValueError):
         arithmetic(self.left_operand, self.right_operand, '?')
コード例 #7
0
 def test_multiplication(self):
     """
     Тестовый случай с операцией умножения.
     """
     result = arithmetic(self.left_operand, self.right_operand, '*')
     self.assertEqual(result, 729)
コード例 #8
0
 def test_division(self):
     """
     Тестовый случай с операцией деления.
     """
     result = arithmetic(self.left_operand, self.right_operand, '/')
     self.assertEqual(result, 9)
コード例 #9
0
 def test_subtraction(self):
     """
     Тестовый случай с операцией вычитания.
     """
     result = arithmetic(self.left_operand, self.right_operand, '-')
     self.assertEqual(result, 72)
コード例 #10
0
 def test_sum(self):
     """
     Тестовый случай с операцией сложения.
     """
     result = arithmetic(self.left_operand, self.right_operand, '+')
     self.assertEqual(result, 90)
コード例 #11
0
 def write_arithmetic(self, p):
     self.file.write('//' + p.command)
     self.file.write(arithmetic.arithmetic(p))
     return
コード例 #12
0
#Тренировки
import arithmetic
import is_year_leap
import square
import season
import bank
import is_prime
import date
import XOR_cipher

print(is_year_leap.is_year_leap(2004))
print(square.square(5))
print(arithmetic.arithmetic(4, 3, '+'))
print(season.season(13))
print(bank.bank(1000, 3))
print(is_prime.is_prime(47))
print(date.date(29, 2, 2000))
print(XOR_cipher.XOR_cipher('help', '3'))