As hash table is disordered, the output of compare matrixes sometimes
would put one member matrix first, that is not a good comparison. We
should put good comparison first.
Signed-off-by: Li Yuanchao <lyc163mail(a)163.com>
---
lib/compare_matrixes.rb | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/lib/compare_matrixes.rb b/lib/compare_matrixes.rb
index d8112e9..8232513 100644
--- a/lib/compare_matrixes.rb
+++ b/lib/compare_matrixes.rb
@@ -383,24 +383,33 @@ end
# compare each matrices_list within pre dimension of group matrices
# input: group matrices
# output: pre compare result of each group
+# the result with more comparison objects first
def compare_group_matrices(group_matrices, suites_list, options)
result_str = ''
- group_matrices.each do |k, v|
- matrices_list = []
- matrices_titles = []
- v.each do |dim, matrix|
- matrices_titles << dim
- matrices_list << matrix
- end
- if options[:no_print]
- result_str += compare_matrixes(matrices_list, suites_list.shift, matrices_titles, k, options: options)
- else
- print compare_matrixes(matrices_list, suites_list.shift, matrices_titles, k, options: options)
- end
+ group_matrices_array = sort_by_matrice_size(group_matrices)
+ group_matrices_array.each do |matrice_kv|
+ result_str += get_matrix_str(matrice_kv[0], matrice_kv[1], suites_list, options)
end
result_str
end
+def get_matrix_str(matrice_key, matrice_value, suites_list, options)
+ m_list = []
+ m_titles = []
+ matrice_value.each do |dim, matrix|
+ m_titles << dim
+ m_list << matrix
+ end
+ return compare_matrixes(m_list, suites_list.shift, m_titles, matrice_key, options: options) if options[:no_print]
+
+ print compare_matrixes(m_list, suites_list.shift, m_titles, matrice_key, options: options)
+end
+
+# big size first
+def sort_by_matrice_size(group_matrices)
+ group_matrices.sort { |a, b| b[1].size <=> a[1].size }
+end
+
# input: groups_matrices
# {
# group_key_1 => {
--
2.23.0