1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix array_sort by different order of a/b (#9106)

This commit is contained in:
yuyi
2021-03-04 18:19:02 +08:00
committed by GitHub
parent d08f994e19
commit 2b9ffbda42
3 changed files with 20 additions and 6 deletions

View File

@ -807,6 +807,18 @@ fn test_sort() {
// assert users.map(it.name).join(' ') == 'Alice Bob Peter'
}
fn test_sort_by_different_order_of_a_b() {
mut x := [1, 2, 3]
x.sort(a < b)
println(x)
assert x == [1, 2, 3]
mut y := [1, 2, 3]
y.sort(b < a)
println(y)
assert y == [3, 2, 1]
}
fn test_f32_sort() {
mut f := [f32(50.0), 15, 1, 79, 38, 0, 27]
f.sort_with_compare(compare_f32)