Skip to content

Commit 34e484c

Browse files
add more bignum variations
an implementation might use a different internal representation for 1.0 vs 1, therefore we test both
1 parent 753061d commit 34e484c

File tree

6 files changed

+456
-30
lines changed

6 files changed

+456
-30
lines changed

tests/draft-next/optional/bignum.json

+76-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"description": "a negative bignum is an integer",
1313
"data": -12345678910111213141516171819202122232425262728293031,
1414
"valid": true
15+
},
16+
{
17+
"description": "a bignum is an integer if it has a zero fractional component",
18+
"data": 12345678910111213141516171819202122232425262728293031.0,
19+
"valid": true
20+
},
21+
{
22+
"description": "a negative bignum is an integer if it has a zero fractional component",
23+
"data": -12345678910111213141516171819202122232425262728293031.0,
24+
"valid": true
1525
}
1626
]
1727
},
@@ -28,9 +38,20 @@
2838
"description": "a negative bignum is a number",
2939
"data": -98249283749234923498293171823948729348710298301928331,
3040
"valid": true
41+
},
42+
{
43+
"description": "a bignum with a zero fractional component is a number",
44+
"data": 98249283749234923498293171823948729348710298301928331.0,
45+
"valid": true
46+
},
47+
{
48+
"description": "a negative bignum with a zero fractional component is a number",
49+
"data": -98249283749234923498293171823948729348710298301928331.0,
50+
"valid": true
3151
}
3252
]
3353
},
54+
,
3455
{
3556
"description": "string",
3657
"schema": { "type": "string" },
@@ -39,6 +60,16 @@
3960
"description": "a bignum is not a string",
4061
"data": 98249283749234923498293171823948729348710298301928331,
4162
"valid": false
63+
},
64+
{
65+
"description": "a bignum with zero fractional component is not a string",
66+
"data": 98249283749234923498293171823948729348710298301928331.0,
67+
"valid": false
68+
},
69+
{
70+
"description": "a float bignum is not a string",
71+
"data": 98249283749234923498293171823948729348710298301928331.1,
72+
"valid": false
4273
}
4374
]
4475
},
@@ -47,9 +78,19 @@
4778
"schema": { "maximum": 18446744073709551615 },
4879
"tests": [
4980
{
50-
"description": "comparison works for high numbers",
81+
"description": "comparison works for high integer numbers",
5182
"data": 18446744073709551600,
5283
"valid": true
84+
},
85+
{
86+
"description": "comparison works for high integer floats",
87+
"data": 18446744073709551600.0,
88+
"valid": true
89+
},
90+
{
91+
"description": "comparison works for high non-integer floats",
92+
"data": 18446744073709551600.1,
93+
"valid": true
5394
}
5495
]
5596
},
@@ -60,7 +101,17 @@
60101
},
61102
"tests": [
62103
{
63-
"description": "comparison works for high numbers",
104+
"description": "comparison works for high integers",
105+
"data": 972783798187987123879878123.188781371,
106+
"valid": false
107+
},
108+
{
109+
"description": "comparison works for high float integers",
110+
"data": 972783798187987123879878123.0,
111+
"valid": false
112+
},
113+
{
114+
"description": "comparison works for high non-integer numbers",
64115
"data": 972783798187987123879878123.188781371,
65116
"valid": false
66117
}
@@ -71,9 +122,19 @@
71122
"schema": { "minimum": -18446744073709551615 },
72123
"tests": [
73124
{
74-
"description": "comparison works for very negative numbers",
125+
"description": "comparison works for very negative integers",
75126
"data": -18446744073709551600,
76127
"valid": true
128+
},
129+
{
130+
"description": "comparison works for very negative float integers",
131+
"data": -18446744073709551600.0,
132+
"valid": true
133+
},
134+
{
135+
"description": "comparison works for very negative non-integer numbers",
136+
"data": -18446744073709551600.1,
137+
"valid": true
77138
}
78139
]
79140
},
@@ -84,8 +145,18 @@
84145
},
85146
"tests": [
86147
{
87-
"description": "comparison works for very negative numbers",
88-
"data": -972783798187987123879878123.188781371,
148+
"description": "comparison works for very negative integers",
149+
"data": -972783798187987123879878123,
150+
"valid": false
151+
},
152+
{
153+
"description": "comparison works for very negative float integers",
154+
"data": -972783798187987123879878123.0,
155+
"valid": false
156+
},
157+
{
158+
"description": "comparison works for very negative float non-integers",
159+
"data": -972783798187987123879878123.1234567,
89160
"valid": false
90161
}
91162
]

tests/draft2019-09/optional/bignum.json

+76-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"description": "a negative bignum is an integer",
1313
"data": -12345678910111213141516171819202122232425262728293031,
1414
"valid": true
15+
},
16+
{
17+
"description": "a bignum is an integer if it has a zero fractional component",
18+
"data": 12345678910111213141516171819202122232425262728293031.0,
19+
"valid": true
20+
},
21+
{
22+
"description": "a negative bignum is an integer if it has a zero fractional component",
23+
"data": -12345678910111213141516171819202122232425262728293031.0,
24+
"valid": true
1525
}
1626
]
1727
},
@@ -28,9 +38,20 @@
2838
"description": "a negative bignum is a number",
2939
"data": -98249283749234923498293171823948729348710298301928331,
3040
"valid": true
41+
},
42+
{
43+
"description": "a bignum with a zero fractional component is a number",
44+
"data": 98249283749234923498293171823948729348710298301928331.0,
45+
"valid": true
46+
},
47+
{
48+
"description": "a negative bignum with a zero fractional component is a number",
49+
"data": -98249283749234923498293171823948729348710298301928331.0,
50+
"valid": true
3151
}
3252
]
3353
},
54+
,
3455
{
3556
"description": "string",
3657
"schema": { "type": "string" },
@@ -39,6 +60,16 @@
3960
"description": "a bignum is not a string",
4061
"data": 98249283749234923498293171823948729348710298301928331,
4162
"valid": false
63+
},
64+
{
65+
"description": "a bignum with zero fractional component is not a string",
66+
"data": 98249283749234923498293171823948729348710298301928331.0,
67+
"valid": false
68+
},
69+
{
70+
"description": "a float bignum is not a string",
71+
"data": 98249283749234923498293171823948729348710298301928331.1,
72+
"valid": false
4273
}
4374
]
4475
},
@@ -47,9 +78,19 @@
4778
"schema": { "maximum": 18446744073709551615 },
4879
"tests": [
4980
{
50-
"description": "comparison works for high numbers",
81+
"description": "comparison works for high integer numbers",
5182
"data": 18446744073709551600,
5283
"valid": true
84+
},
85+
{
86+
"description": "comparison works for high integer floats",
87+
"data": 18446744073709551600.0,
88+
"valid": true
89+
},
90+
{
91+
"description": "comparison works for high non-integer floats",
92+
"data": 18446744073709551600.1,
93+
"valid": true
5394
}
5495
]
5596
},
@@ -60,7 +101,17 @@
60101
},
61102
"tests": [
62103
{
63-
"description": "comparison works for high numbers",
104+
"description": "comparison works for high integers",
105+
"data": 972783798187987123879878123.188781371,
106+
"valid": false
107+
},
108+
{
109+
"description": "comparison works for high float integers",
110+
"data": 972783798187987123879878123.0,
111+
"valid": false
112+
},
113+
{
114+
"description": "comparison works for high non-integer numbers",
64115
"data": 972783798187987123879878123.188781371,
65116
"valid": false
66117
}
@@ -71,9 +122,19 @@
71122
"schema": { "minimum": -18446744073709551615 },
72123
"tests": [
73124
{
74-
"description": "comparison works for very negative numbers",
125+
"description": "comparison works for very negative integers",
75126
"data": -18446744073709551600,
76127
"valid": true
128+
},
129+
{
130+
"description": "comparison works for very negative float integers",
131+
"data": -18446744073709551600.0,
132+
"valid": true
133+
},
134+
{
135+
"description": "comparison works for very negative non-integer numbers",
136+
"data": -18446744073709551600.1,
137+
"valid": true
77138
}
78139
]
79140
},
@@ -84,8 +145,18 @@
84145
},
85146
"tests": [
86147
{
87-
"description": "comparison works for very negative numbers",
88-
"data": -972783798187987123879878123.188781371,
148+
"description": "comparison works for very negative integers",
149+
"data": -972783798187987123879878123,
150+
"valid": false
151+
},
152+
{
153+
"description": "comparison works for very negative float integers",
154+
"data": -972783798187987123879878123.0,
155+
"valid": false
156+
},
157+
{
158+
"description": "comparison works for very negative float non-integers",
159+
"data": -972783798187987123879878123.1234567,
89160
"valid": false
90161
}
91162
]

0 commit comments

Comments
 (0)