Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Yonaba/Moses.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorYonaba <roland.yonaba@gmail.com>2017-04-10 11:38:34 +0300
committerYonaba <roland.yonaba@gmail.com>2017-04-10 11:38:34 +0300
commit9a59cda719263856a92bf8958d76def63eed18f1 (patch)
treea66635b020ff49899a7733ece8420321457f8eda /spec
parent847e57a74bac6a769de0f98ea4003a84d71d1cb2 (diff)
Added _.sortBy
Diffstat (limited to 'spec')
-rw-r--r--spec/table_spec.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/spec/table_spec.lua b/spec/table_spec.lua
index 0f0e757..54c6c96 100644
--- a/spec/table_spec.lua
+++ b/spec/table_spec.lua
@@ -502,7 +502,32 @@ context('Table functions specs', function()
assert_true(_.isEqual(_.sort({'b','a','d','c'}),{'a','b','c','d'}))
end)
- end)
+ end)
+
+ context('sortBy', function()
+
+ test('sort values on the result of a transform function', function()
+ assert_true(_.isEqual(_.sortBy({1,2,3,4,5}, math.sin), {5,4,3,1,2}))
+ end)
+
+ test('the transform function defaults to _.identity', function()
+ assert_true(_.isEqual(_.sortBy({1,2,3,4,5}), {1,2,3,4,5}))
+ end)
+
+ test('transform function can be a string name property', function()
+ local unsorted = {{item = 1, value = 10},{item = 2, value = 5},{item = 3, value = 8}}
+ local sorted = {{item = 2, value = 5},{item = 3, value = 8},{item = 1, value = 10}}
+ assert_true(_.isEqual(_.sortBy(unsorted, 'value'), sorted))
+ end)
+
+ test('can use a custom comparison function', function()
+ local unsorted = {{item = 1, value = 10},{item = 2, value = 5},{item = 3, value = 8}}
+ local sorted = {{item = 1, value = 10},{item = 3, value = 8},{item = 2, value = 5}}
+ local function comp(a,b) return a > b end
+ assert_true(_.isEqual(_.sortBy(unsorted, 'value', comp), sorted))
+ end)
+
+ end)
context('groupBy', function()