| Conditions | 11 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Utility.get_benchmark() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | """Utilities for benchmarks.""" |
||
| 13 | @staticmethod |
||
| 14 | def get_benchmark(benchmark): |
||
| 15 | if not isinstance(benchmark, ''.__class__): |
||
| 16 | return benchmark |
||
| 17 | else: |
||
| 18 | if benchmark == 'rastrigin': |
||
| 19 | return Rastrigin() |
||
| 20 | elif benchmark == 'rosenbrock': |
||
| 21 | return Rosenbrock() |
||
| 22 | elif benchmark == 'griewank': |
||
| 23 | return Griewank() |
||
| 24 | elif benchmark == 'sphere': |
||
| 25 | return Sphere() |
||
| 26 | elif benchmark == 'ackley': |
||
| 27 | return Ackley() |
||
| 28 | elif benchmark == 'schwefel': |
||
| 29 | return Schwefel() |
||
| 30 | elif benchmark == 'schwefel221': |
||
| 31 | return Schwefel221() |
||
| 32 | elif benchmark == 'schwefel222': |
||
| 33 | return Schwefel222() |
||
| 34 | elif benchmark == 'whitley': |
||
| 35 | return Whitley() |
||
| 36 | else: |
||
| 37 | raise TypeError('Passed benchmark is not defined!') |
||
| 38 |