How to use make_value method in Slash

Best Python code snippet using slash

numeric.py

Source:numeric.py Github

copy

Full Screen

...10)11def negative_integer(value):12 if value.is_null:13 return value14 return make_value(Types.INTEGER, value.value * -1)15@FUNCTIONS.register(16 'negative',17 (Types.FLOAT,),18)19def negative_float(value):20 if value.is_null:21 return value22 return make_value(Types.FLOAT, value.value * -1.0)23@FUNCTIONS.register(24 'add',25 (Types.INTEGER, Types.INTEGER),26)27def add_integer(left, right):28 if left.is_null or right.is_null:29 return make_value(Types.INTEGER, None)30 return make_value(Types.INTEGER, left.value + right.value)31@FUNCTIONS.register(32 'add',33 (Types.FLOAT, Types.INTEGER),34 (Types.INTEGER, Types.FLOAT),35 (Types.FLOAT, Types.FLOAT),36)37def add_float(left, right):38 if left.is_null or right.is_null:39 return make_value(Types.FLOAT, None)40 return make_value(Types.FLOAT, left.value + right.value)41@FUNCTIONS.register(42 'subtract',43 (Types.INTEGER, Types.INTEGER),44)45def subtract_integer(left, right):46 if left.is_null or right.is_null:47 return make_value(Types.INTEGER, None)48 return make_value(Types.INTEGER, left.value - right.value)49@FUNCTIONS.register(50 'subtract',51 (Types.FLOAT, Types.INTEGER),52 (Types.INTEGER, Types.FLOAT),53 (Types.FLOAT, Types.FLOAT),54)55def subtract_float(left, right):56 if left.is_null or right.is_null:57 return make_value(Types.FLOAT, None)58 return make_value(Types.FLOAT, left.value - right.value)59@FUNCTIONS.register(60 'multiply',61 (Types.INTEGER, Types.INTEGER),62)63def multiply_integer(left, right):64 if left.is_null or right.is_null:65 return make_value(Types.INTEGER, None)66 return make_value(Types.INTEGER, left.value * right.value)67@FUNCTIONS.register(68 'multiply',69 (Types.FLOAT, Types.INTEGER),70 (Types.INTEGER, Types.FLOAT),71 (Types.FLOAT, Types.FLOAT),72)73def multiply_float(left, right):74 if left.is_null or right.is_null:75 return make_value(Types.FLOAT, None)76 return make_value(Types.FLOAT, left.value * right.value)77@FUNCTIONS.register(78 'modulo',79 (Types.INTEGER, Types.INTEGER),80)81def modulo_integer(left, right):82 if left.is_null or right.is_null:83 return make_value(Types.INTEGER, None)84 return make_value(Types.INTEGER, left.value % right.value)85@FUNCTIONS.register(86 'modulo',87 (Types.FLOAT, Types.INTEGER),88 (Types.INTEGER, Types.FLOAT),89 (Types.FLOAT, Types.FLOAT),90)91def modulo_float(left, right):92 if left.is_null or right.is_null:93 return make_value(Types.FLOAT, None)94 return make_value(Types.FLOAT, left.value % right.value)95@FUNCTIONS.register(96 'pow',97 (Types.INTEGER, Types.INTEGER),98)99def pow_integer(left, right):100 if left.is_null or right.is_null:101 return make_value(Types.INTEGER, None)102 return make_value(Types.INTEGER, left.value ** right.value)103@FUNCTIONS.register(104 'pow',105 (Types.FLOAT, Types.INTEGER),106 (Types.INTEGER, Types.FLOAT),107 (Types.FLOAT, Types.FLOAT),108)109def pow_float(left, right):110 if left.is_null or right.is_null:111 return make_value(Types.FLOAT, None)112 return make_value(Types.FLOAT, left.value ** right.value)113@FUNCTIONS.register(114 'divide',115 (Types.INTEGER, Types.INTEGER),116 (Types.FLOAT, Types.INTEGER),117 (Types.INTEGER, Types.FLOAT),118 (Types.FLOAT, Types.FLOAT),119)120def divide(left, right):121 if left.is_null or right.is_null:122 return make_value(Types.FLOAT, None)123 if right.value == 0:124 raise ExecutionError('Cannot divide by zero')125 return make_value(Types.FLOAT, left.value / float(right.value))126@FUNCTIONS.register(127 'abs',128 (Types.INTEGER,),129 (Types.FLOAT,),130)131def func_abs(value):132 if value.is_null:133 return value134 return make_value(value.data_type, abs(value.raw_value))135def simple_func(func, data_type, value):136 if value.is_null:137 return make_value(data_type, None)138 return make_value(data_type, func(value.raw_value))139SIMPLE_FUNCTIONS = (140 ('ceil', math.ceil, Types.INTEGER),141 ('floor', math.floor, Types.INTEGER),142 ('trunc', math.trunc, Types.INTEGER),143 ('sin', math.sin, Types.FLOAT),144 ('cos', math.cos, Types.FLOAT),145 ('tan', math.tan, Types.FLOAT),146 ('sqrt', math.sqrt, Types.FLOAT),147)148for name, impl, dtype in SIMPLE_FUNCTIONS:149 FUNCTIONS.register(name, (Types.INTEGER,), (Types.FLOAT,))(150 lambda value, impl=impl, dtype=dtype: simple_func(151 impl,152 dtype,153 value,154 )155 )156CONST_PI = make_value(Types.FLOAT, math.pi)157@FUNCTIONS.register(158 'pi',159)160def const_pi():161 return CONST_PI162CONST_E = make_value(Types.FLOAT, math.e)163@FUNCTIONS.register(164 'e',165)166def const_e():167 return CONST_E168@FUNCTIONS.register(169 'random',170)171def func_random():172 return make_value(Types.FLOAT, random.random()) # noqa: bandit:B311173@FUNCTIONS.register(174 'log',175 (Types.INTEGER, Types.INTEGER),176 (Types.INTEGER, Types.FLOAT),177 (Types.FLOAT, Types.INTEGER),178 (Types.FLOAT, Types.FLOAT),179)180def log(value, base):181 if value.is_null or base.is_null:182 return make_value(Types.FLOAT, None)183 if base.raw_value == 10:184 result = math.log10(value.raw_value)185 else:186 result = math.log(value.raw_value, base.raw_value)187 return make_value(Types.FLOAT, result)188@FUNCTIONS.register(189 'hypot',190 (Types.INTEGER, Types.INTEGER),191 (Types.INTEGER, Types.FLOAT),192 (Types.FLOAT, Types.INTEGER),193 (Types.FLOAT, Types.FLOAT),194)195def hypot(x_value, y_value):196 if x_value.is_null or y_value.is_null:197 return make_value(Types.FLOAT, None)198 return make_value(199 Types.FLOAT,200 math.hypot(x_value.raw_value, y_value.raw_value),201 )202QUANT = decimal.Decimal('1')203def decimal_round(value, precision):204 precision = 10 ** precision205 value *= precision206 value = float(decimal.Decimal(value).quantize(207 QUANT,208 decimal.ROUND_HALF_EVEN,209 ))210 value /= precision211 return value212@FUNCTIONS.register(213 'round',214 (Types.INTEGER,),215 (Types.FLOAT,),216)217def round_integer(value):218 if value.is_null:219 return value220 return make_value(Types.INTEGER, int(decimal_round(value.raw_value, 0)))221@FUNCTIONS.register(222 'round',223 (Types.INTEGER, Types.INTEGER),224 (Types.FLOAT, Types.INTEGER),225)226def round_float(value, precision):227 if value.is_null or precision.is_null:228 return make_value(Types.FLOAT, None)229 return make_value(230 Types.FLOAT,231 decimal_round(value.raw_value, precision.raw_value),...

Full Screen

Full Screen

aoc2015-7.py

Source:aoc2015-7.py Github

copy

Full Screen

...3commands_list = commands_input.split('\n')4def real_action(input_list):5 result = {}6 commands = list(input_list)7 def make_value(string):8 nonlocal result9 if string.isdigit():10 return int(string)11 else:12 return result[string]13 def check_if_valid(string):14 nonlocal result15 if string in result or string.isdigit():16 return True17 while len(commands) > 0:18 for command in list(commands):19 if "AND" in command:20 groups = re.search(r"([a-z0-9]+)\s+AND\s+([a-z0-9]+)\s+->\s+([a-z0-9]+)", command)21 if check_if_valid(groups.group(1)) and check_if_valid(groups.group(2)):22 first_value = make_value(groups.group(1))23 second_value = make_value(groups.group(2))24 result[groups.group(3)] = first_value & second_value25 commands.remove(command)26 else:27 continue28 elif "OR" in command:29 groups = re.search(r"([a-z0-9]+)\s+OR\s+([a-z0-9]+)\s+->\s+([a-z0-9]+)", command)30 if check_if_valid(groups.group(1)) and check_if_valid(groups.group(2)):31 first_value = make_value(groups.group(1))32 second_value = make_value(groups.group(2))33 result[groups.group(3)] = first_value | second_value34 commands.remove(command)35 else:36 continue37 elif "RSHIFT" in command:38 groups = re.search(r"([a-z0-9]+)\s+RSHIFT\s+([0-9]+)\s+->\s+([a-z0-9]+)", command)39 if check_if_valid(groups.group(1)):40 first_value = make_value(groups.group(1))41 second_value = make_value(groups.group(2))42 result[groups.group(3)] = first_value >> second_value43 commands.remove(command)44 else:45 continue46 elif "LSHIFT" in command:47 groups = re.search(r"([a-z0-9]+)\s+LSHIFT\s+([0-9]+)\s+->\s+([a-z0-9]+)", command)48 if check_if_valid(groups.group(1)):49 first_value = make_value(groups.group(1))50 second_value = make_value(groups.group(2))51 result[groups.group(3)] = first_value << second_value52 commands.remove(command)53 else:54 continue55 elif "NOT" in command:56 groups = re.search(r"NOT\s+([a-z0-9]+)\s+->\s+([a-z0-9]+)", command)57 if check_if_valid(groups.group(1)):58 first_value = make_value(groups.group(1))59 result[groups.group(2)] = 2**16 - 1 - first_value60 commands.remove(command)61 else:62 continue63 else:64 groups = re.search(r"([a-z0-9]+)\s+->\s+([a-z0-9]+)", command)65 if check_if_valid(groups.group(1)):66 first_value = make_value(groups.group(1))67 result[groups.group(2)] = first_value68 commands.remove(command)69 return result70result_list = real_action(commands_list)...

Full Screen

Full Screen

aoc2015-7_second_try.py

Source:aoc2015-7_second_try.py Github

copy

Full Screen

...6 commands_dict[groups.group(2)] = groups.group(1)7result = {}8def find_value(key, dictionary):9 global result10 def make_value(string):11 global result12 if string.isdigit():13 return int(string)14 elif string in result:15 return result[string]16 else:17 return find_value(string, dictionary)18 if key in result:19 return result[key]20 elif "OR" in dictionary[key]:21 groups = re.search(r"([a-z0-9]+)\s+OR\s+([a-z0-9]+)", dictionary[key])22 result[key] = make_value(groups.group(1)) | make_value(groups.group(2))23 return result[key]24 elif "AND" in dictionary[key]:25 groups = re.search(r"([a-z0-9]+)\s+AND\s+([a-z0-9]+)", dictionary[key])26 result[key] = make_value(groups.group(1)) & make_value(groups.group(2))27 return result[key]28 elif "RSHIFT" in dictionary[key]:29 groups = re.search(r"([a-z0-9]+)\s+RSHIFT\s+([a-z0-9]+)", dictionary[key])30 result[key] = make_value(groups.group(1)) >> make_value(groups.group(2))31 return result[key]32 elif "LSHIFT" in dictionary[key]:33 groups = re.search(r"([a-z0-9]+)\s+LSHIFT\s+([a-z0-9]+)", dictionary[key])34 result[key] = make_value(groups.group(1)) << make_value(groups.group(2))35 return result[key]36 elif "NOT" in dictionary[key]:37 groups = re.search(r"NOT\s+([a-z0-9]+)", dictionary[key])38 result[key] = 2**16 - 1 - make_value(groups.group(1))39 return result[key]40 else:41 result[key] = make_value(dictionary[key])42 return result[key]43print(find_value('a', commands_dict))44commands_dict['b'] = str(find_value('a', commands_dict))45result.clear()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful