From 0f48d2047d43ab53030f067a162059342b106f77 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 19 Oct 2016 15:08:08 +0200 Subject: [PATCH] feat(utils.spec.qml): add tests on `times` --- tests/ui/scripts/Utils/utils.spec.qml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml index 243f03ca8..690c049fd 100644 --- a/tests/ui/scripts/Utils/utils.spec.qml +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -95,6 +95,33 @@ TestCase { // ----------------------------------------------------------------- + function test_times1_data () { + return [ + { + cb: function (n) { return n * 2 }, + n: 10, + output: [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ] + }, + { + cb: function (n) { return n % 2 ? 1 : 0 }, + n: 10, + output: [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ] + } + ] + } + + function test_times1 (data) { + compare(Utils.times(data.n, data.cb), data.output) + } + + function test_times2 () { + var sum = 0 + Utils.times(5, function (i) { sum += (i + 1) }) + compare(sum, 15) + } + + // ----------------------------------------------------------------- + function test_isString_data () { return [ { input: 'foo', output: true },