How to use dump_file method in lisa

Best Python code snippet using lisa_python

test_phriky_units.py

Source:test_phriky_units.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4test_phriky_units5----------------------------------6Tests for `phriky_units` module.7"""8import sys9import unittest10from contextlib import contextmanager11from click.testing import CliRunner12from phriky_units import phriky_units13from phriky_units.cps_units_checker import CPSUnitsChecker14from phriky_units.unit_error_types import UnitErrorTypes15from phriky_units.unit_error import UnitError16# from phriky_units import cli17import os18class TestPhriky_units(unittest.TestCase):19 def setUp(self):20 pass21 def tearDown(self):22 pass23 def test_000_something(self):24 pass25 def test_function_return_0(self):26 cps_unit_checker = CPSUnitsChecker()27 cps_unit_checker.debug = False28 cps_unit_checker.debug_print_AST = False29 cps_unit_checker.debug_scope = False30 dump_file = './dump_files_for_tests/test_it_function_return_0.cpp.dump'31 if os.path.exists('./tests'):32 dump_file = dump_file[1:] #REMOVE LEADING .33 dump_file = './tests' + dump_file34 source_file = dump_file.replace('.dump','')35 cps_unit_checker.main_run_check(dump_file, source_file)36 units_for_f1 = []37 # TEST THAT UNITS ARE ASSIGNED TO FUNCTION38 for tw in cps_unit_checker.all_tree_walkers:39 so = tw.symbol_helper.function_dictionary['scopeObject']40 if so.function:41 if so.function.name == 'f1':42 units_for_f1 = so.function.return_units43 self.assertEquals(units_for_f1, [{'meter': 1}], 'Incorrect units returned for function: f1 . Expected [{\'meter\':1}], received %s' % units_for_f1)44 # TEST THAT UNITS ARE RECEIVED TO FUNCTION45 actual_units = None46 for s in cps_unit_checker.current_configuration.scopes:47 if s.className == 'main':48 if 'x' in s.var_ordered_dict:49 actual_units = s.var_ordered_dict['x'][12]['units']50 51 my_oracle = [{'meter': 1}]52 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))53 54 55 def test_function_return_1(self):56 ''' x SHOULD END UP M/S, but so far THERE'S NO MECHANISM FOR PASSING UNITS IN TO A FUNCTION57 '''58 cps_unit_checker = CPSUnitsChecker()59 dump_file = './dump_files_for_tests/test_it_function_return_1.cpp.dump'60 if os.path.exists('./tests'):61 dump_file = dump_file[1:] #REMOVE LEADING .62 dump_file = './tests' + dump_file63 source_file = dump_file.replace('.dump','')64 cps_unit_checker.main_run_check(dump_file, source_file)65 for tw in cps_unit_checker.all_tree_walkers:66 so = tw.symbol_helper.function_dictionary['scopeObject']67 if so.function:68 if so.function.name == 'f1':69 units_for_f1 = so.function.return_units70 def test_comparisons_1(self):71 cps_unit_checker = CPSUnitsChecker()72 cps_unit_checker.debug = False73 cps_unit_checker.debug_print_AST= False74 dump_file = './dump_files_for_tests/test_it_comparisons_1.cpp.dump'75 if os.path.exists('./tests'):76 dump_file = dump_file[1:] #REMOVE LEADING .77 dump_file = './tests' + dump_file78 source_file = './dump_files_for_tests/test_it_comparisons_1.cpp'79 cps_unit_checker.main_run_check(dump_file, source_file)80 e = cps_unit_checker.errors[0]81 # ORACLES82 token_left_units_oracle = [{'meter': 1}]83 token_right_units_oracle = [{'second': -1, 'meter': 1}]84 # ASSERTIONS85 self.assertEqual(e.token.str, '>')86 self.assertEqual(e.token_left.units, token_left_units_oracle)87 self.assertEqual(e.token_right.units, token_right_units_oracle)88 def test_logical_1(self):89 cps_unit_checker = CPSUnitsChecker()90 cps_unit_checker.debug = False91 cps_unit_checker.debug_print_AST = False92 dump_file = './dump_files_for_tests/test_it_logical_1.cpp.dump'93 if os.path.exists('./tests'):94 dump_file = dump_file[1:] #REMOVE LEADING .95 dump_file = './tests' + dump_file96 source_file = './dump_files_for_tests/test_it_logical_1.cpp'97 cps_unit_checker.main_run_check(dump_file, source_file)98 # TEST 199 e = cps_unit_checker.errors[0]100 # ORACLES101 token_right_units_oracle = [{'meter': 1}]102 # ASSERTIONS103 self.assertEqual(e.linenr, 13)104 self.assertEqual(e.token.str, '&&')105 self.assertEqual(e.token_right.units, token_right_units_oracle)106 # TEST 2107 e = cps_unit_checker.errors[1]108 # ORACLES109 token_left_units_oracle = [{'meter': 1}]110 # ASSERTIONS111 self.assertEqual(e.linenr, 18)112 self.assertEqual(e.token.str, '||')113 self.assertEqual(e.token_left.units, token_left_units_oracle)114 def test_abs_0(self):115 cps_unit_checker = CPSUnitsChecker()116 cps_unit_checker.debug = False117 #cps_unit_checker.debug_print_AST = False118 dump_file = './dump_files_for_tests/test_it_known_function_abs.cpp.dump'119 if os.path.exists('./tests'):120 dump_file = dump_file[1:] #REMOVE LEADING .121 dump_file = './tests' + dump_file122 source_file = dump_file.replace('.dump','')123 cps_unit_checker.main_run_check(dump_file, source_file)124 125 def test_abs_namespace_std_0(self):126 cps_unit_checker = CPSUnitsChecker()127 cps_unit_checker.debug = False128 #cps_unit_checker.debug_print_AST = False129 dump_file = './dump_files_for_tests/test_it_known_function_abs_namespace_std.cpp.dump'130 if os.path.exists('./tests'):131 dump_file = dump_file[1:] #REMOVE LEADING .132 dump_file = './tests' + dump_file133 source_file = dump_file.replace('.dump','')134 cps_unit_checker.main_run_check(dump_file, source_file)135 def test_abs_1(self):136 cps_unit_checker = CPSUnitsChecker()137 cps_unit_checker.debug = False138 #cps_unit_checker.debug_verbose = False139 cps_unit_checker.debug_print_AST = False140 dump_file = './dump_files_for_tests/test_it_known_function_abs_1.cpp.dump'141 if os.path.exists('./tests'):142 dump_file = dump_file[1:] #REMOVE LEADING .143 dump_file = './tests' + dump_file144 source_file = dump_file.replace('.dump','')145 cps_unit_checker.main_run_check(dump_file, source_file)146 var_name = 't'147 var_linenr = 9148 actual_units = None149 for s in cps_unit_checker.current_configuration.scopes:150 if s.className == 'main':151 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:152 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']153 my_oracle = [{'second': 1}]154 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))155 def test_abs_2(self):156 cps_unit_checker = CPSUnitsChecker()157 cps_unit_checker.debug = False158 cps_unit_checker.debug_print_AST = False159 dump_file = './dump_files_for_tests/test_it_known_function_abs_2.cpp.dump'160 if os.path.exists('./tests'):161 dump_file = dump_file[1:] #REMOVE LEADING .162 dump_file = './tests' + dump_file163 source_file = dump_file.replace('.dump','')164 cps_unit_checker.main_run_check(dump_file, source_file)165 var_name = 's'166 var_linenr =11 167 my_oracle = [{'meter': 1}]168 actual_units = None169 for s in cps_unit_checker.current_configuration.scopes:170 if s.className == 'main':171 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:172 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']173 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))174 def test_multiplication_assignment_in_multi_configurations_1(self):175 cps_unit_checker = CPSUnitsChecker()176 cps_unit_checker.debug = False177 #cps_unit_checker.debug_verbose = False178 cps_unit_checker.debug_print_AST = False179 dump_file = './dump_files_for_tests/test_it_multiplication_assignment_in_multi_configurations.cpp.dump'180 if os.path.exists('./tests'):181 dump_file = dump_file[1:] #REMOVE LEADING .182 dump_file = './tests' + dump_file183 source_file = dump_file.replace('.dump','')184 cps_unit_checker.main_run_check(dump_file, source_file)185 var_name = 'a_geometry_msgs_Accel.linear.x'186 var_linenr = 19 187 my_oracle = [{'second': -4, 'meter': 2}] 188 actual_units = None189 for s in cps_unit_checker.current_configuration.scopes:190 if s.className == 'main':191 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:192 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']193 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))194 def test_unit_propagation_by_multiplication_1(self):195 cps_unit_checker = CPSUnitsChecker()196 cps_unit_checker.debug = False197 #cps_unit_checker.debug_verbose = False198 #cps_unit_checker.debug_print_AST = False199 dump_file = './dump_files_for_tests/test_it_unit_propagation_by_multiplication_1.cpp.dump'200 if os.path.exists('./tests'):201 dump_file = dump_file[1:] #REMOVE LEADING .202 dump_file = './tests' + dump_file203 source_file = dump_file.replace('.dump','')204 cps_unit_checker.main_run_check(dump_file, source_file)205 for s in cps_unit_checker.current_configuration.scopes:206 if s.className == 'main':207 if 'f' in s.var_ordered_dict:208 actual_units = s.var_ordered_dict['f'][14]['units']209 my_oracle = [{'second': -4, 'meter': 2}]210 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))211 def test_unit_propagation_by_division_1(self):212 cps_unit_checker = CPSUnitsChecker()213 cps_unit_checker.debug = False214 #cps_unit_checker.debug_verbose = False215 #cps_unit_checker.debug_print_AST = False216 dump_file = './dump_files_for_tests/test_it_unit_propagation_by_division_1.cpp.dump'217 if os.path.exists('./tests'):218 dump_file = dump_file[1:] #REMOVE LEADING .219 dump_file = './tests' + dump_file220 source_file = dump_file.replace('.dump','')221 cps_unit_checker.main_run_check(dump_file, source_file)222 actual_units = None223 for s in cps_unit_checker.current_configuration.scopes:224 if s.className == 'main':225 if 'f' in s.var_ordered_dict:226 actual_units = s.var_ordered_dict['f'][14]['units']227 my_oracle = None228 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))229 def test_mulitple_units_assigned(self):230 cps_unit_checker = CPSUnitsChecker()231 cps_unit_checker.debug = False232 #cps_unit_checker.debug_verbose = False233 cps_unit_checker.debug_print_AST = False234 dump_file = './dump_files_for_tests/test_it_multiple_units_assigned_1.cpp.dump'235 if os.path.exists('./tests'):236 dump_file = dump_file[1:] #REMOVE LEADING .237 dump_file = './tests' + dump_file238 source_file = dump_file.replace('.dump','')239 cps_unit_checker.main_run_check(dump_file, source_file)240 expected_errors = ["test_it_multiple_units_assigned_1.cpp : 11 MULTIPLE UNITS BY ASSIGNMENT: [{'second': -1, 'meter': 1}, {'second': -2, 'meter': 2}]"]241 # self.assertListEqual([e['error_msg'] for e in cps_unit_checker.errors], expected_errors)242 # TEST QUANTITY OF ERRORS243 self.assertEqual(1, len(cps_unit_checker.errors))244 # TEST TyPE OF ERROR245 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)246 # TEST VALUE OF ERROR247 var_name = 'a_geometry_msgs_Accel.linear.x'248 var_linenr =11249 my_oracle = [{'second': -2, 'meter': 1}, {'second': -4, 'meter': 2}]250 actual_units = None251 for s in cps_unit_checker.current_configuration.scopes:252 if s.className == 'main':253 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:254 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']255 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))256 def test_known_functions_sqrt_1(self):257 cps_unit_checker = CPSUnitsChecker()258 cps_unit_checker.debug = False259 #cps_unit_checker.debug_verbose = False260 cps_unit_checker.debug_print_AST = False261 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_1.cpp.dump'262 if os.path.exists('./tests'):263 dump_file = dump_file[1:] #REMOVE LEADING .264 dump_file = './tests' + dump_file265 source_file = dump_file.replace('.dump','')266 cps_unit_checker.main_run_check(dump_file, source_file)267 for s in cps_unit_checker.current_configuration.scopes:268 if s.className == 'main':269 if 'x' in s.var_ordered_dict:270 actual_units = s.var_ordered_dict['x'][12]['units']271 my_oracle = [{'meter': 1}]272 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))273 def test_known_functions_sqrt_2(self):274 cps_unit_checker = CPSUnitsChecker()275 cps_unit_checker.debug = False276 #cps_unit_checker.debug_verbose = False277 cps_unit_checker.debug_print_AST = False278 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_2.cpp.dump'279 if os.path.exists('./tests'):280 dump_file = dump_file[1:] #REMOVE LEADING .281 dump_file = './tests' + dump_file282 source_file = dump_file.replace('.dump','')283 cps_unit_checker.main_run_check(dump_file, source_file)284 for s in cps_unit_checker.current_configuration.scopes:285 if s.className == 'main':286 if 'x' in s.var_ordered_dict:287 actual_units = s.var_ordered_dict['x'][12]['units']288 my_oracle = [{'second': -1, 'meter': 1}]289 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))290 def test_known_functions_sqrt_3(self):291 cps_unit_checker = CPSUnitsChecker()292 cps_unit_checker.debug = False293 #cps_unit_checker.debug_verbose = False294 cps_unit_checker.debug_print_AST = False295 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_3.cpp.dump'296 if os.path.exists('./tests'):297 dump_file = dump_file[1:] #REMOVE LEADING .298 dump_file = './tests' + dump_file299 source_file = dump_file.replace('.dump','')300 cps_unit_checker.main_run_check(dump_file, source_file)301 actual_units = None302 for s in cps_unit_checker.current_configuration.scopes:303 if s.className == 'main':304 if 'x' in s.var_ordered_dict:305 actual_units = s.var_ordered_dict['x'][12]['units']306 my_oracle = None307 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))308 def test_known_functions_sqrt_4(self):309 cps_unit_checker = CPSUnitsChecker()310 cps_unit_checker.debug = False311 #cps_unit_checker.debug_verbose = False312 cps_unit_checker.debug_print_AST = False313 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_4.cpp.dump'314 if os.path.exists('./tests'):315 dump_file = dump_file[1:] #REMOVE LEADING .316 dump_file = './tests' + dump_file317 source_file = dump_file.replace('.dump','')318 cps_unit_checker.main_run_check(dump_file, source_file)319 for s in cps_unit_checker.current_configuration.scopes:320 if s.className == 'main':321 if 'x' in s.var_ordered_dict:322 actual_units = s.var_ordered_dict['x'][14]['units']323 my_oracle = [{'meter': 1}]324 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))325 def test_known_functions_sqrt_5(self):326 cps_unit_checker = CPSUnitsChecker()327 cps_unit_checker.debug = False328 #cps_unit_checker.debug_verbose = False329 cps_unit_checker.debug_print_AST = False330 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_5.cpp.dump'331 if os.path.exists('./tests'):332 dump_file = dump_file[1:] #REMOVE LEADING .333 dump_file = './tests' + dump_file334 source_file = dump_file.replace('.dump','')335 cps_unit_checker.main_run_check(dump_file, source_file)336 for s in cps_unit_checker.current_configuration.scopes:337 if s.className == 'main':338 if 'x' in s.var_ordered_dict:339 actual_units = s.var_ordered_dict['x'][14]['units']340 my_oracle = [{'meter': 1}]341 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))342 def test_known_functions_sqrt_half_units(self):343 cps_unit_checker = CPSUnitsChecker()344 cps_unit_checker.debug = False345 #cps_unit_checker.debug_verbose = False346 cps_unit_checker.debug_print_AST = False347 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_half_units.cpp.dump'348 if os.path.exists('./tests'):349 dump_file = dump_file[1:] #REMOVE LEADING .350 dump_file = './tests' + dump_file351 source_file = dump_file.replace('.dump','')352 cps_unit_checker.main_run_check(dump_file, source_file)353 for s in cps_unit_checker.current_configuration.scopes:354 if s.className == 'main':355 if 'x' in s.var_ordered_dict:356 actual_units = s.var_ordered_dict['x'][11]['units']357 my_oracle = [{'meter': 0.5}]358 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))359 def test_known_functions_atan2_1(self):360 cps_unit_checker = CPSUnitsChecker()361 cps_unit_checker.debug = False362 cps_unit_checker.debug_verbose = False363 cps_unit_checker.debug_print_AST = False364 dump_file = './dump_files_for_tests/test_it_known_function_atan2_1.cpp.dump'365 if os.path.exists('./tests'):366 dump_file = dump_file[1:] #REMOVE LEADING .367 dump_file = './tests' + dump_file368 source_file = dump_file.replace('.dump','')369 cps_unit_checker.main_run_check(dump_file, source_file)370 for s in cps_unit_checker.current_configuration.scopes:371 if s.className == 'main':372 if 'f' in s.var_ordered_dict:373 actual_units = s.var_ordered_dict['f'][7]['units']374 my_oracle = [{'radian': 1}]375 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))376 def test_known_functions_atan2_2(self):377 cps_unit_checker = CPSUnitsChecker()378 cps_unit_checker.debug = False379 #cps_unit_checker.debug_verbose = False380 cps_unit_checker.debug_print_AST = False381 dump_file = './dump_files_for_tests/test_it_known_function_atan2_2.cpp.dump'382 if os.path.exists('./tests'):383 dump_file = dump_file[1:] #REMOVE LEADING .384 dump_file = './tests' + dump_file385 source_file = dump_file.replace('.dump','')386 cps_unit_checker.main_run_check(dump_file, source_file)387 for s in cps_unit_checker.current_configuration.scopes:388 if s.className == 'main':389 if 'f' in s.var_ordered_dict:390 actual_units = s.var_ordered_dict['f'][8]['units']391 my_oracle = [{'radian': 1}]392 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))393 def test_toSec(self):394 cps_unit_checker = CPSUnitsChecker()395 cps_unit_checker.debug = False396 cps_unit_checker.debug_print_AST = False397 dump_file = './dump_files_for_tests/test_it_toSec_0.cpp.dump'398 if os.path.exists('./tests'):399 dump_file = dump_file[1:] #REMOVE LEADING .400 dump_file = './tests' + dump_file401 source_file = dump_file.replace('.dump','')402 cps_unit_checker.main_run_check(dump_file, source_file)403 for s in cps_unit_checker.current_configuration.scopes:404 if s.className == 'main':405 if 'duration' in s.var_ordered_dict:406 actual_units = s.var_ordered_dict['duration'][7]['units']407 my_oracle = [{'second': 1}]408 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))409 for s in cps_unit_checker.current_configuration.scopes:410 if s.className == 'main':411 if 'second' in s.var_ordered_dict:412 actual_units = s.var_ordered_dict['second'][9]['units']413 my_oracle = [{'second': 1}]414 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))415 def test_float_1(self):416 cps_unit_checker = CPSUnitsChecker()417 cps_unit_checker.debug = False418 cps_unit_checker.debug_print_AST = False419 dump_file = './dump_files_for_tests/test_it_float_1.cpp.dump'420 if os.path.exists('./tests'):421 dump_file = dump_file[1:] #REMOVE LEADING .422 dump_file = './tests' + dump_file423 source_file = dump_file.replace('.dump','')424 cps_unit_checker.main_run_check(dump_file, source_file)425 actual_units = None426 for s in cps_unit_checker.current_configuration.scopes:427 if s.className == 'main':428 if 'f' in s.var_ordered_dict and 11 in s.var_ordered_dict['f']:429 actual_units = s.var_ordered_dict['f'][11]['units']430 my_oracle = [{'second': -1, 'meter': 1}]431 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))432 def test_float_2(self):433 cps_unit_checker = CPSUnitsChecker()434 cps_unit_checker.debug = False435 cps_unit_checker.debug_print_AST = False436 dump_file = './dump_files_for_tests/test_it_float_2.cpp.dump'437 if os.path.exists('./tests'):438 dump_file = dump_file[1:] #REMOVE LEADING .439 dump_file = './tests' + dump_file440 source_file = dump_file.replace('.dump','')441 cps_unit_checker.main_run_check(dump_file, source_file)442 actual_units = None443 for s in cps_unit_checker.current_configuration.scopes:444 if s.className == 'main':445 if 'f' in s.var_ordered_dict and 11 in s.var_ordered_dict['f']:446 actual_units = s.var_ordered_dict['f'][11]['units']447 my_oracle = [{'second': -1, 'meter': 1}]448 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))449 def test_float_3(self):450 cps_unit_checker = CPSUnitsChecker()451 cps_unit_checker.debug = False452 cps_unit_checker.debug_print_AST = False453 dump_file = './dump_files_for_tests/test_it_float_3.cpp.dump'454 if os.path.exists('./tests'):455 dump_file = dump_file[1:] #REMOVE LEADING .456 dump_file = './tests' + dump_file457 source_file = dump_file.replace('.dump','')458 cps_unit_checker.main_run_check(dump_file, source_file)459 for s in cps_unit_checker.current_configuration.scopes:460 if s.className == 'main':461 if 'f' in s.var_ordered_dict:462 actual_units = s.var_ordered_dict['f'][12]['units']463 my_oracle = [{'second': -1, 'meter': 1}]464 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))465 def test_float_4(self):466 cps_unit_checker = CPSUnitsChecker()467 cps_unit_checker.debug = False468 cps_unit_checker.debug_print_AST = False469 dump_file = './dump_files_for_tests/test_it_float_4.cpp.dump'470 if os.path.exists('./tests'):471 dump_file = dump_file[1:] #REMOVE LEADING .472 dump_file = './tests' + dump_file473 source_file = dump_file.replace('.dump','')474 cps_unit_checker.main_run_check(dump_file, source_file)475 for s in cps_unit_checker.current_configuration.scopes:476 if s.className == 'main':477 if 'f' in s.var_ordered_dict:478 actual_units = s.var_ordered_dict['f'][13]['units']479 my_oracle = [{'second': -1, 'meter': 1}]480 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))481 def test_float_5(self):482 cps_unit_checker = CPSUnitsChecker()483 cps_unit_checker.debug = False484 cps_unit_checker.debug_print_AST = False485 dump_file = './dump_files_for_tests/test_it_float_5.cpp.dump'486 if os.path.exists('./tests'):487 dump_file = dump_file[1:] #REMOVE LEADING .488 dump_file = './tests' + dump_file489 source_file = dump_file.replace('.dump','')490 cps_unit_checker.main_run_check(dump_file, source_file)491 for s in cps_unit_checker.current_configuration.scopes:492 if s.className == 'main':493 if 'f' in s.var_ordered_dict:494 actual_units = s.var_ordered_dict['f'][11]['units']495 my_oracle = [{'second': -1, 'meter': 1}]496 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))497 def test_pow_1(self):498 cps_unit_checker = CPSUnitsChecker()499 cps_unit_checker.debug = False500 cps_unit_checker.debug_print_AST = False501 dump_file = './dump_files_for_tests/test_it_known_function_pow_1.cpp.dump'502 if os.path.exists('./tests'):503 dump_file = dump_file[1:] #REMOVE LEADING .504 dump_file = './tests' + dump_file505 source_file = dump_file.replace('.dump','')506 cps_unit_checker.main_run_check(dump_file, source_file)507 var_name = 'f'508 var_linenr =10 509 my_oracle = [{'meter': 4}]510 actual_units = None511 for s in cps_unit_checker.current_configuration.scopes:512 if s.className == 'main':513 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:514 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']515 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))516 def test_pow_2(self):517 cps_unit_checker = CPSUnitsChecker()518 cps_unit_checker.debug = False519 cps_unit_checker.debug_print_AST = False520 dump_file = './dump_files_for_tests/test_it_known_function_pow_2.cpp.dump'521 if os.path.exists('./tests'):522 dump_file = dump_file[1:] #REMOVE LEADING .523 dump_file = './tests' + dump_file524 source_file = dump_file.replace('.dump','')525 cps_unit_checker.main_run_check(dump_file, source_file)526 var_name = 'f'527 var_linenr = 11 528 my_oracle = [{'meter': 4}]529 actual_units = None530 for s in cps_unit_checker.current_configuration.scopes:531 if s.className == 'main':532 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:533 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']534 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))535 def test_pow_3(self):536 cps_unit_checker = CPSUnitsChecker()537 cps_unit_checker.debug = False538 cps_unit_checker.debug_print_AST = False539 dump_file = './dump_files_for_tests/test_it_known_function_pow_3.cpp.dump'540 if os.path.exists('./tests'):541 dump_file = dump_file[1:] #REMOVE LEADING .542 dump_file = './tests' + dump_file543 source_file = dump_file.replace('.dump','')544 cps_unit_checker.main_run_check(dump_file, source_file)545 var_name = 'f'546 var_linenr = 10547 my_oracle = [{'meter': 4}]548 actual_units = None549 for s in cps_unit_checker.current_configuration.scopes:550 if s.className == 'main':551 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:552 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']553 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:%s Expected: %s received %s' % (var_name, my_oracle, actual_units))554 def test_floor_1(self):555 cps_unit_checker = CPSUnitsChecker()556 cps_unit_checker.debug = False557 cps_unit_checker.debug_print_AST = False558 dump_file = './dump_files_for_tests/test_it_known_function_floor_1.cpp.dump'559 if os.path.exists('./tests'):560 dump_file = dump_file[1:] #REMOVE LEADING .561 dump_file = './tests' + dump_file562 source_file = dump_file.replace('.dump','')563 cps_unit_checker.main_run_check(dump_file, source_file)564 var_name = 's'565 var_linenr = 8 566 my_oracle = [{'meter': 1, 'second':-1}]567 actual_units = None568 for s in cps_unit_checker.current_configuration.scopes:569 if s.className == 'main':570 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:571 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']572 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))573 def test_ceil_1(self):574 cps_unit_checker = CPSUnitsChecker()575 cps_unit_checker.debug = False576 cps_unit_checker.debug_print_AST = False577 dump_file = './dump_files_for_tests/test_it_known_function_ceil_1.cpp.dump'578 if os.path.exists('./tests'):579 dump_file = dump_file[1:] #REMOVE LEADING .580 dump_file = './tests' + dump_file581 source_file = dump_file.replace('.dump','')582 cps_unit_checker.main_run_check(dump_file, source_file)583 var_name = 's'584 var_linenr = 8 585 my_oracle = [{'meter': 1, 'second':-1}]586 actual_units = None587 for s in cps_unit_checker.current_configuration.scopes:588 if s.className == 'main':589 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:590 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']591 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))592 def test_acos_1(self):593 cps_unit_checker = CPSUnitsChecker()594 cps_unit_checker.debug = False595 cps_unit_checker.debug_print_AST = False596 dump_file = './dump_files_for_tests/test_it_known_function_acos_1.cpp.dump'597 if os.path.exists('./tests'):598 dump_file = dump_file[1:] #REMOVE LEADING .599 dump_file = './tests' + dump_file600 source_file = dump_file.replace('.dump','')601 cps_unit_checker.main_run_check(dump_file, source_file)602 var_name = 'f'603 var_linenr = 7 604 my_oracle = [{'radian': 1}]605 actual_units = None606 for s in cps_unit_checker.current_configuration.scopes:607 if s.className == 'main':608 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:609 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']610 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))611 def test_asin_1(self):612 cps_unit_checker = CPSUnitsChecker()613 cps_unit_checker.debug = False614 cps_unit_checker.debug_print_AST = False615 dump_file = './dump_files_for_tests/test_it_known_function_asin_1.cpp.dump'616 if os.path.exists('./tests'):617 dump_file = dump_file[1:] #REMOVE LEADING .618 dump_file = './tests' + dump_file619 source_file = dump_file.replace('.dump','')620 cps_unit_checker.main_run_check(dump_file, source_file)621 var_name = 'f'622 var_linenr = 7 623 my_oracle = [{'radian': 1}]624 actual_units = None625 for s in cps_unit_checker.current_configuration.scopes:626 if s.className == 'main':627 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:628 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']629 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))630 def test_atan_1(self):631 cps_unit_checker = CPSUnitsChecker()632 cps_unit_checker.debug = False633 cps_unit_checker.debug_print_AST = False634 dump_file = './dump_files_for_tests/test_it_known_function_atan_1.cpp.dump'635 if os.path.exists('./tests'):636 dump_file = dump_file[1:] #REMOVE LEADING .637 dump_file = './tests' + dump_file638 source_file = dump_file.replace('.dump','')639 cps_unit_checker.main_run_check(dump_file, source_file)640 var_name = 'f'641 var_linenr = 7 642 my_oracle = [{'radian': 1}]643 actual_units = None644 for s in cps_unit_checker.current_configuration.scopes:645 if s.className == 'main':646 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:647 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']648 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))649 def test_ternary_1(self):650 cps_unit_checker = CPSUnitsChecker()651 cps_unit_checker.debug = False652 cps_unit_checker.debug_print_AST = False653 dump_file = './dump_files_for_tests/test_it_ternary_1.cpp.dump'654 if os.path.exists('./tests'):655 dump_file = dump_file[1:] #REMOVE LEADING .656 dump_file = './tests' + dump_file657 source_file = dump_file.replace('.dump','')658 cps_unit_checker.main_run_check(dump_file, source_file)659 var_name = 'f'660 var_linenr = 9 661 my_oracle = [{'second': -1, 'meter': 1}, {'second': -1}]662 actual_units = None663 for s in cps_unit_checker.current_configuration.scopes:664 if s.className == 'main':665 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:666 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']667 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))668 def test_function_args_1(self):669 cps_unit_checker = CPSUnitsChecker()670 cps_unit_checker.debug = False671 cps_unit_checker.debug_print_AST = False672 dump_file = './dump_files_for_tests/test_it_function_args_1.cpp.dump'673 if os.path.exists('./tests'):674 dump_file = dump_file[1:] #REMOVE LEADING .675 dump_file = './tests' + dump_file676 source_file = dump_file.replace('.dump','')677 cps_unit_checker.main_run_check(dump_file, source_file)678 # actual_units = None679 f = cps_unit_checker.current_configuration.functions[0].arg_units680 self.assertEqual(f[0][0]['linenr'], 13)681 self.assertEqual(f[0][0]['units'], [{'meter': 1}])682 def test_function_args_2(self):683 cps_unit_checker = CPSUnitsChecker()684 cps_unit_checker.debug = False685 cps_unit_checker.debug_print_AST = False686 dump_file = './dump_files_for_tests/test_it_function_args_2.cpp.dump'687 if os.path.exists('./tests'):688 dump_file = dump_file[1:] #REMOVE LEADING .689 dump_file = './tests' + dump_file690 source_file = dump_file.replace('.dump','')691 cps_unit_checker.main_run_check(dump_file, source_file)692 for f in cps_unit_checker.current_configuration.functions[0].arg_units:693 self.assertEqual(f[0]['linenr'], 13)694 self.assertEqual(f[0]['units'], [{'meter': 1}])695 def test_function_args_3(self):696 cps_unit_checker = CPSUnitsChecker()697 cps_unit_checker.debug = False698 cps_unit_checker.debug_print_AST = False699 dump_file = './dump_files_for_tests/test_it_function_args_3.cpp.dump'700 if os.path.exists('./tests'):701 dump_file = dump_file[1:] #REMOVE LEADING .702 dump_file = './tests' + dump_file703 source_file = dump_file.replace('.dump','')704 cps_unit_checker.main_run_check(dump_file, source_file)705 my_oracle_1 = 4706 my_oracle_2 = [{'meter': 1}]707 actual_units = None708 all_units_list = cps_unit_checker.current_configuration.functions[0].arg_units709 self.assertEqual(len(all_units_list), my_oracle_1)710 for u in all_units_list:711 self.assertEqual(u[0]['units'], my_oracle_2)712 def test_function_args_4(self):713 cps_unit_checker = CPSUnitsChecker()714 cps_unit_checker.debug = False715 cps_unit_checker.debug_print_AST = False716 dump_file = './dump_files_for_tests/test_it_function_args_4.cpp.dump'717 if os.path.exists('./tests'):718 dump_file = dump_file[1:] #REMOVE LEADING .719 dump_file = './tests' + dump_file720 source_file = dump_file.replace('.dump','')721 cps_unit_checker.main_run_check(dump_file, source_file)722 my_oracle = [{'meter': 1}]723 actual_units = None724 for f in cps_unit_checker.current_configuration.functions:725 for arg_u in f.arg_units:726 for arg_use_on_line in arg_u:727 self.assertEqual(arg_use_on_line['units'], my_oracle)728 def test_function_args_5(self):729 cps_unit_checker = CPSUnitsChecker()730 cps_unit_checker.debug = False731 cps_unit_checker.debug_print_AST = False732 dump_file = './dump_files_for_tests/test_it_function_args_5.cpp.dump'733 if os.path.exists('./tests'):734 dump_file = dump_file[1:] #REMOVE LEADING .735 dump_file = './tests' + dump_file736 source_file = dump_file.replace('.dump','')737 cps_unit_checker.main_run_check(dump_file, source_file)738 my_oracle_1 = [{'meter': 1}]739 my_oracle_2 = 15740 f = cps_unit_checker.current_configuration.functions[0]741 self.assertEqual(f.arg_units[0][0]['units'], my_oracle_1)742 self.assertEqual(f.arg_units[0][0]['linenr'], my_oracle_2)743 def test_division_1(self):744 cps_unit_checker = CPSUnitsChecker()745 cps_unit_checker.debug = False746 cps_unit_checker.debug_print_AST = False747 dump_file = './dump_files_for_tests/test_it_division_1.cpp.dump'748 if os.path.exists('./tests'):749 dump_file = dump_file[1:] #REMOVE LEADING .750 dump_file = './tests' + dump_file751 source_file = dump_file.replace('.dump','')752 cps_unit_checker.main_run_check(dump_file, source_file)753 var_name = 'x'754 var_linenr = 9 755 my_oracle = [{'meter': 1}]756 actual_units = None757 for s in cps_unit_checker.current_configuration.scopes:758 if s.className == 'main':759 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:760 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']761 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))762 def test_division_2(self):763 cps_unit_checker = CPSUnitsChecker()764 cps_unit_checker.debug = False765 cps_unit_checker.debug_print_AST = False766 dump_file = './dump_files_for_tests/test_it_division_2.cpp.dump'767 if os.path.exists('./tests'):768 dump_file = dump_file[1:] #REMOVE LEADING .769 dump_file = './tests' + dump_file770 source_file = dump_file.replace('.dump','')771 cps_unit_checker.main_run_check(dump_file, source_file)772 var_name = 'x'773 var_linenr = 9 774 my_oracle = [{'meter': 1}]775 actual_units = None776 for s in cps_unit_checker.current_configuration.scopes:777 if s.className == 'main':778 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:779 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']780 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))781 def test_division_3(self):782 cps_unit_checker = CPSUnitsChecker()783 cps_unit_checker.debug = False784 cps_unit_checker.debug_print_AST = False785 dump_file = './dump_files_for_tests/test_it_division_3.cpp.dump'786 if os.path.exists('./tests'):787 dump_file = dump_file[1:] #REMOVE LEADING .788 dump_file = './tests' + dump_file789 source_file = dump_file.replace('.dump','')790 cps_unit_checker.main_run_check(dump_file, source_file)791 var_name = 'x'792 var_linenr = 9 793 my_oracle = [{'second': 2, 'meter': 1}]794 actual_units = None795 for s in cps_unit_checker.current_configuration.scopes:796 if s.className == 'main':797 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:798 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']799 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))800 def test_division_4(self):801 cps_unit_checker = CPSUnitsChecker()802 cps_unit_checker.debug = False803 cps_unit_checker.debug_print_AST = False804 dump_file = './dump_files_for_tests/test_it_division_4.cpp.dump'805 if os.path.exists('./tests'):806 dump_file = dump_file[1:] #REMOVE LEADING .807 dump_file = './tests' + dump_file808 source_file = dump_file.replace('.dump','')809 cps_unit_checker.main_run_check(dump_file, source_file)810 var_name = 'x'811 var_linenr =10812 my_oracle = [{'second': 2}]813 actual_units = None814 for s in cps_unit_checker.current_configuration.scopes:815 if s.className == 'main':816 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:817 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']818 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))819 def test_logical_2(self):820 cps_unit_checker = CPSUnitsChecker()821 cps_unit_checker.debug = False822 cps_unit_checker.debug_print_AST = False823 dump_file = './dump_files_for_tests/test_it_logical_2.cpp.dump'824 if os.path.exists('./tests'):825 dump_file = dump_file[1:] #REMOVE LEADING .826 dump_file = './tests' + dump_file827 source_file = dump_file.replace('.dump','')828 cps_unit_checker.main_run_check(dump_file, source_file)829 self.assertEqual(0, len(cps_unit_checker.errors))830 def test_error_type_1(self):831 cps_unit_checker = CPSUnitsChecker()832 cps_unit_checker.debug = False833 cps_unit_checker.debug_print_AST = False834 dump_file = './dump_files_for_tests/test_it_error_return_type_1.cpp.dump'835 if os.path.exists('./tests'):836 dump_file = dump_file[1:] #REMOVE LEADING .837 dump_file = './tests' + dump_file838 source_file = dump_file.replace('.dump','')839 cps_unit_checker.current_file_under_analysis = dump_file840 cps_unit_checker.main_run_check(dump_file, source_file)841 self.assertEqual(1, len(cps_unit_checker.errors))842 def test_laser_scan_range_size_1(self):843 cps_unit_checker = CPSUnitsChecker()844 cps_unit_checker.debug = False845 cps_unit_checker.debug_print_AST = False846 dump_file = './dump_files_for_tests/test_it_laser_scan_range_count_1.cpp.dump'847 if os.path.exists('./tests'):848 dump_file = dump_file[1:] #REMOVE LEADING .849 dump_file = './tests' + dump_file850 source_file = dump_file.replace('.dump','')851 cps_unit_checker.main_run_check(dump_file, source_file)852 var_name = 'x'853 var_linenr = 7854 my_oracle = None855 actual_units = None856 for s in cps_unit_checker.current_configuration.scopes:857 if s.className == 'main':858 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:859 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']860 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))861 self.assertEqual(0, len(cps_unit_checker.errors))862 def test_laser_scan_range_size_2(self):863 cps_unit_checker = CPSUnitsChecker()864 cps_unit_checker.debug = False865 cps_unit_checker.debug_print_AST = False866 dump_file = './dump_files_for_tests/test_it_laser_scan_range_count_2.cpp.dump'867 if os.path.exists('./tests'):868 dump_file = dump_file[1:] #REMOVE LEADING .869 dump_file = './tests' + dump_file870 source_file = dump_file.replace('.dump','')871 cps_unit_checker.main_run_check(dump_file, source_file)872 var_name = 'x'873 var_linenr = 7874 my_oracle = [{'meter':1}]875 actual_units = None876 for s in cps_unit_checker.current_configuration.scopes:877 if s.className == 'main':878 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:879 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']880 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))881 def test_ros_duration_isZero_1(self):882 cps_unit_checker = CPSUnitsChecker()883 cps_unit_checker.debug = False884 cps_unit_checker.debug_print_AST = False885 dump_file = './dump_files_for_tests/test_it_ros_duration_isZero_1.cpp.dump'886 if os.path.exists('./tests'):887 dump_file = dump_file[1:] #REMOVE LEADING .888 dump_file = './tests' + dump_file889 source_file = dump_file.replace('.dump','')890 cps_unit_checker.main_run_check(dump_file, source_file)891 var_name = 't'892 var_linenr = 6893 my_oracle = None894 actual_units = None895 for s in cps_unit_checker.current_configuration.scopes:896 if s.className == 'main':897 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:898 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']899 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))900 def test_ros_duration_isZero_2(self):901 cps_unit_checker = CPSUnitsChecker()902 cps_unit_checker.debug = False903 cps_unit_checker.debug_print_AST = False904 dump_file = './dump_files_for_tests/test_it_ros_duration_isZero_2.cpp.dump'905 if os.path.exists('./tests'):906 dump_file = dump_file[1:] #REMOVE LEADING .907 dump_file = './tests' + dump_file908 source_file = dump_file.replace('.dump','')909 cps_unit_checker.main_run_check(dump_file, source_file)910 var_name = 't'911 var_linenr = 6912 my_oracle = [{'second':1}]913 actual_units = None914 for s in cps_unit_checker.current_configuration.scopes:915 if s.className == 'main':916 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:917 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']918 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))919 # def test_ros_header_include_1(self):920 # cps_unit_checker = CPSUnitsChecker()921 # cps_unit_checker.debug = False922 # cps_unit_checker.debug_print_AST = False923 # dump_file = './dump_files_for_tests/src/test_it_header_include_1.cpp.dump'924 # if os.path.exists('./tests'):925 # dump_file = dump_file[1:] #REMOVE LEADING .926 # dump_file = './tests' + dump_file927 # source_file = dump_file.replace('.dump','')928 # cps_unit_checker.main_run_check(dump_file, source_file)929 # self.assertEqual(2, len(cps_unit_checker.errors))930 # def test_ros_header_include_2(self):931 # cps_unit_checker = CPSUnitsChecker()932 # cps_unit_checker.debug = False933 # cps_unit_checker.debug_print_AST = False934 # dump_file = './dump_files_for_tests/src/test_it_header_include_2.cpp.dump'935 # if os.path.exists('./tests'):936 # dump_file = dump_file[1:] #REMOVE LEADING .937 # dump_file = './tests' + dump_file938 # source_file = dump_file.replace('.dump','')939 # cps_unit_checker.main_run_check(dump_file, source_file)940 # self.assertEqual(3, len(cps_unit_checker.errors))941 # # WEAKER - SOMETHING STOCASTIC IS HAPPENING942 # e = cps_unit_checker.errors[0]943 # self.assertEqual(7, e.linenr)944 # self.assertEqual('./dump_files_for_tests/src/../include/test_it_header_include_2.h', e.get_file_URI_where_error_occured())945 # e = cps_unit_checker.errors[1]946 # self.assertEqual(5, e.linenr)947 # self.assertEqual('./dump_files_for_tests/src/test_it_header_include_2.cpp', e.get_file_URI_where_error_occured())948 # DON'T ASSIGN UNITS TO ARRAYS WHEN array.empty() IS CALLED 949 def test_laser_range_empty_1(self):950 cps_unit_checker = CPSUnitsChecker()951 cps_unit_checker.debug = False952 cps_unit_checker.debug_print_AST = False953 dump_file = './dump_files_for_tests/test_it_range_empty_1.cpp.dump'954 if os.path.exists('./tests'):955 dump_file = dump_file[1:] #REMOVE LEADING .956 dump_file = './tests' + dump_file957 source_file = dump_file.replace('.dump','')958 cps_unit_checker.main_run_check(dump_file, source_file)959 self.assertEqual(0, len(cps_unit_checker.errors))960 # DON'T ASSIGN UNITS TO ARRAYS WHEN time.isZero() IS CALLED 961 def test_ros_isZero_3(self):962 cps_unit_checker = CPSUnitsChecker()963 cps_unit_checker.debug = False964 cps_unit_checker.debug_print_AST = False965 dump_file = './dump_files_for_tests/test_it_ros_isZero_3.cpp.dump'966 if os.path.exists('./tests'):967 dump_file = dump_file[1:] #REMOVE LEADING .968 dump_file = './tests' + dump_file969 source_file = dump_file.replace('.dump','')970 cps_unit_checker.main_run_check(dump_file, source_file)971 self.assertEqual(0, len(cps_unit_checker.errors))972 # DON'T ASSIGN UNITS DURING x = y = z = 0973 def test_multiple_initialization_1(self):974 cps_unit_checker = CPSUnitsChecker()975 cps_unit_checker.debug = False976 cps_unit_checker.debug_print_AST = False977 dump_file = './dump_files_for_tests/test_it_multiple_initialization.cpp.dump'978 if os.path.exists('./tests'):979 dump_file = dump_file[1:] #REMOVE LEADING .980 dump_file = './tests' + dump_file981 source_file = dump_file.replace('.dump','')982 cps_unit_checker.main_run_check(dump_file, source_file)983 self.assertEqual(0, len(cps_unit_checker.errors))984 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (INT)985 def test_it_multiplication_with_constant_1(self):986 cps_unit_checker = CPSUnitsChecker()987 cps_unit_checker.debug = False988 cps_unit_checker.debug_print_AST = False989 dump_file = './dump_files_for_tests/test_it_multiplication_with_constant_1.cpp.dump'990 if os.path.exists('./tests'):991 dump_file = dump_file[1:] #REMOVE LEADING .992 dump_file = './tests' + dump_file993 source_file = dump_file.replace('.dump','')994 cps_unit_checker.main_run_check(dump_file, source_file)995 # self.assertEqual(0, len(cps_unit_checker.errors))996 var_name = 'f'997 var_linenr = 9998 my_oracle = [{'second':-1}]999 actual_units = None1000 is_unit_propagation_based_on_constants = False1001 for s in cps_unit_checker.current_configuration.scopes:1002 if s.className == 'main':1003 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1004 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1005 is_unit_propagation_based_on_constants = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_constants']1006 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1007 self.assertTrue(is_unit_propagation_based_on_constants, 'Unit inference should be weakened by constant interaction, but is still strong.')1008 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (FLOAT)1009 def test_it_multiplication_with_constant_2(self):1010 cps_unit_checker = CPSUnitsChecker()1011 cps_unit_checker.debug = False1012 cps_unit_checker.debug_print_AST = False1013 dump_file = './dump_files_for_tests/test_it_multiplication_with_constant_2.cpp.dump'1014 if os.path.exists('./tests'):1015 dump_file = dump_file[1:] #REMOVE LEADING .1016 dump_file = './tests' + dump_file1017 source_file = dump_file.replace('.dump','')1018 cps_unit_checker.main_run_check(dump_file, source_file)1019 # self.assertEqual(0, len(cps_unit_checker.errors))1020 var_name = 'f'1021 var_linenr = 91022 my_oracle = [{'second':-1}]1023 actual_units = None1024 is_unit_propagation_based_on_constants = False1025 for s in cps_unit_checker.current_configuration.scopes:1026 if s.className == 'main':1027 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1028 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1029 is_unit_propagation_based_on_constants = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_constants']1030 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1031 self.assertTrue(is_unit_propagation_based_on_constants, 'Unit inference should be weakened by constant interaction, but is still strong.')1032 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (FLOAT)1033 def test_it_operator_with_unknown_variable_1(self):1034 cps_unit_checker = CPSUnitsChecker()1035 cps_unit_checker.debug = False1036 cps_unit_checker.debug_print_AST = False1037 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_1.cpp.dump'1038 if os.path.exists('./tests'):1039 dump_file = dump_file[1:] #REMOVE LEADING .1040 dump_file = './tests' + dump_file1041 source_file = dump_file.replace('.dump','')1042 cps_unit_checker.main_run_check(dump_file, source_file)1043 # self.assertEqual(0, len(cps_unit_checker.errors))1044 var_name = 'f'1045 var_linenr = 10 1046 my_oracle = [{'second':-1}]1047 actual_units = None1048 is_unit_propagation_based_on_unknown_variable = False1049 for s in cps_unit_checker.current_configuration.scopes:1050 if s.className == 'main':1051 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1052 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1053 is_unit_propagation_based_on_unknown_variable = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_unknown_variable']1054 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1055 self.assertTrue(is_unit_propagation_based_on_unknown_variable, 'Unit inference should be weakened by unknown variable interaction, but is still strong.')1056 # WEAKEN ERROR WHEN MULTIPLIED BY A CONSTANT 1057 def test_it_operator_with_unknown_variable_2(self):1058 cps_unit_checker = CPSUnitsChecker()1059 cps_unit_checker.debug = False1060 cps_unit_checker.debug_print_AST = False1061 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_2.cpp.dump'1062 if os.path.exists('./tests'):1063 dump_file = dump_file[1:] #REMOVE LEADING .1064 dump_file = './tests' + dump_file1065 source_file = dump_file.replace('.dump','')1066 cps_unit_checker.main_run_check(dump_file, source_file)1067 self.assertEqual(2, len(cps_unit_checker.errors))1068 for e in cps_unit_checker.errors:1069 self.assertTrue(e.is_warning, 'Should be a warning but is not marked as such')1070 # WEAKEN ERROR WHEN MULTIPLIED BY A CONSTANT 1071 def test_it_operator_with_unknown_variable_3(self):1072 cps_unit_checker = CPSUnitsChecker()1073 cps_unit_checker.debug = False1074 cps_unit_checker.debug_print_AST = False1075 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_3.cpp.dump'1076 if os.path.exists('./tests'):1077 dump_file = dump_file[1:] #REMOVE LEADING .1078 dump_file = './tests' + dump_file1079 source_file = dump_file.replace('.dump','')1080 cps_unit_checker.main_run_check(dump_file, source_file)1081 self.assertEqual(2, len(cps_unit_checker.errors))1082 # PROPAGATION ACROSS MIN MAX1083 def test_it_min_max_1(self):1084 cps_unit_checker = CPSUnitsChecker()1085 cps_unit_checker.debug = False1086 cps_unit_checker.debug_print_AST = False1087 dump_file = './dump_files_for_tests/test_it_min_max_1.cpp.dump'1088 if os.path.exists('./tests'):1089 dump_file = dump_file[1:] #REMOVE LEADING .1090 dump_file = './tests' + dump_file1091 source_file = dump_file.replace('.dump','')1092 cps_unit_checker.main_run_check(dump_file, source_file)1093 var_name = 'f'1094 var_linenr = 71095 my_oracle = [{'second': -1}]1096 actual_units = None1097 for s in cps_unit_checker.current_configuration.scopes:1098 if s.className == 'main':1099 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1100 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1101 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1102 self.assertEqual(0, len(cps_unit_checker.errors))1103 # PROPAGATION ACROSS MIN MAX1104 def test_it_min_max_2(self):1105 cps_unit_checker = CPSUnitsChecker()1106 cps_unit_checker.debug = False1107 cps_unit_checker.debug_print_AST = False1108 dump_file = './dump_files_for_tests/test_it_min_max_2.cpp.dump'1109 if os.path.exists('./tests'):1110 dump_file = dump_file[1:] #REMOVE LEADING .1111 dump_file = './tests' + dump_file1112 source_file = dump_file.replace('.dump','')1113 cps_unit_checker.main_run_check(dump_file, source_file)1114 var_name = 'f'1115 var_linenr = 81116 my_oracle = [{'second': -1}]1117 actual_units = None1118 for s in cps_unit_checker.current_configuration.scopes:1119 if s.className == 'main':1120 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1121 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1122 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1123 self.assertEqual(0, len(cps_unit_checker.errors))1124 # PROPAGATION ACROSS MIN MAX1125 def test_it_min_max_3(self):1126 cps_unit_checker = CPSUnitsChecker()1127 cps_unit_checker.debug = False1128 cps_unit_checker.debug_print_AST = False1129 dump_file = './dump_files_for_tests/test_it_min_max_3.cpp.dump'1130 if os.path.exists('./tests'):1131 dump_file = dump_file[1:] #REMOVE LEADING .1132 dump_file = './tests' + dump_file1133 source_file = dump_file.replace('.dump','')1134 cps_unit_checker.main_run_check(dump_file, source_file)1135 var_name = 'f'1136 var_linenr = 81137 my_oracle = [{'second': -1}, {'second': -1, 'meter': 1}]1138 actual_units = None1139 for s in cps_unit_checker.current_configuration.scopes:1140 if s.className == 'main':1141 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1142 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1143 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1144 self.assertEqual(1, len(cps_unit_checker.errors))1145 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1146 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1147 self.assertFalse(cps_unit_checker.errors[0].is_warning)1148 # PROPAGATION ACROSS MIN MAX1149 def test_it_min_max_4(self):1150 cps_unit_checker = CPSUnitsChecker()1151 cps_unit_checker.debug = False1152 cps_unit_checker.debug_print_AST = False1153 dump_file = './dump_files_for_tests/test_it_min_max_4.cpp.dump'1154 if os.path.exists('./tests'):1155 dump_file = dump_file[1:] #REMOVE LEADING .1156 dump_file = './tests' + dump_file1157 source_file = dump_file.replace('.dump','')1158 cps_unit_checker.main_run_check(dump_file, source_file)1159 var_name = 'f'1160 var_linenr = 91161 my_oracle = [{'second': -1 }, {'second': -1, 'meter': 1}]1162 actual_units = None1163 is_unit_propagation_based_on_unknown_variable = False1164 for s in cps_unit_checker.current_configuration.scopes:1165 if s.className == 'main':1166 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1167 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1168 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1169 self.assertEqual(1, len(cps_unit_checker.errors))1170 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1171 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1172 self.assertFalse(cps_unit_checker.errors[0].is_warning)1173 # PROTECTION AGAINST MULTILINE1174 def test_it_multiline_1(self):1175 cps_unit_checker = CPSUnitsChecker()1176 cps_unit_checker.debug = False1177 cps_unit_checker.debug_print_AST = False1178 dump_file = './dump_files_for_tests/test_it_multiline_1.cpp.dump'1179 if os.path.exists('./tests'):1180 dump_file = dump_file[1:] #REMOVE LEADING .1181 dump_file = './tests' + dump_file1182 source_file = dump_file.replace('.dump','')1183 cps_unit_checker.main_run_check(dump_file, source_file)1184 var_name = 'f'1185 var_linenr = 251186 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'second': -2.0, 'meter': 2.0}, {'second': -3.0, 'meter': 3.0}, {'second': -2.0, 'meter': 1.0}, {'second': -3.0, 'meter': 2.0}, {'second': -4.0, 'meter': 3.0}]1187 actual_units = None1188 # is_unit_propagation_based_on_unknown_variable = False1189 for s in cps_unit_checker.current_configuration.scopes:1190 if s.className == 'main':1191 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1192 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1193 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1194 # KNOW FUNCTION quatToRPY1195 def test_it_quatToRPY_1(self):1196 cps_unit_checker = CPSUnitsChecker()1197 cps_unit_checker.debug = False1198 cps_unit_checker.debug_print_AST = False1199 dump_file = './dump_files_for_tests/test_it_quatToRPY_1.cpp.dump'1200 if os.path.exists('./tests'):1201 dump_file = dump_file[1:] #REMOVE LEADING .1202 dump_file = './tests' + dump_file1203 source_file = dump_file.replace('.dump','')1204 cps_unit_checker.main_run_check(dump_file, source_file)1205 var_name = 'tw.linear.x'1206 var_linenr = 171207 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian': 1.0}]1208 actual_units = None1209 # is_unit_propagation_based_on_unknown_variable = False1210 for s in cps_unit_checker.current_configuration.scopes:1211 # for v in s.var_ordered_dict:1212 # print v1213 if s.className == 'main':1214 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1215 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1216 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1217 self.assertEqual(1, len(cps_unit_checker.errors))1218 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1219 # WEAK INFERENCE WARNING1220 def test_it_weak_inference_multiplication_1 (self):1221 cps_unit_checker = CPSUnitsChecker()1222 cps_unit_checker.debug = False1223 cps_unit_checker.debug_print_AST = False1224 dump_file = './dump_files_for_tests/test_it_weak_inference_multiplication_1.cpp.dump'1225 if os.path.exists('./tests'):1226 dump_file = dump_file[1:] #REMOVE LEADING .1227 dump_file = './tests' + dump_file1228 source_file = dump_file.replace('.dump','')1229 cps_unit_checker.main_run_check(dump_file, source_file)1230 # for e in cps_unit_checker.errors:1231 # print '\nweak inference: %s warning:%s ' % (e.var_name, str(e.is_warning))1232 var_name = 'tw.linear.x'1233 var_linenr = 191234 my_oracle = [{'second': -1.0, 'meter': 1.0}]1235 actual_units = None1236 # is_unit_propagation_based_on_unknown_variable = False1237 for s in cps_unit_checker.current_configuration.scopes:1238 # for v in s.var_ordered_dict:1239 # print v1240 if s.className == 'main':1241 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1242 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1243 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1244 self.assertEqual(0, len(cps_unit_checker.errors))1245 # WEAK INFERENCE WARNING1246 def test_it_weak_inference_multiplication_2 (self):1247 cps_unit_checker = CPSUnitsChecker()1248 cps_unit_checker.debug = False1249 cps_unit_checker.debug_print_AST = False1250 dump_file = './dump_files_for_tests/test_it_weak_inference_multiplication_2.cpp.dump'1251 if os.path.exists('./tests'):1252 dump_file = dump_file[1:] #REMOVE LEADING .1253 dump_file = './tests' + dump_file1254 source_file = dump_file.replace('.dump','')1255 cps_unit_checker.main_run_check(dump_file, source_file)1256 var_name = 'tw.linear.x'1257 var_linenr = 221258 my_oracle = [{'second': -1.0, 'meter': 1.0}]1259 actual_units = None1260 # is_unit_propagation_based_on_unknown_variable = False1261 for s in cps_unit_checker.current_configuration.scopes:1262 # for v in s.var_ordered_dict:1263 # print v1264 if s.className == 'main':1265 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1266 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1267 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1268 self.assertEqual(0, len(cps_unit_checker.errors))1269 # STRONG INFERENCE BECAUSE ADDITION1270 def test_it_weak_inference_addition_1 (self):1271 cps_unit_checker = CPSUnitsChecker()1272 cps_unit_checker.debug = False1273 cps_unit_checker.debug_print_AST = False1274 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_1.cpp.dump'1275 if os.path.exists('./tests'):1276 dump_file = dump_file[1:] #REMOVE LEADING .1277 dump_file = './tests' + dump_file1278 source_file = dump_file.replace('.dump','')1279 cps_unit_checker.main_run_check(dump_file, source_file)1280 # for e in cps_unit_checker.errors:1281 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1282 var_name = 'tw.linear.x'1283 var_linenr = 221284 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1285 actual_units = None1286 # is_unit_propagation_based_on_unknown_variable = False1287 for s in cps_unit_checker.current_configuration.scopes:1288 # for v in s.var_ordered_dict:1289 # print v1290 if s.className == 'main':1291 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1292 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1293 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1294 self.assertEqual(2, len(cps_unit_checker.errors))1295 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1296 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1297 self.assertFalse(cps_unit_checker.errors[0].is_warning)1298 var_name = 'tw.linear.y'1299 var_linenr = 231300 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1301 actual_units = None1302 # is_unit_propagation_based_on_unknown_variable = False1303 for s in cps_unit_checker.current_configuration.scopes:1304 # for v in s.var_ordered_dict:1305 # print v1306 if s.className == 'main':1307 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1308 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1309 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1310 self.assertTrue(cps_unit_checker.errors[1].was_assigned_mutiple_units)1311 self.assertFalse(cps_unit_checker.errors[1].is_unit_propagation_based_on_unknown_variable)1312 self.assertFalse(cps_unit_checker.errors[1].is_warning)1313 # STRONG INFERENCE BECAUSE ADDITION - SWAPPED OPERAND ORDER1314 def test_it_weak_inference_addition_2 (self):1315 cps_unit_checker = CPSUnitsChecker()1316 cps_unit_checker.debug = False1317 cps_unit_checker.debug_print_AST = False1318 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_2.cpp.dump'1319 if os.path.exists('./tests'):1320 dump_file = dump_file[1:] #REMOVE LEADING .1321 dump_file = './tests' + dump_file1322 source_file = dump_file.replace('.dump','')1323 cps_unit_checker.main_run_check(dump_file, source_file)1324 # for e in cps_unit_checker.errors:1325 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1326 var_name = 'tw.linear.x'1327 var_linenr = 221328 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1329 actual_units = None1330 # is_unit_propagation_based_on_unknown_variable = False1331 for s in cps_unit_checker.current_configuration.scopes:1332 # for v in s.var_ordered_dict:1333 # print v1334 if s.className == 'main':1335 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1336 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1337 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1338 self.assertEqual(2, len(cps_unit_checker.errors))1339 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1340 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1341 self.assertFalse(cps_unit_checker.errors[0].is_warning)1342 var_name = 'tw.linear.y'1343 var_linenr = 231344 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1345 actual_units = None1346 # is_unit_propagation_based_on_unknown_variable = False1347 for s in cps_unit_checker.current_configuration.scopes:1348 # for v in s.var_ordered_dict:1349 # print v1350 if s.className == 'main':1351 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1352 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1353 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1354 self.assertTrue(cps_unit_checker.errors[1].was_assigned_mutiple_units)1355 self.assertFalse(cps_unit_checker.errors[1].is_unit_propagation_based_on_unknown_variable)1356 self.assertFalse(cps_unit_checker.errors[1].is_warning)1357 # STRONG INFERENCE BECAUSE ADDITION - SWAPPED OPERAND ORDER1358 def test_it_weak_inference_addition_3 (self):1359 cps_unit_checker = CPSUnitsChecker()1360 cps_unit_checker.debug = False1361 cps_unit_checker.debug_print_AST = False1362 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_3.cpp.dump'1363 if os.path.exists('./tests'):1364 dump_file = dump_file[1:] #REMOVE LEADING .1365 dump_file = './tests' + dump_file1366 source_file = dump_file.replace('.dump','')1367 cps_unit_checker.main_run_check(dump_file, source_file)1368 # for e in cps_unit_checker.errors:1369 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1370 var_name = 'tw.linear.x'1371 var_linenr = 221372 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1.0}, {'second':1.}]1373 actual_units = None1374 # is_unit_propagation_based_on_unknown_variable = False1375 for s in cps_unit_checker.current_configuration.scopes:1376 # for v in s.var_ordered_dict:1377 # print v1378 if s.className == 'main':1379 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1380 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1381 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1382 self.assertEqual(2, len(cps_unit_checker.errors))1383 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1384 self.assertTrue(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1385 self.assertTrue(cps_unit_checker.errors[0].is_warning)1386 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - STRONG1387 def test_it_addition_without_assignment_1(self):1388 cps_unit_checker = CPSUnitsChecker()1389 cps_unit_checker.debug = False1390 cps_unit_checker.debug_print_AST = False1391 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_1.cpp.dump'1392 if os.path.exists('./tests'):1393 dump_file = dump_file[1:] #REMOVE LEADING .1394 dump_file = './tests' + dump_file1395 source_file = dump_file.replace('.dump','')1396 cps_unit_checker.main_run_check(dump_file, source_file)1397 # for e in cps_unit_checker.errors:1398 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1399 self.assertEqual(1, len(cps_unit_checker.errors))1400 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1401 self.assertFalse(cps_unit_checker.errors[0].is_warning)1402 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - WEAK UNKNOWN VARIABLE1403 def test_it_addition_without_assignment_2(self):1404 cps_unit_checker = CPSUnitsChecker()1405 cps_unit_checker.debug = False1406 cps_unit_checker.debug_print_AST = False1407 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_2.cpp.dump'1408 if os.path.exists('./tests'):1409 dump_file = dump_file[1:] #REMOVE LEADING .1410 dump_file = './tests' + dump_file1411 source_file = dump_file.replace('.dump','')1412 cps_unit_checker.main_run_check(dump_file, source_file)1413 # for e in cps_unit_checker.errors:1414 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1415 self.assertEqual(1, len(cps_unit_checker.errors))1416 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1417 self.assertTrue(cps_unit_checker.errors[0].is_warning)1418 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - WEAK CONSTANT1419 def test_it_addition_without_assignment_3(self):1420 cps_unit_checker = CPSUnitsChecker()1421 cps_unit_checker.debug = False1422 cps_unit_checker.debug_print_AST = False1423 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_3.cpp.dump'1424 if os.path.exists('./tests'):1425 dump_file = dump_file[1:] #REMOVE LEADING .1426 dump_file = './tests' + dump_file1427 source_file = dump_file.replace('.dump','')1428 cps_unit_checker.main_run_check(dump_file, source_file)1429 self.assertEqual(1, len(cps_unit_checker.errors))1430 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1431 self.assertTrue(cps_unit_checker.errors[0].is_warning)1432 # ADDITION STAND ALONE ERROR FOR SUBTRACTION OF INCOMPATIBLE UNITS - STRONG CONSTANT1433 def test_it_addition_without_assignment_4(self):1434 cps_unit_checker = CPSUnitsChecker()1435 cps_unit_checker.debug = False1436 cps_unit_checker.debug_print_AST = False1437 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_4.cpp.dump'1438 if os.path.exists('./tests'):1439 dump_file = dump_file[1:] #REMOVE LEADING .1440 dump_file = './tests' + dump_file1441 source_file = dump_file.replace('.dump','')1442 cps_unit_checker.main_run_check(dump_file, source_file)1443 self.assertEqual(1, len(cps_unit_checker.errors))1444 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1445 self.assertFalse(cps_unit_checker.errors[0].is_warning)1446 # ADDITION OF RADIANS1447 def test_it_radian_addition_1(self):1448 cps_unit_checker = CPSUnitsChecker()1449 cps_unit_checker.debug = False1450 cps_unit_checker.debug_print_AST = False1451 dump_file = './dump_files_for_tests/test_it_radian_addition_1.cpp.dump'1452 if os.path.exists('./tests'):1453 dump_file = dump_file[1:] #REMOVE LEADING .1454 dump_file = './tests' + dump_file1455 source_file = dump_file.replace('.dump','')1456 cps_unit_checker.main_run_check(dump_file, source_file)1457 self.assertEqual(2, len(cps_unit_checker.errors))1458 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1459 self.assertFalse(cps_unit_checker.errors[0].is_warning)1460 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[1].ERROR_TYPE)1461 self.assertFalse(cps_unit_checker.errors[1].is_warning)1462 # ADDITION OF RADIANS1463 def test_it_radian_addition_2(self):1464 cps_unit_checker = CPSUnitsChecker()1465 cps_unit_checker.debug = False1466 cps_unit_checker.debug_print_AST = False1467 dump_file = './dump_files_for_tests/test_it_radian_addition_2.cpp.dump'1468 if os.path.exists('./tests'):1469 dump_file = dump_file[1:] #REMOVE LEADING .1470 dump_file = './tests' + dump_file1471 source_file = dump_file.replace('.dump','')1472 cps_unit_checker.main_run_check(dump_file, source_file)1473 self.assertEqual(1, len(cps_unit_checker.errors))1474 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1475 self.assertFalse(cps_unit_checker.errors[0].is_warning)1476 # MULTIPLICATION OF RADIANS1477 def test_it_radian_multiplication_1(self):1478 cps_unit_checker = CPSUnitsChecker()1479 cps_unit_checker.debug = False1480 cps_unit_checker.debug_print_AST = False1481 dump_file = './dump_files_for_tests/test_it_radian_multiplication_1.cpp.dump'1482 if os.path.exists('./tests'):1483 dump_file = dump_file[1:] #REMOVE LEADING .1484 dump_file = './tests' + dump_file1485 source_file = dump_file.replace('.dump','')1486 cps_unit_checker.main_run_check(dump_file, source_file)1487 self.assertEqual(0, len(cps_unit_checker.errors))1488 # MULTIPLICATION OF RADIANS 21489 def test_it_radian_multiplication_2(self):1490 cps_unit_checker = CPSUnitsChecker()1491 cps_unit_checker.debug = False1492 cps_unit_checker.debug_print_AST = False1493 dump_file = './dump_files_for_tests/test_it_radian_multiplication_2.cpp.dump'1494 if os.path.exists('./tests'):1495 dump_file = dump_file[1:] #REMOVE LEADING .1496 dump_file = './tests' + dump_file1497 source_file = dump_file.replace('.dump','')1498 cps_unit_checker.main_run_check(dump_file, source_file)1499 self.assertEqual(1, len(cps_unit_checker.errors))1500 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1501 self.assertFalse(cps_unit_checker.errors[0].is_warning)1502 # MULTIPLICATION OF RADIANS1503 def test_it_radian_multiplication_3(self):1504 cps_unit_checker = CPSUnitsChecker()1505 cps_unit_checker.debug = False1506 cps_unit_checker.debug_print_AST = False1507 dump_file = './dump_files_for_tests/test_it_radian_multiplication_3.cpp.dump'1508 if os.path.exists('./tests'):1509 dump_file = dump_file[1:] #REMOVE LEADING .1510 dump_file = './tests' + dump_file1511 source_file = dump_file.replace('.dump','')1512 cps_unit_checker.main_run_check(dump_file, source_file)1513 self.assertEqual(0, len(cps_unit_checker.errors))1514 # MULTIPLICATION OF RADIANS 21515 def test_it_radian_multiplication_4(self):1516 cps_unit_checker = CPSUnitsChecker()1517 cps_unit_checker.debug = False1518 cps_unit_checker.debug_print_AST = False1519 dump_file = './dump_files_for_tests/test_it_radian_multiplication_4.cpp.dump'1520 if os.path.exists('./tests'):1521 dump_file = dump_file[1:] #REMOVE LEADING .1522 dump_file = './tests' + dump_file1523 source_file = dump_file.replace('.dump','')1524 cps_unit_checker.main_run_check(dump_file, source_file)1525 self.assertEqual(1, len(cps_unit_checker.errors))1526 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1527 self.assertFalse(cps_unit_checker.errors[0].is_warning)1528 # getXYZ 1529 def test_it_getXYZ_1 (self):1530 cps_unit_checker = CPSUnitsChecker()1531 cps_unit_checker.debug = False1532 cps_unit_checker.debug_print_AST = False1533 dump_file = './dump_files_for_tests/test_it_getXYZ_1.cpp.dump'1534 if os.path.exists('./tests'):1535 dump_file = dump_file[1:] #REMOVE LEADING .1536 dump_file = './tests' + dump_file1537 source_file = dump_file.replace('.dump','')1538 cps_unit_checker.main_run_check(dump_file, source_file)1539 # for e in cps_unit_checker.errors:1540 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1541 self.assertEqual(0, len(cps_unit_checker.errors))1542 # getXYZ 1543 def test_it_getXYZ_2 (self):1544 cps_unit_checker = CPSUnitsChecker()1545 cps_unit_checker.debug = False1546 cps_unit_checker.debug_print_AST = False1547 dump_file = './dump_files_for_tests/test_it_getXYZ_2.cpp.dump'1548 if os.path.exists('./tests'):1549 dump_file = dump_file[1:] #REMOVE LEADING .1550 dump_file = './tests' + dump_file1551 source_file = dump_file.replace('.dump','')1552 cps_unit_checker.main_run_check(dump_file, source_file)1553 # for e in cps_unit_checker.errors:1554 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1555 var_name = 'tw.linear.x'1556 var_linenr = 101557 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'meter':1}]1558 actual_units = None1559 # is_unit_propagation_based_on_unknown_variable = False1560 for s in cps_unit_checker.current_configuration.scopes:1561 # for v in s.var_ordered_dict:1562 # print v1563 if s.className == 'main':1564 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1565 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1566 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1567 self.assertEqual(1, len(cps_unit_checker.errors))1568 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1569 # getXYZ 1570 def test_it_getXYZ_3 (self):1571 cps_unit_checker = CPSUnitsChecker()1572 cps_unit_checker.debug = False1573 cps_unit_checker.debug_print_AST = False1574 dump_file = './dump_files_for_tests/test_it_getXYZ_3.cpp.dump'1575 if os.path.exists('./tests'):1576 dump_file = dump_file[1:] #REMOVE LEADING .1577 dump_file = './tests' + dump_file1578 source_file = dump_file.replace('.dump','')1579 cps_unit_checker.main_run_check(dump_file, source_file)1580 var_name = 'tw.linear.x'1581 var_linenr = 101582 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'quaternion':1}]1583 actual_units = None1584 # is_unit_propagation_based_on_unknown_variable = False1585 for s in cps_unit_checker.current_configuration.scopes:1586 # for v in s.var_ordered_dict:1587 # print v1588 if s.className == 'main':1589 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1590 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1591 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1592 self.assertEqual(1, len(cps_unit_checker.errors))1593 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1594 # getXYZ 1595 def test_it_getXYZ_4 (self):1596 cps_unit_checker = CPSUnitsChecker()1597 cps_unit_checker.debug = False1598 cps_unit_checker.debug_print_AST = False1599 dump_file = './dump_files_for_tests/test_it_getXYZ_4.cpp.dump'1600 if os.path.exists('./tests'):1601 dump_file = dump_file[1:] #REMOVE LEADING .1602 dump_file = './tests' + dump_file1603 source_file = dump_file.replace('.dump','')1604 cps_unit_checker.main_run_check(dump_file, source_file)1605 # for e in cps_unit_checker.errors:1606 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1607 self.assertEqual(1, len(cps_unit_checker.errors))1608 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1609 self.assertFalse(cps_unit_checker.errors[0].is_warning)1610 # getXYZ 1611 def test_it_getXYZ_5 (self):1612 cps_unit_checker = CPSUnitsChecker()1613 cps_unit_checker.debug = False1614 cps_unit_checker.debug_print_AST = False1615 dump_file = './dump_files_for_tests/test_it_getXYZ_5.cpp.dump'1616 if os.path.exists('./tests'):1617 dump_file = dump_file[1:] #REMOVE LEADING .1618 dump_file = './tests' + dump_file1619 source_file = dump_file.replace('.dump','')1620 cps_unit_checker.main_run_check(dump_file, source_file)1621 self.assertEqual(1, len(cps_unit_checker.errors))1622 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1623 self.assertFalse(cps_unit_checker.errors[0].is_warning)1624 # QUATERNION ADDITION 11625 def test_it_quaternion_addition_1 (self):1626 cps_unit_checker = CPSUnitsChecker()1627 cps_unit_checker.debug = False1628 cps_unit_checker.debug_print_AST = False1629 dump_file = './dump_files_for_tests/test_it_quaternion_addition_1.cpp.dump'1630 if os.path.exists('./tests'):1631 dump_file = dump_file[1:] #REMOVE LEADING .1632 dump_file = './tests' + dump_file1633 source_file = dump_file.replace('.dump','')1634 cps_unit_checker.main_run_check(dump_file, source_file)1635 self.assertEqual(2, len(cps_unit_checker.errors))1636 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1637 self.assertFalse(cps_unit_checker.errors[0].is_warning)1638 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[1].ERROR_TYPE)1639 self.assertFalse(cps_unit_checker.errors[1].is_warning)1640 # QUATERNION ADDITION 21641 def test_it_quaternion_addition_2 (self):1642 cps_unit_checker = CPSUnitsChecker()1643 cps_unit_checker.debug = False1644 cps_unit_checker.debug_print_AST = False1645 dump_file = './dump_files_for_tests/test_it_quaternion_addition_2.cpp.dump'1646 if os.path.exists('./tests'):1647 dump_file = dump_file[1:] #REMOVE LEADING .1648 dump_file = './tests' + dump_file1649 source_file = dump_file.replace('.dump','')1650 cps_unit_checker.main_run_check(dump_file, source_file)1651 self.assertEqual(1, len(cps_unit_checker.errors))1652 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1653 self.assertFalse(cps_unit_checker.errors[0].is_warning)1654 # QUATERNION ADDITION 31655 def test_it_quaternion_addition_3 (self):1656 cps_unit_checker = CPSUnitsChecker()1657 cps_unit_checker.debug = False1658 cps_unit_checker.debug_print_AST = False1659 dump_file = './dump_files_for_tests/test_it_quaternion_addition_3.cpp.dump'1660 if os.path.exists('./tests'):1661 dump_file = dump_file[1:] #REMOVE LEADING .1662 dump_file = './tests' + dump_file1663 source_file = dump_file.replace('.dump','')1664 cps_unit_checker.main_run_check(dump_file, source_file)1665 self.assertEqual(0, len(cps_unit_checker.errors))1666 # QUATERNION ADDITION 41667 def test_it_quaternion_addition_4 (self):1668 cps_unit_checker = CPSUnitsChecker()1669 cps_unit_checker.debug = False1670 cps_unit_checker.debug_print_AST = False1671 dump_file = './dump_files_for_tests/test_it_quaternion_addition_4.cpp.dump'1672 if os.path.exists('./tests'):1673 dump_file = dump_file[1:] #REMOVE LEADING .1674 dump_file = './tests' + dump_file1675 source_file = dump_file.replace('.dump','')1676 cps_unit_checker.main_run_check(dump_file, source_file)1677 self.assertEqual(0, len(cps_unit_checker.errors))1678 # QUATERNION MULTIPLICATION 11679 def test_it_quaternion_multiplication_1 (self):1680 cps_unit_checker = CPSUnitsChecker()1681 cps_unit_checker.debug = False1682 cps_unit_checker.debug_print_AST = False1683 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_1.cpp.dump'1684 if os.path.exists('./tests'):1685 dump_file = dump_file[1:] #REMOVE LEADING .1686 dump_file = './tests' + dump_file1687 source_file = dump_file.replace('.dump','')1688 cps_unit_checker.main_run_check(dump_file, source_file)1689 self.assertEqual(0, len(cps_unit_checker.errors))1690 # QUATERNION MULTIPLICATION 21691 def test_it_quaternion_multiplication_2 (self):1692 cps_unit_checker = CPSUnitsChecker()1693 cps_unit_checker.debug = False1694 cps_unit_checker.debug_print_AST = False1695 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_2.cpp.dump'1696 if os.path.exists('./tests'):1697 dump_file = dump_file[1:] #REMOVE LEADING .1698 dump_file = './tests' + dump_file1699 source_file = dump_file.replace('.dump','')1700 cps_unit_checker.main_run_check(dump_file, source_file)1701 self.assertEqual(0, len(cps_unit_checker.errors))1702 # QUATERNION MULTIPLICATION 31703 def test_it_quaternion_multiplication_3 (self):1704 cps_unit_checker = CPSUnitsChecker()1705 cps_unit_checker.debug = False1706 cps_unit_checker.debug_print_AST = False1707 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_3.cpp.dump'1708 if os.path.exists('./tests'):1709 dump_file = dump_file[1:] #REMOVE LEADING .1710 dump_file = './tests' + dump_file1711 source_file = dump_file.replace('.dump','')1712 cps_unit_checker.main_run_check(dump_file, source_file)1713 self.assertEqual(0, len(cps_unit_checker.errors))1714 # QUATERNION MULTIPLICATION 41715 def test_it_quaternion_multiplication_4 (self):1716 cps_unit_checker = CPSUnitsChecker()1717 cps_unit_checker.debug = False1718 cps_unit_checker.debug_print_AST = False1719 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_4.cpp.dump'1720 if os.path.exists('./tests'):1721 dump_file = dump_file[1:] #REMOVE LEADING .1722 dump_file = './tests' + dump_file1723 source_file = dump_file.replace('.dump','')1724 cps_unit_checker.main_run_check(dump_file, source_file)1725 self.assertEqual(0, len(cps_unit_checker.errors))1726 # QUATERNION MULTIPLICATION CLOSURE1727 def test_it_quaternion_closed_under_multiplication_1 (self):1728 cps_unit_checker = CPSUnitsChecker()1729 cps_unit_checker.debug = False1730 cps_unit_checker.debug_print_AST = False1731 dump_file = './dump_files_for_tests/test_it_quaternion_closed_under_multiplication_1.cpp.dump'1732 if os.path.exists('./tests'):1733 dump_file = dump_file[1:] #REMOVE LEADING .1734 dump_file = './tests' + dump_file1735 source_file = dump_file.replace('.dump','')1736 cps_unit_checker.main_run_check(dump_file, source_file)1737 self.assertEqual(0, len(cps_unit_checker.errors))1738 # QUATERNION MULTIPLICATION CLOSURE1739 def test_it_quaternion_closed_under_multiplication_2 (self):1740 cps_unit_checker = CPSUnitsChecker()1741 cps_unit_checker.debug = False1742 cps_unit_checker.debug_print_AST = False1743 dump_file = './dump_files_for_tests/test_it_quaternion_closed_under_multiplication_2.cpp.dump'1744 if os.path.exists('./tests'):1745 dump_file = dump_file[1:] #REMOVE LEADING .1746 dump_file = './tests' + dump_file1747 source_file = dump_file.replace('.dump','')1748 cps_unit_checker.main_run_check(dump_file, source_file)1749 self.assertEqual(1, len(cps_unit_checker.errors))1750 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1751 self.assertFalse(cps_unit_checker.errors[0].is_warning)1752 # RADIAN MULTIPLICATION CLOSURE1753 def test_it_radian_closed_under_multiplication_1 (self):1754 cps_unit_checker = CPSUnitsChecker()1755 cps_unit_checker.debug = False1756 cps_unit_checker.debug_print_AST = False1757 dump_file = './dump_files_for_tests/test_it_radian_closed_under_multiplication_1.cpp.dump'1758 if os.path.exists('./tests'):1759 dump_file = dump_file[1:] #REMOVE LEADING .1760 dump_file = './tests' + dump_file1761 source_file = dump_file.replace('.dump','')1762 cps_unit_checker.main_run_check(dump_file, source_file)1763 self.assertEqual(0, len(cps_unit_checker.errors))1764 # RADIAN MULTIPLICATION CLOSURE1765 def test_it_radian_closed_under_multiplication_2 (self):1766 cps_unit_checker = CPSUnitsChecker()1767 cps_unit_checker.debug = False1768 cps_unit_checker.debug_print_AST = False1769 dump_file = './dump_files_for_tests/test_it_radian_closed_under_multiplication_2.cpp.dump'1770 if os.path.exists('./tests'):1771 dump_file = dump_file[1:] #REMOVE LEADING .1772 dump_file = './tests' + dump_file1773 source_file = dump_file.replace('.dump','')1774 cps_unit_checker.main_run_check(dump_file, source_file)1775 self.assertEqual(1, len(cps_unit_checker.errors))1776 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1777 self.assertFalse(cps_unit_checker.errors[0].is_warning)1778 # dt Heuristic1779 def test_it_dt_heuristic (self):1780 cps_unit_checker = CPSUnitsChecker()1781 cps_unit_checker.debug = False1782 cps_unit_checker.debug_print_AST = False1783 dump_file = './dump_files_for_tests/test_it_dt_heuristic_1.cpp.dump'1784 if os.path.exists('./tests'):1785 dump_file = dump_file[1:] #REMOVE LEADING .1786 dump_file = './tests' + dump_file1787 source_file = dump_file.replace('.dump','')1788 cps_unit_checker.main_run_check(dump_file, source_file)1789 self.assertEqual(0, len(cps_unit_checker.errors))1790 # dt Heuristic1791 def test_it_plus_equals_1 (self):1792 cps_unit_checker = CPSUnitsChecker()1793 cps_unit_checker.debug = False1794 cps_unit_checker.debug_print_AST = False1795 dump_file = './dump_files_for_tests/test_it_plus_equals_1.cpp.dump'1796 if os.path.exists('./tests'):1797 dump_file = dump_file[1:] #REMOVE LEADING .1798 dump_file = './tests' + dump_file1799 source_file = dump_file.replace('.dump','')1800 cps_unit_checker.main_run_check(dump_file, source_file)1801 self.assertEqual(0, len(cps_unit_checker.errors))1802 # dt Heuristic1803 def test_it_range_1 (self):1804 cps_unit_checker = CPSUnitsChecker()1805 cps_unit_checker.debug = False1806 cps_unit_checker.debug_print_AST = False1807 dump_file = './dump_files_for_tests/test_it_range_1.cpp.dump'1808 if os.path.exists('./tests'):1809 dump_file = dump_file[1:] #REMOVE LEADING .1810 dump_file = './tests' + dump_file1811 source_file = dump_file.replace('.dump','')1812 cps_unit_checker.main_run_check(dump_file, source_file)1813 self.assertEqual(0, len(cps_unit_checker.errors))1814 # same named argument in interface scope bug1815 def test_it_scope_bug_1 (self):1816 cps_unit_checker = CPSUnitsChecker()1817 dump_file = './dump_files_for_tests/test_it_cppcheck_scope_bug_at_argument_1.cpp.dump'1818 if os.path.exists('./tests'):1819 dump_file = dump_file[1:] #REMOVE LEADING .1820 dump_file = './tests' + dump_file1821 source_file = dump_file.replace('.dump','')1822 cps_unit_checker.main_run_check(dump_file, source_file)1823 self.assertEqual(0, len(cps_unit_checker.errors))1824if __name__ == '__main__':...

Full Screen

Full Screen

test_cps_units_checker.py

Source:test_cps_units_checker.py Github

copy

Full Screen

1#!/usr/local/bin/python2import sys3# sys.path.append('/Users/jore/courses/NIMBUS/RESEARCH/CPS_TYPES/cps_units/')4import unittest5from detect_physical_unit_inconsistencies import CPSUnitsChecker6from unit_error_types import UnitErrorTypes7from unit_error import UnitError8import os9global_debug = False10global_debug_verbose = False11global_debug_AST = False12class TestStringMethods(unittest.TestCase):13 14 def test_function_return_0(self):15 cps_unit_checker = CPSUnitsChecker()16 cps_unit_checker.debug = False17 cps_unit_checker.debug_print_AST = False18 cps_unit_checker.debug_scope = False19 dump_file = './dump_files_for_tests/test_it_function_return_0.cpp.dump'20 source_file = dump_file.replace('.dump','')21 cps_unit_checker.main_run_check(dump_file, source_file)22 units_for_f1 = []23 # TEST THAT UNITS ARE ASSIGNED TO FUNCTION24 for tw in cps_unit_checker.all_tree_walkers:25 so = tw.symbol_helper.function_dictionary['scopeObject']26 if so.function:27 if so.function.name == 'f1':28 units_for_f1 = so.function.return_units29 self.assertEquals(units_for_f1, [{'meter': 1}], 'Incorrect units returned for function: f1 . Expected [{\'meter\':1}], received %s' % units_for_f1)30 # TEST THAT UNITS ARE RECEIVED TO FUNCTION31 actual_units = None32 for s in cps_unit_checker.current_configuration.scopes:33 if s.className == 'main':34 if 'x' in s.var_ordered_dict:35 actual_units = s.var_ordered_dict['x'][12]['units']36 37 my_oracle = [{'meter': 1}]38 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))39 40 41 def test_function_return_1(self):42 ''' x SHOULD END UP M/S, but so far THERE'S NO MECHANISM FOR PASSING UNITS IN TO A FUNCTION43 '''44 cps_unit_checker = CPSUnitsChecker()45 dump_file = './dump_files_for_tests/test_it_function_return_1.cpp.dump'46 source_file = dump_file.replace('.dump','')47 cps_unit_checker.main_run_check(dump_file, source_file)48 for tw in cps_unit_checker.all_tree_walkers:49 so = tw.symbol_helper.function_dictionary['scopeObject']50 if so.function:51 if so.function.name == 'f1':52 units_for_f1 = so.function.return_units53 def test_comparisons_1(self):54 cps_unit_checker = CPSUnitsChecker()55 cps_unit_checker.debug = False56 cps_unit_checker.debug_print_AST= False57 dump_file = './dump_files_for_tests/test_it_comparisons_1.cpp.dump'58 source_file = './dump_files_for_tests/test_it_comparisons_1.cpp'59 cps_unit_checker.main_run_check(dump_file, source_file)60 e = cps_unit_checker.errors[0]61 # ORACLES62 token_left_units_oracle = [{'meter': 1}]63 token_right_units_oracle = [{'second': -1, 'meter': 1}]64 # ASSERTIONS65 self.assertEqual(e.token.str, '>')66 self.assertEqual(e.token_left.units, token_left_units_oracle)67 self.assertEqual(e.token_right.units, token_right_units_oracle)68 def test_logical_1(self):69 cps_unit_checker = CPSUnitsChecker()70 cps_unit_checker.debug = False71 cps_unit_checker.debug_print_AST = False72 dump_file = './dump_files_for_tests/test_it_logical_1.cpp.dump'73 source_file = './dump_files_for_tests/test_it_logical_1.cpp'74 cps_unit_checker.main_run_check(dump_file, source_file)75 # TEST 176 e = cps_unit_checker.errors[0]77 # ORACLES78 token_right_units_oracle = [{'meter': 1}]79 # ASSERTIONS80 self.assertEqual(e.linenr, 13)81 self.assertEqual(e.token.str, '&&')82 self.assertEqual(e.token_right.units, token_right_units_oracle)83 # TEST 284 e = cps_unit_checker.errors[1]85 # ORACLES86 token_left_units_oracle = [{'meter': 1}]87 # ASSERTIONS88 self.assertEqual(e.linenr, 18)89 self.assertEqual(e.token.str, '||')90 self.assertEqual(e.token_left.units, token_left_units_oracle)91 def test_abs_0(self):92 cps_unit_checker = CPSUnitsChecker()93 cps_unit_checker.debug = False94 #cps_unit_checker.debug_print_AST = False95 dump_file = './dump_files_for_tests/test_it_known_function_abs.cpp.dump'96 source_file = dump_file.replace('.dump','')97 cps_unit_checker.main_run_check(dump_file, source_file)98 99 def test_abs_namespace_std_0(self):100 cps_unit_checker = CPSUnitsChecker()101 cps_unit_checker.debug = False102 #cps_unit_checker.debug_print_AST = False103 dump_file = './dump_files_for_tests/test_it_known_function_abs_namespace_std.cpp.dump'104 source_file = dump_file.replace('.dump','')105 cps_unit_checker.main_run_check(dump_file, source_file)106 def test_abs_1(self):107 cps_unit_checker = CPSUnitsChecker()108 cps_unit_checker.debug = False109 #cps_unit_checker.debug_verbose = False110 cps_unit_checker.debug_print_AST = False111 dump_file = './dump_files_for_tests/test_it_known_function_abs_1.cpp.dump'112 source_file = dump_file.replace('.dump','')113 cps_unit_checker.main_run_check(dump_file, source_file)114 var_name = 't'115 var_linenr = 9116 actual_units = None117 for s in cps_unit_checker.current_configuration.scopes:118 if s.className == 'main':119 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:120 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']121 my_oracle = [{'second': 1}]122 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))123 def test_abs_2(self):124 cps_unit_checker = CPSUnitsChecker()125 cps_unit_checker.debug = False126 cps_unit_checker.debug_print_AST = False127 dump_file = './dump_files_for_tests/test_it_known_function_abs_2.cpp.dump'128 source_file = dump_file.replace('.dump','')129 cps_unit_checker.main_run_check(dump_file, source_file)130 var_name = 's'131 var_linenr =11 132 my_oracle = [{'meter': 1}]133 actual_units = None134 for s in cps_unit_checker.current_configuration.scopes:135 if s.className == 'main':136 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:137 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']138 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))139 def test_multiplication_assignment_in_multi_configurations_1(self):140 cps_unit_checker = CPSUnitsChecker()141 cps_unit_checker.debug = False142 #cps_unit_checker.debug_verbose = False143 cps_unit_checker.debug_print_AST = False144 dump_file = './dump_files_for_tests/test_it_multiplication_assignment_in_multi_configurations.cpp.dump'145 source_file = dump_file.replace('.dump','')146 cps_unit_checker.main_run_check(dump_file, source_file)147 var_name = 'a_geometry_msgs_Accel.linear.x'148 var_linenr = 19 149 my_oracle = [{'second': -4, 'meter': 2}] 150 actual_units = None151 for s in cps_unit_checker.current_configuration.scopes:152 if s.className == 'main':153 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:154 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']155 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))156 def test_unit_propagation_by_multiplication_1(self):157 cps_unit_checker = CPSUnitsChecker()158 cps_unit_checker.debug = False159 #cps_unit_checker.debug_verbose = False160 #cps_unit_checker.debug_print_AST = False161 dump_file = './dump_files_for_tests/test_it_unit_propagation_by_multiplication_1.cpp.dump'162 source_file = dump_file.replace('.dump','')163 cps_unit_checker.main_run_check(dump_file, source_file)164 for s in cps_unit_checker.current_configuration.scopes:165 if s.className == 'main':166 if 'f' in s.var_ordered_dict:167 actual_units = s.var_ordered_dict['f'][14]['units']168 my_oracle = [{'second': -4, 'meter': 2}]169 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))170 def test_unit_propagation_by_division_1(self):171 cps_unit_checker = CPSUnitsChecker()172 cps_unit_checker.debug = False173 #cps_unit_checker.debug_verbose = False174 #cps_unit_checker.debug_print_AST = False175 dump_file = './dump_files_for_tests/test_it_unit_propagation_by_division_1.cpp.dump'176 source_file = dump_file.replace('.dump','')177 cps_unit_checker.main_run_check(dump_file, source_file)178 actual_units = None179 for s in cps_unit_checker.current_configuration.scopes:180 if s.className == 'main':181 if 'f' in s.var_ordered_dict:182 actual_units = s.var_ordered_dict['f'][14]['units']183 my_oracle = None184 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))185 def test_mulitple_units_assigned(self):186 cps_unit_checker = CPSUnitsChecker()187 cps_unit_checker.debug = False188 #cps_unit_checker.debug_verbose = False189 cps_unit_checker.debug_print_AST = False190 dump_file = './dump_files_for_tests/test_it_multiple_units_assigned_1.cpp.dump'191 source_file = dump_file.replace('.dump','')192 cps_unit_checker.main_run_check(dump_file, source_file)193 expected_errors = ["test_it_multiple_units_assigned_1.cpp : 11 MULTIPLE UNITS BY ASSIGNMENT: [{'second': -1, 'meter': 1}, {'second': -2, 'meter': 2}]"]194 # self.assertListEqual([e['error_msg'] for e in cps_unit_checker.errors], expected_errors)195 # TEST QUANTITY OF ERRORS196 self.assertEqual(1, len(cps_unit_checker.errors))197 # TEST TyPE OF ERROR198 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)199 # TEST VALUE OF ERROR200 var_name = 'a_geometry_msgs_Accel.linear.x'201 var_linenr =11202 my_oracle = [{'second': -2, 'meter': 1}, {'second': -4, 'meter': 2}]203 actual_units = None204 for s in cps_unit_checker.current_configuration.scopes:205 if s.className == 'main':206 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:207 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']208 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))209 def test_known_functions_sqrt_1(self):210 cps_unit_checker = CPSUnitsChecker()211 cps_unit_checker.debug = False212 #cps_unit_checker.debug_verbose = False213 cps_unit_checker.debug_print_AST = False214 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_1.cpp.dump'215 source_file = dump_file.replace('.dump','')216 cps_unit_checker.main_run_check(dump_file, source_file)217 for s in cps_unit_checker.current_configuration.scopes:218 if s.className == 'main':219 if 'x' in s.var_ordered_dict:220 actual_units = s.var_ordered_dict['x'][12]['units']221 my_oracle = [{'meter': 1}]222 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))223 def test_known_functions_sqrt_2(self):224 cps_unit_checker = CPSUnitsChecker()225 cps_unit_checker.debug = False226 #cps_unit_checker.debug_verbose = False227 cps_unit_checker.debug_print_AST = False228 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_2.cpp.dump'229 source_file = dump_file.replace('.dump','')230 cps_unit_checker.main_run_check(dump_file, source_file)231 for s in cps_unit_checker.current_configuration.scopes:232 if s.className == 'main':233 if 'x' in s.var_ordered_dict:234 actual_units = s.var_ordered_dict['x'][12]['units']235 my_oracle = [{'second': -1, 'meter': 1}]236 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))237 def test_known_functions_sqrt_3(self):238 cps_unit_checker = CPSUnitsChecker()239 cps_unit_checker.debug = False240 #cps_unit_checker.debug_verbose = False241 cps_unit_checker.debug_print_AST = False242 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_3.cpp.dump'243 source_file = dump_file.replace('.dump','')244 cps_unit_checker.main_run_check(dump_file, source_file)245 actual_units = None246 for s in cps_unit_checker.current_configuration.scopes:247 if s.className == 'main':248 if 'x' in s.var_ordered_dict:249 actual_units = s.var_ordered_dict['x'][12]['units']250 my_oracle = None251 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))252 def test_known_functions_sqrt_4(self):253 cps_unit_checker = CPSUnitsChecker()254 cps_unit_checker.debug = False255 #cps_unit_checker.debug_verbose = False256 cps_unit_checker.debug_print_AST = False257 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_4.cpp.dump'258 source_file = dump_file.replace('.dump','')259 cps_unit_checker.main_run_check(dump_file, source_file)260 for s in cps_unit_checker.current_configuration.scopes:261 if s.className == 'main':262 if 'x' in s.var_ordered_dict:263 actual_units = s.var_ordered_dict['x'][14]['units']264 my_oracle = [{'meter': 1}]265 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))266 def test_known_functions_sqrt_5(self):267 cps_unit_checker = CPSUnitsChecker()268 cps_unit_checker.debug = False269 #cps_unit_checker.debug_verbose = False270 cps_unit_checker.debug_print_AST = False271 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_5.cpp.dump'272 source_file = dump_file.replace('.dump','')273 cps_unit_checker.main_run_check(dump_file, source_file)274 for s in cps_unit_checker.current_configuration.scopes:275 if s.className == 'main':276 if 'x' in s.var_ordered_dict:277 actual_units = s.var_ordered_dict['x'][14]['units']278 my_oracle = [{'meter': 1}]279 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))280 def test_known_functions_sqrt_half_units(self):281 cps_unit_checker = CPSUnitsChecker()282 cps_unit_checker.debug = False283 #cps_unit_checker.debug_verbose = False284 cps_unit_checker.debug_print_AST = False285 dump_file = './dump_files_for_tests/test_it_known_function_sqrt_half_units.cpp.dump'286 source_file = dump_file.replace('.dump','')287 cps_unit_checker.main_run_check(dump_file, source_file)288 for s in cps_unit_checker.current_configuration.scopes:289 if s.className == 'main':290 if 'x' in s.var_ordered_dict:291 actual_units = s.var_ordered_dict['x'][11]['units']292 my_oracle = [{'meter': 0.5}]293 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))294 def test_known_functions_atan2_1(self):295 cps_unit_checker = CPSUnitsChecker()296 cps_unit_checker.debug = False297 cps_unit_checker.debug_verbose = False298 cps_unit_checker.debug_print_AST = False299 dump_file = './dump_files_for_tests/test_it_known_function_atan2_1.cpp.dump'300 source_file = dump_file.replace('.dump','')301 cps_unit_checker.main_run_check(dump_file, source_file)302 for s in cps_unit_checker.current_configuration.scopes:303 if s.className == 'main':304 if 'f' in s.var_ordered_dict:305 actual_units = s.var_ordered_dict['f'][7]['units']306 my_oracle = [{'radian': 1}]307 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))308 def test_known_functions_atan2_2(self):309 cps_unit_checker = CPSUnitsChecker()310 cps_unit_checker.debug = False311 #cps_unit_checker.debug_verbose = False312 cps_unit_checker.debug_print_AST = False313 dump_file = './dump_files_for_tests/test_it_known_function_atan2_2.cpp.dump'314 source_file = dump_file.replace('.dump','')315 cps_unit_checker.main_run_check(dump_file, source_file)316 for s in cps_unit_checker.current_configuration.scopes:317 if s.className == 'main':318 if 'f' in s.var_ordered_dict:319 actual_units = s.var_ordered_dict['f'][8]['units']320 my_oracle = [{'radian': 1}]321 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))322 def test_toSec(self):323 cps_unit_checker = CPSUnitsChecker()324 cps_unit_checker.debug = False325 cps_unit_checker.debug_print_AST = False326 dump_file = './dump_files_for_tests/test_it_toSec_0.cpp.dump'327 source_file = dump_file.replace('.dump','')328 cps_unit_checker.main_run_check(dump_file, source_file)329 for s in cps_unit_checker.current_configuration.scopes:330 if s.className == 'main':331 if 'duration' in s.var_ordered_dict:332 actual_units = s.var_ordered_dict['duration'][7]['units']333 my_oracle = [{'second': 1}]334 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))335 for s in cps_unit_checker.current_configuration.scopes:336 if s.className == 'main':337 if 'second' in s.var_ordered_dict:338 actual_units = s.var_ordered_dict['second'][9]['units']339 my_oracle = [{'second': 1}]340 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))341 def test_float_1(self):342 cps_unit_checker = CPSUnitsChecker()343 cps_unit_checker.debug = False344 cps_unit_checker.debug_print_AST = False345 dump_file = './dump_files_for_tests/test_it_float_1.cpp.dump'346 source_file = dump_file.replace('.dump','')347 cps_unit_checker.main_run_check(dump_file, source_file)348 actual_units = None349 for s in cps_unit_checker.current_configuration.scopes:350 if s.className == 'main':351 if 'f' in s.var_ordered_dict and 11 in s.var_ordered_dict['f']:352 actual_units = s.var_ordered_dict['f'][11]['units']353 my_oracle = [{'second': -1, 'meter': 1}]354 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))355 def test_float_2(self):356 cps_unit_checker = CPSUnitsChecker()357 cps_unit_checker.debug = False358 cps_unit_checker.debug_print_AST = False359 dump_file = './dump_files_for_tests/test_it_float_2.cpp.dump'360 source_file = dump_file.replace('.dump','')361 cps_unit_checker.main_run_check(dump_file, source_file)362 actual_units = None363 for s in cps_unit_checker.current_configuration.scopes:364 if s.className == 'main':365 if 'f' in s.var_ordered_dict and 11 in s.var_ordered_dict['f']:366 actual_units = s.var_ordered_dict['f'][11]['units']367 my_oracle = [{'second': -1, 'meter': 1}]368 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))369 def test_float_3(self):370 cps_unit_checker = CPSUnitsChecker()371 cps_unit_checker.debug = False372 cps_unit_checker.debug_print_AST = False373 dump_file = './dump_files_for_tests/test_it_float_3.cpp.dump'374 source_file = dump_file.replace('.dump','')375 cps_unit_checker.main_run_check(dump_file, source_file)376 for s in cps_unit_checker.current_configuration.scopes:377 if s.className == 'main':378 if 'f' in s.var_ordered_dict:379 actual_units = s.var_ordered_dict['f'][12]['units']380 my_oracle = [{'second': -1, 'meter': 1}]381 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))382 def test_float_4(self):383 cps_unit_checker = CPSUnitsChecker()384 cps_unit_checker.debug = False385 cps_unit_checker.debug_print_AST = False386 dump_file = './dump_files_for_tests/test_it_float_4.cpp.dump'387 source_file = dump_file.replace('.dump','')388 cps_unit_checker.main_run_check(dump_file, source_file)389 for s in cps_unit_checker.current_configuration.scopes:390 if s.className == 'main':391 if 'f' in s.var_ordered_dict:392 actual_units = s.var_ordered_dict['f'][13]['units']393 my_oracle = [{'second': -1, 'meter': 1}]394 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))395 def test_float_5(self):396 cps_unit_checker = CPSUnitsChecker()397 cps_unit_checker.debug = False398 cps_unit_checker.debug_print_AST = False399 dump_file = './dump_files_for_tests/test_it_float_5.cpp.dump'400 source_file = dump_file.replace('.dump','')401 cps_unit_checker.main_run_check(dump_file, source_file)402 for s in cps_unit_checker.current_configuration.scopes:403 if s.className == 'main':404 if 'f' in s.var_ordered_dict:405 actual_units = s.var_ordered_dict['f'][11]['units']406 my_oracle = [{'second': -1, 'meter': 1}]407 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))408 def test_pow_1(self):409 cps_unit_checker = CPSUnitsChecker()410 cps_unit_checker.debug = False411 cps_unit_checker.debug_print_AST = False412 dump_file = './dump_files_for_tests/test_it_known_function_pow_1.cpp.dump'413 source_file = dump_file.replace('.dump','')414 cps_unit_checker.main_run_check(dump_file, source_file)415 var_name = 'f'416 var_linenr =10 417 my_oracle = [{'meter': 4}]418 actual_units = None419 for s in cps_unit_checker.current_configuration.scopes:420 if s.className == 'main':421 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:422 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']423 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))424 def test_pow_2(self):425 cps_unit_checker = CPSUnitsChecker()426 cps_unit_checker.debug = False427 cps_unit_checker.debug_print_AST = False428 dump_file = './dump_files_for_tests/test_it_known_function_pow_2.cpp.dump'429 source_file = dump_file.replace('.dump','')430 cps_unit_checker.main_run_check(dump_file, source_file)431 var_name = 'f'432 var_linenr = 11 433 my_oracle = [{'meter': 4}]434 actual_units = None435 for s in cps_unit_checker.current_configuration.scopes:436 if s.className == 'main':437 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:438 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']439 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))440 def test_pow_3(self):441 cps_unit_checker = CPSUnitsChecker()442 cps_unit_checker.debug = False443 cps_unit_checker.debug_print_AST = False444 dump_file = './dump_files_for_tests/test_it_known_function_pow_3.cpp.dump'445 source_file = dump_file.replace('.dump','')446 cps_unit_checker.main_run_check(dump_file, source_file)447 var_name = 'f'448 var_linenr = 10449 my_oracle = [{'meter': 4}]450 actual_units = None451 for s in cps_unit_checker.current_configuration.scopes:452 if s.className == 'main':453 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:454 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']455 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:%s Expected: %s received %s' % (var_name, my_oracle, actual_units))456 def test_floor_1(self):457 cps_unit_checker = CPSUnitsChecker()458 cps_unit_checker.debug = False459 cps_unit_checker.debug_print_AST = False460 dump_file = './dump_files_for_tests/test_it_known_function_floor_1.cpp.dump'461 source_file = dump_file.replace('.dump','')462 cps_unit_checker.main_run_check(dump_file, source_file)463 var_name = 's'464 var_linenr = 8 465 my_oracle = [{'meter': 1, 'second':-1}]466 actual_units = None467 for s in cps_unit_checker.current_configuration.scopes:468 if s.className == 'main':469 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:470 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']471 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))472 def test_ceil_1(self):473 cps_unit_checker = CPSUnitsChecker()474 cps_unit_checker.debug = False475 cps_unit_checker.debug_print_AST = False476 dump_file = './dump_files_for_tests/test_it_known_function_ceil_1.cpp.dump'477 source_file = dump_file.replace('.dump','')478 cps_unit_checker.main_run_check(dump_file, source_file)479 var_name = 's'480 var_linenr = 8 481 my_oracle = [{'meter': 1, 'second':-1}]482 actual_units = None483 for s in cps_unit_checker.current_configuration.scopes:484 if s.className == 'main':485 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:486 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']487 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))488 def test_acos_1(self):489 cps_unit_checker = CPSUnitsChecker()490 cps_unit_checker.debug = False491 cps_unit_checker.debug_print_AST = False492 dump_file = './dump_files_for_tests/test_it_known_function_acos_1.cpp.dump'493 source_file = dump_file.replace('.dump','')494 cps_unit_checker.main_run_check(dump_file, source_file)495 var_name = 'f'496 var_linenr = 7 497 my_oracle = [{'radian': 1}]498 actual_units = None499 for s in cps_unit_checker.current_configuration.scopes:500 if s.className == 'main':501 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:502 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']503 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))504 def test_asin_1(self):505 cps_unit_checker = CPSUnitsChecker()506 cps_unit_checker.debug = False507 cps_unit_checker.debug_print_AST = False508 dump_file = './dump_files_for_tests/test_it_known_function_asin_1.cpp.dump'509 source_file = dump_file.replace('.dump','')510 cps_unit_checker.main_run_check(dump_file, source_file)511 var_name = 'f'512 var_linenr = 7 513 my_oracle = [{'radian': 1}]514 actual_units = None515 for s in cps_unit_checker.current_configuration.scopes:516 if s.className == 'main':517 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:518 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']519 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))520 def test_atan_1(self):521 cps_unit_checker = CPSUnitsChecker()522 cps_unit_checker.debug = False523 cps_unit_checker.debug_print_AST = False524 dump_file = './dump_files_for_tests/test_it_known_function_atan_1.cpp.dump'525 source_file = dump_file.replace('.dump','')526 cps_unit_checker.main_run_check(dump_file, source_file)527 var_name = 'f'528 var_linenr = 7 529 my_oracle = [{'radian': 1}]530 actual_units = None531 for s in cps_unit_checker.current_configuration.scopes:532 if s.className == 'main':533 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:534 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']535 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))536 def test_ternary_1(self):537 cps_unit_checker = CPSUnitsChecker()538 cps_unit_checker.debug = False539 cps_unit_checker.debug_print_AST = False540 dump_file = './dump_files_for_tests/test_it_ternary_1.cpp.dump'541 source_file = dump_file.replace('.dump','')542 cps_unit_checker.main_run_check(dump_file, source_file)543 var_name = 'f'544 var_linenr = 9 545 my_oracle = [{'second': -1, 'meter': 1}, {'second': -1}]546 actual_units = None547 for s in cps_unit_checker.current_configuration.scopes:548 if s.className == 'main':549 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:550 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']551 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))552 def test_function_args_1(self):553 cps_unit_checker = CPSUnitsChecker()554 cps_unit_checker.debug = False555 cps_unit_checker.debug_print_AST = False556 dump_file = './dump_files_for_tests/test_it_function_args_1.cpp.dump'557 source_file = dump_file.replace('.dump','')558 cps_unit_checker.main_run_check(dump_file, source_file)559 # actual_units = None560 f = cps_unit_checker.current_configuration.functions[0].arg_units561 self.assertEqual(f[0][0]['linenr'], 13)562 self.assertEqual(f[0][0]['units'], [{'meter': 1}])563 def test_function_args_2(self):564 cps_unit_checker = CPSUnitsChecker()565 cps_unit_checker.debug = False566 cps_unit_checker.debug_print_AST = False567 dump_file = './dump_files_for_tests/test_it_function_args_2.cpp.dump'568 source_file = dump_file.replace('.dump','')569 cps_unit_checker.main_run_check(dump_file, source_file)570 for f in cps_unit_checker.current_configuration.functions[0].arg_units:571 self.assertEqual(f[0]['linenr'], 13)572 self.assertEqual(f[0]['units'], [{'meter': 1}])573 def test_function_args_3(self):574 cps_unit_checker = CPSUnitsChecker()575 cps_unit_checker.debug = False576 cps_unit_checker.debug_print_AST = False577 dump_file = './dump_files_for_tests/test_it_function_args_3.cpp.dump'578 source_file = dump_file.replace('.dump','')579 cps_unit_checker.main_run_check(dump_file, source_file)580 my_oracle_1 = 4581 my_oracle_2 = [{'meter': 1}]582 actual_units = None583 all_units_list = cps_unit_checker.current_configuration.functions[0].arg_units584 self.assertEqual(len(all_units_list), my_oracle_1)585 for u in all_units_list:586 self.assertEqual(u[0]['units'], my_oracle_2)587 def test_function_args_4(self):588 cps_unit_checker = CPSUnitsChecker()589 cps_unit_checker.debug = False590 cps_unit_checker.debug_print_AST = False591 dump_file = './dump_files_for_tests/test_it_function_args_4.cpp.dump'592 source_file = dump_file.replace('.dump','')593 cps_unit_checker.main_run_check(dump_file, source_file)594 my_oracle = [{'meter': 1}]595 actual_units = None596 for f in cps_unit_checker.current_configuration.functions:597 for arg_u in f.arg_units:598 for arg_use_on_line in arg_u:599 self.assertEqual(arg_use_on_line['units'], my_oracle)600 def test_function_args_5(self):601 cps_unit_checker = CPSUnitsChecker()602 cps_unit_checker.debug = False603 cps_unit_checker.debug_print_AST = False604 dump_file = './dump_files_for_tests/test_it_function_args_5.cpp.dump'605 source_file = dump_file.replace('.dump','')606 cps_unit_checker.main_run_check(dump_file, source_file)607 my_oracle_1 = [{'meter': 1}]608 my_oracle_2 = 15609 f = cps_unit_checker.current_configuration.functions[0]610 self.assertEqual(f.arg_units[0][0]['units'], my_oracle_1)611 self.assertEqual(f.arg_units[0][0]['linenr'], my_oracle_2)612 def test_division_1(self):613 cps_unit_checker = CPSUnitsChecker()614 cps_unit_checker.debug = False615 cps_unit_checker.debug_print_AST = False616 dump_file = './dump_files_for_tests/test_it_division_1.cpp.dump'617 source_file = dump_file.replace('.dump','')618 cps_unit_checker.main_run_check(dump_file, source_file)619 var_name = 'x'620 var_linenr = 9 621 my_oracle = [{'meter': 1}]622 actual_units = None623 for s in cps_unit_checker.current_configuration.scopes:624 if s.className == 'main':625 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:626 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']627 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))628 def test_division_2(self):629 cps_unit_checker = CPSUnitsChecker()630 cps_unit_checker.debug = False631 cps_unit_checker.debug_print_AST = False632 dump_file = './dump_files_for_tests/test_it_division_2.cpp.dump'633 source_file = dump_file.replace('.dump','')634 cps_unit_checker.main_run_check(dump_file, source_file)635 var_name = 'x'636 var_linenr = 9 637 my_oracle = [{'meter': 1}]638 actual_units = None639 for s in cps_unit_checker.current_configuration.scopes:640 if s.className == 'main':641 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:642 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']643 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))644 def test_division_3(self):645 cps_unit_checker = CPSUnitsChecker()646 cps_unit_checker.debug = False647 cps_unit_checker.debug_print_AST = False648 dump_file = './dump_files_for_tests/test_it_division_3.cpp.dump'649 source_file = dump_file.replace('.dump','')650 cps_unit_checker.main_run_check(dump_file, source_file)651 var_name = 'x'652 var_linenr = 9 653 my_oracle = [{'second': 2, 'meter': 1}]654 actual_units = None655 for s in cps_unit_checker.current_configuration.scopes:656 if s.className == 'main':657 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:658 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']659 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))660 def test_division_4(self):661 cps_unit_checker = CPSUnitsChecker()662 cps_unit_checker.debug = False663 cps_unit_checker.debug_print_AST = False664 dump_file = './dump_files_for_tests/test_it_division_4.cpp.dump'665 source_file = dump_file.replace('.dump','')666 cps_unit_checker.main_run_check(dump_file, source_file)667 var_name = 'x'668 var_linenr =10669 my_oracle = [{'second': 2}]670 actual_units = None671 for s in cps_unit_checker.current_configuration.scopes:672 if s.className == 'main':673 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:674 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']675 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))676 def test_logical_2(self):677 cps_unit_checker = CPSUnitsChecker()678 cps_unit_checker.debug = False679 cps_unit_checker.debug_print_AST = False680 dump_file = './dump_files_for_tests/test_it_logical_2.cpp.dump'681 source_file = dump_file.replace('.dump','')682 cps_unit_checker.main_run_check(dump_file, source_file)683 self.assertEqual(0, len(cps_unit_checker.errors))684 def test_error_type_1(self):685 cps_unit_checker = CPSUnitsChecker()686 cps_unit_checker.debug = False687 cps_unit_checker.debug_print_AST = False688 dump_file = './dump_files_for_tests/test_it_error_return_type_1.cpp.dump'689 source_file = dump_file.replace('.dump','')690 cps_unit_checker.current_file_under_analysis = dump_file691 cps_unit_checker.main_run_check(dump_file, source_file)692 self.assertEqual(1, len(cps_unit_checker.errors))693 def test_laser_scan_range_size_1(self):694 cps_unit_checker = CPSUnitsChecker()695 cps_unit_checker.debug = False696 cps_unit_checker.debug_print_AST = False697 dump_file = './dump_files_for_tests/test_it_laser_scan_range_count_1.cpp.dump'698 source_file = dump_file.replace('.dump','')699 cps_unit_checker.main_run_check(dump_file, source_file)700 var_name = 'x'701 var_linenr = 7702 my_oracle = None703 actual_units = None704 for s in cps_unit_checker.current_configuration.scopes:705 if s.className == 'main':706 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:707 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']708 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))709 self.assertEqual(0, len(cps_unit_checker.errors))710 def test_laser_scan_range_size_2(self):711 cps_unit_checker = CPSUnitsChecker()712 cps_unit_checker.debug = False713 cps_unit_checker.debug_print_AST = False714 dump_file = './dump_files_for_tests/test_it_laser_scan_range_count_2.cpp.dump'715 source_file = dump_file.replace('.dump','')716 cps_unit_checker.main_run_check(dump_file, source_file)717 var_name = 'x'718 var_linenr = 7719 my_oracle = [{'meter':1}]720 actual_units = None721 for s in cps_unit_checker.current_configuration.scopes:722 if s.className == 'main':723 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:724 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']725 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))726 def test_ros_duration_isZero_1(self):727 cps_unit_checker = CPSUnitsChecker()728 cps_unit_checker.debug = False729 cps_unit_checker.debug_print_AST = False730 dump_file = './dump_files_for_tests/test_it_ros_duration_isZero_1.cpp.dump'731 source_file = dump_file.replace('.dump','')732 cps_unit_checker.main_run_check(dump_file, source_file)733 var_name = 't'734 var_linenr = 6735 my_oracle = None736 actual_units = None737 for s in cps_unit_checker.current_configuration.scopes:738 if s.className == 'main':739 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:740 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']741 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))742 def test_ros_duration_isZero_2(self):743 cps_unit_checker = CPSUnitsChecker()744 cps_unit_checker.debug = False745 cps_unit_checker.debug_print_AST = False746 dump_file = './dump_files_for_tests/test_it_ros_duration_isZero_2.cpp.dump'747 source_file = dump_file.replace('.dump','')748 cps_unit_checker.main_run_check(dump_file, source_file)749 var_name = 't'750 var_linenr = 6751 my_oracle = [{'second':1}]752 actual_units = None753 for s in cps_unit_checker.current_configuration.scopes:754 if s.className == 'main':755 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:756 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']757 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))758 def test_ros_header_include_1(self):759 cps_unit_checker = CPSUnitsChecker()760 cps_unit_checker.debug = False761 cps_unit_checker.debug_print_AST = False762 dump_file = './dump_files_for_tests/src/test_it_header_include_1.cpp.dump'763 source_file = dump_file.replace('.dump','')764 cps_unit_checker.main_run_check(dump_file, source_file)765 self.assertEqual(2, len(cps_unit_checker.errors))766 def test_ros_header_include_2(self):767 cps_unit_checker = CPSUnitsChecker()768 cps_unit_checker.debug = False769 cps_unit_checker.debug_print_AST = False770 dump_file = './dump_files_for_tests/src/test_it_header_include_2.cpp.dump'771 source_file = dump_file.replace('.dump','')772 cps_unit_checker.main_run_check(dump_file, source_file)773 self.assertEqual(3, len(cps_unit_checker.errors))774 # WEAKER - SOMETHING STOCASTIC IS HAPPENING775 e = cps_unit_checker.errors[0]776 self.assertEqual(7, e.linenr)777 self.assertEqual('./dump_files_for_tests/src/../include/test_it_header_include_2.h', e.get_file_URI_where_error_occured())778 e = cps_unit_checker.errors[1]779 self.assertEqual(5, e.linenr)780 self.assertEqual('./dump_files_for_tests/src/test_it_header_include_2.cpp', e.get_file_URI_where_error_occured())781 # DON'T ASSIGN UNITS TO ARRAYS WHEN array.empty() IS CALLED 782 def test_laser_range_empty_1(self):783 cps_unit_checker = CPSUnitsChecker()784 cps_unit_checker.debug = False785 cps_unit_checker.debug_print_AST = False786 dump_file = './dump_files_for_tests/test_it_range_empty_1.cpp.dump'787 source_file = dump_file.replace('.dump','')788 cps_unit_checker.main_run_check(dump_file, source_file)789 self.assertEqual(0, len(cps_unit_checker.errors))790 # DON'T ASSIGN UNITS TO ARRAYS WHEN time.isZero() IS CALLED 791 def test_ros_isZero_3(self):792 cps_unit_checker = CPSUnitsChecker()793 cps_unit_checker.debug = False794 cps_unit_checker.debug_print_AST = False795 dump_file = './dump_files_for_tests/test_it_ros_isZero_3.cpp.dump'796 source_file = dump_file.replace('.dump','')797 cps_unit_checker.main_run_check(dump_file, source_file)798 self.assertEqual(0, len(cps_unit_checker.errors))799 # DON'T ASSIGN UNITS DURING x = y = z = 0800 def test_multiple_initialization_1(self):801 cps_unit_checker = CPSUnitsChecker()802 cps_unit_checker.debug = False803 cps_unit_checker.debug_print_AST = False804 dump_file = './dump_files_for_tests/test_it_multiple_initialization.cpp.dump'805 source_file = dump_file.replace('.dump','')806 cps_unit_checker.main_run_check(dump_file, source_file)807 self.assertEqual(0, len(cps_unit_checker.errors))808 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (INT)809 def test_it_multiplication_with_constant_1(self):810 cps_unit_checker = CPSUnitsChecker()811 cps_unit_checker.debug = False812 cps_unit_checker.debug_print_AST = False813 dump_file = './dump_files_for_tests/test_it_multiplication_with_constant_1.cpp.dump'814 source_file = dump_file.replace('.dump','')815 cps_unit_checker.main_run_check(dump_file, source_file)816 # self.assertEqual(0, len(cps_unit_checker.errors))817 var_name = 'f'818 var_linenr = 9819 my_oracle = [{'second':-1}]820 actual_units = None821 is_unit_propagation_based_on_constants = False822 for s in cps_unit_checker.current_configuration.scopes:823 if s.className == 'main':824 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:825 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']826 is_unit_propagation_based_on_constants = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_constants']827 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))828 self.assertTrue(is_unit_propagation_based_on_constants, 'Unit inference should be weakened by constant interaction, but is still strong.')829 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (FLOAT)830 def test_it_multiplication_with_constant_2(self):831 cps_unit_checker = CPSUnitsChecker()832 cps_unit_checker.debug = False833 cps_unit_checker.debug_print_AST = False834 dump_file = './dump_files_for_tests/test_it_multiplication_with_constant_2.cpp.dump'835 source_file = dump_file.replace('.dump','')836 cps_unit_checker.main_run_check(dump_file, source_file)837 # self.assertEqual(0, len(cps_unit_checker.errors))838 var_name = 'f'839 var_linenr = 9840 my_oracle = [{'second':-1}]841 actual_units = None842 is_unit_propagation_based_on_constants = False843 for s in cps_unit_checker.current_configuration.scopes:844 if s.className == 'main':845 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:846 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']847 is_unit_propagation_based_on_constants = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_constants']848 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))849 self.assertTrue(is_unit_propagation_based_on_constants, 'Unit inference should be weakened by constant interaction, but is still strong.')850 # WEAKEN ASSIGNMENT WHEN MULTIPLIED BY A CONSTANT (FLOAT)851 def test_it_operator_with_unknown_variable_1(self):852 cps_unit_checker = CPSUnitsChecker()853 cps_unit_checker.debug = False854 cps_unit_checker.debug_print_AST = False855 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_1.cpp.dump'856 source_file = dump_file.replace('.dump','')857 cps_unit_checker.main_run_check(dump_file, source_file)858 # self.assertEqual(0, len(cps_unit_checker.errors))859 var_name = 'f'860 var_linenr = 10 861 my_oracle = [{'second':-1}]862 actual_units = None863 is_unit_propagation_based_on_unknown_variable = False864 for s in cps_unit_checker.current_configuration.scopes:865 if s.className == 'main':866 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:867 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']868 is_unit_propagation_based_on_unknown_variable = s.var_ordered_dict[var_name][var_linenr]['is_unit_propagation_based_on_unknown_variable']869 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))870 self.assertTrue(is_unit_propagation_based_on_unknown_variable, 'Unit inference should be weakened by unknown variable interaction, but is still strong.')871 # WEAKEN ERROR WHEN MULTIPLIED BY A CONSTANT 872 def test_it_operator_with_unknown_variable_2(self):873 cps_unit_checker = CPSUnitsChecker()874 cps_unit_checker.debug = False875 cps_unit_checker.debug_print_AST = False876 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_2.cpp.dump'877 source_file = dump_file.replace('.dump','')878 cps_unit_checker.main_run_check(dump_file, source_file)879 self.assertEqual(2, len(cps_unit_checker.errors))880 for e in cps_unit_checker.errors:881 self.assertTrue(e.is_warning, 'Should be a warning but is not marked as such')882 # WEAKEN ERROR WHEN MULTIPLIED BY A CONSTANT 883 def test_it_operator_with_unknown_variable_3(self):884 cps_unit_checker = CPSUnitsChecker()885 cps_unit_checker.debug = False886 cps_unit_checker.debug_print_AST = False887 dump_file = './dump_files_for_tests/test_it_operator_with_unknown_variable_3.cpp.dump'888 source_file = dump_file.replace('.dump','')889 cps_unit_checker.main_run_check(dump_file, source_file)890 self.assertEqual(2, len(cps_unit_checker.errors))891 # PROPAGATION ACROSS MIN MAX892 def test_it_min_max_1(self):893 cps_unit_checker = CPSUnitsChecker()894 cps_unit_checker.debug = False895 cps_unit_checker.debug_print_AST = False896 dump_file = './dump_files_for_tests/test_it_min_max_1.cpp.dump'897 source_file = dump_file.replace('.dump','')898 cps_unit_checker.main_run_check(dump_file, source_file)899 var_name = 'f'900 var_linenr = 7901 my_oracle = [{'second': -1}]902 actual_units = None903 for s in cps_unit_checker.current_configuration.scopes:904 if s.className == 'main':905 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:906 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']907 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))908 self.assertEqual(0, len(cps_unit_checker.errors))909 # PROPAGATION ACROSS MIN MAX910 def test_it_min_max_2(self):911 cps_unit_checker = CPSUnitsChecker()912 cps_unit_checker.debug = False913 cps_unit_checker.debug_print_AST = False914 dump_file = './dump_files_for_tests/test_it_min_max_2.cpp.dump'915 source_file = dump_file.replace('.dump','')916 cps_unit_checker.main_run_check(dump_file, source_file)917 var_name = 'f'918 var_linenr = 8919 my_oracle = [{'second': -1}]920 actual_units = None921 for s in cps_unit_checker.current_configuration.scopes:922 if s.className == 'main':923 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:924 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']925 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))926 self.assertEqual(0, len(cps_unit_checker.errors))927 # PROPAGATION ACROSS MIN MAX928 def test_it_min_max_3(self):929 cps_unit_checker = CPSUnitsChecker()930 cps_unit_checker.debug = False931 cps_unit_checker.debug_print_AST = False932 dump_file = './dump_files_for_tests/test_it_min_max_3.cpp.dump'933 source_file = dump_file.replace('.dump','')934 cps_unit_checker.main_run_check(dump_file, source_file)935 var_name = 'f'936 var_linenr = 8937 my_oracle = [{'second': -1}, {'second': -1, 'meter': 1}]938 actual_units = None939 for s in cps_unit_checker.current_configuration.scopes:940 if s.className == 'main':941 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:942 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']943 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))944 self.assertEqual(1, len(cps_unit_checker.errors))945 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)946 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)947 self.assertFalse(cps_unit_checker.errors[0].is_warning)948 # PROPAGATION ACROSS MIN MAX949 def test_it_min_max_4(self):950 cps_unit_checker = CPSUnitsChecker()951 cps_unit_checker.debug = False952 cps_unit_checker.debug_print_AST = False953 dump_file = './dump_files_for_tests/test_it_min_max_4.cpp.dump'954 source_file = dump_file.replace('.dump','')955 cps_unit_checker.main_run_check(dump_file, source_file)956 var_name = 'f'957 var_linenr = 9958 my_oracle = [{'second': -1 }, {'second': -1, 'meter': 1}]959 actual_units = None960 is_unit_propagation_based_on_unknown_variable = False961 for s in cps_unit_checker.current_configuration.scopes:962 if s.className == 'main':963 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:964 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']965 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))966 self.assertEqual(1, len(cps_unit_checker.errors))967 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)968 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)969 self.assertFalse(cps_unit_checker.errors[0].is_warning)970 # PROTECTION AGAINST MULTILINE971 def test_it_multiline_1(self):972 cps_unit_checker = CPSUnitsChecker()973 cps_unit_checker.debug = False974 cps_unit_checker.debug_print_AST = False975 dump_file = './dump_files_for_tests/test_it_multiline_1.cpp.dump'976 source_file = dump_file.replace('.dump','')977 cps_unit_checker.main_run_check(dump_file, source_file)978 var_name = 'f'979 var_linenr = 25980 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'second': -2.0, 'meter': 2.0}, {'second': -3.0, 'meter': 3.0}, {'second': -2.0, 'meter': 1.0}, {'second': -3.0, 'meter': 2.0}, {'second': -4.0, 'meter': 3.0}]981 actual_units = None982 # is_unit_propagation_based_on_unknown_variable = False983 for s in cps_unit_checker.current_configuration.scopes:984 if s.className == 'main':985 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:986 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']987 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))988 # KNOW FUNCTION quatToRPY989 def test_it_quatToRPY_1(self):990 cps_unit_checker = CPSUnitsChecker()991 cps_unit_checker.debug = False992 cps_unit_checker.debug_print_AST = False993 dump_file = './dump_files_for_tests/test_it_quatToRPY_1.cpp.dump'994 source_file = dump_file.replace('.dump','')995 cps_unit_checker.main_run_check(dump_file, source_file)996 var_name = 'tw.linear.x'997 var_linenr = 17998 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian': 1.0}]999 actual_units = None1000 # is_unit_propagation_based_on_unknown_variable = False1001 for s in cps_unit_checker.current_configuration.scopes:1002 # for v in s.var_ordered_dict:1003 # print v1004 if s.className == 'main':1005 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1006 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1007 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1008 self.assertEqual(1, len(cps_unit_checker.errors))1009 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1010 # WEAK INFERENCE WARNING1011 def test_it_weak_inference_multiplication_1 (self):1012 cps_unit_checker = CPSUnitsChecker()1013 cps_unit_checker.debug = False1014 cps_unit_checker.debug_print_AST = False1015 dump_file = './dump_files_for_tests/test_it_weak_inference_multiplication_1.cpp.dump'1016 source_file = dump_file.replace('.dump','')1017 cps_unit_checker.main_run_check(dump_file, source_file)1018 # for e in cps_unit_checker.errors:1019 # print '\nweak inference: %s warning:%s ' % (e.var_name, str(e.is_warning))1020 var_name = 'tw.linear.x'1021 var_linenr = 191022 my_oracle = [{'second': -1.0, 'meter': 1.0}]1023 actual_units = None1024 # is_unit_propagation_based_on_unknown_variable = False1025 for s in cps_unit_checker.current_configuration.scopes:1026 # for v in s.var_ordered_dict:1027 # print v1028 if s.className == 'main':1029 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1030 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1031 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1032 self.assertEqual(0, len(cps_unit_checker.errors))1033 # WEAK INFERENCE WARNING1034 def test_it_weak_inference_multiplication_2 (self):1035 cps_unit_checker = CPSUnitsChecker()1036 cps_unit_checker.debug = False1037 cps_unit_checker.debug_print_AST = False1038 dump_file = './dump_files_for_tests/test_it_weak_inference_multiplication_2.cpp.dump'1039 source_file = dump_file.replace('.dump','')1040 cps_unit_checker.main_run_check(dump_file, source_file)1041 var_name = 'tw.linear.x'1042 var_linenr = 221043 my_oracle = [{'second': -1.0, 'meter': 1.0}]1044 actual_units = None1045 # is_unit_propagation_based_on_unknown_variable = False1046 for s in cps_unit_checker.current_configuration.scopes:1047 # for v in s.var_ordered_dict:1048 # print v1049 if s.className == 'main':1050 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1051 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1052 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1053 self.assertEqual(0, len(cps_unit_checker.errors))1054 # STRONG INFERENCE BECAUSE ADDITION1055 def test_it_weak_inference_addition_1 (self):1056 cps_unit_checker = CPSUnitsChecker()1057 cps_unit_checker.debug = False1058 cps_unit_checker.debug_print_AST = False1059 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_1.cpp.dump'1060 source_file = dump_file.replace('.dump','')1061 cps_unit_checker.main_run_check(dump_file, source_file)1062 # for e in cps_unit_checker.errors:1063 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1064 var_name = 'tw.linear.x'1065 var_linenr = 221066 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1067 actual_units = None1068 # is_unit_propagation_based_on_unknown_variable = False1069 for s in cps_unit_checker.current_configuration.scopes:1070 # for v in s.var_ordered_dict:1071 # print v1072 if s.className == 'main':1073 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1074 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1075 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1076 self.assertEqual(2, len(cps_unit_checker.errors))1077 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1078 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1079 self.assertFalse(cps_unit_checker.errors[0].is_warning)1080 var_name = 'tw.linear.y'1081 var_linenr = 231082 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1083 actual_units = None1084 # is_unit_propagation_based_on_unknown_variable = False1085 for s in cps_unit_checker.current_configuration.scopes:1086 # for v in s.var_ordered_dict:1087 # print v1088 if s.className == 'main':1089 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1090 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1091 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1092 self.assertTrue(cps_unit_checker.errors[1].was_assigned_mutiple_units)1093 self.assertFalse(cps_unit_checker.errors[1].is_unit_propagation_based_on_unknown_variable)1094 self.assertFalse(cps_unit_checker.errors[1].is_warning)1095 # STRONG INFERENCE BECAUSE ADDITION - SWAPPED OPERAND ORDER1096 def test_it_weak_inference_addition_2 (self):1097 cps_unit_checker = CPSUnitsChecker()1098 cps_unit_checker.debug = False1099 cps_unit_checker.debug_print_AST = False1100 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_2.cpp.dump'1101 source_file = dump_file.replace('.dump','')1102 cps_unit_checker.main_run_check(dump_file, source_file)1103 # for e in cps_unit_checker.errors:1104 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1105 var_name = 'tw.linear.x'1106 var_linenr = 221107 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1108 actual_units = None1109 # is_unit_propagation_based_on_unknown_variable = False1110 for s in cps_unit_checker.current_configuration.scopes:1111 # for v in s.var_ordered_dict:1112 # print v1113 if s.className == 'main':1114 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1115 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1116 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1117 self.assertEqual(2, len(cps_unit_checker.errors))1118 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1119 self.assertFalse(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1120 self.assertFalse(cps_unit_checker.errors[0].is_warning)1121 var_name = 'tw.linear.y'1122 var_linenr = 231123 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1}]1124 actual_units = None1125 # is_unit_propagation_based_on_unknown_variable = False1126 for s in cps_unit_checker.current_configuration.scopes:1127 # for v in s.var_ordered_dict:1128 # print v1129 if s.className == 'main':1130 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1131 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1132 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1133 self.assertTrue(cps_unit_checker.errors[1].was_assigned_mutiple_units)1134 self.assertFalse(cps_unit_checker.errors[1].is_unit_propagation_based_on_unknown_variable)1135 self.assertFalse(cps_unit_checker.errors[1].is_warning)1136 # STRONG INFERENCE BECAUSE ADDITION - SWAPPED OPERAND ORDER1137 def test_it_weak_inference_addition_3 (self):1138 cps_unit_checker = CPSUnitsChecker()1139 cps_unit_checker.debug = False1140 cps_unit_checker.debug_print_AST = False1141 dump_file = './dump_files_for_tests/test_it_weak_inference_addition_3.cpp.dump'1142 source_file = dump_file.replace('.dump','')1143 cps_unit_checker.main_run_check(dump_file, source_file)1144 # for e in cps_unit_checker.errors:1145 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1146 var_name = 'tw.linear.x'1147 var_linenr = 221148 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'radian':1.0}, {'second':1.}]1149 actual_units = None1150 # is_unit_propagation_based_on_unknown_variable = False1151 for s in cps_unit_checker.current_configuration.scopes:1152 # for v in s.var_ordered_dict:1153 # print v1154 if s.className == 'main':1155 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1156 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1157 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1158 self.assertEqual(2, len(cps_unit_checker.errors))1159 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1160 self.assertTrue(cps_unit_checker.errors[0].is_unit_propagation_based_on_unknown_variable)1161 self.assertTrue(cps_unit_checker.errors[0].is_warning)1162 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - STRONG1163 def test_it_addition_without_assignment_1(self):1164 cps_unit_checker = CPSUnitsChecker()1165 cps_unit_checker.debug = False1166 cps_unit_checker.debug_print_AST = False1167 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_1.cpp.dump'1168 source_file = dump_file.replace('.dump','')1169 cps_unit_checker.main_run_check(dump_file, source_file)1170 # for e in cps_unit_checker.errors:1171 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1172 self.assertEqual(1, len(cps_unit_checker.errors))1173 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1174 self.assertFalse(cps_unit_checker.errors[0].is_warning)1175 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - WEAK UNKNOWN VARIABLE1176 def test_it_addition_without_assignment_2(self):1177 cps_unit_checker = CPSUnitsChecker()1178 cps_unit_checker.debug = False1179 cps_unit_checker.debug_print_AST = False1180 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_2.cpp.dump'1181 source_file = dump_file.replace('.dump','')1182 cps_unit_checker.main_run_check(dump_file, source_file)1183 # for e in cps_unit_checker.errors:1184 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1185 self.assertEqual(1, len(cps_unit_checker.errors))1186 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1187 self.assertTrue(cps_unit_checker.errors[0].is_warning)1188 # ADDITION STAND ALONE ERROR FOR ADDITION OF INCOMPATIBLE UNITS - WEAK CONSTANT1189 def test_it_addition_without_assignment_3(self):1190 cps_unit_checker = CPSUnitsChecker()1191 cps_unit_checker.debug = False1192 cps_unit_checker.debug_print_AST = False1193 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_3.cpp.dump'1194 source_file = dump_file.replace('.dump','')1195 cps_unit_checker.main_run_check(dump_file, source_file)1196 self.assertEqual(1, len(cps_unit_checker.errors))1197 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1198 self.assertTrue(cps_unit_checker.errors[0].is_warning)1199 # ADDITION STAND ALONE ERROR FOR SUBTRACTION OF INCOMPATIBLE UNITS - STRONG CONSTANT1200 def test_it_addition_without_assignment_4(self):1201 cps_unit_checker = CPSUnitsChecker()1202 cps_unit_checker.debug = False1203 cps_unit_checker.debug_print_AST = False1204 dump_file = './dump_files_for_tests/test_it_addition_without_assignment_4.cpp.dump'1205 source_file = dump_file.replace('.dump','')1206 cps_unit_checker.main_run_check(dump_file, source_file)1207 self.assertEqual(1, len(cps_unit_checker.errors))1208 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1209 self.assertFalse(cps_unit_checker.errors[0].is_warning)1210 # ADDITION OF RADIANS1211 def test_it_radian_addition_1(self):1212 cps_unit_checker = CPSUnitsChecker()1213 cps_unit_checker.debug = False1214 cps_unit_checker.debug_print_AST = False1215 dump_file = './dump_files_for_tests/test_it_radian_addition_1.cpp.dump'1216 source_file = dump_file.replace('.dump','')1217 cps_unit_checker.main_run_check(dump_file, source_file)1218 self.assertEqual(2, len(cps_unit_checker.errors))1219 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1220 self.assertFalse(cps_unit_checker.errors[0].is_warning)1221 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[1].ERROR_TYPE)1222 self.assertFalse(cps_unit_checker.errors[1].is_warning)1223 # ADDITION OF RADIANS1224 def test_it_radian_addition_2(self):1225 cps_unit_checker = CPSUnitsChecker()1226 cps_unit_checker.debug = False1227 cps_unit_checker.debug_print_AST = False1228 dump_file = './dump_files_for_tests/test_it_radian_addition_2.cpp.dump'1229 source_file = dump_file.replace('.dump','')1230 cps_unit_checker.main_run_check(dump_file, source_file)1231 self.assertEqual(1, len(cps_unit_checker.errors))1232 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1233 self.assertFalse(cps_unit_checker.errors[0].is_warning)1234 # MULTIPLICATION OF RADIANS1235 def test_it_radian_multiplication_1(self):1236 cps_unit_checker = CPSUnitsChecker()1237 cps_unit_checker.debug = False1238 cps_unit_checker.debug_print_AST = False1239 dump_file = './dump_files_for_tests/test_it_radian_multiplication_1.cpp.dump'1240 source_file = dump_file.replace('.dump','')1241 cps_unit_checker.main_run_check(dump_file, source_file)1242 self.assertEqual(0, len(cps_unit_checker.errors))1243 # MULTIPLICATION OF RADIANS 21244 def test_it_radian_multiplication_2(self):1245 cps_unit_checker = CPSUnitsChecker()1246 cps_unit_checker.debug = False1247 cps_unit_checker.debug_print_AST = False1248 dump_file = './dump_files_for_tests/test_it_radian_multiplication_2.cpp.dump'1249 source_file = dump_file.replace('.dump','')1250 cps_unit_checker.main_run_check(dump_file, source_file)1251 self.assertEqual(1, len(cps_unit_checker.errors))1252 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1253 self.assertFalse(cps_unit_checker.errors[0].is_warning)1254 # MULTIPLICATION OF RADIANS1255 def test_it_radian_multiplication_3(self):1256 cps_unit_checker = CPSUnitsChecker()1257 cps_unit_checker.debug = False1258 cps_unit_checker.debug_print_AST = False1259 dump_file = './dump_files_for_tests/test_it_radian_multiplication_3.cpp.dump'1260 source_file = dump_file.replace('.dump','')1261 cps_unit_checker.main_run_check(dump_file, source_file)1262 self.assertEqual(0, len(cps_unit_checker.errors))1263 # MULTIPLICATION OF RADIANS 21264 def test_it_radian_multiplication_4(self):1265 cps_unit_checker = CPSUnitsChecker()1266 cps_unit_checker.debug = False1267 cps_unit_checker.debug_print_AST = False1268 dump_file = './dump_files_for_tests/test_it_radian_multiplication_4.cpp.dump'1269 source_file = dump_file.replace('.dump','')1270 cps_unit_checker.main_run_check(dump_file, source_file)1271 self.assertEqual(1, len(cps_unit_checker.errors))1272 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1273 self.assertFalse(cps_unit_checker.errors[0].is_warning)1274 # getXYZ 1275 def test_it_getXYZ_1 (self):1276 cps_unit_checker = CPSUnitsChecker()1277 cps_unit_checker.debug = False1278 cps_unit_checker.debug_print_AST = False1279 dump_file = './dump_files_for_tests/test_it_getXYZ_1.cpp.dump'1280 source_file = dump_file.replace('.dump','')1281 cps_unit_checker.main_run_check(dump_file, source_file)1282 # for e in cps_unit_checker.errors:1283 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1284 self.assertEqual(0, len(cps_unit_checker.errors))1285 # getXYZ 1286 def test_it_getXYZ_2 (self):1287 cps_unit_checker = CPSUnitsChecker()1288 cps_unit_checker.debug = False1289 cps_unit_checker.debug_print_AST = False1290 dump_file = './dump_files_for_tests/test_it_getXYZ_2.cpp.dump'1291 source_file = dump_file.replace('.dump','')1292 cps_unit_checker.main_run_check(dump_file, source_file)1293 # for e in cps_unit_checker.errors:1294 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1295 var_name = 'tw.linear.x'1296 var_linenr = 101297 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'meter':1}]1298 actual_units = None1299 # is_unit_propagation_based_on_unknown_variable = False1300 for s in cps_unit_checker.current_configuration.scopes:1301 # for v in s.var_ordered_dict:1302 # print v1303 if s.className == 'main':1304 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1305 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1306 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1307 self.assertEqual(1, len(cps_unit_checker.errors))1308 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1309 # getXYZ 1310 def test_it_getXYZ_3 (self):1311 cps_unit_checker = CPSUnitsChecker()1312 cps_unit_checker.debug = False1313 cps_unit_checker.debug_print_AST = False1314 dump_file = './dump_files_for_tests/test_it_getXYZ_3.cpp.dump'1315 source_file = dump_file.replace('.dump','')1316 cps_unit_checker.main_run_check(dump_file, source_file)1317 var_name = 'tw.linear.x'1318 var_linenr = 101319 my_oracle = [{'second': -1.0, 'meter': 1.0}, {'quaternion':1}]1320 actual_units = None1321 # is_unit_propagation_based_on_unknown_variable = False1322 for s in cps_unit_checker.current_configuration.scopes:1323 # for v in s.var_ordered_dict:1324 # print v1325 if s.className == 'main':1326 if var_name in s.var_ordered_dict and var_linenr in s.var_ordered_dict[var_name]:1327 actual_units = s.var_ordered_dict[var_name][var_linenr]['units']1328 self.assertEquals(actual_units, my_oracle, 'Incorrect units assigned to symbol:x Expected: %s received %s' % (my_oracle, actual_units))1329 self.assertEqual(1, len(cps_unit_checker.errors))1330 self.assertTrue(cps_unit_checker.errors[0].was_assigned_mutiple_units)1331 # getXYZ 1332 def test_it_getXYZ_4 (self):1333 cps_unit_checker = CPSUnitsChecker()1334 cps_unit_checker.debug = False1335 cps_unit_checker.debug_print_AST = False1336 dump_file = './dump_files_for_tests/test_it_getXYZ_4.cpp.dump'1337 source_file = dump_file.replace('.dump','')1338 cps_unit_checker.main_run_check(dump_file, source_file)1339 # for e in cps_unit_checker.errors:1340 # print '\nweak inference addition : %s warning:%s ' % (e.var_name, str(e.is_warning))1341 self.assertEqual(1, len(cps_unit_checker.errors))1342 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1343 self.assertFalse(cps_unit_checker.errors[0].is_warning)1344 # getXYZ 1345 def test_it_getXYZ_5 (self):1346 cps_unit_checker = CPSUnitsChecker()1347 cps_unit_checker.debug = False1348 cps_unit_checker.debug_print_AST = False1349 dump_file = './dump_files_for_tests/test_it_getXYZ_5.cpp.dump'1350 source_file = dump_file.replace('.dump','')1351 cps_unit_checker.main_run_check(dump_file, source_file)1352 self.assertEqual(1, len(cps_unit_checker.errors))1353 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1354 self.assertFalse(cps_unit_checker.errors[0].is_warning)1355 # QUATERNION ADDITION 11356 def test_it_quaternion_addition_1 (self):1357 cps_unit_checker = CPSUnitsChecker()1358 cps_unit_checker.debug = False1359 cps_unit_checker.debug_print_AST = False1360 dump_file = './dump_files_for_tests/test_it_quaternion_addition_1.cpp.dump'1361 source_file = dump_file.replace('.dump','')1362 cps_unit_checker.main_run_check(dump_file, source_file)1363 self.assertEqual(2, len(cps_unit_checker.errors))1364 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1365 self.assertFalse(cps_unit_checker.errors[0].is_warning)1366 self.assertEqual(UnitErrorTypes.ADDITION_OF_INCOMPATIBLE_UNITS, cps_unit_checker.errors[1].ERROR_TYPE)1367 self.assertFalse(cps_unit_checker.errors[1].is_warning)1368 # QUATERNION ADDITION 21369 def test_it_quaternion_addition_2 (self):1370 cps_unit_checker = CPSUnitsChecker()1371 cps_unit_checker.debug = False1372 cps_unit_checker.debug_print_AST = False1373 dump_file = './dump_files_for_tests/test_it_quaternion_addition_2.cpp.dump'1374 source_file = dump_file.replace('.dump','')1375 cps_unit_checker.main_run_check(dump_file, source_file)1376 self.assertEqual(1, len(cps_unit_checker.errors))1377 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1378 self.assertFalse(cps_unit_checker.errors[0].is_warning)1379 # QUATERNION ADDITION 31380 def test_it_quaternion_addition_3 (self):1381 cps_unit_checker = CPSUnitsChecker()1382 cps_unit_checker.debug = False1383 cps_unit_checker.debug_print_AST = False1384 dump_file = './dump_files_for_tests/test_it_quaternion_addition_3.cpp.dump'1385 source_file = dump_file.replace('.dump','')1386 cps_unit_checker.main_run_check(dump_file, source_file)1387 self.assertEqual(0, len(cps_unit_checker.errors))1388 # QUATERNION ADDITION 41389 def test_it_quaternion_addition_4 (self):1390 cps_unit_checker = CPSUnitsChecker()1391 cps_unit_checker.debug = False1392 cps_unit_checker.debug_print_AST = False1393 dump_file = './dump_files_for_tests/test_it_quaternion_addition_4.cpp.dump'1394 source_file = dump_file.replace('.dump','')1395 cps_unit_checker.main_run_check(dump_file, source_file)1396 self.assertEqual(0, len(cps_unit_checker.errors))1397 # QUATERNION MULTIPLICATION 11398 def test_it_quaternion_multiplication_1 (self):1399 cps_unit_checker = CPSUnitsChecker()1400 cps_unit_checker.debug = False1401 cps_unit_checker.debug_print_AST = False1402 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_1.cpp.dump'1403 source_file = dump_file.replace('.dump','')1404 cps_unit_checker.main_run_check(dump_file, source_file)1405 self.assertEqual(0, len(cps_unit_checker.errors))1406 # QUATERNION MULTIPLICATION 21407 def test_it_quaternion_multiplication_2 (self):1408 cps_unit_checker = CPSUnitsChecker()1409 cps_unit_checker.debug = False1410 cps_unit_checker.debug_print_AST = False1411 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_2.cpp.dump'1412 source_file = dump_file.replace('.dump','')1413 cps_unit_checker.main_run_check(dump_file, source_file)1414 self.assertEqual(0, len(cps_unit_checker.errors))1415 # QUATERNION MULTIPLICATION 31416 def test_it_quaternion_multiplication_3 (self):1417 cps_unit_checker = CPSUnitsChecker()1418 cps_unit_checker.debug = False1419 cps_unit_checker.debug_print_AST = False1420 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_3.cpp.dump'1421 source_file = dump_file.replace('.dump','')1422 cps_unit_checker.main_run_check(dump_file, source_file)1423 self.assertEqual(0, len(cps_unit_checker.errors))1424 # QUATERNION MULTIPLICATION 41425 def test_it_quaternion_multiplication_4 (self):1426 cps_unit_checker = CPSUnitsChecker()1427 cps_unit_checker.debug = False1428 cps_unit_checker.debug_print_AST = False1429 dump_file = './dump_files_for_tests/test_it_quaternion_multiplication_4.cpp.dump'1430 source_file = dump_file.replace('.dump','')1431 cps_unit_checker.main_run_check(dump_file, source_file)1432 self.assertEqual(0, len(cps_unit_checker.errors))1433 # QUATERNION MULTIPLICATION CLOSURE1434 def test_it_quaternion_closed_under_multiplication_1 (self):1435 cps_unit_checker = CPSUnitsChecker()1436 cps_unit_checker.debug = False1437 cps_unit_checker.debug_print_AST = False1438 dump_file = './dump_files_for_tests/test_it_quaternion_closed_under_multiplication_1.cpp.dump'1439 source_file = dump_file.replace('.dump','')1440 cps_unit_checker.main_run_check(dump_file, source_file)1441 self.assertEqual(0, len(cps_unit_checker.errors))1442 # QUATERNION MULTIPLICATION CLOSURE1443 def test_it_quaternion_closed_under_multiplication_2 (self):1444 cps_unit_checker = CPSUnitsChecker()1445 cps_unit_checker.debug = False1446 cps_unit_checker.debug_print_AST = False1447 dump_file = './dump_files_for_tests/test_it_quaternion_closed_under_multiplication_2.cpp.dump'1448 source_file = dump_file.replace('.dump','')1449 cps_unit_checker.main_run_check(dump_file, source_file)1450 self.assertEqual(1, len(cps_unit_checker.errors))1451 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1452 self.assertFalse(cps_unit_checker.errors[0].is_warning)1453 # RADIAN MULTIPLICATION CLOSURE1454 def test_it_radian_closed_under_multiplication_1 (self):1455 cps_unit_checker = CPSUnitsChecker()1456 cps_unit_checker.debug = False1457 cps_unit_checker.debug_print_AST = False1458 dump_file = './dump_files_for_tests/test_it_radian_closed_under_multiplication_1.cpp.dump'1459 source_file = dump_file.replace('.dump','')1460 cps_unit_checker.main_run_check(dump_file, source_file)1461 self.assertEqual(0, len(cps_unit_checker.errors))1462 # RADIAN MULTIPLICATION CLOSURE1463 def test_it_radian_closed_under_multiplication_2 (self):1464 cps_unit_checker = CPSUnitsChecker()1465 cps_unit_checker.debug = False1466 cps_unit_checker.debug_print_AST = False1467 dump_file = './dump_files_for_tests/test_it_radian_closed_under_multiplication_2.cpp.dump'1468 source_file = dump_file.replace('.dump','')1469 cps_unit_checker.main_run_check(dump_file, source_file)1470 self.assertEqual(1, len(cps_unit_checker.errors))1471 self.assertEqual(UnitErrorTypes.VARIABLE_MULTIPLE_UNITS, cps_unit_checker.errors[0].ERROR_TYPE)1472 self.assertFalse(cps_unit_checker.errors[0].is_warning)1473 # dt Heuristic1474 def test_it_dt_heuristic (self):1475 cps_unit_checker = CPSUnitsChecker()1476 cps_unit_checker.debug = False1477 cps_unit_checker.debug_print_AST = False1478 dump_file = './dump_files_for_tests/test_it_dt_heuristic_1.cpp.dump'1479 source_file = dump_file.replace('.dump','')1480 cps_unit_checker.main_run_check(dump_file, source_file)1481 self.assertEqual(0, len(cps_unit_checker.errors))1482 # dt Heuristic1483 def test_it_plus_equals_1 (self):1484 cps_unit_checker = CPSUnitsChecker()1485 cps_unit_checker.debug = False1486 cps_unit_checker.debug_print_AST = False1487 dump_file = './dump_files_for_tests/test_it_plus_equals_1.cpp.dump'1488 source_file = dump_file.replace('.dump','')1489 cps_unit_checker.main_run_check(dump_file, source_file)1490 self.assertEqual(0, len(cps_unit_checker.errors))1491 # dt Heuristic1492 def test_it_range_1 (self):1493 cps_unit_checker = CPSUnitsChecker()1494 cps_unit_checker.debug = False1495 cps_unit_checker.debug_print_AST = False1496 dump_file = './dump_files_for_tests/test_it_range_1.cpp.dump'1497 source_file = dump_file.replace('.dump','')1498 cps_unit_checker.main_run_check(dump_file, source_file)1499 self.assertEqual(0, len(cps_unit_checker.errors))1500 # same named argument in interface scope bug1501 def test_it_scope_bug_1 (self):1502 cps_unit_checker = CPSUnitsChecker()1503 cps_unit_checker.debug = False1504 cps_unit_checker.debug_print_AST = False1505 dump_file = './dump_files_for_tests/test_it_cppcheck_scope_bug_at_argument_1.cpp.dump'1506 source_file = dump_file.replace('.dump','')1507 cps_unit_checker.main_run_check(dump_file, source_file)1508 self.assertEqual(0, len(cps_unit_checker.errors))1509if __name__ == '__main__':...

Full Screen

Full Screen

ai_writer.py

Source:ai_writer.py Github

copy

Full Screen

1import numpy as np2from sklearn.linear_model.bayes import BayesianRidge3from sklearn.linear_model import LinearRegression4from sklearn.ensemble import GradientBoostingRegressor5from sklearn.tree import DecisionTreeRegressor6import sys7import pickle as pk8def list_to_array(var_name, values):9 value_array = []10 if (type(values) is np.ndarray and len(values.shape) > 0) or (type(values) is list):11 for i in values:12 value_array.append(str(i))13 else:14 value_array.append(str(values))15 ret = var_name + "={" + ','.join(value_array) + "};\n"16 # print ret17 return ret18def list_to_2d_vector(var_name, values):19 value_array = []20 if type(values) is np.ndarray or type(values) is list:21 for val in values:22 val_array = []23 for i in val:24 val_array.append(str(i))25 value_array.append("{" + ','.join(val_array) + "}\n")26 else:27 print "ERROR!!"28 exit(1)29 value_array.append(str(values))30 ret = var_name + "={" + ','.join(value_array) + "};\n"31 # print ret32 return ret33def write_hpp(filename, regressors):34 dump_file = open(filename, "w")35 dump_file.write('#include "tree.h"\n')36 dump_file.write('#include "linear.h"\n')37 dump_file.write('#include "gradientboost.h"\n')38 dump_file.write('using namespace std;\n')39 if isinstance(regressors, list):40 num_models = len(regressors)41 # Write coefficient !42 features = []43 for node_id, (feature_indices, regressor) in enumerate(regressors):44 features.append(feature_indices)45 if isinstance(regressor, DecisionTreeRegressor):46 dump_file.write(list_to_array("int dt_children_left_{}[]".format(node_id), regressor.tree_.children_left))47 dump_file.write(48 list_to_array("int dt_children_right_{}[]".format(node_id), regressor.tree_.children_right))49 dump_file.write(list_to_array("int dt_feature_{}[]".format(node_id), regressor.tree_.feature))50 dump_file.write(list_to_array("double dt_threshold_{}[]".format(node_id), regressor.tree_.threshold))51 dump_file.write(list_to_array("double dt_value_{}[]".format(node_id), np.squeeze(regressor.tree_.value)))52 elif isinstance(regressor, BayesianRidge) or isinstance(regressor, LinearRegression):53 # print _id,_key,item.coef_54 coeff = [np.squeeze(regressor.intercept_)] + np.squeeze(regressor.coef_).tolist()55 # print "print: ",coeff56 dump_file.write(list_to_array("double li_coeff_{}[]".format(node_id), coeff))57 dump_file.write("int li_coeff_len_{}={};\n".format(node_id, len(coeff)))58 elif isinstance(regressor, GradientBoostingRegressor):59 dump_file.write("double gb_mean_{}={};\n".format(node_id, regressor.init_.mean))60 dump_file.write("double gb_learning_rate_{}={};\n".format(node_id, regressor.learning_rate))61 tot_node = 062 for row_idx, rows in enumerate(regressor.estimators_):63 for col_idx, ele in enumerate(rows):64 dump_file.write(list_to_array("int gb_children_left_{}_{}_{}[]".format(node_id, row_idx, col_idx),65 ele.tree_.children_left))66 dump_file.write(list_to_array("int gb_children_right_{}_{}_{}[]".format(node_id, row_idx, col_idx),67 ele.tree_.children_right))68 dump_file.write(list_to_array("int gb_feature_{}_{}_{}[]".format(node_id, row_idx, col_idx),69 ele.tree_.feature))70 dump_file.write(list_to_array("double gb_threshold_{}_{}_{}[]".format(node_id, row_idx, col_idx),71 ele.tree_.threshold))72 dump_file.write(list_to_array("double gb_value_{}_{}_{}[]".format(node_id, row_idx, col_idx),73 np.squeeze(ele.tree_.value)))74 tot_node += 175 dump_file.write("int gb_total_node_{}={};\n".format(node_id, tot_node))76 big_forest = []77 for row_idx, rows in enumerate(regressor.estimators_):78 forest = []79 for col_idx, ele in enumerate(rows):80 forest.append(" Tree(" + \81 " gb_children_left_{}_{}_{},".format(node_id, row_idx, col_idx) + \82 " gb_children_right_{}_{}_{},".format(node_id, row_idx, col_idx) + \83 " gb_feature_{}_{}_{},".format(node_id, row_idx, col_idx) + \84 " gb_threshold_{}_{}_{},".format(node_id, row_idx, col_idx) + \85 " gb_value_{}_{}_{}".format(node_id, row_idx, col_idx) + \86 ")")87 my_forest = "vector<Tree>({" + ",".join(forest) + "})"88 big_forest.append(my_forest)89 dump_file.write(90 "vector<vector<Tree> > gb_forest_{}( ".format(node_id) + '{' + ",".join(big_forest) + "});")91 # elif constant!=None:92 else:93 assert False94 # coeff = [constant];95 # dump_file.write(list2array("double li_coeff_{}[]".format(_id), coeff))96 # dump_file.write("int li_coeff_len_{}={};\n".format(_id, len(coeff)))97 dump_file.write("void ai_model_read(vector<Regression*>& ai){\n")98 dump_file.write("\tint num_models={};\n".format(num_models))99 dump_file.write("\tai.resize(num_models);\n")100 # dump_file.write("\tfor(int i=0; i<num_models; i++) {\n");101 for node_id, (feature_indices, regressor) in enumerate(regressors):102 if isinstance(regressor, DecisionTreeRegressor):103 dump_file.write("\tai[{}]=new Tree({},{},{},{},{});\n".format(104 node_id,105 "dt_children_left_{}".format(node_id),106 "dt_children_right_{}".format(node_id),107 "dt_feature_{}".format(node_id),108 "dt_threshold_{}".format(node_id),109 "dt_value_{}".format(node_id)))110 elif isinstance(regressor, GradientBoostingRegressor):111 dump_file.write("\tai[{}]=new GradientBoost({},{},{},{});\n".format(112 node_id113 , "gb_forest_{}".format(node_id)114 , "gb_total_node_{}".format(node_id)115 , "gb_mean_{}".format(node_id)116 , "gb_learning_rate_{}".format(node_id)117 ))118 # elif isinstance(item, BayesianRidge) or isinstance(item, LinearRegression):119 else:120 dump_file.write("\tai[{}]=new LinearRegression({},{});\n".format(121 node_id,122 "li_coeff_{}".format(node_id),123 "li_coeff_len_{}".format(node_id)))124 # dump_file.write("\t}\n");125 dump_file.write("}\n")126 dump_file.write(list_to_2d_vector("vector<vector<int> > features", features))127 # dump_file.write(list2array("uint8_t test_data[]",td))128 # dump_file.write(list2array("float test_predict[]",tp))129 dump_file.write('''130uint32_t* get_data(int id, uint8_t* data, uint32_t* buffer)131{132// static std::vector<uint32_t> _data;133// _data.erase(_data.begin(), _data.end());134 int idx=0;135 for(auto i : features[id])136 {137 buffer[idx]=data[i];138 idx++;139 }140 return buffer;141}142std::vector<Regression*> ai;143std::vector<Regression*>& get_ai()144{145 ai_model_read(ai);146 return ai;147}148#ifdef _OPEPMP149#ifndef _AVG_MODEL_150#include <omp.h>151#endif152#endif153double predict(uint8_t* data)154{155 static std::vector<Regression*>& ai=get_ai();156 double ret=0.0;157 int len=features.size();158#pragma omp parallel for reduction(+:ret)159 for(int i=0; i<len; i++)160 {161 uint32_t buffer[2048];162 ret+=ai[i]->predict(get_data(i, data, buffer));163 }164 return ret/len;165}166''')167def read_ai_file(inputfile_name):168 with open(inputfile_name, "rb") as ai_file:169 (ai, td, tp) = pk.load(ai_file)170 if ai is not None:171 print "OK" # DEBUG("Ok!")172 else:173 print "Illegal file!" # ERROR( "Illegal file!")174 sys.exit(2)175 return ai, td, tp176from ai_text_writer import write_regressors177if __name__ == "__main__":178 print sys.argv179 (ai, td, tp) = read_ai_file(sys.argv[1])180 gr_count = 0181 for i in ai:182 for _id, (feature_list, item) in enumerate(ai):183 if isinstance(item, GradientBoostingRegressor):184 gr_count += 1185 if gr_count < 20:186 write_hpp(sys.argv[2], ai)187 else:188 # writeCPP(sys.argv[2], ai)189 write_regressors(sys.argv[2], ai, td, tp)...

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 lisa 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