mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Tests for numbers builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
Anand Krishnamoorthi
parent
17257f9f1d
commit
6b87e99fb9
@@ -1,419 +0,0 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: abs
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [abs(-9), abs(9), abs(-9.1), abs(9.1)]
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
z = abs(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [9, 9, 9.1, 9.1]
|
||||
|
||||
- note: abs-extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = abs(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`abs` expects 1 argument"
|
||||
|
||||
- note: abs-invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = abs("-9")
|
||||
query: data.test.x
|
||||
error: "`abs` expects numeric argument"
|
||||
|
||||
- note: ceil
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [ceil(9.1), ceil(-9.1), ceil(9), ceil(-9)]
|
||||
# Undefined
|
||||
y { false }
|
||||
z = ceil(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [10, -9, 9, -9]
|
||||
|
||||
- note: ceil-extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = ceil(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`ceil` expects 1 argument"
|
||||
|
||||
- note: ceil-invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = ceil("-9")
|
||||
query: data.test.x
|
||||
error: "`ceil` expects numeric argument"
|
||||
|
||||
- note: floor
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [floor(9.1), floor(-9.1), floor(9), floor(-9)]
|
||||
# Undefined
|
||||
y { false }
|
||||
z = floor(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [9, -10, 9, -9]
|
||||
|
||||
- note: floor-extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = floor(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`floor` expects 1 argument"
|
||||
|
||||
- note: floor-invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = floor("-9")
|
||||
query: data.test.x
|
||||
error: "`floor` expects numeric argument"
|
||||
|
||||
- note: numbers.range
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
r1 = numbers.range(1, 5)
|
||||
r2 = numbers.range(5, 1)
|
||||
r3 = numbers.range(-1, -5)
|
||||
r4 = numbers.range(-5, -1)
|
||||
|
||||
# Single item range
|
||||
r5 = numbers.range(8, 8)
|
||||
|
||||
# Non-integer start and end result in Undefined.
|
||||
r6 = numbers.range(1.01, 5)
|
||||
r7 = numbers.range(1, 5.01)
|
||||
|
||||
y { false }
|
||||
r8 = numbers.range(y, 10)
|
||||
r9 = numbers.range(10, y)
|
||||
|
||||
query: data.test
|
||||
want_result:
|
||||
r1: [1, 2, 3, 4, 5]
|
||||
r2: [5, 4, 3, 2, 1]
|
||||
r3: [-1, -2, -3, -4, -5]
|
||||
r4: [-5, -4, -3, -2, -1]
|
||||
r5: [8]
|
||||
|
||||
- note: numbers.range-less-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects 2 arguments"
|
||||
|
||||
- note: numbers.range-more-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1, 2, 3)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects 2 arguments"
|
||||
|
||||
- note: numbers.range-invalid-start
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range("1", 2)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects numeric argument"
|
||||
|
||||
- note: numbers.range-invalid-end
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1, "2")
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects numeric argument"
|
||||
|
||||
- note: round
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [round(-9.4), round(-9.5), round(-9.6),
|
||||
round(9.4), round(9.5), round(9.6),
|
||||
round(8), round(-8)]
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
z = round(y)
|
||||
query: data.test.x
|
||||
want_result: [-9, -10, -10, 9, 10, 10, 8, -8]
|
||||
|
||||
- note: round-extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = round(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`round` expects 1 argument"
|
||||
|
||||
- note: round-invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = round("-9")
|
||||
query: data.test.x
|
||||
error: "`round` expects numeric argument"
|
||||
|
||||
- note: rand.intn
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("x", 50000)
|
||||
y = rand.intn("y", 50000)
|
||||
z = [p |
|
||||
p := rand.intn("x", 50000)
|
||||
]
|
||||
a = rand.intn("x", 25000)
|
||||
|
||||
results = [
|
||||
x == z[0],
|
||||
x != y,
|
||||
x != a,
|
||||
rand.intn("b", 0)
|
||||
]
|
||||
query: data.test.results
|
||||
want_result: [true, true, true, 0]
|
||||
|
||||
- note: rand.intn-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
y { false }
|
||||
r1 = rand.intn(y, 10)
|
||||
r2 = rand.intn(10, y)
|
||||
r3 = rand.intn("a", 10.3)
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: rand.intn-extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("abc", 10, 11)
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects 2 arguments"
|
||||
|
||||
- note: rand.intn-less-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("abc")
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects 2 arguments"
|
||||
|
||||
- note: rand.intn-invalid-type-1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn(1, 2)
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects string argument"
|
||||
|
||||
- note: rand.intn-invalid-type-2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("a", "b")
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects numeric argument"
|
||||
|
||||
|
||||
- note: div
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import future.keywords.if
|
||||
|
||||
x = 1/3
|
||||
|
||||
# Undefined
|
||||
y if false
|
||||
a = 1 / 0
|
||||
b = y / 1
|
||||
c = 1 / y
|
||||
d = 13.3 % 3
|
||||
e = 13 % 3.1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 0.3333333333333333
|
||||
|
||||
- note: div-non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" / 9
|
||||
query: data.test.x
|
||||
error: "`div` expects numeric argument."
|
||||
|
||||
- note: mod
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 10%3
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 % 0
|
||||
b = y % 1
|
||||
c = 1 % y
|
||||
query: data.test
|
||||
want_result:
|
||||
x : 1
|
||||
|
||||
- note: mod-non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" % 9
|
||||
query: data.test.x
|
||||
error: "`mod` expects numeric argument."
|
||||
|
||||
- note: mod-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
a { false }
|
||||
x = a % 10
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: mod-by-zero
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 1%0
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: mul
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 * -1 * 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 * y
|
||||
b = y * 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: -13.5
|
||||
|
||||
- note: mul-non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" * 9
|
||||
query: data.test.x
|
||||
error: "`mul` expects numeric argument."
|
||||
|
||||
- note: add
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 + -1 + 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 + y
|
||||
b = y + 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 6.5
|
||||
|
||||
- note: add-non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" + 9
|
||||
query: data.test.x
|
||||
error: "`add` expects numeric argument."
|
||||
|
||||
- note: sub
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 - -1 - 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 - y
|
||||
b = y - 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: -0.5
|
||||
|
||||
- note: sub-non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" - 9
|
||||
query: data.test.x
|
||||
error: "`sub` expects numeric argument."
|
||||
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 16 / 2 % 5 / 2
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 1.5
|
||||
|
||||
# TODO: Lockdown associativity and precedence of operators.
|
||||
35
tests/interpreter/cases/builtins/numbers/abs.yaml
Normal file
35
tests/interpreter/cases/builtins/numbers/abs.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: abs
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [abs(-9), abs(9), abs(-9.1), abs(9.1)]
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
z = abs(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [9, 9, 9.1, 9.1]
|
||||
|
||||
- note: extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = abs(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`abs` expects 1 argument"
|
||||
|
||||
- note: invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = abs("-9")
|
||||
query: data.test.x
|
||||
error: "`abs` expects numeric argument"
|
||||
26
tests/interpreter/cases/builtins/numbers/add.yaml
Normal file
26
tests/interpreter/cases/builtins/numbers/add.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: add
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 + -1 + 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 + y
|
||||
b = y + 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 6.5
|
||||
|
||||
- note: non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" + 9
|
||||
query: data.test.x
|
||||
error: "`add` expects numeric argument."
|
||||
@@ -0,0 +1,5 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
# TODO: Lockdown associativity and precedence of operators.
|
||||
cases: []
|
||||
34
tests/interpreter/cases/builtins/numbers/ceil.yaml
Normal file
34
tests/interpreter/cases/builtins/numbers/ceil.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: ceil
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [ceil(9.1), ceil(-9.1), ceil(9), ceil(-9)]
|
||||
# Undefined
|
||||
y { false }
|
||||
z = ceil(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [10, -9, 9, -9]
|
||||
|
||||
- note: extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = ceil(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`ceil` expects 1 argument"
|
||||
|
||||
- note: invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = ceil("-9")
|
||||
query: data.test.x
|
||||
error: "`ceil` expects numeric argument"
|
||||
32
tests/interpreter/cases/builtins/numbers/div.yaml
Normal file
32
tests/interpreter/cases/builtins/numbers/div.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: div
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import future.keywords.if
|
||||
|
||||
x = 1/3
|
||||
|
||||
# Undefined
|
||||
y if false
|
||||
a = 1 / 0
|
||||
b = y / 1
|
||||
c = 1 / y
|
||||
d = 13.3 % 3
|
||||
e = 13 % 3.1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 0.3333333333333333
|
||||
|
||||
- note: non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" / 9
|
||||
query: data.test.x
|
||||
error: "`div` expects numeric argument."
|
||||
35
tests/interpreter/cases/builtins/numbers/floor.yaml
Normal file
35
tests/interpreter/cases/builtins/numbers/floor.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: floor
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [floor(9.1), floor(-9.1), floor(9), floor(-9)]
|
||||
# Undefined
|
||||
y { false }
|
||||
z = floor(y)
|
||||
query: data.test
|
||||
want_result:
|
||||
x: [9, -10, 9, -9]
|
||||
|
||||
- note: extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = floor(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`floor` expects 1 argument"
|
||||
|
||||
- note: invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = floor("-9")
|
||||
query: data.test.x
|
||||
error: "`floor` expects numeric argument"
|
||||
|
||||
72
tests/interpreter/cases/builtins/numbers/intn.yaml
Normal file
72
tests/interpreter/cases/builtins/numbers/intn.yaml
Normal file
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: rand.intn
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("x", 50000)
|
||||
y = rand.intn("y", 50000)
|
||||
z = [p |
|
||||
p := rand.intn("x", 50000)
|
||||
]
|
||||
a = rand.intn("x", 25000)
|
||||
|
||||
results = [
|
||||
x == z[0],
|
||||
x != y,
|
||||
x != a,
|
||||
rand.intn("b", 0)
|
||||
]
|
||||
query: data.test.results
|
||||
want_result: [true, true, true, 0]
|
||||
|
||||
- note: undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
y { false }
|
||||
r1 = rand.intn(y, 10)
|
||||
r2 = rand.intn(10, y)
|
||||
r3 = rand.intn("a", 10.3)
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("abc", 10, 11)
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects 2 arguments"
|
||||
|
||||
- note: less-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("abc")
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects 2 arguments"
|
||||
|
||||
- note: invalid-type-1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn(1, 2)
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects string argument"
|
||||
|
||||
- note: invalid-type-2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = rand.intn("a", "b")
|
||||
query: data.test.x
|
||||
error: "`rand.intn` expects numeric argument"
|
||||
47
tests/interpreter/cases/builtins/numbers/mod.yaml
Normal file
47
tests/interpreter/cases/builtins/numbers/mod.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: mod
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 10%3
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 % 0
|
||||
b = y % 1
|
||||
c = 1 % y
|
||||
query: data.test
|
||||
want_result:
|
||||
x : 1
|
||||
|
||||
- note: non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" % 9
|
||||
query: data.test.x
|
||||
error: "`mod` expects numeric argument."
|
||||
|
||||
- note: undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
a { false }
|
||||
x = a % 10
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: by-zero
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 1%0
|
||||
query: data.test
|
||||
want_result: {}
|
||||
26
tests/interpreter/cases/builtins/numbers/mul.yaml
Normal file
26
tests/interpreter/cases/builtins/numbers/mul.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: mul
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 * -1 * 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 * y
|
||||
b = y * 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: -13.5
|
||||
|
||||
- note: non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" * 9
|
||||
query: data.test.x
|
||||
error: "`mul` expects numeric argument."
|
||||
68
tests/interpreter/cases/builtins/numbers/range.yaml
Normal file
68
tests/interpreter/cases/builtins/numbers/range.yaml
Normal file
@@ -0,0 +1,68 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: numbers.range
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
r1 = numbers.range(1, 5)
|
||||
r2 = numbers.range(5, 1)
|
||||
r3 = numbers.range(-1, -5)
|
||||
r4 = numbers.range(-5, -1)
|
||||
|
||||
# Single item range
|
||||
r5 = numbers.range(8, 8)
|
||||
|
||||
# Non-integer start and end result in Undefined.
|
||||
r6 = numbers.range(1.01, 5)
|
||||
r7 = numbers.range(1, 5.01)
|
||||
|
||||
y { false }
|
||||
r8 = numbers.range(y, 10)
|
||||
r9 = numbers.range(10, y)
|
||||
|
||||
query: data.test
|
||||
want_result:
|
||||
r1: [1, 2, 3, 4, 5]
|
||||
r2: [5, 4, 3, 2, 1]
|
||||
r3: [-1, -2, -3, -4, -5]
|
||||
r4: [-5, -4, -3, -2, -1]
|
||||
r5: [8]
|
||||
|
||||
- note: less-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects 2 arguments"
|
||||
|
||||
- note: more-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1, 2, 3)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects 2 arguments"
|
||||
|
||||
- note: invalid-start
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range("1", 2)
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects numeric argument"
|
||||
|
||||
- note: invalid-end
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = numbers.range(1, "2")
|
||||
query: data.test.x
|
||||
error: "`numbers.range` expects numeric argument"
|
||||
36
tests/interpreter/cases/builtins/numbers/round.yaml
Normal file
36
tests/interpreter/cases/builtins/numbers/round.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: round
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = [round(-9.4), round(-9.5), round(-9.6),
|
||||
round(9.4), round(9.5), round(9.6),
|
||||
round(8), round(-8)]
|
||||
|
||||
# Undefined
|
||||
y { false }
|
||||
z = round(y)
|
||||
query: data.test.x
|
||||
want_result: [-9, -10, -10, 9, 10, 10, 8, -8]
|
||||
|
||||
- note: extra-args
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = round(-9, 10)
|
||||
query: data.test.x
|
||||
error: "`round` expects 1 argument"
|
||||
|
||||
- note: invalid-type
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = round("-9")
|
||||
query: data.test.x
|
||||
error: "`round` expects numeric argument"
|
||||
36
tests/interpreter/cases/builtins/numbers/sub.yaml
Normal file
36
tests/interpreter/cases/builtins/numbers/sub.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: sub
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 3 - -1 - 4.5
|
||||
# Undefined
|
||||
y { false }
|
||||
a = 1 - y
|
||||
b = y - 1
|
||||
query: data.test
|
||||
want_result:
|
||||
x: -0.5
|
||||
|
||||
- note: non-numeric
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = "1" - 9
|
||||
query: data.test.x
|
||||
error: "`sub` expects numeric argument."
|
||||
|
||||
- note: all
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
x = 16 / 2 % 5 / 2
|
||||
query: data.test
|
||||
want_result:
|
||||
x: 1.5
|
||||
Reference in New Issue
Block a user