-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_round_test.go
104 lines (92 loc) · 2 KB
/
func_round_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package testing
import "testing"
func Test_Func_Round_IntsWithPrecision(t *testing.T) {
rsl := `
a = 1
b = 2
print(round(a, b))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "1\n")
assertNoErrors(t)
}
func Test_Func_Round_FloatsWithPrecision(t *testing.T) {
rsl := `
a = 2.234
b = 1
print(round(a, b))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2.2\n")
assertNoErrors(t)
}
func Test_Func_Round_FloatsWithZeroPrecision(t *testing.T) {
rsl := `
a = 2.234
b = 0
c = round(a, b)
print(c, type_of(c))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2 int\n")
assertNoErrors(t)
}
func Test_Func_Round_IntsWithoutPrecision(t *testing.T) {
rsl := `
a = 1
print(round(a))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "1\n")
assertNoErrors(t)
}
func Test_Func_Round_FloatsWithoutPrecision(t *testing.T) {
rsl := `
a = 2.234
b = round(a)
print(b, type_of(b))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2 int\n")
assertNoErrors(t)
}
func Test_Func_Round_ErrorsPrecisionLessThan0(t *testing.T) {
rsl := `
a = 1
b = -1
print(round(a, b))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L4:16
print(round(a, b))
^ Precision must be non-negative, got -1
`
assertError(t, 1, expected)
}
func Test_Func_Round_ErrorsPrecisionString(t *testing.T) {
rsl := `
a = 1
b = "ab"
print(round(a, b))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L4:16
print(round(a, b))
^ Got "string" as the 2nd argument of round(), but must be: int
`
assertError(t, 1, expected)
}
func Test_Func_Round_ErrorsWithString(t *testing.T) {
rsl := `
a = "ab"
b = 1
print(round(a, b))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L4:13
print(round(a, b))
^
Got "string" as the 1st argument of round(), but must be: float or int
`
assertError(t, 1, expected)
}