From c45213329cf1e7fdb5cec3dabaf5fb10f95cb2aa Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Wed, 30 Jan 2019 15:30:31 +1100 Subject: [PATCH] utils: Assert sort stability. Make sure the sort order seems stable. Signed-off-by: Tim 'mithro' Ansell --- utils/sort_db.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/sort_db.py b/utils/sort_db.py index 82d1457f..09580ea2 100755 --- a/utils/sort_db.py +++ b/utils/sort_db.py @@ -303,6 +303,13 @@ def sort_db(filename): tosort.sort(key=cmp.cmp_key) + # Make sure the sort is stable + copy = tosort.copy() + copy.sort(key=cmp.cmp_key) + assert len(copy) == len(tosort) + for i in range(0, len(copy)): + assert copy[i] == tosort[i], "\n%r\n != \n%r\n" % (copy[i], tosort[i]) + with open(filename, 'w') as f: for _, l in tosort: f.write(l)