Total Complexity | 47 |
Total Lines | 161 |
Duplicated Lines | 0 % |
Complex classes like pyclustering.cluster.tests.Test 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 | """! |
||
39 | class Test(unittest.TestCase): |
||
40 | def templateClustering(self, file, radius, order, solver, initial, storage_flag, conn_weigh_flag, tolerance, connection, expected_cluster_length, ccore_flag): |
||
41 | result_testing = False; |
||
42 | |||
43 | # If phases crosses each other because of random part of the network then we should try again. |
||
44 | for attempt in range(0, 4, 1): |
||
45 | sample = read_sample(file); |
||
46 | network = syncnet(sample, radius, connection, initial, conn_weigh_flag, ccore_flag); |
||
47 | analyser = network.process(order, solver, storage_flag); |
||
48 | |||
49 | clusters = analyser.allocate_clusters(tolerance); |
||
50 | |||
51 | obtained_cluster_sizes = [len(cluster) for cluster in clusters]; |
||
52 | |||
53 | if (len(obtained_cluster_sizes) != len(expected_cluster_length)): |
||
54 | continue; |
||
55 | |||
56 | obtained_cluster_sizes.sort(); |
||
57 | expected_cluster_length.sort(); |
||
58 | |||
59 | if (obtained_cluster_sizes != expected_cluster_length): |
||
60 | continue; |
||
61 | |||
62 | # Unit-test is passed |
||
63 | result_testing = True; |
||
64 | break; |
||
65 | |||
66 | assert result_testing; |
||
67 | |||
68 | |||
69 | def testClusteringSampleSimple1(self): |
||
70 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 5], False); |
||
71 | |||
72 | def testClusteringSampleSimple1ListRepr(self): |
||
73 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.LIST, [5, 5], False); |
||
74 | |||
75 | def testClusteringSampleSimple1ByCore(self): |
||
76 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [5, 5], True); |
||
77 | |||
78 | def testClusteringSampleSimple2(self): |
||
79 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 8, 10], False); |
||
80 | |||
81 | def testClusteringSampleSimple2ListRepr(self): |
||
82 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.LIST, [5, 8, 10], False); |
||
83 | |||
84 | def testClusteringSampleSimple2ByCore(self): |
||
85 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [5, 8, 10], True); |
||
86 | |||
87 | def testClusteringSampleSimple3(self): |
||
88 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [10, 10, 10, 30], False); |
||
89 | |||
90 | def testClusteringSampleSimple3ListRepr(self): |
||
91 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.LIST, [10, 10, 10, 30], False); |
||
92 | |||
93 | def testClusteringSampleSimple3ByCore(self): |
||
94 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [10, 10, 10, 30], True); |
||
95 | |||
96 | def testClusteringSampleSimple4(self): |
||
97 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [15, 15, 15, 15, 15], False); |
||
98 | |||
99 | def testClusteringSampleSimple4ByCore(self): |
||
100 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [15, 15, 15, 15, 15], True); |
||
101 | |||
102 | def testClusteringSampleSimple5(self): |
||
103 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [15, 15, 15, 15], False); |
||
104 | |||
105 | def testClusteringSampleSimple5ByCore(self): |
||
106 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [15, 15, 15, 15], True); |
||
107 | |||
108 | def testClusteringSampleElongateByCore(self): |
||
109 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_ELONGATE, 0.5, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [135, 20], True); |
||
110 | |||
111 | |||
112 | def testClusterAllocationHighToleranceSampleSimple1(self): |
||
113 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, conn_represent.MATRIX, [10], False); |
||
114 | |||
115 | def testClusterAllocationHighToleranceSampleSimple1ByCore(self): |
||
116 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, None, [10], True); |
||
117 | |||
118 | def testClusterAllocationHighToleranceSampleSimple2(self): |
||
119 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, conn_represent.MATRIX, [23], False); |
||
120 | |||
121 | def testClusterAllocationHighToleranceSampleSimple2ByCore(self): |
||
122 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, None, [23], True); |
||
123 | |||
124 | def testClusterAllocationHighToleranceSampleSimple3(self): |
||
125 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, conn_represent.MATRIX, [60], False); |
||
126 | |||
127 | def testClusterAllocationHighToleranceSampleSimple3ByCore(self): |
||
128 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, None, [60], True); |
||
129 | |||
130 | def testClusterAllocationHighToleranceSampleSimple4(self): |
||
131 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 0.7, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, conn_represent.MATRIX, [75], False); |
||
132 | |||
133 | def testClusterAllocationHighToleranceSampleSimple4ByCore(self): |
||
134 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE4, 0.7, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, None, [75], True); |
||
135 | |||
136 | def testClusterAllocationHighToleranceSampleSimple5(self): |
||
137 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 0.7, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, conn_represent.MATRIX, [60], False); |
||
138 | |||
139 | def testClusterAllocationHighToleranceSampleSimple5ByCore(self): |
||
140 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE5, 0.7, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 2 * pi, None, [60], True); |
||
141 | |||
142 | |||
143 | def testClusterAllocationConnWeightSampleSimple1(self): |
||
144 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 2, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, conn_represent.MATRIX, [5, 5], False); |
||
145 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 10, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, conn_represent.MATRIX, [10], False); |
||
146 | |||
147 | def testClusterAllocationConnWeightSampleSimple2(self): |
||
148 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 2, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, conn_represent.MATRIX, [5, 8, 10], False); |
||
149 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 10, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, conn_represent.MATRIX, [23], False); |
||
150 | |||
151 | def testClusterAllocationConnWeightSampleSimple1ByCore(self): |
||
152 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 2, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, None, [5, 5], True); |
||
153 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 10, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, None, [10], True); |
||
154 | |||
155 | def testClusterAllocationConnWeightSampleSimple2ByCore(self): |
||
156 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 2, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, None, [5, 8, 10], True); |
||
157 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 10, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, True, 0.05, None, [23], True); |
||
158 | |||
159 | |||
160 | def testClusteringWithoutDynamicCollectingSampleSimple1(self): |
||
161 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [5, 5], False); |
||
162 | |||
163 | def testClusteringWithoutDynamicCollectingSampleSimple1ByCore(self): |
||
164 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [5, 5], True); |
||
165 | |||
166 | def testClusteringWithoutDynamicCollectingSampleSimple2(self): |
||
167 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [5, 8, 10], False); |
||
168 | |||
169 | def testClusteringWithoutDynamicCollectingSampleSimple2ByCore(self): |
||
170 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [5, 8, 10], True); |
||
171 | |||
172 | def testClusteringWithoutDynamicCollectingSampleSimple3(self): |
||
173 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [10, 10, 10, 30], False); |
||
174 | |||
175 | def testClusteringWithoutDynamicCollectingSampleSimple3ByCore(self): |
||
176 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE3, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [10, 10, 10, 30], False); |
||
177 | |||
178 | |||
179 | def testClusteringRandomInitialSampleSimple1(self): |
||
180 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 5], False); |
||
181 | |||
182 | def testClusteringRandomInitialSampleSimple1ByCore(self): |
||
183 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, None, [5, 5], True); |
||
184 | |||
185 | def testClusteringRandomInitialSampleSimple2(self): |
||
186 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, conn_represent.MATRIX, [5, 8, 10], False); |
||
187 | |||
188 | def testClusteringRandomInitialSampleSimple2ByCore(self): |
||
189 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE2, 1, 0.999, solve_type.FAST, initial_type.RANDOM_GAUSSIAN, False, False, 0.05, None, [5, 8, 10], True); |
||
190 | |||
191 | |||
192 | def testClusteringSolverRK4SampleSimple1(self): |
||
193 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.RK4, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 5], False); |
||
194 | |||
195 | def testClusteringSolverRK4SampleSimple1ByCore(self): |
||
196 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.RK4, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 5], True); |
||
197 | |||
198 | def testClusteringSolverRKF45SampleSimple1ByCore(self): |
||
199 | self.templateClustering(SIMPLE_SAMPLES.SAMPLE_SIMPLE1, 1, 0.999, solve_type.RKF45, initial_type.RANDOM_GAUSSIAN, True, False, 0.05, conn_represent.MATRIX, [5, 5], True); |
||
200 | |||
203 | unittest.main(); |