| Conditions | 1 |
| Total Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import unittest |
||
| 41 | def test_tsp_optimization(self): |
||
| 42 | optimization = self.route4me.optimization |
||
| 43 | address = self.route4me.address |
||
| 44 | optimization.add(data={ |
||
| 45 | 'algorithm_type': ALGORITHM_TYPE.TSP, |
||
| 46 | 'share_route': 0, |
||
| 47 | 'store_route': 0, |
||
| 48 | 'route_time': 0, |
||
| 49 | 'route_max_duration': 86400, |
||
| 50 | 'vehicle_capacity': 1, |
||
| 51 | 'vehicle_max_distance_mi': 10000, |
||
| 52 | 'route_name': 'Single Driver Round Trip', |
||
| 53 | 'optimize': OPTIMIZE.DISTANCE, |
||
| 54 | 'distance_unit': DISTANCE_UNIT.MI, |
||
| 55 | 'device_type': DEVICE_TYPE.WEB, |
||
| 56 | 'travel_mode': TRAVEL_MODE.DRIVING, |
||
| 57 | }) |
||
| 58 | address.add_address( |
||
| 59 | address='754 5th Ave New York, NY 10019', |
||
| 60 | lat=40.7636197, |
||
| 61 | lng=-73.9744388, |
||
| 62 | alias='Bergdorf Goodman', |
||
| 63 | is_depot=1, |
||
| 64 | time=0 |
||
| 65 | ) |
||
| 66 | address.add_address( |
||
| 67 | address='717 5th Ave New York, NY 10022', |
||
| 68 | lat=40.7669692, |
||
| 69 | lng=-73.9693864, |
||
| 70 | alias='Giorgio Armani', |
||
| 71 | time=0 |
||
| 72 | ) |
||
| 73 | address.add_address( |
||
| 74 | address='888 Madison Ave New York, NY 10014', |
||
| 75 | lat=40.7715154, |
||
| 76 | lng=-73.9669241, |
||
| 77 | alias='Ralph Lauren Women\'s and Home', |
||
| 78 | time=0 |
||
| 79 | ) |
||
| 80 | address.add_address( |
||
| 81 | address='1011 Madison Ave New York, NY 10075', |
||
| 82 | lat=40.7772129, |
||
| 83 | lng=-73.9669, |
||
| 84 | alias='Yigal Azrou\u00ebl', |
||
| 85 | time=0 |
||
| 86 | ) |
||
| 87 | address.add_address( |
||
| 88 | address='440 Columbus Ave New York, NY 10024', |
||
| 89 | lat=40.7808364, |
||
| 90 | lng=-73.9732729, |
||
| 91 | alias='Frank Stella Clothier', |
||
| 92 | time=0 |
||
| 93 | ) |
||
| 94 | address.add_address( |
||
| 95 | address='324 Columbus Ave #1 New York, NY 10023', |
||
| 96 | lat=40.7803123, |
||
| 97 | lng=-73.9793079, |
||
| 98 | alias='Liana', |
||
| 99 | time=0 |
||
| 100 | ) |
||
| 101 | address.add_address( |
||
| 102 | address='110 W End Ave New York, NY 10023', |
||
| 103 | lat=40.7753077, |
||
| 104 | lng=-73.9861529, |
||
| 105 | alias='Toga Bike Shop', |
||
| 106 | time=0 |
||
| 107 | ) |
||
| 108 | address.add_address( |
||
| 109 | address='555 W 57th St New York, NY 10019', |
||
| 110 | lat=40.7718005, |
||
| 111 | lng=-73.9897716, |
||
| 112 | alias='BMW of Manhattan', |
||
| 113 | time=0 |
||
| 114 | ) |
||
| 115 | address.add_address( |
||
| 116 | address='57 W 57th St New York, NY 10019', |
||
| 117 | lat=40.7558695, |
||
| 118 | lng=-73.9862019, |
||
| 119 | alias='Verizon Wireless', |
||
| 120 | time=0 |
||
| 121 | ) |
||
| 122 | response = self.route4me.run_optimization() |
||
| 123 | self.assertEqual(4, response.get('state')) |
||
| 124 | |||
| 127 | unittest.main() |