mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
This commit is contained in:
parent
30abdf652c
commit
ccb0c8cd1c
@ -12,10 +12,10 @@ static bool _stable_sort_merge(char* a,
|
||||
int (*f_lt)(const void* a, const void* b, void* extra),
|
||||
void* extra) {
|
||||
while(a < a_end && b < b_end) {
|
||||
int res = f_lt(a, b, extra);
|
||||
int res = f_lt(b, a, extra);
|
||||
// check error
|
||||
if(res == -1) return false;
|
||||
if(res) {
|
||||
if(res == 0) { // !(b<a) -> (a>=b)
|
||||
memcpy(r, a, elem_size);
|
||||
a += elem_size;
|
||||
} else {
|
||||
|
@ -88,7 +88,7 @@ assert list(range(5, 1, -2)) == [5, 3]
|
||||
# test sort
|
||||
a = [8, 2, 4, 2, 9]
|
||||
assert a.sort() == None
|
||||
assert a == [2, 2, 4, 8, 9]
|
||||
assert (a == [2, 2, 4, 8, 9]), a
|
||||
|
||||
a = []
|
||||
assert a.sort() == None
|
||||
|
@ -143,3 +143,9 @@ class A:
|
||||
x: list[int] = [i for i in range(1, 4)]
|
||||
|
||||
assert A.x == [1, 2, 3]
|
||||
|
||||
# stable sort
|
||||
a = [(0, 1), (1, 1), (1, 2)]
|
||||
b = sorted(a, key=lambda x: x[0])
|
||||
if b != [(0, 1), (1, 1), (1, 2)]:
|
||||
assert False, b
|
Loading…
x
Reference in New Issue
Block a user