Lines Matching full:assert
4 load("assert.star", "assert")
11 assert.eq(type(0.0), "float")
14 assert.true(123.0)
15 assert.true(-1.0)
16 assert.true(not 0.0)
17 assert.true(-1.0e-45)
18 assert.true(float("NaN"))
21 assert.fails(lambda: len(0.0), 'has no len')
22 assert.fails(lambda: [x for x in 0.0], 'float value is not iterable')
25 assert.eq(type(1.234), "float")
26 assert.eq(type(1e10), "float")
27 assert.eq(type(1e+10), "float")
28 assert.eq(type(1e-10), "float")
29 assert.eq(type(1.234e10), "float")
30 assert.eq(type(1.234e+10), "float")
31 assert.eq(type(1.234e-10), "float")
34 assert.eq(0.0, 0)
35 assert.eq(0, 0.0)
36 assert.eq(1.0, 1)
37 assert.eq(1, 1.0)
38 assert.true(1.23e45 != 1229999999999999973814869011019624571608236031)
39 assert.true(1.23e45 == 1229999999999999973814869011019624571608236032)
40 assert.true(1.23e45 != 1229999999999999973814869011019624571608236033)
41 assert.true(1229999999999999973814869011019624571608236031 != 1.23e45)
42 assert.true(1229999999999999973814869011019624571608236032 == 1.23e45)
43 assert.true(1229999999999999973814869011019624571608236033 != 1.23e45)
47 assert.eq(float(p53-1), p53-1)
48 assert.eq(float(p53+0), p53+0)
49 assert.eq(float(p53+1), p53+0) #
50 assert.eq(float(p53+2), p53+2)
51 assert.eq(float(p53+3), p53+4) #
52 assert.eq(float(p53+4), p53+4)
53 assert.eq(float(p53+5), p53+4) #
54 assert.eq(float(p53+6), p53+6)
55 assert.eq(float(p53+7), p53+8) #
56 assert.eq(float(p53+8), p53+8)
58 assert.true(float(p53+1) != p53+1) # comparisons are exact
59 assert.eq(float(p53+1) - (p53+1), 0) # arithmetic entails rounding
61 assert.fails(lambda: {123.0: "f", 123: "i"}, "duplicate key: 123")
66 assert.eq(len(d), 1)
67 assert.eq(d[123.0], "y")
70 assert.eq(str(0.), "0.0")
71 assert.eq(str(.0), "0.0")
72 assert.true(5.0 != 4.999999999999999)
73 assert.eq(5.0, 4.9999999999999999) # both literals denote 5.0
74 assert.eq(1.23e45, 1.23 * 1000000000000000000000000000000000000000000000)
75 assert.eq(str(1.23e-45 - (1.23 / 1000000000000000000000000000000000000000000000)), "-1.555753819465…
85 assert.eq(+(123.0), 123.0)
86 assert.eq(-(123.0), -123.0)
87 assert.eq(-(-(123.0)), 123.0)
88 assert.eq(+(inf), inf)
89 assert.eq(-(inf), neginf)
90 assert.eq(-(neginf), inf)
91 assert.eq(str(-(nan)), "nan")
93 assert.eq(1.2e3 + 5.6e7, 5.60012e+07)
94 assert.eq(1.2e3 + 1, 1201)
95 assert.eq(1 + 1.2e3, 1201)
96 assert.eq(str(1.2e3 + nan), "nan")
97 assert.eq(inf + 0, inf)
98 assert.eq(inf + 1, inf)
99 assert.eq(inf + inf, inf)
100 assert.eq(str(inf + neginf), "nan")
102 assert.eq(1.2e3 - 5.6e7, -5.59988e+07)
103 assert.eq(1.2e3 - 1, 1199)
104 assert.eq(1 - 1.2e3, -1199)
105 assert.eq(str(1.2e3 - nan), "nan")
106 assert.eq(inf - 0, inf)
107 assert.eq(inf - 1, inf)
108 assert.eq(str(inf - inf), "nan")
109 assert.eq(inf - neginf, inf)
111 assert.eq(1.5e6 * 2.2e3, 3.3e9)
112 assert.eq(1.5e6 * 123, 1.845e+08)
113 assert.eq(123 * 1.5e6, 1.845e+08)
114 assert.eq(str(1.2e3 * nan), "nan")
115 assert.eq(str(inf * 0), "nan")
116 assert.eq(inf * 1, inf)
117 assert.eq(inf * inf, inf)
118 assert.eq(inf * neginf, neginf)
120 assert.eq(100.0 % 7.0, 2)
121 assert.eq(100.0 % -7.0, -5) # NB: different from Go / Java
122 assert.eq(-100.0 % 7.0, 5) # NB: different from Go / Java
123 assert.eq(-100.0 % -7.0, -2)
124 assert.eq(-100.0 % 7, 5)
125 assert.eq(100 % 7.0, 2)
126 assert.eq(str(1.2e3 % nan), "nan")
127 assert.eq(str(inf % 1), "nan")
128 assert.eq(str(inf % inf), "nan")
129 assert.eq(str(inf % neginf), "nan")
131 assert.eq(str(100.0 / 7.0), "14.285714285714286")
132 assert.eq(str(100 / 7.0), "14.285714285714286")
133 assert.eq(str(100.0 / 7), "14.285714285714286")
134 assert.eq(str(100.0 / nan), "nan")
136 assert.eq(100.0 // 7.0, 14)
137 assert.eq(100 // 7.0, 14)
138 assert.eq(100.0 // 7, 14)
139 assert.eq(100.0 // -7.0, -15)
140 assert.eq(100 // -7.0, -15)
141 assert.eq(100.0 // -7, -15)
142 assert.eq(str(1 // neginf), "-0.0")
143 assert.eq(str(100.0 // nan), "nan")
146 assert.eq(0.0 + 1.0, 1.0)
147 assert.eq(1.0 + 1.0, 2.0)
148 assert.eq(1.25 + 2.75, 4.0)
149 assert.eq(5.0 + 7.0, 12.0)
150 assert.eq(5.1 + 7, 12.1) # float + int
151 assert.eq(7 + 5.1, 12.1) # int + float
154 assert.eq(5.0 - 7.0, -2.0)
155 assert.eq(5.1 - 7.1, -2.0)
156 assert.eq(5.5 - 7, -1.5)
157 assert.eq(5 - 7.5, -2.5)
158 assert.eq(0.0 - 1.0, -1.0)
161 assert.eq(5.0 * 7.0, 35.0)
162 assert.eq(5.5 * 2.5, 13.75)
163 assert.eq(5.5 * 7, 38.5)
164 assert.eq(5 * 7.1, 35.5)
168 assert.eq(100.0 / 8.0, 12.5)
169 assert.eq(100.0 / -8.0, -12.5)
170 assert.eq(-100.0 / 8.0, -12.5)
171 assert.eq(-100.0 / -8.0, 12.5)
172 assert.eq(98.0 / 8.0, 12.25)
173 assert.eq(98.0 / -8.0, -12.25)
174 assert.eq(-98.0 / 8.0, -12.25)
175 assert.eq(-98.0 / -8.0, 12.25)
176 assert.eq(2.5 / 2.0, 1.25)
177 assert.eq(2.5 / 2, 1.25)
178 assert.eq(5 / 4.0, 1.25)
179 assert.eq(5 / 4, 1.25)
180 assert.fails(lambda: 1.0 / 0, "floating-point division by zero")
181 assert.fails(lambda: 1.0 / 0.0, "floating-point division by zero")
182 assert.fails(lambda: 1 / 0.0, "floating-point division by zero")
185 assert.eq(100.0 // 8.0, 12.0)
186 assert.eq(100.0 // -8.0, -13.0)
187 assert.eq(-100.0 // 8.0, -13.0)
188 assert.eq(-100.0 // -8.0, 12.0)
189 assert.eq(98.0 // 8.0, 12.0)
190 assert.eq(98.0 // -8.0, -13.0)
191 assert.eq(-98.0 // 8.0, -13.0)
192 assert.eq(-98.0 // -8.0, 12.0)
193 assert.eq(2.5 // 2.0, 1.0)
194 assert.eq(2.5 // 2, 1.0)
195 assert.eq(5 // 4.0, 1.0)
196 assert.eq(5 // 4, 1)
197 assert.eq(type(5 // 4), "int")
198 assert.fails(lambda: 1.0 // 0, "floored division by zero")
199 assert.fails(lambda: 1.0 // 0.0, "floored division by zero")
200 assert.fails(lambda: 1 // 0.0, "floored division by zero")
203 assert.eq(100.0 % 8.0, 4.0)
204 assert.eq(100.0 % -8.0, -4.0)
205 assert.eq(-100.0 % 8.0, 4.0)
206 assert.eq(-100.0 % -8.0, -4.0)
207 assert.eq(98.0 % 8.0, 2.0)
208 assert.eq(98.0 % -8.0, -6.0)
209 assert.eq(-98.0 % 8.0, 6.0)
210 assert.eq(-98.0 % -8.0, -2.0)
211 assert.eq(2.5 % 2.0, 0.5)
212 assert.eq(2.5 % 2, 0.5)
213 assert.eq(5 % 4.0, 1.0)
214 assert.fails(lambda: 1.0 % 0, "floating-point modulo by zero")
215 assert.fails(lambda: 1.0 % 0.0, "floating-point modulo by zero")
216 assert.fails(lambda: 1 % 0.0, "floating-point modulo by zero")
219 assert.fails(lambda: "abc"[1.0], "want int")
220 assert.fails(lambda: ["A", "B", "C"].insert(1.0, "D"), "want int")
221 assert.fails(lambda: range(3)[1.0], "got float, want int")
225 assert.true(nan == nan) # \
226 assert.true(nan >= nan) # unlike Python
227 assert.true(nan <= nan) # /
228 assert.true(not (nan > nan))
229 assert.true(not (nan < nan))
230 assert.true(not (nan != nan)) # unlike Python
233 assert.eq(
239 assert.eq(str(sorted([7, 3, nan, 1, 9])), "[1, 3, 7, 9, nan]")
240 assert.eq(str(sorted([7, 3, nan, 1, 9], reverse=True)), "[nan, 9, 7, 3, 1]")
245 assert.eq(len(nandict), 1) # (same as Python)
246 assert.eq(nandict[nan], 2) # (same as Python)
247 assert.fails(lambda: {nan: 1, nan: 2}, "duplicate key: nan")
250 assert.eq(str(nandict), "{nan: 3}") # (Python: {nan: 2, nan: 3})
252 assert.eq(str({inf: 1, neginf: 2}), "{+inf: 1, -inf: 2}")
255 assert.eq(0.0, negzero)
258 assert.eq(+inf / +inf, nan)
259 assert.eq(+inf / -inf, nan)
260 assert.eq(-inf / +inf, nan)
261 assert.eq(0.0 / +inf, 0.0)
262 assert.eq(0.0 / -inf, 0.0)
263 assert.true(inf > -inf)
264 assert.eq(inf, -neginf)
265 # TODO(adonovan): assert inf > any finite number, etc.
269 assert.eq(negz, 0)
272 assert.eq(max([1, nan, 3]), nan)
273 assert.eq(max([nan, 2, 3]), nan)
274 assert.eq(min([1, nan, 3]), 1)
275 assert.eq(min([nan, 2, 3]), 2)
280 assert.lt(-inf, -fltmax)
281 assert.lt(-fltmax, -1.0)
282 assert.lt(-1.0, -fltmin)
283 assert.lt(-fltmin, 0.0)
284 assert.lt(0, fltmin)
285 assert.lt(fltmin, 1.0)
286 assert.lt(1.0, fltmax)
287 assert.lt(fltmax, inf)
290 assert.eq(0, 0.0)
291 assert.eq(1, 1.0)
292 assert.eq(-1, -1.0)
293 assert.ne(-1, -1.0 + 1e-7)
294 assert.lt(-2, -2 + 1e-15)
297 assert.eq(int(100.1), 100)
298 assert.eq(int(100.0), 100)
299 assert.eq(int(99.9), 99)
300 assert.eq(int(-99.9), -99)
301 assert.eq(int(-100.0), -100)
302 assert.eq(int(-100.1), -100)
303 assert.eq(int(1e100), int("100000000000000001590289110975991804683608085639452813897813275577478387…
304 assert.fails(lambda: int(inf), "cannot convert.*infinity")
305 assert.fails(lambda: int(nan), "cannot convert.*NaN")
308 assert.eq(float(), 0.0)
310 assert.eq(float(False), 0.0)
311 assert.eq(float(True), 1.0)
313 assert.eq(float(0), 0.0)
314 assert.eq(float(1), 1.0)
315 assert.eq(float(123), 123.0)
316 assert.eq(float(123 * 1000000 * 1000000 * 1000000 * 1000000 * 1000000), 1.23e+32)
318 assert.eq(float(1.1), 1.1)
319 assert.fails(lambda: float(None), "want number or string")
320 assert.ne(False, 0.0) # differs from Python
321 assert.ne(True, 1.0)
323 assert.eq(float("1.1"), 1.1)
324 assert.fails(lambda: float("1.1abc"), "invalid float literal")
325 assert.fails(lambda: float("1e100.0"), "invalid float literal")
326 assert.fails(lambda: float("1e1000"), "floating-point number too large")
327 assert.eq(float("-1.1"), -1.1)
328 assert.eq(float("+1.1"), +1.1)
329 assert.eq(float("+Inf"), inf)
330 assert.eq(float("-Inf"), neginf)
331 assert.eq(float("NaN"), nan)
332 assert.eq(float("NaN"), nan)
333 assert.eq(float("+NAN"), nan)
334 assert.eq(float("-nan"), nan)
335 assert.eq(str(float("Inf")), "+inf")
336 assert.eq(str(float("+INF")), "+inf")
337 assert.eq(str(float("-inf")), "-inf")
338 assert.eq(str(float("+InFiniTy")), "+inf")
339 assert.eq(str(float("-iNFiniTy")), "-inf")
340 assert.fails(lambda: float("one point two"), "invalid float literal: one point two")
341 assert.fails(lambda: float("1.2.3"), "invalid float literal: 1.2.3")
342 assert.fails(lambda: float(123 << 500 << 500 << 50), "int too large to convert to float")
343 assert.fails(lambda: float(-123 << 500 << 500 << 50), "int too large to convert to float")
344 assert.fails(lambda: float(str(-123 << 500 << 500 << 50)), "floating-point number too large")
347 assert.fails(lambda: (1<<500<<500<<500) + 0.0, "int too large to convert to float")
348 assert.fails(lambda: 0.0 + (1<<500<<500<<500), "int too large to convert to float")
349 assert.fails(lambda: (1<<500<<500<<500) - 0.0, "int too large to convert to float")
350 assert.fails(lambda: 0.0 - (1<<500<<500<<500), "int too large to convert to float")
351 assert.fails(lambda: (1<<500<<500<<500) * 1.0, "int too large to convert to float")
352 assert.fails(lambda: 1.0 * (1<<500<<500<<500), "int too large to convert to float")
353 assert.fails(lambda: (1<<500<<500<<500) / 1.0, "int too large to convert to float")
354 assert.fails(lambda: 1.0 / (1<<500<<500<<500), "int too large to convert to float")
355 assert.fails(lambda: (1<<500<<500<<500) // 1.0, "int too large to convert to float")
356 assert.fails(lambda: 1.0 // (1<<500<<500<<500), "int too large to convert to float")
357 assert.fails(lambda: (1<<500<<500<<500) % 1.0, "int too large to convert to float")
358 assert.fails(lambda: 1.0 % (1<<500<<500<<500), "int too large to convert to float")
362 assert.eq(int(0.0), 0)
363 assert.eq(int(1.0), 1)
364 assert.eq(int(1.1), 1)
365 assert.eq(int(0.9), 0)
366 assert.eq(int(-1.1), -1.0)
367 assert.eq(int(-1.0), -1.0)
368 assert.eq(int(-0.9), 0.0)
369 assert.eq(int(1.23e+32), 123000000000000004979083645550592)
370 assert.eq(int(-1.23e-32), 0)
371 assert.eq(int(1.23e-32), 0)
372 assert.fails(lambda: int(float("+Inf")), "cannot convert float infinity to integer")
373 assert.fails(lambda: int(float("-Inf")), "cannot convert float infinity to integer")
374 assert.fails(lambda: int(float("NaN")), "cannot convert float NaN to integer")
389 assert.true(False, "{%v: None} != {%v: None}: hashes vary" % fh, ih)
395 assert.eq("%d" % 0, "0")
396 assert.eq("%d" % 0.0, "0")
397 assert.eq("%d" % 123, "123")
398 assert.eq("%d" % 123.0, "123")
399 assert.eq("%d" % 1.23e45, "1229999999999999973814869011019624571608236032")
401 assert.eq("%d" % negzero, "0")
402 assert.fails(lambda: "%d" % float("NaN"), "cannot convert float NaN to integer")
403 assert.fails(lambda: "%d" % float("+Inf"), "cannot convert float infinity to integer")
404 assert.fails(lambda: "%d" % float("-Inf"), "cannot convert float infinity to integer")
407 assert.eq("%e" % 0, "0.000000e+00")
408 assert.eq("%e" % 0.0, "0.000000e+00")
409 assert.eq("%e" % 123, "1.230000e+02")
410 assert.eq("%e" % 123.0, "1.230000e+02")
411 assert.eq("%e" % 1.23e45, "1.230000e+45")
412 assert.eq("%e" % -1.23e-45, "-1.230000e-45")
413 assert.eq("%e" % nan, "nan")
414 assert.eq("%e" % inf, "+inf")
415 assert.eq("%e" % neginf, "-inf")
416 assert.eq("%e" % negzero, "-0.000000e+00")
417 assert.fails(lambda: "%e" % "123", "requires float, not str")
419 assert.eq("%f" % 0, "0.000000")
420 assert.eq("%f" % 0.0, "0.000000")
421 assert.eq("%f" % 123, "123.000000")
422 assert.eq("%f" % 123.0, "123.000000")
424 assert.eq("%f" % 1.23e45, "1229999999999999973814869011019624571608236032.000000")
425 assert.eq("%f" % -1.23e-45, "-0.000000")
426 assert.eq("%f" % nan, "nan")
427 assert.eq("%f" % inf, "+inf")
428 assert.eq("%f" % neginf, "-inf")
429 assert.eq("%f" % negzero, "-0.000000")
430 assert.fails(lambda: "%f" % "123", "requires float, not str")
432 assert.eq("%g" % 0, "0.0")
433 assert.eq("%g" % 0.0, "0.0")
434 assert.eq("%g" % 123, "123.0")
435 assert.eq("%g" % 123.0, "123.0")
436 assert.eq("%g" % 1.110, "1.11")
437 assert.eq("%g" % 1e5, "100000.0")
438 assert.eq("%g" % 1e6, "1e+06") # Note: threshold of scientific notation is 1e17 in Starlark/Java
439 assert.eq("%g" % 1.23e45, "1.23e+45")
440 assert.eq("%g" % -1.23e-45, "-1.23e-45")
441 assert.eq("%g" % nan, "nan")
442 assert.eq("%g" % inf, "+inf")
443 assert.eq("%g" % neginf, "-inf")
444 assert.eq("%g" % negzero, "-0.0")
446 assert.eq(str(0.0), "0.0")
447 assert.eq(str(123.0), "123.0")
448 assert.eq(str(1.23e45), "1.23e+45")
449 assert.eq(str(-1.23e-45), "-1.23e-45")
450 assert.eq(str(nan), "nan")
451 assert.eq(str(inf), "+inf")
452 assert.eq(str(neginf), "-inf")
453 assert.eq(str(negzero), "-0.0")
454 assert.fails(lambda: "%g" % "123", "requires float, not str")
458 assert.eq(type(i0), "int")
459 assert.eq(type(f0), "float")
503 assert.contains(want, got)