ianmcook commented on a change in pull request #9745: URL: https://github.com/apache/arrow/pull/9745#discussion_r600151615
########## File path: r/tests/testthat/test-compute-sort.R ########## @@ -0,0 +1,157 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +context("compute: sorting") + +library(dplyr) + +tbl <- example_data_for_sorting + +test_that("Scalar sort", { + expect_identical( + as.vector(sort(Scalar$create(42L))), + 42L + ) +}) + +test_that("Array sort on integers", { + expect_equal( + Array$create(tbl$int)$SortIndices(), + Array$create(0L:9L, type = uint64()) + ) + expect_equal( + Array$create(rev(tbl$int))$SortIndices(descending = TRUE), + Array$create(c(1L:9L, 0L), type = uint64()) + ) + expect_equal( + as.vector(sort(Array$create(tbl$int))), + sort(tbl$int) + ) + expect_equal( + as.vector(sort(Array$create(tbl$int), na.last = NA)), Review comment: I did this mostly as an aid to myself, so that I could see which rows would have ties in some columns and pick other columns to break the ties. I can scramble the rows of the test data by appending a ` %>% dplyr::slice_sample(prop = 1L)` if you think it's better to sort the control data in the test code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org