| author | |
| committer | |
| log | c2db077574be841da586fa62d67619c901dd535d |
| tree | c8eb64846fa7ffb9027fa1ca035dd8ca5712b9d4 |
| parent | be6d022257d8d7e99bd080823d4d8f0175f320c5 |
| signature |
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.
This makes release mode test builds more accurately test
the actual code that will be run.
However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.
Here is the explanation of when to use either one, copied from
the assert doc comments:
Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.
closes #1304239 files changed, 4106 insertions(+), 3960 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -658,6 +658,7 @@ set(ZIG_STD_FILES |
| 658 | 658 | "special/test_runner.zig" |
| 659 | 659 | "spinlock.zig" |
| 660 | 660 | "statically_initialized_mutex.zig" |
| 661 | "testing.zig" | |
| 661 | 662 | "unicode.zig" |
| 662 | 663 | "zig/ast.zig" |
| 663 | 664 | "zig/index.zig" |
doc/docgen.zig+2-2| ... | ... | @@ -4,7 +4,7 @@ const io = std.io; |
| 4 | 4 | const os = std.os; |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | const mem = std.mem; |
| 7 | const assert = std.debug.assert; | |
| 7 | const testing = std.testing; | |
| 8 | 8 | |
| 9 | 9 | const max_doc_file_size = 10 * 1024 * 1024; |
| 10 | 10 | |
| ... | ... | @@ -620,7 +620,7 @@ const TermState = enum { |
| 620 | 620 | test "term color" { |
| 621 | 621 | const input_bytes = "A\x1b[32;1mgreen\x1b[0mB"; |
| 622 | 622 | const result = try termColor(std.debug.global_allocator, input_bytes); |
| 623 | assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B")); | |
| 623 | testing.expectEqualSlices(u8, "A<span class=\"t32\">green</span>B", result)); | |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
src-self-hosted/arg.zig+12-11| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const debug = std.debug; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | |
| 5 | 6 | const Allocator = mem.Allocator; |
| ... | ... | @@ -272,21 +273,21 @@ test "parse arguments" { |
| 272 | 273 | |
| 273 | 274 | var args = try Args.parse(std.debug.global_allocator, spec1, cliargs); |
| 274 | 275 | |
| 275 | debug.assert(args.present("help")); | |
| 276 | debug.assert(!args.present("help2")); | |
| 277 | debug.assert(!args.present("init")); | |
| 276 | testing.expect(args.present("help")); | |
| 277 | testing.expect(!args.present("help2")); | |
| 278 | testing.expect(!args.present("init")); | |
| 278 | 279 | |
| 279 | debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig")); | |
| 280 | debug.assert(mem.eql(u8, args.single("color").?, "on")); | |
| 280 | testing.expect(mem.eql(u8, args.single("build-file").?, "build.zig")); | |
| 281 | testing.expect(mem.eql(u8, args.single("color").?, "on")); | |
| 281 | 282 | |
| 282 | 283 | const objects = args.many("object").?; |
| 283 | debug.assert(mem.eql(u8, objects[0], "obj1")); | |
| 284 | debug.assert(mem.eql(u8, objects[1], "obj2")); | |
| 284 | testing.expect(mem.eql(u8, objects[0], "obj1")); | |
| 285 | testing.expect(mem.eql(u8, objects[1], "obj2")); | |
| 285 | 286 | |
| 286 | debug.assert(mem.eql(u8, args.single("library").?, "lib2")); | |
| 287 | testing.expect(mem.eql(u8, args.single("library").?, "lib2")); | |
| 287 | 288 | |
| 288 | 289 | const pos = args.positionals.toSliceConst(); |
| 289 | debug.assert(mem.eql(u8, pos[0], "build")); | |
| 290 | debug.assert(mem.eql(u8, pos[1], "pos1")); | |
| 291 | debug.assert(mem.eql(u8, pos[2], "pos2")); | |
| 290 | testing.expect(mem.eql(u8, pos[0], "build")); | |
| 291 | testing.expect(mem.eql(u8, pos[1], "pos1")); | |
| 292 | testing.expect(mem.eql(u8, pos[2], "pos2")); | |
| 292 | 293 | } |
src-self-hosted/test.zig+2-2| ... | ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); |
| 4 | 4 | const Target = @import("target.zig").Target; |
| 5 | 5 | const Compilation = @import("compilation.zig").Compilation; |
| 6 | 6 | const introspect = @import("introspect.zig"); |
| 7 | const assertOrPanic = std.debug.assertOrPanic; | |
| 7 | const testing = std.testing; | |
| 8 | 8 | const errmsg = @import("errmsg.zig"); |
| 9 | 9 | const ZigCompiler = @import("compilation.zig").ZigCompiler; |
| 10 | 10 | |
| ... | ... | @@ -210,7 +210,7 @@ pub const TestContext = struct { |
| 210 | 210 | @panic("build incorrectly failed"); |
| 211 | 211 | }, |
| 212 | 212 | Compilation.Event.Fail => |msgs| { |
| 213 | assertOrPanic(msgs.len != 0); | |
| 213 | testing.expect(msgs.len != 0); | |
| 214 | 214 | for (msgs) |msg| { |
| 215 | 215 | if (mem.endsWith(u8, msg.realpath, path) and mem.eql(u8, msg.text, text)) { |
| 216 | 216 | const span = msg.getSpan(); |
src/ir.cpp+14-10| ... | ... | @@ -17543,21 +17543,16 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, |
| 17543 | 17543 | enum_field_val->data.x_struct.fields = inner_fields; |
| 17544 | 17544 | } |
| 17545 | 17545 | |
| 17546 | static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) { | |
| 17546 | static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigType *type_entry, ConstExprValue **out) { | |
| 17547 | 17547 | Error err; |
| 17548 | 17548 | assert(type_entry != nullptr); |
| 17549 | 17549 | assert(!type_is_invalid(type_entry)); |
| 17550 | 17550 | |
| 17551 | if ((err = ensure_complete_type(ira->codegen, type_entry))) | |
| 17551 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | |
| 17552 | 17552 | return err; |
| 17553 | 17553 | |
| 17554 | if (type_entry == ira->codegen->builtin_types.entry_global_error_set) { | |
| 17555 | zig_panic("TODO implement @typeInfo for global error set"); | |
| 17556 | } | |
| 17557 | ||
| 17558 | 17554 | ConstExprValue *result = nullptr; |
| 17559 | switch (type_entry->id) | |
| 17560 | { | |
| 17555 | switch (type_entry->id) { | |
| 17561 | 17556 | case ZigTypeIdInvalid: |
| 17562 | 17557 | zig_unreachable(); |
| 17563 | 17558 | case ZigTypeIdMetaType: |
| ... | ... | @@ -17778,6 +17773,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE |
| 17778 | 17773 | ensure_field_index(result->type, "errors", 0); |
| 17779 | 17774 | |
| 17780 | 17775 | ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); |
| 17776 | if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) { | |
| 17777 | return ErrorSemanticAnalyzeFail; | |
| 17778 | } | |
| 17779 | if (type_is_global_error_set(type_entry)) { | |
| 17780 | ir_add_error_node(ira, source_node, | |
| 17781 | buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936")); | |
| 17782 | return ErrorSemanticAnalyzeFail; | |
| 17783 | } | |
| 17784 | ||
| 17781 | 17785 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 17782 | 17786 | ConstExprValue *error_array = create_const_vals(1); |
| 17783 | 17787 | error_array->special = ConstValSpecialStatic; |
| ... | ... | @@ -18103,7 +18107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE |
| 18103 | 18107 | { |
| 18104 | 18108 | ZigType *fn_type = type_entry->data.bound_fn.fn_type; |
| 18105 | 18109 | assert(fn_type->id == ZigTypeIdFn); |
| 18106 | if ((err = ir_make_type_info_value(ira, fn_type, &result))) | |
| 18110 | if ((err = ir_make_type_info_value(ira, source_node, fn_type, &result))) | |
| 18107 | 18111 | return err; |
| 18108 | 18112 | |
| 18109 | 18113 | break; |
| ... | ... | @@ -18128,7 +18132,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 18128 | 18132 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 18129 | 18133 | |
| 18130 | 18134 | ConstExprValue *payload; |
| 18131 | if ((err = ir_make_type_info_value(ira, type_entry, &payload))) | |
| 18135 | if ((err = ir_make_type_info_value(ira, instruction->base.source_node, type_entry, &payload))) | |
| 18132 | 18136 | return ira->codegen->invalid_instruction; |
| 18133 | 18137 | |
| 18134 | 18138 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
std/array_list.zig+53-53| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const debug = std.debug; |
| 3 | 3 | const assert = debug.assert; |
| 4 | const assertError = debug.assertError; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | const Allocator = mem.Allocator; |
| 7 | 7 | |
| ... | ... | @@ -212,8 +212,8 @@ test "std.ArrayList.init" { |
| 212 | 212 | var list = ArrayList(i32).init(allocator); |
| 213 | 213 | defer list.deinit(); |
| 214 | 214 | |
| 215 | assert(list.count() == 0); | |
| 216 | assert(list.capacity() == 0); | |
| 215 | testing.expect(list.count() == 0); | |
| 216 | testing.expect(list.capacity() == 0); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "std.ArrayList.basic" { |
| ... | ... | @@ -224,7 +224,7 @@ test "std.ArrayList.basic" { |
| 224 | 224 | defer list.deinit(); |
| 225 | 225 | |
| 226 | 226 | // setting on empty list is out of bounds |
| 227 | assertError(list.setOrError(0, 1), error.OutOfBounds); | |
| 227 | testing.expectError(error.OutOfBounds, list.setOrError(0, 1)); | |
| 228 | 228 | |
| 229 | 229 | { |
| 230 | 230 | var i: usize = 0; |
| ... | ... | @@ -236,44 +236,44 @@ test "std.ArrayList.basic" { |
| 236 | 236 | { |
| 237 | 237 | var i: usize = 0; |
| 238 | 238 | while (i < 10) : (i += 1) { |
| 239 | assert(list.items[i] == @intCast(i32, i + 1)); | |
| 239 | testing.expect(list.items[i] == @intCast(i32, i + 1)); | |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | for (list.toSlice()) |v, i| { |
| 244 | assert(v == @intCast(i32, i + 1)); | |
| 244 | testing.expect(v == @intCast(i32, i + 1)); | |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | for (list.toSliceConst()) |v, i| { |
| 248 | assert(v == @intCast(i32, i + 1)); | |
| 248 | testing.expect(v == @intCast(i32, i + 1)); | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | assert(list.pop() == 10); | |
| 252 | assert(list.len == 9); | |
| 251 | testing.expect(list.pop() == 10); | |
| 252 | testing.expect(list.len == 9); | |
| 253 | 253 | |
| 254 | 254 | list.appendSlice([]const i32{ |
| 255 | 255 | 1, |
| 256 | 256 | 2, |
| 257 | 257 | 3, |
| 258 | 258 | }) catch unreachable; |
| 259 | assert(list.len == 12); | |
| 260 | assert(list.pop() == 3); | |
| 261 | assert(list.pop() == 2); | |
| 262 | assert(list.pop() == 1); | |
| 263 | assert(list.len == 9); | |
| 259 | testing.expect(list.len == 12); | |
| 260 | testing.expect(list.pop() == 3); | |
| 261 | testing.expect(list.pop() == 2); | |
| 262 | testing.expect(list.pop() == 1); | |
| 263 | testing.expect(list.len == 9); | |
| 264 | 264 | |
| 265 | 265 | list.appendSlice([]const i32{}) catch unreachable; |
| 266 | assert(list.len == 9); | |
| 266 | testing.expect(list.len == 9); | |
| 267 | 267 | |
| 268 | 268 | // can only set on indices < self.len |
| 269 | 269 | list.set(7, 33); |
| 270 | 270 | list.set(8, 42); |
| 271 | 271 | |
| 272 | assertError(list.setOrError(9, 99), error.OutOfBounds); | |
| 273 | assertError(list.setOrError(10, 123), error.OutOfBounds); | |
| 272 | testing.expectError(error.OutOfBounds, list.setOrError(9, 99)); | |
| 273 | testing.expectError(error.OutOfBounds, list.setOrError(10, 123)); | |
| 274 | 274 | |
| 275 | assert(list.pop() == 42); | |
| 276 | assert(list.pop() == 33); | |
| 275 | testing.expect(list.pop() == 42); | |
| 276 | testing.expect(list.pop() == 33); | |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | test "std.ArrayList.swapRemove" { |
| ... | ... | @@ -289,18 +289,18 @@ test "std.ArrayList.swapRemove" { |
| 289 | 289 | try list.append(7); |
| 290 | 290 | |
| 291 | 291 | //remove from middle |
| 292 | assert(list.swapRemove(3) == 4); | |
| 293 | assert(list.at(3) == 7); | |
| 294 | assert(list.len == 6); | |
| 292 | testing.expect(list.swapRemove(3) == 4); | |
| 293 | testing.expect(list.at(3) == 7); | |
| 294 | testing.expect(list.len == 6); | |
| 295 | 295 | |
| 296 | 296 | //remove from end |
| 297 | assert(list.swapRemove(5) == 6); | |
| 298 | assert(list.len == 5); | |
| 297 | testing.expect(list.swapRemove(5) == 6); | |
| 298 | testing.expect(list.len == 5); | |
| 299 | 299 | |
| 300 | 300 | //remove from front |
| 301 | assert(list.swapRemove(0) == 1); | |
| 302 | assert(list.at(0) == 5); | |
| 303 | assert(list.len == 4); | |
| 301 | testing.expect(list.swapRemove(0) == 1); | |
| 302 | testing.expect(list.at(0) == 5); | |
| 303 | testing.expect(list.len == 4); | |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | test "std.ArrayList.swapRemoveOrError" { |
| ... | ... | @@ -308,27 +308,27 @@ test "std.ArrayList.swapRemoveOrError" { |
| 308 | 308 | defer list.deinit(); |
| 309 | 309 | |
| 310 | 310 | // Test just after initialization |
| 311 | assertError(list.swapRemoveOrError(0), error.OutOfBounds); | |
| 311 | testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); | |
| 312 | 312 | |
| 313 | 313 | // Test after adding one item and remote it |
| 314 | 314 | try list.append(1); |
| 315 | assert((try list.swapRemoveOrError(0)) == 1); | |
| 316 | assertError(list.swapRemoveOrError(0), error.OutOfBounds); | |
| 315 | testing.expect((try list.swapRemoveOrError(0)) == 1); | |
| 316 | testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); | |
| 317 | 317 | |
| 318 | 318 | // Test after adding two items and remote both |
| 319 | 319 | try list.append(1); |
| 320 | 320 | try list.append(2); |
| 321 | assert((try list.swapRemoveOrError(1)) == 2); | |
| 322 | assert((try list.swapRemoveOrError(0)) == 1); | |
| 323 | assertError(list.swapRemoveOrError(0), error.OutOfBounds); | |
| 321 | testing.expect((try list.swapRemoveOrError(1)) == 2); | |
| 322 | testing.expect((try list.swapRemoveOrError(0)) == 1); | |
| 323 | testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); | |
| 324 | 324 | |
| 325 | 325 | // Test out of bounds with one item |
| 326 | 326 | try list.append(1); |
| 327 | assertError(list.swapRemoveOrError(1), error.OutOfBounds); | |
| 327 | testing.expectError(error.OutOfBounds, list.swapRemoveOrError(1)); | |
| 328 | 328 | |
| 329 | 329 | // Test out of bounds with two items |
| 330 | 330 | try list.append(2); |
| 331 | assertError(list.swapRemoveOrError(2), error.OutOfBounds); | |
| 331 | testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2)); | |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | test "std.ArrayList.iterator" { |
| ... | ... | @@ -342,22 +342,22 @@ test "std.ArrayList.iterator" { |
| 342 | 342 | var count: i32 = 0; |
| 343 | 343 | var it = list.iterator(); |
| 344 | 344 | while (it.next()) |next| { |
| 345 | assert(next == count + 1); | |
| 345 | testing.expect(next == count + 1); | |
| 346 | 346 | count += 1; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | assert(count == 3); | |
| 350 | assert(it.next() == null); | |
| 349 | testing.expect(count == 3); | |
| 350 | testing.expect(it.next() == null); | |
| 351 | 351 | it.reset(); |
| 352 | 352 | count = 0; |
| 353 | 353 | while (it.next()) |next| { |
| 354 | assert(next == count + 1); | |
| 354 | testing.expect(next == count + 1); | |
| 355 | 355 | count += 1; |
| 356 | 356 | if (count == 2) break; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | it.reset(); |
| 360 | assert(it.next().? == 1); | |
| 360 | testing.expect(it.next().? == 1); | |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | test "std.ArrayList.insert" { |
| ... | ... | @@ -368,10 +368,10 @@ test "std.ArrayList.insert" { |
| 368 | 368 | try list.append(2); |
| 369 | 369 | try list.append(3); |
| 370 | 370 | try list.insert(0, 5); |
| 371 | assert(list.items[0] == 5); | |
| 372 | assert(list.items[1] == 1); | |
| 373 | assert(list.items[2] == 2); | |
| 374 | assert(list.items[3] == 3); | |
| 371 | testing.expect(list.items[0] == 5); | |
| 372 | testing.expect(list.items[1] == 1); | |
| 373 | testing.expect(list.items[2] == 2); | |
| 374 | testing.expect(list.items[3] == 3); | |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | test "std.ArrayList.insertSlice" { |
| ... | ... | @@ -386,17 +386,17 @@ test "std.ArrayList.insertSlice" { |
| 386 | 386 | 9, |
| 387 | 387 | 8, |
| 388 | 388 | }); |
| 389 | assert(list.items[0] == 1); | |
| 390 | assert(list.items[1] == 9); | |
| 391 | assert(list.items[2] == 8); | |
| 392 | assert(list.items[3] == 2); | |
| 393 | assert(list.items[4] == 3); | |
| 394 | assert(list.items[5] == 4); | |
| 389 | testing.expect(list.items[0] == 1); | |
| 390 | testing.expect(list.items[1] == 9); | |
| 391 | testing.expect(list.items[2] == 8); | |
| 392 | testing.expect(list.items[3] == 2); | |
| 393 | testing.expect(list.items[4] == 3); | |
| 394 | testing.expect(list.items[5] == 4); | |
| 395 | 395 | |
| 396 | 396 | const items = []const i32{1}; |
| 397 | 397 | try list.insertSlice(0, items[0..0]); |
| 398 | assert(list.len == 6); | |
| 399 | assert(list.items[0] == 1); | |
| 398 | testing.expect(list.len == 6); | |
| 399 | testing.expect(list.items[0] == 1); | |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | const Item = struct { |
| ... | ... | @@ -407,5 +407,5 @@ const Item = struct { |
| 407 | 407 | test "std.ArrayList: ArrayList(T) of struct T" { |
| 408 | 408 | var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(debug.global_allocator) }; |
| 409 | 409 | try root.sub_items.append( Item{ .integer = 42, .sub_items = ArrayList(Item).init(debug.global_allocator) } ); |
| 410 | assert(root.sub_items.items[0].integer == 42); | |
| 410 | testing.expect(root.sub_items.items[0].integer == 42); | |
| 411 | 411 | } |
std/atomic/queue.zig+12-11| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const AtomicOrder = builtin.AtomicOrder; |
| 4 | 4 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 5 | const assert = std.debug.assert; |
| 6 | const expect = std.testing.expect; | |
| 6 | 7 | |
| 7 | 8 | /// Many producer, many consumer, non-allocating, thread-safe. |
| 8 | 9 | /// Uses a mutex to protect access. |
| ... | ... | @@ -174,14 +175,14 @@ test "std.atomic.Queue" { |
| 174 | 175 | { |
| 175 | 176 | var i: usize = 0; |
| 176 | 177 | while (i < put_thread_count) : (i += 1) { |
| 177 | std.debug.assertOrPanic(startPuts(&context) == 0); | |
| 178 | expect(startPuts(&context) == 0); | |
| 178 | 179 | } |
| 179 | 180 | } |
| 180 | 181 | context.puts_done = 1; |
| 181 | 182 | { |
| 182 | 183 | var i: usize = 0; |
| 183 | 184 | while (i < put_thread_count) : (i += 1) { |
| 184 | std.debug.assertOrPanic(startGets(&context) == 0); | |
| 185 | expect(startGets(&context) == 0); | |
| 185 | 186 | } |
| 186 | 187 | } |
| 187 | 188 | } else { |
| ... | ... | @@ -264,7 +265,7 @@ test "std.atomic.Queue single-threaded" { |
| 264 | 265 | }; |
| 265 | 266 | queue.put(&node_1); |
| 266 | 267 | |
| 267 | assert(queue.get().?.data == 0); | |
| 268 | expect(queue.get().?.data == 0); | |
| 268 | 269 | |
| 269 | 270 | var node_2 = Queue(i32).Node{ |
| 270 | 271 | .data = 2, |
| ... | ... | @@ -280,9 +281,9 @@ test "std.atomic.Queue single-threaded" { |
| 280 | 281 | }; |
| 281 | 282 | queue.put(&node_3); |
| 282 | 283 | |
| 283 | assert(queue.get().?.data == 1); | |
| 284 | expect(queue.get().?.data == 1); | |
| 284 | 285 | |
| 285 | assert(queue.get().?.data == 2); | |
| 286 | expect(queue.get().?.data == 2); | |
| 286 | 287 | |
| 287 | 288 | var node_4 = Queue(i32).Node{ |
| 288 | 289 | .data = 4, |
| ... | ... | @@ -291,12 +292,12 @@ test "std.atomic.Queue single-threaded" { |
| 291 | 292 | }; |
| 292 | 293 | queue.put(&node_4); |
| 293 | 294 | |
| 294 | assert(queue.get().?.data == 3); | |
| 295 | expect(queue.get().?.data == 3); | |
| 295 | 296 | node_3.next = null; |
| 296 | 297 | |
| 297 | assert(queue.get().?.data == 4); | |
| 298 | expect(queue.get().?.data == 4); | |
| 298 | 299 | |
| 299 | assert(queue.get() == null); | |
| 300 | expect(queue.get() == null); | |
| 300 | 301 | } |
| 301 | 302 | |
| 302 | 303 | test "std.atomic.Queue dump" { |
| ... | ... | @@ -311,7 +312,7 @@ test "std.atomic.Queue dump" { |
| 311 | 312 | // Test empty stream |
| 312 | 313 | sos.reset(); |
| 313 | 314 | try queue.dumpToStream(SliceOutStream.Error, &sos.stream); |
| 314 | assert(mem.eql(u8, buffer[0..sos.pos], | |
| 315 | expect(mem.eql(u8, buffer[0..sos.pos], | |
| 315 | 316 | \\head: (null) |
| 316 | 317 | \\tail: (null) |
| 317 | 318 | \\ |
| ... | ... | @@ -335,7 +336,7 @@ test "std.atomic.Queue dump" { |
| 335 | 336 | \\ (null) |
| 336 | 337 | \\ |
| 337 | 338 | , @ptrToInt(queue.head), @ptrToInt(queue.tail)); |
| 338 | assert(mem.eql(u8, buffer[0..sos.pos], expected)); | |
| 339 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); | |
| 339 | 340 | |
| 340 | 341 | // Test a stream with two elements |
| 341 | 342 | var node_1 = Queue(i32).Node{ |
| ... | ... | @@ -356,5 +357,5 @@ test "std.atomic.Queue dump" { |
| 356 | 357 | \\ (null) |
| 357 | 358 | \\ |
| 358 | 359 | , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail)); |
| 359 | assert(mem.eql(u8, buffer[0..sos.pos], expected)); | |
| 360 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); | |
| 360 | 361 | } |
std/atomic/stack.zig+3-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const assert = std.debug.assert; |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const AtomicOrder = builtin.AtomicOrder; |
| 4 | const expect = std.testing.expect; | |
| 4 | 5 | |
| 5 | 6 | /// Many reader, many writer, non-allocating, thread-safe |
| 6 | 7 | /// Uses a spinlock to protect push() and pop() |
| ... | ... | @@ -108,14 +109,14 @@ test "std.atomic.stack" { |
| 108 | 109 | { |
| 109 | 110 | var i: usize = 0; |
| 110 | 111 | while (i < put_thread_count) : (i += 1) { |
| 111 | std.debug.assertOrPanic(startPuts(&context) == 0); | |
| 112 | expect(startPuts(&context) == 0); | |
| 112 | 113 | } |
| 113 | 114 | } |
| 114 | 115 | context.puts_done = 1; |
| 115 | 116 | { |
| 116 | 117 | var i: usize = 0; |
| 117 | 118 | while (i < put_thread_count) : (i += 1) { |
| 118 | std.debug.assertOrPanic(startGets(&context) == 0); | |
| 119 | expect(startGets(&context) == 0); | |
| 119 | 120 | } |
| 120 | 121 | } |
| 121 | 122 | } else { |
std/base64.zig+7-6| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | |
| 5 | 6 | pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| ... | ... | @@ -394,7 +395,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void |
| 394 | 395 | var buffer: [0x100]u8 = undefined; |
| 395 | 396 | var encoded = buffer[0..Base64Encoder.calcSize(expected_decoded.len)]; |
| 396 | 397 | standard_encoder.encode(encoded, expected_decoded); |
| 397 | assert(mem.eql(u8, encoded, expected_encoded)); | |
| 398 | testing.expectEqualSlices(u8, expected_encoded, encoded); | |
| 398 | 399 | } |
| 399 | 400 | |
| 400 | 401 | // Base64Decoder |
| ... | ... | @@ -402,7 +403,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void |
| 402 | 403 | var buffer: [0x100]u8 = undefined; |
| 403 | 404 | var decoded = buffer[0..try standard_decoder.calcSize(expected_encoded)]; |
| 404 | 405 | try standard_decoder.decode(decoded, expected_encoded); |
| 405 | assert(mem.eql(u8, decoded, expected_decoded)); | |
| 406 | testing.expectEqualSlices(u8, expected_decoded, decoded); | |
| 406 | 407 | } |
| 407 | 408 | |
| 408 | 409 | // Base64DecoderWithIgnore |
| ... | ... | @@ -411,8 +412,8 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void |
| 411 | 412 | var buffer: [0x100]u8 = undefined; |
| 412 | 413 | var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(expected_encoded.len)]; |
| 413 | 414 | var written = try standard_decoder_ignore_nothing.decode(decoded, expected_encoded); |
| 414 | assert(written <= decoded.len); | |
| 415 | assert(mem.eql(u8, decoded[0..written], expected_decoded)); | |
| 415 | testing.expect(written <= decoded.len); | |
| 416 | testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | 419 | // Base64DecoderUnsafe |
| ... | ... | @@ -420,7 +421,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void |
| 420 | 421 | var buffer: [0x100]u8 = undefined; |
| 421 | 422 | var decoded = buffer[0..standard_decoder_unsafe.calcSize(expected_encoded)]; |
| 422 | 423 | standard_decoder_unsafe.decode(decoded, expected_encoded); |
| 423 | assert(mem.eql(u8, decoded, expected_decoded)); | |
| 424 | testing.expectEqualSlices(u8, expected_decoded, decoded); | |
| 424 | 425 | } |
| 425 | 426 | } |
| 426 | 427 | |
| ... | ... | @@ -429,7 +430,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi |
| 429 | 430 | var buffer: [0x100]u8 = undefined; |
| 430 | 431 | var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(encoded.len)]; |
| 431 | 432 | var written = try standard_decoder_ignore_space.decode(decoded, encoded); |
| 432 | assert(mem.eql(u8, decoded[0..written], expected_decoded)); | |
| 433 | testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | |
| 433 | 434 | } |
| 434 | 435 | |
| 435 | 436 | fn testError(encoded: []const u8, expected_err: anyerror) !void { |
std/buf_map.zig+8-8| ... | ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); |
| 2 | 2 | const HashMap = std.HashMap; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | const assert = std.debug.assert; | |
| 5 | const testing = std.testing; | |
| 6 | 6 | |
| 7 | 7 | /// BufMap copies keys and values before they go into the map, and |
| 8 | 8 | /// frees them when they get removed. |
| ... | ... | @@ -90,17 +90,17 @@ test "BufMap" { |
| 90 | 90 | defer bufmap.deinit(); |
| 91 | 91 | |
| 92 | 92 | try bufmap.set("x", "1"); |
| 93 | assert(mem.eql(u8, bufmap.get("x").?, "1")); | |
| 94 | assert(1 == bufmap.count()); | |
| 93 | testing.expect(mem.eql(u8, bufmap.get("x").?, "1")); | |
| 94 | testing.expect(1 == bufmap.count()); | |
| 95 | 95 | |
| 96 | 96 | try bufmap.set("x", "2"); |
| 97 | assert(mem.eql(u8, bufmap.get("x").?, "2")); | |
| 98 | assert(1 == bufmap.count()); | |
| 97 | testing.expect(mem.eql(u8, bufmap.get("x").?, "2")); | |
| 98 | testing.expect(1 == bufmap.count()); | |
| 99 | 99 | |
| 100 | 100 | try bufmap.set("x", "3"); |
| 101 | assert(mem.eql(u8, bufmap.get("x").?, "3")); | |
| 102 | assert(1 == bufmap.count()); | |
| 101 | testing.expect(mem.eql(u8, bufmap.get("x").?, "3")); | |
| 102 | testing.expect(1 == bufmap.count()); | |
| 103 | 103 | |
| 104 | 104 | bufmap.delete("x"); |
| 105 | assert(0 == bufmap.count()); | |
| 105 | testing.expect(0 == bufmap.count()); | |
| 106 | 106 | } |
std/buf_set.zig+3-3| ... | ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); |
| 2 | 2 | const HashMap = @import("hash_map.zig").HashMap; |
| 3 | 3 | const mem = @import("mem.zig"); |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | const assert = std.debug.assert; | |
| 5 | const testing = std.testing; | |
| 6 | 6 | |
| 7 | 7 | pub const BufSet = struct { |
| 8 | 8 | hash_map: BufSetHashMap, |
| ... | ... | @@ -68,9 +68,9 @@ test "BufSet" { |
| 68 | 68 | defer bufset.deinit(); |
| 69 | 69 | |
| 70 | 70 | try bufset.put("x"); |
| 71 | assert(bufset.count() == 1); | |
| 71 | testing.expect(bufset.count() == 1); | |
| 72 | 72 | bufset.delete("x"); |
| 73 | assert(bufset.count() == 0); | |
| 73 | testing.expect(bufset.count() == 0); | |
| 74 | 74 | |
| 75 | 75 | try bufset.put("x"); |
| 76 | 76 | try bufset.put("y"); |
std/buffer.zig+8-7| ... | ... | @@ -3,6 +3,7 @@ const debug = std.debug; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | 5 | const assert = debug.assert; |
| 6 | const testing = std.testing; | |
| 6 | 7 | const ArrayList = std.ArrayList; |
| 7 | 8 | |
| 8 | 9 | /// A buffer that allocates memory and maintains a null byte at the end. |
| ... | ... | @@ -141,19 +142,19 @@ test "simple Buffer" { |
| 141 | 142 | const cstr = @import("cstr.zig"); |
| 142 | 143 | |
| 143 | 144 | var buf = try Buffer.init(debug.global_allocator, ""); |
| 144 | assert(buf.len() == 0); | |
| 145 | testing.expect(buf.len() == 0); | |
| 145 | 146 | try buf.append("hello"); |
| 146 | 147 | try buf.append(" "); |
| 147 | 148 | try buf.append("world"); |
| 148 | assert(buf.eql("hello world")); | |
| 149 | assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst())); | |
| 149 | testing.expect(buf.eql("hello world")); | |
| 150 | testing.expect(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst())); | |
| 150 | 151 | |
| 151 | 152 | var buf2 = try Buffer.initFromBuffer(buf); |
| 152 | assert(buf.eql(buf2.toSliceConst())); | |
| 153 | testing.expect(buf.eql(buf2.toSliceConst())); | |
| 153 | 154 | |
| 154 | assert(buf.startsWith("hell")); | |
| 155 | assert(buf.endsWith("orld")); | |
| 155 | testing.expect(buf.startsWith("hell")); | |
| 156 | testing.expect(buf.endsWith("orld")); | |
| 156 | 157 | |
| 157 | 158 | try buf2.resize(4); |
| 158 | assert(buf.startsWith(buf2.toSlice())); | |
| 159 | testing.expect(buf.startsWith(buf2.toSlice())); | |
| 159 | 160 | } |
std/crypto/chacha20.zig+8-7| ... | ... | @@ -4,6 +4,7 @@ const std = @import("../index.zig"); |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const endian = std.endian; |
| 6 | 6 | const assert = std.debug.assert; |
| 7 | const testing = std.testing; | |
| 7 | 8 | const builtin = @import("builtin"); |
| 8 | 9 | const maxInt = std.math.maxInt; |
| 9 | 10 | |
| ... | ... | @@ -216,12 +217,12 @@ test "crypto.chacha20 test vector sunscreen" { |
| 216 | 217 | }; |
| 217 | 218 | |
| 218 | 219 | chaCha20IETF(result[0..], input[0..], 1, key, nonce); |
| 219 | assert(mem.eql(u8, expected_result, result)); | |
| 220 | testing.expectEqualSlices(u8, expected_result, result); | |
| 220 | 221 | |
| 221 | 222 | // Chacha20 is self-reversing. |
| 222 | 223 | var plaintext: [114]u8 = undefined; |
| 223 | 224 | chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce); |
| 224 | assert(mem.compare(u8, input, plaintext) == mem.Compare.Equal); | |
| 225 | testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal); | |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 |
| ... | ... | @@ -256,7 +257,7 @@ test "crypto.chacha20 test vector 1" { |
| 256 | 257 | const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 257 | 258 | |
| 258 | 259 | chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); |
| 259 | assert(mem.eql(u8, expected_result, result)); | |
| 260 | testing.expectEqualSlices(u8, expected_result, result); | |
| 260 | 261 | } |
| 261 | 262 | |
| 262 | 263 | test "crypto.chacha20 test vector 2" { |
| ... | ... | @@ -290,7 +291,7 @@ test "crypto.chacha20 test vector 2" { |
| 290 | 291 | const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 291 | 292 | |
| 292 | 293 | chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); |
| 293 | assert(mem.eql(u8, expected_result, result)); | |
| 294 | testing.expectEqualSlices(u8, expected_result, result); | |
| 294 | 295 | } |
| 295 | 296 | |
| 296 | 297 | test "crypto.chacha20 test vector 3" { |
| ... | ... | @@ -324,7 +325,7 @@ test "crypto.chacha20 test vector 3" { |
| 324 | 325 | const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 }; |
| 325 | 326 | |
| 326 | 327 | chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); |
| 327 | assert(mem.eql(u8, expected_result, result)); | |
| 328 | testing.expectEqualSlices(u8, expected_result, result); | |
| 328 | 329 | } |
| 329 | 330 | |
| 330 | 331 | test "crypto.chacha20 test vector 4" { |
| ... | ... | @@ -358,7 +359,7 @@ test "crypto.chacha20 test vector 4" { |
| 358 | 359 | const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 }; |
| 359 | 360 | |
| 360 | 361 | chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); |
| 361 | assert(mem.eql(u8, expected_result, result)); | |
| 362 | testing.expectEqualSlices(u8, expected_result, result); | |
| 362 | 363 | } |
| 363 | 364 | |
| 364 | 365 | test "crypto.chacha20 test vector 5" { |
| ... | ... | @@ -430,5 +431,5 @@ test "crypto.chacha20 test vector 5" { |
| 430 | 431 | }; |
| 431 | 432 | |
| 432 | 433 | chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce); |
| 433 | assert(mem.eql(u8, expected_result, result)); | |
| 434 | testing.expectEqualSlices(u8, expected_result, result); | |
| 434 | 435 | } |
std/crypto/poly1305.zig+1-1| ... | ... | @@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" { |
| 230 | 230 | var mac: [16]u8 = undefined; |
| 231 | 231 | Poly1305.create(mac[0..], msg, key); |
| 232 | 232 | |
| 233 | std.debug.assert(std.mem.eql(u8, mac, expected_mac)); | |
| 233 | std.testing.expectEqualSlices(u8, expected_mac, mac); | |
| 234 | 234 | } |
std/crypto/test.zig+5-4| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | const debug = @import("../debug/index.zig"); | |
| 2 | const mem = @import("../mem.zig"); | |
| 3 | const fmt = @import("../fmt/index.zig"); | |
| 1 | const std = @import("../index.zig"); | |
| 2 | const testing = std.testing; | |
| 3 | const mem = std.mem; | |
| 4 | const fmt = std.fmt; | |
| 4 | 5 | |
| 5 | 6 | // Hash using the specified hasher `H` asserting `expected == H(input)`. |
| 6 | 7 | pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void { |
| ... | ... | @@ -17,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void { |
| 17 | 18 | r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable; |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | debug.assert(mem.eql(u8, expected_bytes, input)); | |
| 21 | testing.expectEqualSlices(u8, expected_bytes, input); | |
| 21 | 22 | } |
std/crypto/x25519.zig+12-12| ... | ... | @@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" { |
| 581 | 581 | var pk_calculated: [32]u8 = undefined; |
| 582 | 582 | try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); |
| 583 | 583 | try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50"); |
| 584 | std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk)); | |
| 585 | std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected)); | |
| 584 | std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk)); | |
| 585 | std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected)); | |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | test "x25519 rfc7748 vector1" { |
| ... | ... | @@ -593,8 +593,8 @@ test "x25519 rfc7748 vector1" { |
| 593 | 593 | |
| 594 | 594 | var output: [32]u8 = undefined; |
| 595 | 595 | |
| 596 | std.debug.assert(X25519.create(output[0..], secret_key, public_key)); | |
| 597 | std.debug.assert(std.mem.eql(u8, output, expected_output)); | |
| 596 | std.testing.expect(X25519.create(output[0..], secret_key, public_key)); | |
| 597 | std.testing.expect(std.mem.eql(u8, output, expected_output)); | |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | test "x25519 rfc7748 vector2" { |
| ... | ... | @@ -605,8 +605,8 @@ test "x25519 rfc7748 vector2" { |
| 605 | 605 | |
| 606 | 606 | var output: [32]u8 = undefined; |
| 607 | 607 | |
| 608 | std.debug.assert(X25519.create(output[0..], secret_key, public_key)); | |
| 609 | std.debug.assert(std.mem.eql(u8, output, expected_output)); | |
| 608 | std.testing.expect(X25519.create(output[0..], secret_key, public_key)); | |
| 609 | std.testing.expect(std.mem.eql(u8, output, expected_output)); | |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | test "x25519 rfc7748 one iteration" { |
| ... | ... | @@ -619,13 +619,13 @@ test "x25519 rfc7748 one iteration" { |
| 619 | 619 | var i: usize = 0; |
| 620 | 620 | while (i < 1) : (i += 1) { |
| 621 | 621 | var output: [32]u8 = undefined; |
| 622 | std.debug.assert(X25519.create(output[0..], k, u)); | |
| 622 | std.testing.expect(X25519.create(output[0..], k, u)); | |
| 623 | 623 | |
| 624 | 624 | std.mem.copy(u8, u[0..], k[0..]); |
| 625 | 625 | std.mem.copy(u8, k[0..], output[0..]); |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | std.debug.assert(std.mem.eql(u8, k[0..], expected_output)); | |
| 628 | std.testing.expect(std.mem.eql(u8, k[0..], expected_output)); | |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | test "x25519 rfc7748 1,000 iterations" { |
| ... | ... | @@ -643,13 +643,13 @@ test "x25519 rfc7748 1,000 iterations" { |
| 643 | 643 | var i: usize = 0; |
| 644 | 644 | while (i < 1000) : (i += 1) { |
| 645 | 645 | var output: [32]u8 = undefined; |
| 646 | std.debug.assert(X25519.create(output[0..], k, u)); | |
| 646 | std.testing.expect(X25519.create(output[0..], k, u)); | |
| 647 | 647 | |
| 648 | 648 | std.mem.copy(u8, u[0..], k[0..]); |
| 649 | 649 | std.mem.copy(u8, k[0..], output[0..]); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | std.debug.assert(std.mem.eql(u8, k[0..], expected_output)); | |
| 652 | std.testing.expect(std.mem.eql(u8, k[0..], expected_output)); | |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | test "x25519 rfc7748 1,000,000 iterations" { |
| ... | ... | @@ -666,11 +666,11 @@ test "x25519 rfc7748 1,000,000 iterations" { |
| 666 | 666 | var i: usize = 0; |
| 667 | 667 | while (i < 1000000) : (i += 1) { |
| 668 | 668 | var output: [32]u8 = undefined; |
| 669 | std.debug.assert(X25519.create(output[0..], k, u)); | |
| 669 | std.testing.expect(X25519.create(output[0..], k, u)); | |
| 670 | 670 | |
| 671 | 671 | std.mem.copy(u8, u[0..], k[0..]); |
| 672 | 672 | std.mem.copy(u8, k[0..], output[0..]); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | std.debug.assert(std.mem.eql(u8, k[0..], expected_output)); | |
| 675 | std.testing.expect(std.mem.eql(u8, k[0..], expected_output)); | |
| 676 | 676 | } |
std/cstr.zig+3-3| ... | ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const debug = std.debug; |
| 4 | 4 | const mem = std.mem; |
| 5 | const assert = debug.assert; | |
| 5 | const testing = std.testing; | |
| 6 | 6 | |
| 7 | 7 | pub const line_sep = switch (builtin.os) { |
| 8 | 8 | builtin.Os.windows => "\r\n", |
| ... | ... | @@ -42,8 +42,8 @@ test "cstr fns" { |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | fn testCStrFnsImpl() void { |
| 45 | assert(cmp(c"aoeu", c"aoez") == -1); | |
| 46 | assert(len(c"123456789") == 9); | |
| 45 | testing.expect(cmp(c"aoeu", c"aoez") == -1); | |
| 46 | testing.expect(len(c"123456789") == 9); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /// Returns a mutable slice with 1 more byte of length which is a null byte. |
std/debug/index.zig+8-30| ... | ... | @@ -107,37 +107,15 @@ pub fn dumpStackTrace(stack_trace: *const builtin.StackTrace) void { |
| 107 | 107 | /// This function invokes undefined behavior when `ok` is `false`. |
| 108 | 108 | /// In Debug and ReleaseSafe modes, calls to this function are always |
| 109 | 109 | /// generated, and the `unreachable` statement triggers a panic. |
| 110 | /// In ReleaseFast and ReleaseSmall modes, calls to this function can be | |
| 111 | /// optimized away. | |
| 110 | /// In ReleaseFast and ReleaseSmall modes, calls to this function are | |
| 111 | /// optimized away, and in fact the optimizer is able to use the assertion | |
| 112 | /// in its heuristics. | |
| 113 | /// Inside a test block, it is best to use the `std.testing` module rather | |
| 114 | /// than this function, because this function may not detect a test failure | |
| 115 | /// in ReleaseFast and ReleaseSafe mode. Outside of a test block, this assert | |
| 116 | /// function is the correct function to use. | |
| 112 | 117 | pub fn assert(ok: bool) void { |
| 113 | if (!ok) { | |
| 114 | // In ReleaseFast test mode, we still want assert(false) to crash, so | |
| 115 | // we insert an explicit call to @panic instead of unreachable. | |
| 116 | // TODO we should use `assertOrPanic` in tests and remove this logic. | |
| 117 | if (builtin.is_test) { | |
| 118 | @panic("assertion failure"); | |
| 119 | } else { | |
| 120 | unreachable; // assertion failure | |
| 121 | } | |
| 122 | } | |
| 123 | } | |
| 124 | ||
| 125 | /// TODO: add `==` operator for `error_union == error_set`, and then | |
| 126 | /// remove this function | |
| 127 | pub fn assertError(value: var, expected_error: anyerror) void { | |
| 128 | if (value) { | |
| 129 | @panic("expected error"); | |
| 130 | } else |actual_error| { | |
| 131 | assert(actual_error == expected_error); | |
| 132 | } | |
| 133 | } | |
| 134 | ||
| 135 | /// Call this function when you want to panic if the condition is not true. | |
| 136 | /// If `ok` is `false`, this function will panic in every release mode. | |
| 137 | pub fn assertOrPanic(ok: bool) void { | |
| 138 | if (!ok) { | |
| 139 | @panic("assertion failure"); | |
| 140 | } | |
| 118 | if (!ok) unreachable; // assertion failure | |
| 141 | 119 | } |
| 142 | 120 | |
| 143 | 121 | pub fn panic(comptime format: []const u8, args: ...) noreturn { |
std/dynamic_library.zig+2-1| ... | ... | @@ -6,6 +6,7 @@ const mem = std.mem; |
| 6 | 6 | const cstr = std.cstr; |
| 7 | 7 | const os = std.os; |
| 8 | 8 | const assert = std.debug.assert; |
| 9 | const testing = std.testing; | |
| 9 | 10 | const elf = std.elf; |
| 10 | 11 | const linux = os.linux; |
| 11 | 12 | const windows = os.windows; |
| ... | ... | @@ -206,7 +207,7 @@ test "dynamic_library" { |
| 206 | 207 | }; |
| 207 | 208 | |
| 208 | 209 | const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| { |
| 209 | assert(err == error.FileNotFound); | |
| 210 | testing.expect(err == error.FileNotFound); | |
| 210 | 211 | return; |
| 211 | 212 | }; |
| 212 | 213 | @panic("Expected error from function"); |
std/event/channel.zig+5-4| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 6 | const AtomicOrder = builtin.AtomicOrder; |
| 6 | 7 | const Loop = std.event.Loop; |
| ... | ... | @@ -350,19 +351,19 @@ async fn testChannelGetter(loop: *Loop, channel: *Channel(i32)) void { |
| 350 | 351 | |
| 351 | 352 | const value1_promise = try async channel.get(); |
| 352 | 353 | const value1 = await value1_promise; |
| 353 | assert(value1 == 1234); | |
| 354 | testing.expect(value1 == 1234); | |
| 354 | 355 | |
| 355 | 356 | const value2_promise = try async channel.get(); |
| 356 | 357 | const value2 = await value2_promise; |
| 357 | assert(value2 == 4567); | |
| 358 | testing.expect(value2 == 4567); | |
| 358 | 359 | |
| 359 | 360 | const value3_promise = try async channel.getOrNull(); |
| 360 | 361 | const value3 = await value3_promise; |
| 361 | assert(value3 == null); | |
| 362 | testing.expect(value3 == null); | |
| 362 | 363 | |
| 363 | 364 | const last_put = try async testPut(channel, 4444); |
| 364 | 365 | const value4 = await try async channel.getOrNull(); |
| 365 | assert(value4.? == 4444); | |
| 366 | testing.expect(value4.? == 4444); | |
| 366 | 367 | await last_put; |
| 367 | 368 | } |
| 368 | 369 |
std/event/fs.zig+5-4| ... | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("../index.zig"); |
| 3 | 3 | const event = std.event; |
| 4 | 4 | const assert = std.debug.assert; |
| 5 | const testing = std.testing; | |
| 5 | 6 | const os = std.os; |
| 6 | 7 | const mem = std.mem; |
| 7 | 8 | const posix = os.posix; |
| ... | ... | @@ -1349,13 +1350,13 @@ async fn testFsWatch(loop: *Loop) !void { |
| 1349 | 1350 | try await try async writeFile(loop, file_path, contents); |
| 1350 | 1351 | |
| 1351 | 1352 | const read_contents = try await try async readFile(loop, file_path, 1024 * 1024); |
| 1352 | assert(mem.eql(u8, read_contents, contents)); | |
| 1353 | testing.expectEqualSlices(u8, contents, read_contents); | |
| 1353 | 1354 | |
| 1354 | 1355 | // now watch the file |
| 1355 | 1356 | var watch = try Watch(void).create(loop, 0); |
| 1356 | 1357 | defer watch.destroy(); |
| 1357 | 1358 | |
| 1358 | assert((try await try async watch.addFile(file_path, {})) == null); | |
| 1359 | testing.expect((try await try async watch.addFile(file_path, {})) == null); | |
| 1359 | 1360 | |
| 1360 | 1361 | const ev = try async watch.channel.get(); |
| 1361 | 1362 | var ev_consumed = false; |
| ... | ... | @@ -1375,10 +1376,10 @@ async fn testFsWatch(loop: *Loop) !void { |
| 1375 | 1376 | WatchEventId.Delete => @panic("wrong event"), |
| 1376 | 1377 | } |
| 1377 | 1378 | const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024); |
| 1378 | assert(mem.eql(u8, contents_updated, | |
| 1379 | testing.expectEqualSlices(u8, | |
| 1379 | 1380 | \\line 1 |
| 1380 | 1381 | \\lorem ipsum |
| 1381 | )); | |
| 1382 | , contents_updated); | |
| 1382 | 1383 | |
| 1383 | 1384 | // TODO test deleting the file and then re-adding it. we should get events for both |
| 1384 | 1385 | } |
std/event/future.zig+2-1| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const builtin = @import("builtin"); |
| 4 | 5 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 6 | const AtomicOrder = builtin.AtomicOrder; |
| ... | ... | @@ -114,7 +115,7 @@ async fn testFuture(loop: *Loop) void { |
| 114 | 115 | |
| 115 | 116 | const result = (await a) + (await b); |
| 116 | 117 | cancel c; |
| 117 | assert(result == 12); | |
| 118 | testing.expect(result == 12); | |
| 118 | 119 | } |
| 119 | 120 | |
| 120 | 121 | async fn waitOnFuture(future: *Future(i32)) i32 { |
std/event/group.zig+3-3| ... | ... | @@ -4,7 +4,7 @@ const Lock = std.event.Lock; |
| 4 | 4 | const Loop = std.event.Loop; |
| 5 | 5 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 6 | 6 | const AtomicOrder = builtin.AtomicOrder; |
| 7 | const assert = std.debug.assert; | |
| 7 | const testing = std.testing; | |
| 8 | 8 | |
| 9 | 9 | /// ReturnType must be `void` or `E!void` |
| 10 | 10 | pub fn Group(comptime ReturnType: type) type { |
| ... | ... | @@ -146,12 +146,12 @@ async fn testGroup(loop: *Loop) void { |
| 146 | 146 | group.add(async sleepALittle(&count) catch @panic("memory")) catch @panic("memory"); |
| 147 | 147 | group.call(increaseByTen, &count) catch @panic("memory"); |
| 148 | 148 | await (async group.wait() catch @panic("memory")); |
| 149 | assert(count == 11); | |
| 149 | testing.expect(count == 11); | |
| 150 | 150 | |
| 151 | 151 | var another = Group(anyerror!void).init(loop); |
| 152 | 152 | another.add(async somethingElse() catch @panic("memory")) catch @panic("memory"); |
| 153 | 153 | another.call(doSomethingThatFails) catch @panic("memory"); |
| 154 | std.debug.assertError(await (async another.wait() catch @panic("memory")), error.ItBroke); | |
| 154 | testing.expectError(error.ItBroke, await (async another.wait() catch @panic("memory"))); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | async fn sleepALittle(count: *usize) void { |
std/event/lock.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 6 | 7 | const AtomicOrder = builtin.AtomicOrder; |
| ... | ... | @@ -141,7 +142,7 @@ test "std.event.Lock" { |
| 141 | 142 | defer cancel handle; |
| 142 | 143 | loop.run(); |
| 143 | 144 | |
| 144 | assert(mem.eql(i32, shared_test_data, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len)); | |
| 145 | testing.expectEqualSlices(i32, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len, shared_test_data); | |
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | async fn testLock(loop: *Loop, lock: *Lock) void { |
std/event/loop.zig+3-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 6 | 7 | const AtomicOrder = builtin.AtomicOrder; |
| ... | ... | @@ -896,7 +897,7 @@ test "std.event.Loop - call" { |
| 896 | 897 | |
| 897 | 898 | loop.run(); |
| 898 | 899 | |
| 899 | assert(did_it); | |
| 900 | testing.expect(did_it); | |
| 900 | 901 | } |
| 901 | 902 | |
| 902 | 903 | async fn testEventLoop() i32 { |
| ... | ... | @@ -905,6 +906,6 @@ async fn testEventLoop() i32 { |
| 905 | 906 | |
| 906 | 907 | async fn testEventLoop2(h: promise->i32, did_it: *bool) void { |
| 907 | 908 | const value = await h; |
| 908 | assert(value == 1234); | |
| 909 | testing.expect(value == 1234); | |
| 909 | 910 | did_it.* = true; |
| 910 | 911 | } |
std/event/net.zig+2-2| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | |
| 3 | const testing = std.testing; | |
| 4 | 4 | const event = std.event; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | const os = std.os; |
| ... | ... | @@ -326,7 +326,7 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv |
| 326 | 326 | var buf: [512]u8 = undefined; |
| 327 | 327 | const amt_read = try socket_file.read(buf[0..]); |
| 328 | 328 | const msg = buf[0..amt_read]; |
| 329 | assert(mem.eql(u8, msg, "hello from server\n")); | |
| 329 | testing.expect(mem.eql(u8, msg, "hello from server\n")); | |
| 330 | 330 | server.close(); |
| 331 | 331 | } |
| 332 | 332 |
std/event/rwlock.zig+4-3| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 6 | 7 | const AtomicOrder = builtin.AtomicOrder; |
| ... | ... | @@ -231,7 +232,7 @@ test "std.event.RwLock" { |
| 231 | 232 | loop.run(); |
| 232 | 233 | |
| 233 | 234 | const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len; |
| 234 | assert(mem.eql(i32, shared_test_data, expected_result)); | |
| 235 | testing.expectEqualSlices(i32, expected_result, shared_test_data); | |
| 235 | 236 | } |
| 236 | 237 | |
| 237 | 238 | async fn testLock(loop: *Loop, lock: *RwLock) void { |
| ... | ... | @@ -293,7 +294,7 @@ async fn readRunner(lock: *RwLock) void { |
| 293 | 294 | const handle = await lock_promise; |
| 294 | 295 | defer handle.release(); |
| 295 | 296 | |
| 296 | assert(shared_test_index == 0); | |
| 297 | assert(shared_test_data[i] == @intCast(i32, shared_count)); | |
| 297 | testing.expect(shared_test_index == 0); | |
| 298 | testing.expect(shared_test_data[i] == @intCast(i32, shared_count)); | |
| 298 | 299 | } |
| 299 | 300 | } |
std/fmt/index.zig+79-79| ... | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | 3 | const debug = std.debug; |
| 4 | 4 | const assert = debug.assert; |
| 5 | const assertError = debug.assertError; | |
| 5 | const testing = std.testing; | |
| 6 | 6 | const mem = std.mem; |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const errol = @import("errol/index.zig"); |
| ... | ... | @@ -588,7 +588,7 @@ pub fn formatFloatDecimal( |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | // Remaining fractional portion, zero-padding if insufficient. |
| 591 | debug.assert(precision >= printed); | |
| 591 | assert(precision >= printed); | |
| 592 | 592 | if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) { |
| 593 | 593 | try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]); |
| 594 | 594 | return; |
| ... | ... | @@ -798,13 +798,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | test "fmt.parseInt" { |
| 801 | assert((parseInt(i32, "-10", 10) catch unreachable) == -10); | |
| 802 | assert((parseInt(i32, "+10", 10) catch unreachable) == 10); | |
| 803 | assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 804 | assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 805 | assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 806 | assert((parseInt(u8, "255", 10) catch unreachable) == 255); | |
| 807 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); | |
| 801 | testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10); | |
| 802 | testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10); | |
| 803 | testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 804 | testing.expect(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 805 | testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter); | |
| 806 | testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255); | |
| 807 | testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); | |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | const ParseUnsignedError = error{ |
| ... | ... | @@ -829,30 +829,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | test "parseUnsigned" { |
| 832 | assert((try parseUnsigned(u16, "050124", 10)) == 50124); | |
| 833 | assert((try parseUnsigned(u16, "65535", 10)) == 65535); | |
| 834 | assertError(parseUnsigned(u16, "65536", 10), error.Overflow); | |
| 832 | testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124); | |
| 833 | testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535); | |
| 834 | testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10)); | |
| 835 | 835 | |
| 836 | assert((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff); | |
| 837 | assertError(parseUnsigned(u64, "10000000000000000", 16), error.Overflow); | |
| 836 | testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff); | |
| 837 | testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16)); | |
| 838 | 838 | |
| 839 | assert((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF); | |
| 839 | testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF); | |
| 840 | 840 | |
| 841 | assert((try parseUnsigned(u7, "1", 10)) == 1); | |
| 842 | assert((try parseUnsigned(u7, "1000", 2)) == 8); | |
| 841 | testing.expect((try parseUnsigned(u7, "1", 10)) == 1); | |
| 842 | testing.expect((try parseUnsigned(u7, "1000", 2)) == 8); | |
| 843 | 843 | |
| 844 | assertError(parseUnsigned(u32, "f", 10), error.InvalidCharacter); | |
| 845 | assertError(parseUnsigned(u8, "109", 8), error.InvalidCharacter); | |
| 844 | testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10)); | |
| 845 | testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8)); | |
| 846 | 846 | |
| 847 | assert((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747); | |
| 847 | testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747); | |
| 848 | 848 | |
| 849 | 849 | // these numbers should fit even though the radix itself doesn't fit in the destination type |
| 850 | assert((try parseUnsigned(u1, "0", 10)) == 0); | |
| 851 | assert((try parseUnsigned(u1, "1", 10)) == 1); | |
| 852 | assertError(parseUnsigned(u1, "2", 10), error.Overflow); | |
| 853 | assert((try parseUnsigned(u1, "001", 16)) == 1); | |
| 854 | assert((try parseUnsigned(u2, "3", 16)) == 3); | |
| 855 | assertError(parseUnsigned(u2, "4", 16), error.Overflow); | |
| 850 | testing.expect((try parseUnsigned(u1, "0", 10)) == 0); | |
| 851 | testing.expect((try parseUnsigned(u1, "1", 10)) == 1); | |
| 852 | testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10)); | |
| 853 | testing.expect((try parseUnsigned(u1, "001", 16)) == 1); | |
| 854 | testing.expect((try parseUnsigned(u2, "3", 16)) == 3); | |
| 855 | testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16)); | |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { |
| ... | ... | @@ -910,19 +910,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 910 | 910 | test "buf print int" { |
| 911 | 911 | var buffer: [max_int_digits]u8 = undefined; |
| 912 | 912 | const buf = buffer[0..]; |
| 913 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110")); | |
| 914 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678")); | |
| 915 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e")); | |
| 916 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, 0), "-BC614E")); | |
| 913 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110")); | |
| 914 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678")); | |
| 915 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e")); | |
| 916 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, 0), "-BC614E")); | |
| 917 | 917 | |
| 918 | assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, 0), "12345678")); | |
| 918 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, 0), "12345678")); | |
| 919 | 919 | |
| 920 | assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, 6), "000666")); | |
| 921 | assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234")); | |
| 922 | assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 1), "1234")); | |
| 920 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, 6), "000666")); | |
| 921 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234")); | |
| 922 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 1), "1234")); | |
| 923 | 923 | |
| 924 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, 3), "+42")); | |
| 925 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42")); | |
| 924 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, 3), "+42")); | |
| 925 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42")); | |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 { |
| ... | ... | @@ -939,7 +939,7 @@ test "parse u64 digit too big" { |
| 939 | 939 | |
| 940 | 940 | test "parse unsigned comptime" { |
| 941 | 941 | comptime { |
| 942 | assert((try parseUnsigned(usize, "2", 10)) == 2); | |
| 942 | testing.expect((try parseUnsigned(usize, "2", 10)) == 2); | |
| 943 | 943 | } |
| 944 | 944 | } |
| 945 | 945 | |
| ... | ... | @@ -977,17 +977,17 @@ test "fmt.format" { |
| 977 | 977 | var context = BufPrintContext{ .remaining = buf1[0..] }; |
| 978 | 978 | try formatType(1234, "", &context, error{BufferTooSmall}, bufPrintWrite); |
| 979 | 979 | var res = buf1[0 .. buf1.len - context.remaining.len]; |
| 980 | assert(mem.eql(u8, res, "1234")); | |
| 980 | testing.expect(mem.eql(u8, res, "1234")); | |
| 981 | 981 | |
| 982 | 982 | context = BufPrintContext{ .remaining = buf1[0..] }; |
| 983 | 983 | try formatType('a', "c", &context, error{BufferTooSmall}, bufPrintWrite); |
| 984 | 984 | res = buf1[0 .. buf1.len - context.remaining.len]; |
| 985 | assert(mem.eql(u8, res, "a")); | |
| 985 | testing.expect(mem.eql(u8, res, "a")); | |
| 986 | 986 | |
| 987 | 987 | context = BufPrintContext{ .remaining = buf1[0..] }; |
| 988 | 988 | try formatType(0b1100, "b", &context, error{BufferTooSmall}, bufPrintWrite); |
| 989 | 989 | res = buf1[0 .. buf1.len - context.remaining.len]; |
| 990 | assert(mem.eql(u8, res, "1100")); | |
| 990 | testing.expect(mem.eql(u8, res, "1100")); | |
| 991 | 991 | } |
| 992 | 992 | { |
| 993 | 993 | const value: [3]u8 = "abc"; |
| ... | ... | @@ -1053,19 +1053,19 @@ test "fmt.format" { |
| 1053 | 1053 | var buf1: [32]u8 = undefined; |
| 1054 | 1054 | const value: f32 = 1.34; |
| 1055 | 1055 | const result = try bufPrint(buf1[0..], "f32: {e}\n", value); |
| 1056 | assert(mem.eql(u8, result, "f32: 1.34000003e+00\n")); | |
| 1056 | testing.expect(mem.eql(u8, result, "f32: 1.34000003e+00\n")); | |
| 1057 | 1057 | } |
| 1058 | 1058 | { |
| 1059 | 1059 | var buf1: [32]u8 = undefined; |
| 1060 | 1060 | const value: f32 = 12.34; |
| 1061 | 1061 | const result = try bufPrint(buf1[0..], "f32: {e}\n", value); |
| 1062 | assert(mem.eql(u8, result, "f32: 1.23400001e+01\n")); | |
| 1062 | testing.expect(mem.eql(u8, result, "f32: 1.23400001e+01\n")); | |
| 1063 | 1063 | } |
| 1064 | 1064 | { |
| 1065 | 1065 | var buf1: [32]u8 = undefined; |
| 1066 | 1066 | const value: f64 = -12.34e10; |
| 1067 | 1067 | const result = try bufPrint(buf1[0..], "f64: {e}\n", value); |
| 1068 | assert(mem.eql(u8, result, "f64: -1.234e+11\n")); | |
| 1068 | testing.expect(mem.eql(u8, result, "f64: -1.234e+11\n")); | |
| 1069 | 1069 | } |
| 1070 | 1070 | { |
| 1071 | 1071 | // This fails on release due to a minor rounding difference. |
| ... | ... | @@ -1075,26 +1075,26 @@ test "fmt.format" { |
| 1075 | 1075 | var buf1: [32]u8 = undefined; |
| 1076 | 1076 | const value: f64 = 9.999960e-40; |
| 1077 | 1077 | const result = try bufPrint(buf1[0..], "f64: {e}\n", value); |
| 1078 | assert(mem.eql(u8, result, "f64: 9.99996e-40\n")); | |
| 1078 | testing.expect(mem.eql(u8, result, "f64: 9.99996e-40\n")); | |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | { |
| 1082 | 1082 | var buf1: [32]u8 = undefined; |
| 1083 | 1083 | const value: f64 = 1.409706e-42; |
| 1084 | 1084 | const result = try bufPrint(buf1[0..], "f64: {e5}\n", value); |
| 1085 | assert(mem.eql(u8, result, "f64: 1.40971e-42\n")); | |
| 1085 | testing.expect(mem.eql(u8, result, "f64: 1.40971e-42\n")); | |
| 1086 | 1086 | } |
| 1087 | 1087 | { |
| 1088 | 1088 | var buf1: [32]u8 = undefined; |
| 1089 | 1089 | const value: f64 = @bitCast(f32, u32(814313563)); |
| 1090 | 1090 | const result = try bufPrint(buf1[0..], "f64: {e5}\n", value); |
| 1091 | assert(mem.eql(u8, result, "f64: 1.00000e-09\n")); | |
| 1091 | testing.expect(mem.eql(u8, result, "f64: 1.00000e-09\n")); | |
| 1092 | 1092 | } |
| 1093 | 1093 | { |
| 1094 | 1094 | var buf1: [32]u8 = undefined; |
| 1095 | 1095 | const value: f64 = @bitCast(f32, u32(1006632960)); |
| 1096 | 1096 | const result = try bufPrint(buf1[0..], "f64: {e5}\n", value); |
| 1097 | assert(mem.eql(u8, result, "f64: 7.81250e-03\n")); | |
| 1097 | testing.expect(mem.eql(u8, result, "f64: 7.81250e-03\n")); | |
| 1098 | 1098 | } |
| 1099 | 1099 | { |
| 1100 | 1100 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. |
| ... | ... | @@ -1102,47 +1102,47 @@ test "fmt.format" { |
| 1102 | 1102 | var buf1: [32]u8 = undefined; |
| 1103 | 1103 | const value: f64 = @bitCast(f32, u32(1203982400)); |
| 1104 | 1104 | const result = try bufPrint(buf1[0..], "f64: {e5}\n", value); |
| 1105 | assert(mem.eql(u8, result, "f64: 1.00001e+05\n")); | |
| 1105 | testing.expect(mem.eql(u8, result, "f64: 1.00001e+05\n")); | |
| 1106 | 1106 | } |
| 1107 | 1107 | { |
| 1108 | 1108 | var buf1: [32]u8 = undefined; |
| 1109 | 1109 | const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64); |
| 1110 | assert(mem.eql(u8, result, "f64: nan\n")); | |
| 1110 | testing.expect(mem.eql(u8, result, "f64: nan\n")); | |
| 1111 | 1111 | } |
| 1112 | 1112 | if (builtin.arch != builtin.Arch.armv8) { |
| 1113 | 1113 | // negative nan is not defined by IEE 754, |
| 1114 | 1114 | // and ARM thus normalizes it to positive nan |
| 1115 | 1115 | var buf1: [32]u8 = undefined; |
| 1116 | 1116 | const result = try bufPrint(buf1[0..], "f64: {}\n", -math.nan_f64); |
| 1117 | assert(mem.eql(u8, result, "f64: -nan\n")); | |
| 1117 | testing.expect(mem.eql(u8, result, "f64: -nan\n")); | |
| 1118 | 1118 | } |
| 1119 | 1119 | { |
| 1120 | 1120 | var buf1: [32]u8 = undefined; |
| 1121 | 1121 | const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64); |
| 1122 | assert(mem.eql(u8, result, "f64: inf\n")); | |
| 1122 | testing.expect(mem.eql(u8, result, "f64: inf\n")); | |
| 1123 | 1123 | } |
| 1124 | 1124 | { |
| 1125 | 1125 | var buf1: [32]u8 = undefined; |
| 1126 | 1126 | const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64); |
| 1127 | assert(mem.eql(u8, result, "f64: -inf\n")); | |
| 1127 | testing.expect(mem.eql(u8, result, "f64: -inf\n")); | |
| 1128 | 1128 | } |
| 1129 | 1129 | { |
| 1130 | 1130 | var buf1: [64]u8 = undefined; |
| 1131 | 1131 | const value: f64 = 1.52314e+29; |
| 1132 | 1132 | const result = try bufPrint(buf1[0..], "f64: {.}\n", value); |
| 1133 | assert(mem.eql(u8, result, "f64: 152314000000000000000000000000\n")); | |
| 1133 | testing.expect(mem.eql(u8, result, "f64: 152314000000000000000000000000\n")); | |
| 1134 | 1134 | } |
| 1135 | 1135 | { |
| 1136 | 1136 | var buf1: [32]u8 = undefined; |
| 1137 | 1137 | const value: f32 = 1.1234; |
| 1138 | 1138 | const result = try bufPrint(buf1[0..], "f32: {.1}\n", value); |
| 1139 | assert(mem.eql(u8, result, "f32: 1.1\n")); | |
| 1139 | testing.expect(mem.eql(u8, result, "f32: 1.1\n")); | |
| 1140 | 1140 | } |
| 1141 | 1141 | { |
| 1142 | 1142 | var buf1: [32]u8 = undefined; |
| 1143 | 1143 | const value: f32 = 1234.567; |
| 1144 | 1144 | const result = try bufPrint(buf1[0..], "f32: {.2}\n", value); |
| 1145 | assert(mem.eql(u8, result, "f32: 1234.57\n")); | |
| 1145 | testing.expect(mem.eql(u8, result, "f32: 1234.57\n")); | |
| 1146 | 1146 | } |
| 1147 | 1147 | { |
| 1148 | 1148 | var buf1: [32]u8 = undefined; |
| ... | ... | @@ -1150,92 +1150,92 @@ test "fmt.format" { |
| 1150 | 1150 | const result = try bufPrint(buf1[0..], "f32: {.4}\n", value); |
| 1151 | 1151 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 1152 | 1152 | // -11.12339... is rounded back up to -11.1234 |
| 1153 | assert(mem.eql(u8, result, "f32: -11.1234\n")); | |
| 1153 | testing.expect(mem.eql(u8, result, "f32: -11.1234\n")); | |
| 1154 | 1154 | } |
| 1155 | 1155 | { |
| 1156 | 1156 | var buf1: [32]u8 = undefined; |
| 1157 | 1157 | const value: f32 = 91.12345; |
| 1158 | 1158 | const result = try bufPrint(buf1[0..], "f32: {.5}\n", value); |
| 1159 | assert(mem.eql(u8, result, "f32: 91.12345\n")); | |
| 1159 | testing.expect(mem.eql(u8, result, "f32: 91.12345\n")); | |
| 1160 | 1160 | } |
| 1161 | 1161 | { |
| 1162 | 1162 | var buf1: [32]u8 = undefined; |
| 1163 | 1163 | const value: f64 = 91.12345678901235; |
| 1164 | 1164 | const result = try bufPrint(buf1[0..], "f64: {.10}\n", value); |
| 1165 | assert(mem.eql(u8, result, "f64: 91.1234567890\n")); | |
| 1165 | testing.expect(mem.eql(u8, result, "f64: 91.1234567890\n")); | |
| 1166 | 1166 | } |
| 1167 | 1167 | { |
| 1168 | 1168 | var buf1: [32]u8 = undefined; |
| 1169 | 1169 | const value: f64 = 0.0; |
| 1170 | 1170 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1171 | assert(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1171 | testing.expect(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1172 | 1172 | } |
| 1173 | 1173 | { |
| 1174 | 1174 | var buf1: [32]u8 = undefined; |
| 1175 | 1175 | const value: f64 = 5.700; |
| 1176 | 1176 | const result = try bufPrint(buf1[0..], "f64: {.0}\n", value); |
| 1177 | assert(mem.eql(u8, result, "f64: 6\n")); | |
| 1177 | testing.expect(mem.eql(u8, result, "f64: 6\n")); | |
| 1178 | 1178 | } |
| 1179 | 1179 | { |
| 1180 | 1180 | var buf1: [32]u8 = undefined; |
| 1181 | 1181 | const value: f64 = 9.999; |
| 1182 | 1182 | const result = try bufPrint(buf1[0..], "f64: {.1}\n", value); |
| 1183 | assert(mem.eql(u8, result, "f64: 10.0\n")); | |
| 1183 | testing.expect(mem.eql(u8, result, "f64: 10.0\n")); | |
| 1184 | 1184 | } |
| 1185 | 1185 | { |
| 1186 | 1186 | var buf1: [32]u8 = undefined; |
| 1187 | 1187 | const value: f64 = 1.0; |
| 1188 | 1188 | const result = try bufPrint(buf1[0..], "f64: {.3}\n", value); |
| 1189 | assert(mem.eql(u8, result, "f64: 1.000\n")); | |
| 1189 | testing.expect(mem.eql(u8, result, "f64: 1.000\n")); | |
| 1190 | 1190 | } |
| 1191 | 1191 | { |
| 1192 | 1192 | var buf1: [32]u8 = undefined; |
| 1193 | 1193 | const value: f64 = 0.0003; |
| 1194 | 1194 | const result = try bufPrint(buf1[0..], "f64: {.8}\n", value); |
| 1195 | assert(mem.eql(u8, result, "f64: 0.00030000\n")); | |
| 1195 | testing.expect(mem.eql(u8, result, "f64: 0.00030000\n")); | |
| 1196 | 1196 | } |
| 1197 | 1197 | { |
| 1198 | 1198 | var buf1: [32]u8 = undefined; |
| 1199 | 1199 | const value: f64 = 1.40130e-45; |
| 1200 | 1200 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1201 | assert(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1201 | testing.expect(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1202 | 1202 | } |
| 1203 | 1203 | { |
| 1204 | 1204 | var buf1: [32]u8 = undefined; |
| 1205 | 1205 | const value: f64 = 9.999960e-40; |
| 1206 | 1206 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1207 | assert(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1207 | testing.expect(mem.eql(u8, result, "f64: 0.00000\n")); | |
| 1208 | 1208 | } |
| 1209 | 1209 | // libc checks |
| 1210 | 1210 | { |
| 1211 | 1211 | var buf1: [32]u8 = undefined; |
| 1212 | 1212 | const value: f64 = f64(@bitCast(f32, u32(916964781))); |
| 1213 | 1213 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1214 | assert(mem.eql(u8, result, "f64: 0.00001\n")); | |
| 1214 | testing.expect(mem.eql(u8, result, "f64: 0.00001\n")); | |
| 1215 | 1215 | } |
| 1216 | 1216 | { |
| 1217 | 1217 | var buf1: [32]u8 = undefined; |
| 1218 | 1218 | const value: f64 = f64(@bitCast(f32, u32(925353389))); |
| 1219 | 1219 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1220 | assert(mem.eql(u8, result, "f64: 0.00001\n")); | |
| 1220 | testing.expect(mem.eql(u8, result, "f64: 0.00001\n")); | |
| 1221 | 1221 | } |
| 1222 | 1222 | { |
| 1223 | 1223 | var buf1: [32]u8 = undefined; |
| 1224 | 1224 | const value: f64 = f64(@bitCast(f32, u32(1036831278))); |
| 1225 | 1225 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1226 | assert(mem.eql(u8, result, "f64: 0.10000\n")); | |
| 1226 | testing.expect(mem.eql(u8, result, "f64: 0.10000\n")); | |
| 1227 | 1227 | } |
| 1228 | 1228 | { |
| 1229 | 1229 | var buf1: [32]u8 = undefined; |
| 1230 | 1230 | const value: f64 = f64(@bitCast(f32, u32(1065353133))); |
| 1231 | 1231 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1232 | assert(mem.eql(u8, result, "f64: 1.00000\n")); | |
| 1232 | testing.expect(mem.eql(u8, result, "f64: 1.00000\n")); | |
| 1233 | 1233 | } |
| 1234 | 1234 | { |
| 1235 | 1235 | var buf1: [32]u8 = undefined; |
| 1236 | 1236 | const value: f64 = f64(@bitCast(f32, u32(1092616192))); |
| 1237 | 1237 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1238 | assert(mem.eql(u8, result, "f64: 10.00000\n")); | |
| 1238 | testing.expect(mem.eql(u8, result, "f64: 10.00000\n")); | |
| 1239 | 1239 | } |
| 1240 | 1240 | // libc differences |
| 1241 | 1241 | { |
| ... | ... | @@ -1245,7 +1245,7 @@ test "fmt.format" { |
| 1245 | 1245 | // floats of the form x.yyyy25 on a precision point. |
| 1246 | 1246 | const value: f64 = f64(@bitCast(f32, u32(1015021568))); |
| 1247 | 1247 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1248 | assert(mem.eql(u8, result, "f64: 0.01563\n")); | |
| 1248 | testing.expect(mem.eql(u8, result, "f64: 0.01563\n")); | |
| 1249 | 1249 | } |
| 1250 | 1250 | // std-windows-x86_64-Debug-bare test case fails |
| 1251 | 1251 | { |
| ... | ... | @@ -1255,7 +1255,7 @@ test "fmt.format" { |
| 1255 | 1255 | var buf1: [32]u8 = undefined; |
| 1256 | 1256 | const value: f64 = f64(@bitCast(f32, u32(1518338049))); |
| 1257 | 1257 | const result = try bufPrint(buf1[0..], "f64: {.5}\n", value); |
| 1258 | assert(mem.eql(u8, result, "f64: 18014400656965630.00000\n")); | |
| 1258 | testing.expect(mem.eql(u8, result, "f64: 18014400656965630.00000\n")); | |
| 1259 | 1259 | } |
| 1260 | 1260 | //custom type format |
| 1261 | 1261 | { |
| ... | ... | @@ -1336,10 +1336,10 @@ test "fmt.format" { |
| 1336 | 1336 | |
| 1337 | 1337 | var buf: [100]u8 = undefined; |
| 1338 | 1338 | const uu_result = try bufPrint(buf[0..], "{}", uu_inst); |
| 1339 | debug.assert(mem.eql(u8, uu_result[0..3], "UU@")); | |
| 1339 | testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); | |
| 1340 | 1340 | |
| 1341 | 1341 | const eu_result = try bufPrint(buf[0..], "{}", eu_inst); |
| 1342 | debug.assert(mem.eql(u8, uu_result[0..3], "EU@")); | |
| 1342 | testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); | |
| 1343 | 1343 | } |
| 1344 | 1344 | //enum format |
| 1345 | 1345 | { |
| ... | ... | @@ -1398,11 +1398,11 @@ pub fn trim(buf: []const u8) []const u8 { |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | 1400 | test "fmt.trim" { |
| 1401 | assert(mem.eql(u8, "abc", trim("\n abc \t"))); | |
| 1402 | assert(mem.eql(u8, "", trim(" "))); | |
| 1403 | assert(mem.eql(u8, "", trim(""))); | |
| 1404 | assert(mem.eql(u8, "abc", trim(" abc"))); | |
| 1405 | assert(mem.eql(u8, "abc", trim("abc "))); | |
| 1401 | testing.expect(mem.eql(u8, "abc", trim("\n abc \t"))); | |
| 1402 | testing.expect(mem.eql(u8, "", trim(" "))); | |
| 1403 | testing.expect(mem.eql(u8, "", trim(""))); | |
| 1404 | testing.expect(mem.eql(u8, "abc", trim(" abc"))); | |
| 1405 | testing.expect(mem.eql(u8, "abc", trim("abc "))); | |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | pub fn isWhiteSpace(byte: u8) bool { |
std/hash/adler.zig+6-6| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | // https://github.com/madler/zlib/blob/master/adler32.c |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | const debug = std.debug; | |
| 7 | const testing = std.testing; | |
| 8 | 8 | |
| 9 | 9 | pub const Adler32 = struct { |
| 10 | 10 | const base = 65521; |
| ... | ... | @@ -89,19 +89,19 @@ pub const Adler32 = struct { |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | test "adler32 sanity" { |
| 92 | debug.assert(Adler32.hash("a") == 0x620062); | |
| 93 | debug.assert(Adler32.hash("example") == 0xbc002ed); | |
| 92 | testing.expect(Adler32.hash("a") == 0x620062); | |
| 93 | testing.expect(Adler32.hash("example") == 0xbc002ed); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "adler32 long" { |
| 97 | 97 | const long1 = []u8{1} ** 1024; |
| 98 | debug.assert(Adler32.hash(long1[0..]) == 0x06780401); | |
| 98 | testing.expect(Adler32.hash(long1[0..]) == 0x06780401); | |
| 99 | 99 | |
| 100 | 100 | const long2 = []u8{1} ** 1025; |
| 101 | debug.assert(Adler32.hash(long2[0..]) == 0x0a7a0402); | |
| 101 | testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | test "adler32 very long" { |
| 105 | 105 | const long = []u8{1} ** 5553; |
| 106 | debug.assert(Adler32.hash(long[0..]) == 0x707f15b2); | |
| 106 | testing.expect(Adler32.hash(long[0..]) == 0x707f15b2); | |
| 107 | 107 | } |
std/hash/crc.zig+13-12| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const debug = std.debug; |
| 10 | const testing = std.testing; | |
| 10 | 11 | |
| 11 | 12 | pub const Polynomial = struct { |
| 12 | 13 | const IEEE = 0xedb88320; |
| ... | ... | @@ -101,17 +102,17 @@ pub fn Crc32WithPoly(comptime poly: u32) type { |
| 101 | 102 | test "crc32 ieee" { |
| 102 | 103 | const Crc32Ieee = Crc32WithPoly(Polynomial.IEEE); |
| 103 | 104 | |
| 104 | debug.assert(Crc32Ieee.hash("") == 0x00000000); | |
| 105 | debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 106 | debug.assert(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 105 | testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 106 | testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 107 | testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | test "crc32 castagnoli" { |
| 110 | 111 | const Crc32Castagnoli = Crc32WithPoly(Polynomial.Castagnoli); |
| 111 | 112 | |
| 112 | debug.assert(Crc32Castagnoli.hash("") == 0x00000000); | |
| 113 | debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 114 | debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 113 | testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 114 | testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 115 | testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | // half-byte lookup table implementation. |
| ... | ... | @@ -165,15 +166,15 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type { |
| 165 | 166 | test "small crc32 ieee" { |
| 166 | 167 | const Crc32Ieee = Crc32SmallWithPoly(Polynomial.IEEE); |
| 167 | 168 | |
| 168 | debug.assert(Crc32Ieee.hash("") == 0x00000000); | |
| 169 | debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 170 | debug.assert(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 169 | testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 170 | testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 171 | testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 171 | 172 | } |
| 172 | 173 | |
| 173 | 174 | test "small crc32 castagnoli" { |
| 174 | 175 | const Crc32Castagnoli = Crc32SmallWithPoly(Polynomial.Castagnoli); |
| 175 | 176 | |
| 176 | debug.assert(Crc32Castagnoli.hash("") == 0x00000000); | |
| 177 | debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 178 | debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 177 | testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 178 | testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 179 | testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 179 | 180 | } |
std/hash/fnv.zig+9-9| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // https://tools.ietf.org/html/draft-eastlake-fnv-14 |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | const debug = std.debug; | |
| 8 | const testing = std.testing; | |
| 9 | 9 | |
| 10 | 10 | pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5); |
| 11 | 11 | pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325); |
| ... | ... | @@ -41,18 +41,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type { |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | test "fnv1a-32" { |
| 44 | debug.assert(Fnv1a_32.hash("") == 0x811c9dc5); | |
| 45 | debug.assert(Fnv1a_32.hash("a") == 0xe40c292c); | |
| 46 | debug.assert(Fnv1a_32.hash("foobar") == 0xbf9cf968); | |
| 44 | testing.expect(Fnv1a_32.hash("") == 0x811c9dc5); | |
| 45 | testing.expect(Fnv1a_32.hash("a") == 0xe40c292c); | |
| 46 | testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "fnv1a-64" { |
| 50 | debug.assert(Fnv1a_64.hash("") == 0xcbf29ce484222325); | |
| 51 | debug.assert(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c); | |
| 52 | debug.assert(Fnv1a_64.hash("foobar") == 0x85944171f73967e8); | |
| 50 | testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325); | |
| 51 | testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c); | |
| 52 | testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "fnv1a-128" { |
| 56 | debug.assert(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d); | |
| 57 | debug.assert(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964); | |
| 56 | testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d); | |
| 57 | testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964); | |
| 58 | 58 | } |
std/hash/siphash.zig+8-7| ... | ... | @@ -6,7 +6,8 @@ |
| 6 | 6 | // https://131002.net/siphash/ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | const debug = std.debug; | |
| 9 | const assert = std.debug.assert; | |
| 10 | const testing = std.testing; | |
| 10 | 11 | const math = std.math; |
| 11 | 12 | const mem = std.mem; |
| 12 | 13 | |
| ... | ... | @@ -21,8 +22,8 @@ pub fn SipHash128(comptime c_rounds: usize, comptime d_rounds: usize) type { |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) type { |
| 24 | debug.assert(T == u64 or T == u128); | |
| 25 | debug.assert(c_rounds > 0 and d_rounds > 0); | |
| 25 | assert(T == u64 or T == u128); | |
| 26 | assert(c_rounds > 0 and d_rounds > 0); | |
| 26 | 27 | |
| 27 | 28 | return struct { |
| 28 | 29 | const Self = @This(); |
| ... | ... | @@ -40,7 +41,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) |
| 40 | 41 | msg_len: u8, |
| 41 | 42 | |
| 42 | 43 | pub fn init(key: []const u8) Self { |
| 43 | debug.assert(key.len >= 16); | |
| 44 | assert(key.len >= 16); | |
| 44 | 45 | |
| 45 | 46 | const k0 = mem.readIntSliceLittle(u64, key[0..8]); |
| 46 | 47 | const k1 = mem.readIntSliceLittle(u64, key[8..16]); |
| ... | ... | @@ -119,7 +120,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) |
| 119 | 120 | } |
| 120 | 121 | |
| 121 | 122 | fn round(d: *Self, b: []const u8) void { |
| 122 | debug.assert(b.len == 8); | |
| 123 | assert(b.len == 8); | |
| 123 | 124 | |
| 124 | 125 | const m = mem.readIntSliceLittle(u64, b[0..]); |
| 125 | 126 | d.v3 ^= m; |
| ... | ... | @@ -236,7 +237,7 @@ test "siphash64-2-4 sanity" { |
| 236 | 237 | buffer[i] = @intCast(u8, i); |
| 237 | 238 | |
| 238 | 239 | const expected = mem.readIntLittle(u64, &vector); |
| 239 | debug.assert(siphash.hash(test_key, buffer[0..i]) == expected); | |
| 240 | testing.expect(siphash.hash(test_key, buffer[0..i]) == expected); | |
| 240 | 241 | } |
| 241 | 242 | } |
| 242 | 243 | |
| ... | ... | @@ -315,6 +316,6 @@ test "siphash128-2-4 sanity" { |
| 315 | 316 | buffer[i] = @intCast(u8, i); |
| 316 | 317 | |
| 317 | 318 | const expected = mem.readIntLittle(u128, &vector); |
| 318 | debug.assert(siphash.hash(test_key, buffer[0..i]) == expected); | |
| 319 | testing.expect(siphash.hash(test_key, buffer[0..i]) == expected); | |
| 319 | 320 | } |
| 320 | 321 | } |
std/hash_map.zig+30-29| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const debug = std.debug; |
| 3 | 3 | const assert = debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const math = std.math; |
| 5 | 6 | const mem = std.mem; |
| 6 | 7 | const Allocator = mem.Allocator; |
| ... | ... | @@ -342,37 +343,37 @@ test "basic hash map usage" { |
| 342 | 343 | var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); |
| 343 | 344 | defer map.deinit(); |
| 344 | 345 | |
| 345 | assert((try map.put(1, 11)) == null); | |
| 346 | assert((try map.put(2, 22)) == null); | |
| 347 | assert((try map.put(3, 33)) == null); | |
| 348 | assert((try map.put(4, 44)) == null); | |
| 349 | assert((try map.put(5, 55)) == null); | |
| 346 | testing.expect((try map.put(1, 11)) == null); | |
| 347 | testing.expect((try map.put(2, 22)) == null); | |
| 348 | testing.expect((try map.put(3, 33)) == null); | |
| 349 | testing.expect((try map.put(4, 44)) == null); | |
| 350 | testing.expect((try map.put(5, 55)) == null); | |
| 350 | 351 | |
| 351 | assert((try map.put(5, 66)).?.value == 55); | |
| 352 | assert((try map.put(5, 55)).?.value == 66); | |
| 352 | testing.expect((try map.put(5, 66)).?.value == 55); | |
| 353 | testing.expect((try map.put(5, 55)).?.value == 66); | |
| 353 | 354 | |
| 354 | 355 | const gop1 = try map.getOrPut(5); |
| 355 | assert(gop1.found_existing == true); | |
| 356 | assert(gop1.kv.value == 55); | |
| 356 | testing.expect(gop1.found_existing == true); | |
| 357 | testing.expect(gop1.kv.value == 55); | |
| 357 | 358 | gop1.kv.value = 77; |
| 358 | assert(map.get(5).?.value == 77); | |
| 359 | testing.expect(map.get(5).?.value == 77); | |
| 359 | 360 | |
| 360 | 361 | const gop2 = try map.getOrPut(99); |
| 361 | assert(gop2.found_existing == false); | |
| 362 | testing.expect(gop2.found_existing == false); | |
| 362 | 363 | gop2.kv.value = 42; |
| 363 | assert(map.get(99).?.value == 42); | |
| 364 | testing.expect(map.get(99).?.value == 42); | |
| 364 | 365 | |
| 365 | 366 | const gop3 = try map.getOrPutValue(5, 5); |
| 366 | assert(gop3.value == 77); | |
| 367 | testing.expect(gop3.value == 77); | |
| 367 | 368 | |
| 368 | 369 | const gop4 = try map.getOrPutValue(100, 41); |
| 369 | assert(gop4.value == 41); | |
| 370 | testing.expect(gop4.value == 41); | |
| 370 | 371 | |
| 371 | assert(map.contains(2)); | |
| 372 | assert(map.get(2).?.value == 22); | |
| 372 | testing.expect(map.contains(2)); | |
| 373 | testing.expect(map.get(2).?.value == 22); | |
| 373 | 374 | _ = map.remove(2); |
| 374 | assert(map.remove(2) == null); | |
| 375 | assert(map.get(2) == null); | |
| 375 | testing.expect(map.remove(2) == null); | |
| 376 | testing.expect(map.get(2) == null); | |
| 376 | 377 | } |
| 377 | 378 | |
| 378 | 379 | test "iterator hash map" { |
| ... | ... | @@ -382,9 +383,9 @@ test "iterator hash map" { |
| 382 | 383 | var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); |
| 383 | 384 | defer reset_map.deinit(); |
| 384 | 385 | |
| 385 | assert((try reset_map.put(1, 11)) == null); | |
| 386 | assert((try reset_map.put(2, 22)) == null); | |
| 387 | assert((try reset_map.put(3, 33)) == null); | |
| 386 | testing.expect((try reset_map.put(1, 11)) == null); | |
| 387 | testing.expect((try reset_map.put(2, 22)) == null); | |
| 388 | testing.expect((try reset_map.put(3, 33)) == null); | |
| 388 | 389 | |
| 389 | 390 | var keys = []i32{ |
| 390 | 391 | 3, |
| ... | ... | @@ -400,26 +401,26 @@ test "iterator hash map" { |
| 400 | 401 | var it = reset_map.iterator(); |
| 401 | 402 | var count: usize = 0; |
| 402 | 403 | while (it.next()) |next| { |
| 403 | assert(next.key == keys[count]); | |
| 404 | assert(next.value == values[count]); | |
| 404 | testing.expect(next.key == keys[count]); | |
| 405 | testing.expect(next.value == values[count]); | |
| 405 | 406 | count += 1; |
| 406 | 407 | } |
| 407 | 408 | |
| 408 | assert(count == 3); | |
| 409 | assert(it.next() == null); | |
| 409 | testing.expect(count == 3); | |
| 410 | testing.expect(it.next() == null); | |
| 410 | 411 | it.reset(); |
| 411 | 412 | count = 0; |
| 412 | 413 | while (it.next()) |next| { |
| 413 | assert(next.key == keys[count]); | |
| 414 | assert(next.value == values[count]); | |
| 414 | testing.expect(next.key == keys[count]); | |
| 415 | testing.expect(next.value == values[count]); | |
| 415 | 416 | count += 1; |
| 416 | 417 | if (count == 2) break; |
| 417 | 418 | } |
| 418 | 419 | |
| 419 | 420 | it.reset(); |
| 420 | 421 | var entry = it.next().?; |
| 421 | assert(entry.key == keys[0]); | |
| 422 | assert(entry.value == values[0]); | |
| 422 | testing.expect(entry.key == keys[0]); | |
| 423 | testing.expect(entry.value == values[0]); | |
| 423 | 424 | } |
| 424 | 425 | |
| 425 | 426 | pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) { |
std/heap.zig+28-27| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const debug = std.debug; |
| 3 | 3 | const assert = debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const os = std.os; |
| 6 | 7 | const builtin = @import("builtin"); |
| ... | ... | @@ -487,11 +488,11 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 487 | 488 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); |
| 488 | 489 | |
| 489 | 490 | var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5); |
| 490 | assert(slice0.len == 5); | |
| 491 | testing.expect(slice0.len == 5); | |
| 491 | 492 | var slice1 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 10); |
| 492 | assert(slice1.ptr == slice0.ptr); | |
| 493 | assert(slice1.len == 10); | |
| 494 | debug.assertError(fixed_buffer_allocator.allocator.realloc(u8, slice1, 11), error.OutOfMemory); | |
| 493 | testing.expect(slice1.ptr == slice0.ptr); | |
| 494 | testing.expect(slice1.len == 10); | |
| 495 | testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(u8, slice1, 11)); | |
| 495 | 496 | } |
| 496 | 497 | // check that we don't re-use the memory if it's not the most recent block |
| 497 | 498 | { |
| ... | ... | @@ -502,10 +503,10 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 502 | 503 | slice0[1] = 2; |
| 503 | 504 | var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2); |
| 504 | 505 | var slice2 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 4); |
| 505 | assert(slice0.ptr != slice2.ptr); | |
| 506 | assert(slice1.ptr != slice2.ptr); | |
| 507 | assert(slice2[0] == 1); | |
| 508 | assert(slice2[1] == 2); | |
| 506 | testing.expect(slice0.ptr != slice2.ptr); | |
| 507 | testing.expect(slice1.ptr != slice2.ptr); | |
| 508 | testing.expect(slice2[0] == 1); | |
| 509 | testing.expect(slice2[1] == 2); | |
| 509 | 510 | } |
| 510 | 511 | } |
| 511 | 512 | |
| ... | ... | @@ -519,28 +520,28 @@ test "ThreadSafeFixedBufferAllocator" { |
| 519 | 520 | |
| 520 | 521 | fn testAllocator(allocator: *mem.Allocator) !void { |
| 521 | 522 | var slice = try allocator.alloc(*i32, 100); |
| 522 | assert(slice.len == 100); | |
| 523 | testing.expect(slice.len == 100); | |
| 523 | 524 | for (slice) |*item, i| { |
| 524 | 525 | item.* = try allocator.create(i32); |
| 525 | 526 | item.*.* = @intCast(i32, i); |
| 526 | 527 | } |
| 527 | 528 | |
| 528 | 529 | slice = try allocator.realloc(*i32, slice, 20000); |
| 529 | assert(slice.len == 20000); | |
| 530 | testing.expect(slice.len == 20000); | |
| 530 | 531 | |
| 531 | 532 | for (slice[0..100]) |item, i| { |
| 532 | assert(item.* == @intCast(i32, i)); | |
| 533 | testing.expect(item.* == @intCast(i32, i)); | |
| 533 | 534 | allocator.destroy(item); |
| 534 | 535 | } |
| 535 | 536 | |
| 536 | 537 | slice = try allocator.realloc(*i32, slice, 50); |
| 537 | assert(slice.len == 50); | |
| 538 | testing.expect(slice.len == 50); | |
| 538 | 539 | slice = try allocator.realloc(*i32, slice, 25); |
| 539 | assert(slice.len == 25); | |
| 540 | testing.expect(slice.len == 25); | |
| 540 | 541 | slice = try allocator.realloc(*i32, slice, 0); |
| 541 | assert(slice.len == 0); | |
| 542 | testing.expect(slice.len == 0); | |
| 542 | 543 | slice = try allocator.realloc(*i32, slice, 10); |
| 543 | assert(slice.len == 10); | |
| 544 | testing.expect(slice.len == 10); | |
| 544 | 545 | |
| 545 | 546 | allocator.free(slice); |
| 546 | 547 | } |
| ... | ... | @@ -548,25 +549,25 @@ fn testAllocator(allocator: *mem.Allocator) !void { |
| 548 | 549 | fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !void { |
| 549 | 550 | // initial |
| 550 | 551 | var slice = try allocator.alignedAlloc(u8, alignment, 10); |
| 551 | assert(slice.len == 10); | |
| 552 | testing.expect(slice.len == 10); | |
| 552 | 553 | // grow |
| 553 | 554 | slice = try allocator.alignedRealloc(u8, alignment, slice, 100); |
| 554 | assert(slice.len == 100); | |
| 555 | testing.expect(slice.len == 100); | |
| 555 | 556 | // shrink |
| 556 | 557 | slice = try allocator.alignedRealloc(u8, alignment, slice, 10); |
| 557 | assert(slice.len == 10); | |
| 558 | testing.expect(slice.len == 10); | |
| 558 | 559 | // go to zero |
| 559 | 560 | slice = try allocator.alignedRealloc(u8, alignment, slice, 0); |
| 560 | assert(slice.len == 0); | |
| 561 | testing.expect(slice.len == 0); | |
| 561 | 562 | // realloc from zero |
| 562 | 563 | slice = try allocator.alignedRealloc(u8, alignment, slice, 100); |
| 563 | assert(slice.len == 100); | |
| 564 | testing.expect(slice.len == 100); | |
| 564 | 565 | // shrink with shrink |
| 565 | 566 | slice = allocator.alignedShrink(u8, alignment, slice, 10); |
| 566 | assert(slice.len == 10); | |
| 567 | testing.expect(slice.len == 10); | |
| 567 | 568 | // shrink to zero |
| 568 | 569 | slice = allocator.alignedShrink(u8, alignment, slice, 0); |
| 569 | assert(slice.len == 0); | |
| 570 | testing.expect(slice.len == 0); | |
| 570 | 571 | } |
| 571 | 572 | |
| 572 | 573 | fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void { |
| ... | ... | @@ -581,19 +582,19 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo |
| 581 | 582 | _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask); |
| 582 | 583 | |
| 583 | 584 | var slice = try allocator.allocFn(allocator, 500, large_align); |
| 584 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 585 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 585 | 586 | |
| 586 | 587 | slice = try allocator.reallocFn(allocator, slice, 100, large_align); |
| 587 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 588 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 588 | 589 | |
| 589 | 590 | slice = try allocator.reallocFn(allocator, slice, 5000, large_align); |
| 590 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 591 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 591 | 592 | |
| 592 | 593 | slice = try allocator.reallocFn(allocator, slice, 10, large_align); |
| 593 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 594 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 594 | 595 | |
| 595 | 596 | slice = try allocator.reallocFn(allocator, slice, 20000, large_align); |
| 596 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 597 | testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); | |
| 597 | 598 | |
| 598 | 599 | allocator.free(slice); |
| 599 | 600 | } |
std/index.zig+8-7| ... | ... | @@ -31,6 +31,7 @@ pub const hash_map = @import("hash_map.zig"); |
| 31 | 31 | pub const heap = @import("heap.zig"); |
| 32 | 32 | pub const io = @import("io.zig"); |
| 33 | 33 | pub const json = @import("json.zig"); |
| 34 | pub const lazyInit = @import("lazy_init.zig").lazyInit; | |
| 34 | 35 | pub const macho = @import("macho.zig"); |
| 35 | 36 | pub const math = @import("math/index.zig"); |
| 36 | 37 | pub const mem = @import("mem.zig"); |
| ... | ... | @@ -41,11 +42,10 @@ pub const pdb = @import("pdb.zig"); |
| 41 | 42 | pub const rand = @import("rand/index.zig"); |
| 42 | 43 | pub const rb = @import("rb.zig"); |
| 43 | 44 | pub const sort = @import("sort.zig"); |
| 45 | pub const testing = @import("testing.zig"); | |
| 44 | 46 | pub const unicode = @import("unicode.zig"); |
| 45 | 47 | pub const zig = @import("zig/index.zig"); |
| 46 | 48 | |
| 47 | pub const lazyInit = @import("lazy_init.zig").lazyInit; | |
| 48 | ||
| 49 | 49 | test "std" { |
| 50 | 50 | // run tests from these |
| 51 | 51 | _ = @import("array_list.zig"); |
| ... | ... | @@ -60,7 +60,6 @@ test "std" { |
| 60 | 60 | _ = @import("segmented_list.zig"); |
| 61 | 61 | _ = @import("spinlock.zig"); |
| 62 | 62 | |
| 63 | _ = @import("dynamic_library.zig"); | |
| 64 | 63 | _ = @import("base64.zig"); |
| 65 | 64 | _ = @import("build.zig"); |
| 66 | 65 | _ = @import("c/index.zig"); |
| ... | ... | @@ -69,24 +68,26 @@ test "std" { |
| 69 | 68 | _ = @import("cstr.zig"); |
| 70 | 69 | _ = @import("debug/index.zig"); |
| 71 | 70 | _ = @import("dwarf.zig"); |
| 71 | _ = @import("dynamic_library.zig"); | |
| 72 | 72 | _ = @import("elf.zig"); |
| 73 | 73 | _ = @import("empty.zig"); |
| 74 | 74 | _ = @import("event.zig"); |
| 75 | 75 | _ = @import("fmt/index.zig"); |
| 76 | 76 | _ = @import("hash/index.zig"); |
| 77 | _ = @import("heap.zig"); | |
| 77 | 78 | _ = @import("io.zig"); |
| 78 | 79 | _ = @import("json.zig"); |
| 80 | _ = @import("lazy_init.zig"); | |
| 79 | 81 | _ = @import("macho.zig"); |
| 80 | 82 | _ = @import("math/index.zig"); |
| 81 | _ = @import("meta/index.zig"); | |
| 82 | 83 | _ = @import("mem.zig"); |
| 84 | _ = @import("meta/index.zig"); | |
| 83 | 85 | _ = @import("net.zig"); |
| 84 | _ = @import("heap.zig"); | |
| 85 | 86 | _ = @import("os/index.zig"); |
| 86 | _ = @import("rand/index.zig"); | |
| 87 | 87 | _ = @import("pdb.zig"); |
| 88 | _ = @import("rand/index.zig"); | |
| 88 | 89 | _ = @import("sort.zig"); |
| 90 | _ = @import("testing.zig"); | |
| 89 | 91 | _ = @import("unicode.zig"); |
| 90 | 92 | _ = @import("zig/index.zig"); |
| 91 | _ = @import("lazy_init.zig"); | |
| 92 | 93 | } |
std/io.zig+9-8| ... | ... | @@ -13,6 +13,7 @@ const trait = meta.trait; |
| 13 | 13 | const Buffer = std.Buffer; |
| 14 | 14 | const fmt = std.fmt; |
| 15 | 15 | const File = std.os.File; |
| 16 | const testing = std.testing; | |
| 16 | 17 | |
| 17 | 18 | const is_posix = builtin.os != builtin.Os.windows; |
| 18 | 19 | const is_windows = builtin.os == builtin.Os.windows; |
| ... | ... | @@ -664,7 +665,7 @@ test "io.SliceOutStream" { |
| 664 | 665 | const stream = &slice_stream.stream; |
| 665 | 666 | |
| 666 | 667 | try stream.print("{}{}!", "Hello", "World"); |
| 667 | debug.assertOrPanic(mem.eql(u8, "HelloWorld!", slice_stream.getWritten())); | |
| 668 | testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten()); | |
| 668 | 669 | } |
| 669 | 670 | |
| 670 | 671 | var null_out_stream_state = NullOutStream.init(); |
| ... | ... | @@ -726,7 +727,7 @@ test "io.CountingOutStream" { |
| 726 | 727 | |
| 727 | 728 | const bytes = "yay" ** 10000; |
| 728 | 729 | stream.write(bytes) catch unreachable; |
| 729 | debug.assertOrPanic(counting_stream.bytes_written == bytes.len); | |
| 730 | testing.expect(counting_stream.bytes_written == bytes.len); | |
| 730 | 731 | } |
| 731 | 732 | |
| 732 | 733 | pub fn BufferedOutStream(comptime Error: type) type { |
| ... | ... | @@ -1014,10 +1015,10 @@ test "io.readLineFrom" { |
| 1014 | 1015 | ); |
| 1015 | 1016 | const stream = &mem_stream.stream; |
| 1016 | 1017 | |
| 1017 | debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineFrom(stream, &buf))); | |
| 1018 | debug.assertOrPanic(mem.eql(u8, "Line 22", try readLineFrom(stream, &buf))); | |
| 1019 | debug.assertError(readLineFrom(stream, &buf), error.EndOfStream); | |
| 1020 | debug.assertOrPanic(mem.eql(u8, buf.toSlice(), "Line 1Line 22Line 333")); | |
| 1018 | testing.expectEqualSlices(u8, "Line 1", try readLineFrom(stream, &buf)); | |
| 1019 | testing.expectEqualSlices(u8, "Line 22", try readLineFrom(stream, &buf)); | |
| 1020 | testing.expectError(error.EndOfStream, readLineFrom(stream, &buf)); | |
| 1021 | testing.expectEqualSlices(u8, "Line 1Line 22Line 333", buf.toSlice()); | |
| 1021 | 1022 | } |
| 1022 | 1023 | |
| 1023 | 1024 | pub fn readLineSlice(slice: []u8) ![]u8 { |
| ... | ... | @@ -1045,8 +1046,8 @@ test "io.readLineSliceFrom" { |
| 1045 | 1046 | ); |
| 1046 | 1047 | const stream = &mem_stream.stream; |
| 1047 | 1048 | |
| 1048 | debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineSliceFrom(stream, buf[0..]))); | |
| 1049 | debug.assertError(readLineSliceFrom(stream, buf[0..]), error.OutOfMemory); | |
| 1049 | testing.expectEqualSlices(u8, "Line 1", try readLineSliceFrom(stream, buf[0..])); | |
| 1050 | testing.expectError(error.OutOfMemory, readLineSliceFrom(stream, buf[0..])); | |
| 1050 | 1051 | } |
| 1051 | 1052 | |
| 1052 | 1053 | /// Creates a deserializer that deserializes types from any stream. |
std/io_test.zig+101-101| ... | ... | @@ -3,8 +3,8 @@ const io = std.io; |
| 3 | 3 | const meta = std.meta; |
| 4 | 4 | const trait = std.trait; |
| 5 | 5 | const DefaultPrng = std.rand.DefaultPrng; |
| 6 | const assert = std.debug.assert; | |
| 7 | const assertError = std.debug.assertError; | |
| 6 | const expect = std.testing.expect; | |
| 7 | const expectError = std.testing.expectError; | |
| 8 | 8 | const mem = std.mem; |
| 9 | 9 | const os = std.os; |
| 10 | 10 | const builtin = @import("builtin"); |
| ... | ... | @@ -35,7 +35,7 @@ test "write a file, read it, then delete it" { |
| 35 | 35 | |
| 36 | 36 | const file_size = try file.getEndPos(); |
| 37 | 37 | const expected_file_size = "begin".len + data.len + "end".len; |
| 38 | assert(file_size == expected_file_size); | |
| 38 | expect(file_size == expected_file_size); | |
| 39 | 39 | |
| 40 | 40 | var file_in_stream = file.inStream(); |
| 41 | 41 | var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream); |
| ... | ... | @@ -43,9 +43,9 @@ test "write a file, read it, then delete it" { |
| 43 | 43 | const contents = try st.readAllAlloc(allocator, 2 * 1024); |
| 44 | 44 | defer allocator.free(contents); |
| 45 | 45 | |
| 46 | assert(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 47 | assert(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data)); | |
| 48 | assert(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 46 | expect(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 47 | expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data)); | |
| 48 | expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 49 | 49 | } |
| 50 | 50 | try os.deleteFile(tmp_file_name); |
| 51 | 51 | } |
| ... | ... | @@ -61,7 +61,7 @@ test "BufferOutStream" { |
| 61 | 61 | const y: i32 = 1234; |
| 62 | 62 | try buf_stream.print("x: {}\ny: {}\n", x, y); |
| 63 | 63 | |
| 64 | assert(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | |
| 64 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | test "SliceInStream" { |
| ... | ... | @@ -71,15 +71,15 @@ test "SliceInStream" { |
| 71 | 71 | var dest: [4]u8 = undefined; |
| 72 | 72 | |
| 73 | 73 | var read = try ss.stream.read(dest[0..4]); |
| 74 | assert(read == 4); | |
| 75 | assert(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 74 | expect(read == 4); | |
| 75 | expect(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 76 | 76 | |
| 77 | 77 | read = try ss.stream.read(dest[0..4]); |
| 78 | assert(read == 3); | |
| 79 | assert(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 78 | expect(read == 3); | |
| 79 | expect(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 80 | 80 | |
| 81 | 81 | read = try ss.stream.read(dest[0..4]); |
| 82 | assert(read == 0); | |
| 82 | expect(read == 0); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "PeekStream" { |
| ... | ... | @@ -93,26 +93,26 @@ test "PeekStream" { |
| 93 | 93 | ps.putBackByte(10); |
| 94 | 94 | |
| 95 | 95 | var read = try ps.stream.read(dest[0..4]); |
| 96 | assert(read == 4); | |
| 97 | assert(dest[0] == 10); | |
| 98 | assert(dest[1] == 9); | |
| 99 | assert(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 96 | expect(read == 4); | |
| 97 | expect(dest[0] == 10); | |
| 98 | expect(dest[1] == 9); | |
| 99 | expect(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 100 | 100 | |
| 101 | 101 | read = try ps.stream.read(dest[0..4]); |
| 102 | assert(read == 4); | |
| 103 | assert(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 102 | expect(read == 4); | |
| 103 | expect(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 104 | 104 | |
| 105 | 105 | read = try ps.stream.read(dest[0..4]); |
| 106 | assert(read == 2); | |
| 107 | assert(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 106 | expect(read == 2); | |
| 107 | expect(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 108 | 108 | |
| 109 | 109 | ps.putBackByte(11); |
| 110 | 110 | ps.putBackByte(12); |
| 111 | 111 | |
| 112 | 112 | read = try ps.stream.read(dest[0..4]); |
| 113 | assert(read == 2); | |
| 114 | assert(dest[0] == 12); | |
| 115 | assert(dest[1] == 11); | |
| 113 | expect(read == 2); | |
| 114 | expect(dest[0] == 12); | |
| 115 | expect(dest[1] == 11); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | test "SliceOutStream" { |
| ... | ... | @@ -120,19 +120,19 @@ test "SliceOutStream" { |
| 120 | 120 | var ss = io.SliceOutStream.init(buffer[0..]); |
| 121 | 121 | |
| 122 | 122 | try ss.stream.write("Hello"); |
| 123 | assert(mem.eql(u8, ss.getWritten(), "Hello")); | |
| 123 | expect(mem.eql(u8, ss.getWritten(), "Hello")); | |
| 124 | 124 | |
| 125 | 125 | try ss.stream.write("world"); |
| 126 | assert(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 126 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 127 | 127 | |
| 128 | assertError(ss.stream.write("!"), error.OutOfSpace); | |
| 129 | assert(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 128 | expectError(error.OutOfSpace, ss.stream.write("!")); | |
| 129 | expect(mem.eql(u8, ss.getWritten(), "Helloworld")); | |
| 130 | 130 | |
| 131 | 131 | ss.reset(); |
| 132 | assert(ss.getWritten().len == 0); | |
| 132 | expect(ss.getWritten().len == 0); | |
| 133 | 133 | |
| 134 | assertError(ss.stream.write("Hello world!"), error.OutOfSpace); | |
| 135 | assert(mem.eql(u8, ss.getWritten(), "Hello worl")); | |
| 134 | expectError(error.OutOfSpace, ss.stream.write("Hello world!")); | |
| 135 | expect(mem.eql(u8, ss.getWritten(), "Hello worl")); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "BitInStream" { |
| ... | ... | @@ -145,66 +145,66 @@ test "BitInStream" { |
| 145 | 145 | |
| 146 | 146 | var out_bits: usize = undefined; |
| 147 | 147 | |
| 148 | assert(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 149 | assert(out_bits == 1); | |
| 150 | assert(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 151 | assert(out_bits == 2); | |
| 152 | assert(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 153 | assert(out_bits == 3); | |
| 154 | assert(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 155 | assert(out_bits == 4); | |
| 156 | assert(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 157 | assert(out_bits == 5); | |
| 158 | assert(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 159 | assert(out_bits == 1); | |
| 148 | expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 149 | expect(out_bits == 1); | |
| 150 | expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 151 | expect(out_bits == 2); | |
| 152 | expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 153 | expect(out_bits == 3); | |
| 154 | expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 155 | expect(out_bits == 4); | |
| 156 | expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 157 | expect(out_bits == 5); | |
| 158 | expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 159 | expect(out_bits == 1); | |
| 160 | 160 | |
| 161 | 161 | mem_in_be.pos = 0; |
| 162 | 162 | bit_stream_be.bit_count = 0; |
| 163 | assert(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 164 | assert(out_bits == 15); | |
| 163 | expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 164 | expect(out_bits == 15); | |
| 165 | 165 | |
| 166 | 166 | mem_in_be.pos = 0; |
| 167 | 167 | bit_stream_be.bit_count = 0; |
| 168 | assert(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 169 | assert(out_bits == 16); | |
| 168 | expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 169 | expect(out_bits == 16); | |
| 170 | 170 | |
| 171 | 171 | _ = try bit_stream_be.readBits(u0, 0, &out_bits); |
| 172 | 172 | |
| 173 | assert(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 174 | assert(out_bits == 0); | |
| 175 | assertError(bit_stream_be.readBitsNoEof(u1, 1), error.EndOfStream); | |
| 173 | expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 174 | expect(out_bits == 0); | |
| 175 | expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | |
| 176 | 176 | |
| 177 | 177 | var mem_in_le = io.SliceInStream.init(mem_le[0..]); |
| 178 | 178 | var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream); |
| 179 | 179 | |
| 180 | assert(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 181 | assert(out_bits == 1); | |
| 182 | assert(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 183 | assert(out_bits == 2); | |
| 184 | assert(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 185 | assert(out_bits == 3); | |
| 186 | assert(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 187 | assert(out_bits == 4); | |
| 188 | assert(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 189 | assert(out_bits == 5); | |
| 190 | assert(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 191 | assert(out_bits == 1); | |
| 180 | expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 181 | expect(out_bits == 1); | |
| 182 | expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 183 | expect(out_bits == 2); | |
| 184 | expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 185 | expect(out_bits == 3); | |
| 186 | expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 187 | expect(out_bits == 4); | |
| 188 | expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 189 | expect(out_bits == 5); | |
| 190 | expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 191 | expect(out_bits == 1); | |
| 192 | 192 | |
| 193 | 193 | mem_in_le.pos = 0; |
| 194 | 194 | bit_stream_le.bit_count = 0; |
| 195 | assert(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 196 | assert(out_bits == 15); | |
| 195 | expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 196 | expect(out_bits == 15); | |
| 197 | 197 | |
| 198 | 198 | mem_in_le.pos = 0; |
| 199 | 199 | bit_stream_le.bit_count = 0; |
| 200 | assert(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 201 | assert(out_bits == 16); | |
| 200 | expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 201 | expect(out_bits == 16); | |
| 202 | 202 | |
| 203 | 203 | _ = try bit_stream_le.readBits(u0, 0, &out_bits); |
| 204 | 204 | |
| 205 | assert(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 206 | assert(out_bits == 0); | |
| 207 | assertError(bit_stream_le.readBitsNoEof(u1, 1), error.EndOfStream); | |
| 205 | expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 206 | expect(out_bits == 0); | |
| 207 | expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | test "BitOutStream" { |
| ... | ... | @@ -222,17 +222,17 @@ test "BitOutStream" { |
| 222 | 222 | try bit_stream_be.writeBits(u9(5), 5); |
| 223 | 223 | try bit_stream_be.writeBits(u1(1), 1); |
| 224 | 224 | |
| 225 | assert(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); | |
| 225 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011); | |
| 226 | 226 | |
| 227 | 227 | mem_out_be.pos = 0; |
| 228 | 228 | |
| 229 | 229 | try bit_stream_be.writeBits(u15(0b110011010000101), 15); |
| 230 | 230 | try bit_stream_be.flushBits(); |
| 231 | assert(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); | |
| 231 | expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010); | |
| 232 | 232 | |
| 233 | 233 | mem_out_be.pos = 0; |
| 234 | 234 | try bit_stream_be.writeBits(u32(0b110011010000101), 16); |
| 235 | assert(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); | |
| 235 | expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101); | |
| 236 | 236 | |
| 237 | 237 | try bit_stream_be.writeBits(u0(0), 0); |
| 238 | 238 | |
| ... | ... | @@ -246,16 +246,16 @@ test "BitOutStream" { |
| 246 | 246 | try bit_stream_le.writeBits(u9(5), 5); |
| 247 | 247 | try bit_stream_le.writeBits(u1(1), 1); |
| 248 | 248 | |
| 249 | assert(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); | |
| 249 | expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101); | |
| 250 | 250 | |
| 251 | 251 | mem_out_le.pos = 0; |
| 252 | 252 | try bit_stream_le.writeBits(u15(0b110011010000101), 15); |
| 253 | 253 | try bit_stream_le.flushBits(); |
| 254 | assert(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); | |
| 254 | expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110); | |
| 255 | 255 | |
| 256 | 256 | mem_out_le.pos = 0; |
| 257 | 257 | try bit_stream_le.writeBits(u32(0b1100110100001011), 16); |
| 258 | assert(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); | |
| 258 | expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101); | |
| 259 | 259 | |
| 260 | 260 | try bit_stream_le.writeBits(u0(0), 0); |
| 261 | 261 | } |
| ... | ... | @@ -290,20 +290,20 @@ test "BitStreams with File Stream" { |
| 290 | 290 | |
| 291 | 291 | var out_bits: usize = undefined; |
| 292 | 292 | |
| 293 | assert(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 294 | assert(out_bits == 1); | |
| 295 | assert(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 296 | assert(out_bits == 2); | |
| 297 | assert(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 298 | assert(out_bits == 3); | |
| 299 | assert(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 300 | assert(out_bits == 4); | |
| 301 | assert(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 302 | assert(out_bits == 5); | |
| 303 | assert(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 304 | assert(out_bits == 1); | |
| 293 | expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 294 | expect(out_bits == 1); | |
| 295 | expect(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 296 | expect(out_bits == 2); | |
| 297 | expect(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 298 | expect(out_bits == 3); | |
| 299 | expect(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 300 | expect(out_bits == 4); | |
| 301 | expect(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 302 | expect(out_bits == 5); | |
| 303 | expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 304 | expect(out_bits == 1); | |
| 305 | 305 | |
| 306 | assertError(bit_stream.readBitsNoEof(u1, 1), error.EndOfStream); | |
| 306 | expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); | |
| 307 | 307 | } |
| 308 | 308 | try os.deleteFile(tmp_file_name); |
| 309 | 309 | } |
| ... | ... | @@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa |
| 345 | 345 | const S = @IntType(true, i); |
| 346 | 346 | const x = try deserializer.deserializeInt(U); |
| 347 | 347 | const y = try deserializer.deserializeInt(S); |
| 348 | assert(x == U(i)); | |
| 349 | if (i != 0) assert(y == S(-1)) else assert(y == 0); | |
| 348 | expect(x == U(i)); | |
| 349 | if (i != 0) expect(y == S(-1)) else expect(y == 0); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | const u8_bit_count = comptime meta.bitCount(u8); |
| ... | ... | @@ -356,7 +356,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa |
| 356 | 356 | const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0); |
| 357 | 357 | const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte; |
| 358 | 358 | |
| 359 | assert(in.pos == if (is_packed) total_packed_bytes else total_bytes); | |
| 359 | expect(in.pos == if (is_packed) total_packed_bytes else total_bytes); | |
| 360 | 360 | |
| 361 | 361 | //Verify that empty error set works with serializer. |
| 362 | 362 | //deserializer is covered by SliceInStream |
| ... | ... | @@ -408,14 +408,14 @@ fn testIntSerializerDeserializerInfNaN(comptime endian: builtin.Endian, |
| 408 | 408 | const inf_check_f64 = try deserializer.deserialize(f64); |
| 409 | 409 | //const nan_check_f128 = try deserializer.deserialize(f128); |
| 410 | 410 | //const inf_check_f128 = try deserializer.deserialize(f128); |
| 411 | assert(std.math.isNan(nan_check_f16)); | |
| 412 | assert(std.math.isInf(inf_check_f16)); | |
| 413 | assert(std.math.isNan(nan_check_f32)); | |
| 414 | assert(std.math.isInf(inf_check_f32)); | |
| 415 | assert(std.math.isNan(nan_check_f64)); | |
| 416 | assert(std.math.isInf(inf_check_f64)); | |
| 417 | //assert(std.math.isNan(nan_check_f128)); | |
| 418 | //assert(std.math.isInf(inf_check_f128)); | |
| 411 | expect(std.math.isNan(nan_check_f16)); | |
| 412 | expect(std.math.isInf(inf_check_f16)); | |
| 413 | expect(std.math.isNan(nan_check_f32)); | |
| 414 | expect(std.math.isInf(inf_check_f32)); | |
| 415 | expect(std.math.isNan(nan_check_f64)); | |
| 416 | expect(std.math.isInf(inf_check_f64)); | |
| 417 | //expect(std.math.isNan(nan_check_f128)); | |
| 418 | //expect(std.math.isInf(inf_check_f128)); | |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | test "Serializer/Deserializer Int: Inf/NaN" { |
| ... | ... | @@ -528,7 +528,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packe |
| 528 | 528 | try serializer.serialize(my_inst); |
| 529 | 529 | |
| 530 | 530 | const my_copy = try deserializer.deserialize(MyStruct); |
| 531 | assert(meta.eql(my_copy, my_inst)); | |
| 531 | expect(meta.eql(my_copy, my_inst)); | |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | test "Serializer/Deserializer generic" { |
| ... | ... | @@ -565,11 +565,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime is_packed: bool) !void |
| 565 | 565 | var deserializer = io.Deserializer(endian, is_packed, InError).init(in_stream); |
| 566 | 566 | |
| 567 | 567 | try serializer.serialize(u14(3)); |
| 568 | assertError(deserializer.deserialize(A), error.InvalidEnumTag); | |
| 568 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); | |
| 569 | 569 | out.pos = 0; |
| 570 | 570 | try serializer.serialize(u14(3)); |
| 571 | 571 | try serializer.serialize(u14(88)); |
| 572 | assertError(deserializer.deserialize(C), error.InvalidEnumTag); | |
| 572 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); | |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | test "Deserializer bad data" { |
std/json.zig+9-8| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | const std = @import("index.zig"); |
| 6 | 6 | const debug = std.debug; |
| 7 | const testing = std.testing; | |
| 7 | 8 | const mem = std.mem; |
| 8 | 9 | const maxInt = std.math.maxInt; |
| 9 | 10 | |
| ... | ... | @@ -960,7 +961,7 @@ test "json.token" { |
| 960 | 961 | checkNext(&p, Token.Id.ObjectEnd); |
| 961 | 962 | checkNext(&p, Token.Id.ObjectEnd); |
| 962 | 963 | |
| 963 | debug.assert((try p.next()) == null); | |
| 964 | testing.expect((try p.next()) == null); | |
| 964 | 965 | } |
| 965 | 966 | |
| 966 | 967 | // Validate a JSON string. This does not limit number precision so a decoder may not necessarily |
| ... | ... | @@ -981,7 +982,7 @@ pub fn validate(s: []const u8) bool { |
| 981 | 982 | } |
| 982 | 983 | |
| 983 | 984 | test "json.validate" { |
| 984 | debug.assert(validate("{}")); | |
| 985 | testing.expect(validate("{}")); | |
| 985 | 986 | } |
| 986 | 987 | |
| 987 | 988 | const Allocator = std.mem.Allocator; |
| ... | ... | @@ -1378,20 +1379,20 @@ test "json.parser.dynamic" { |
| 1378 | 1379 | var image = root.Object.get("Image").?.value; |
| 1379 | 1380 | |
| 1380 | 1381 | const width = image.Object.get("Width").?.value; |
| 1381 | debug.assert(width.Integer == 800); | |
| 1382 | testing.expect(width.Integer == 800); | |
| 1382 | 1383 | |
| 1383 | 1384 | const height = image.Object.get("Height").?.value; |
| 1384 | debug.assert(height.Integer == 600); | |
| 1385 | testing.expect(height.Integer == 600); | |
| 1385 | 1386 | |
| 1386 | 1387 | const title = image.Object.get("Title").?.value; |
| 1387 | debug.assert(mem.eql(u8, title.String, "View from 15th Floor")); | |
| 1388 | testing.expect(mem.eql(u8, title.String, "View from 15th Floor")); | |
| 1388 | 1389 | |
| 1389 | 1390 | const animated = image.Object.get("Animated").?.value; |
| 1390 | debug.assert(animated.Bool == false); | |
| 1391 | testing.expect(animated.Bool == false); | |
| 1391 | 1392 | |
| 1392 | 1393 | const array_of_object = image.Object.get("ArrayOfObject").?.value; |
| 1393 | debug.assert(array_of_object.Array.len == 1); | |
| 1394 | testing.expect(array_of_object.Array.len == 1); | |
| 1394 | 1395 | |
| 1395 | 1396 | const obj0 = array_of_object.Array.at(0).Object.get("n").?.value; |
| 1396 | debug.assert(mem.eql(u8, obj0.String, "m")); | |
| 1397 | testing.expect(mem.eql(u8, obj0.String, "m")); | |
| 1397 | 1398 | } |
std/json_test.zig+3-3| ... | ... | @@ -6,15 +6,15 @@ |
| 6 | 6 | const std = @import("index.zig"); |
| 7 | 7 | |
| 8 | 8 | fn ok(comptime s: []const u8) void { |
| 9 | std.debug.assert(std.json.validate(s)); | |
| 9 | std.testing.expect(std.json.validate(s)); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn err(comptime s: []const u8) void { |
| 13 | std.debug.assert(!std.json.validate(s)); | |
| 13 | std.testing.expect(!std.json.validate(s)); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn any(comptime s: []const u8) void { |
| 17 | std.debug.assert(true); | |
| 17 | std.testing.expect(true); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
std/lazy_init.zig+5-4| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 6 | const AtomicOrder = builtin.AtomicOrder; |
| 6 | 7 | |
| ... | ... | @@ -63,12 +64,12 @@ test "std.lazyInit" { |
| 63 | 64 | global_number.resolve(); |
| 64 | 65 | } |
| 65 | 66 | if (global_number.get()) |x| { |
| 66 | assert(x.* == 1234); | |
| 67 | testing.expect(x.* == 1234); | |
| 67 | 68 | } else { |
| 68 | 69 | @panic("bad"); |
| 69 | 70 | } |
| 70 | 71 | if (global_number.get()) |x| { |
| 71 | assert(x.* == 1234); | |
| 72 | testing.expect(x.* == 1234); | |
| 72 | 73 | } else { |
| 73 | 74 | @panic("bad"); |
| 74 | 75 | } |
| ... | ... | @@ -80,6 +81,6 @@ test "std.lazyInit(void)" { |
| 80 | 81 | if (global_void.get()) |_| @panic("bad") else { |
| 81 | 82 | global_void.resolve(); |
| 82 | 83 | } |
| 83 | assert(global_void.get() != null); | |
| 84 | assert(global_void.get() != null); | |
| 84 | testing.expect(global_void.get() != null); | |
| 85 | testing.expect(global_void.get() != null); | |
| 85 | 86 | } |
std/linked_list.zig+15-14| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const debug = std.debug; |
| 3 | 3 | const assert = debug.assert; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const Allocator = mem.Allocator; |
| 6 | 7 | |
| ... | ... | @@ -246,7 +247,7 @@ test "basic linked list test" { |
| 246 | 247 | var it = list.first; |
| 247 | 248 | var index: u32 = 1; |
| 248 | 249 | while (it) |node| : (it = node.next) { |
| 249 | assert(node.data == index); | |
| 250 | testing.expect(node.data == index); | |
| 250 | 251 | index += 1; |
| 251 | 252 | } |
| 252 | 253 | } |
| ... | ... | @@ -256,7 +257,7 @@ test "basic linked list test" { |
| 256 | 257 | var it = list.last; |
| 257 | 258 | var index: u32 = 1; |
| 258 | 259 | while (it) |node| : (it = node.prev) { |
| 259 | assert(node.data == (6 - index)); | |
| 260 | testing.expect(node.data == (6 - index)); | |
| 260 | 261 | index += 1; |
| 261 | 262 | } |
| 262 | 263 | } |
| ... | ... | @@ -265,9 +266,9 @@ test "basic linked list test" { |
| 265 | 266 | var last = list.pop(); // {2, 3, 4} |
| 266 | 267 | list.remove(three); // {2, 4} |
| 267 | 268 | |
| 268 | assert(list.first.?.data == 2); | |
| 269 | assert(list.last.?.data == 4); | |
| 270 | assert(list.len == 2); | |
| 269 | testing.expect(list.first.?.data == 2); | |
| 270 | testing.expect(list.last.?.data == 4); | |
| 271 | testing.expect(list.len == 2); | |
| 271 | 272 | } |
| 272 | 273 | |
| 273 | 274 | test "linked list concatenation" { |
| ... | ... | @@ -294,18 +295,18 @@ test "linked list concatenation" { |
| 294 | 295 | |
| 295 | 296 | list1.concatByMoving(&list2); |
| 296 | 297 | |
| 297 | assert(list1.last == five); | |
| 298 | assert(list1.len == 5); | |
| 299 | assert(list2.first == null); | |
| 300 | assert(list2.last == null); | |
| 301 | assert(list2.len == 0); | |
| 298 | testing.expect(list1.last == five); | |
| 299 | testing.expect(list1.len == 5); | |
| 300 | testing.expect(list2.first == null); | |
| 301 | testing.expect(list2.last == null); | |
| 302 | testing.expect(list2.len == 0); | |
| 302 | 303 | |
| 303 | 304 | // Traverse forwards. |
| 304 | 305 | { |
| 305 | 306 | var it = list1.first; |
| 306 | 307 | var index: u32 = 1; |
| 307 | 308 | while (it) |node| : (it = node.next) { |
| 308 | assert(node.data == index); | |
| 309 | testing.expect(node.data == index); | |
| 309 | 310 | index += 1; |
| 310 | 311 | } |
| 311 | 312 | } |
| ... | ... | @@ -315,7 +316,7 @@ test "linked list concatenation" { |
| 315 | 316 | var it = list1.last; |
| 316 | 317 | var index: u32 = 1; |
| 317 | 318 | while (it) |node| : (it = node.prev) { |
| 318 | assert(node.data == (6 - index)); | |
| 319 | testing.expect(node.data == (6 - index)); | |
| 319 | 320 | index += 1; |
| 320 | 321 | } |
| 321 | 322 | } |
| ... | ... | @@ -328,7 +329,7 @@ test "linked list concatenation" { |
| 328 | 329 | var it = list2.first; |
| 329 | 330 | var index: u32 = 1; |
| 330 | 331 | while (it) |node| : (it = node.next) { |
| 331 | assert(node.data == index); | |
| 332 | testing.expect(node.data == index); | |
| 332 | 333 | index += 1; |
| 333 | 334 | } |
| 334 | 335 | } |
| ... | ... | @@ -338,7 +339,7 @@ test "linked list concatenation" { |
| 338 | 339 | var it = list2.last; |
| 339 | 340 | var index: u32 = 1; |
| 340 | 341 | while (it) |node| : (it = node.prev) { |
| 341 | assert(node.data == (6 - index)); | |
| 342 | testing.expect(node.data == (6 - index)); | |
| 342 | 343 | index += 1; |
| 343 | 344 | } |
| 344 | 345 | } |
std/math/acos.zig+19-19| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | const std = @import("../index.zig"); |
| 6 | 6 | const math = std.math; |
| 7 | const assert = std.debug.assert; | |
| 7 | const expect = std.testing.expect; | |
| 8 | 8 | |
| 9 | 9 | pub fn acos(x: var) @typeOf(x) { |
| 10 | 10 | const T = @typeOf(x); |
| ... | ... | @@ -143,38 +143,38 @@ fn acos64(x: f64) f64 { |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "math.acos" { |
| 146 | assert(acos(f32(0.0)) == acos32(0.0)); | |
| 147 | assert(acos(f64(0.0)) == acos64(0.0)); | |
| 146 | expect(acos(f32(0.0)) == acos32(0.0)); | |
| 147 | expect(acos(f64(0.0)) == acos64(0.0)); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "math.acos32" { |
| 151 | 151 | const epsilon = 0.000001; |
| 152 | 152 | |
| 153 | assert(math.approxEq(f32, acos32(0.0), 1.570796, epsilon)); | |
| 154 | assert(math.approxEq(f32, acos32(0.2), 1.369438, epsilon)); | |
| 155 | assert(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon)); | |
| 156 | assert(math.approxEq(f32, acos32(0.5), 1.047198, epsilon)); | |
| 157 | assert(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon)); | |
| 158 | assert(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon)); | |
| 153 | expect(math.approxEq(f32, acos32(0.0), 1.570796, epsilon)); | |
| 154 | expect(math.approxEq(f32, acos32(0.2), 1.369438, epsilon)); | |
| 155 | expect(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon)); | |
| 156 | expect(math.approxEq(f32, acos32(0.5), 1.047198, epsilon)); | |
| 157 | expect(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon)); | |
| 158 | expect(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon)); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | test "math.acos64" { |
| 162 | 162 | const epsilon = 0.000001; |
| 163 | 163 | |
| 164 | assert(math.approxEq(f64, acos64(0.0), 1.570796, epsilon)); | |
| 165 | assert(math.approxEq(f64, acos64(0.2), 1.369438, epsilon)); | |
| 166 | assert(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon)); | |
| 167 | assert(math.approxEq(f64, acos64(0.5), 1.047198, epsilon)); | |
| 168 | assert(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon)); | |
| 169 | assert(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon)); | |
| 164 | expect(math.approxEq(f64, acos64(0.0), 1.570796, epsilon)); | |
| 165 | expect(math.approxEq(f64, acos64(0.2), 1.369438, epsilon)); | |
| 166 | expect(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon)); | |
| 167 | expect(math.approxEq(f64, acos64(0.5), 1.047198, epsilon)); | |
| 168 | expect(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon)); | |
| 169 | expect(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon)); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "math.acos32.special" { |
| 173 | assert(math.isNan(acos32(-2))); | |
| 174 | assert(math.isNan(acos32(1.5))); | |
| 173 | expect(math.isNan(acos32(-2))); | |
| 174 | expect(math.isNan(acos32(1.5))); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "math.acos64.special" { |
| 178 | assert(math.isNan(acos64(-2))); | |
| 179 | assert(math.isNan(acos64(1.5))); | |
| 178 | expect(math.isNan(acos64(-2))); | |
| 179 | expect(math.isNan(acos64(1.5))); | |
| 180 | 180 | } |
std/math/acosh.zig+15-15| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | const builtin = @import("builtin"); |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | |
| 11 | 11 | pub fn acosh(x: var) @typeOf(x) { |
| 12 | 12 | const T = @typeOf(x); |
| ... | ... | @@ -55,34 +55,34 @@ fn acosh64(x: f64) f64 { |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "math.acosh" { |
| 58 | assert(acosh(f32(1.5)) == acosh32(1.5)); | |
| 59 | assert(acosh(f64(1.5)) == acosh64(1.5)); | |
| 58 | expect(acosh(f32(1.5)) == acosh32(1.5)); | |
| 59 | expect(acosh(f64(1.5)) == acosh64(1.5)); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | test "math.acosh32" { |
| 63 | 63 | const epsilon = 0.000001; |
| 64 | 64 | |
| 65 | assert(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon)); | |
| 66 | assert(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon)); | |
| 67 | assert(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon)); | |
| 68 | assert(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon)); | |
| 65 | expect(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon)); | |
| 66 | expect(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon)); | |
| 67 | expect(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon)); | |
| 68 | expect(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "math.acosh64" { |
| 72 | 72 | const epsilon = 0.000001; |
| 73 | 73 | |
| 74 | assert(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon)); | |
| 75 | assert(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon)); | |
| 76 | assert(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon)); | |
| 77 | assert(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon)); | |
| 74 | expect(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon)); | |
| 75 | expect(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon)); | |
| 76 | expect(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon)); | |
| 77 | expect(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon)); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "math.acosh32.special" { |
| 81 | assert(math.isNan(acosh32(math.nan(f32)))); | |
| 82 | assert(math.isSignalNan(acosh32(0.5))); | |
| 81 | expect(math.isNan(acosh32(math.nan(f32)))); | |
| 82 | expect(math.isSignalNan(acosh32(0.5))); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "math.acosh64.special" { |
| 86 | assert(math.isNan(acosh64(math.nan(f64)))); | |
| 87 | assert(math.isSignalNan(acosh64(0.5))); | |
| 86 | expect(math.isNan(acosh64(math.nan(f64)))); | |
| 87 | expect(math.isSignalNan(acosh64(0.5))); | |
| 88 | 88 | } |
std/math/asin.zig+23-23| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | |
| 10 | 10 | pub fn asin(x: var) @typeOf(x) { |
| 11 | 11 | const T = @typeOf(x); |
| ... | ... | @@ -136,42 +136,42 @@ fn asin64(x: f64) f64 { |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "math.asin" { |
| 139 | assert(asin(f32(0.0)) == asin32(0.0)); | |
| 140 | assert(asin(f64(0.0)) == asin64(0.0)); | |
| 139 | expect(asin(f32(0.0)) == asin32(0.0)); | |
| 140 | expect(asin(f64(0.0)) == asin64(0.0)); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "math.asin32" { |
| 144 | 144 | const epsilon = 0.000001; |
| 145 | 145 | |
| 146 | assert(math.approxEq(f32, asin32(0.0), 0.0, epsilon)); | |
| 147 | assert(math.approxEq(f32, asin32(0.2), 0.201358, epsilon)); | |
| 148 | assert(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon)); | |
| 149 | assert(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon)); | |
| 150 | assert(math.approxEq(f32, asin32(0.5), 0.523599, epsilon)); | |
| 151 | assert(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon)); | |
| 146 | expect(math.approxEq(f32, asin32(0.0), 0.0, epsilon)); | |
| 147 | expect(math.approxEq(f32, asin32(0.2), 0.201358, epsilon)); | |
| 148 | expect(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon)); | |
| 149 | expect(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon)); | |
| 150 | expect(math.approxEq(f32, asin32(0.5), 0.523599, epsilon)); | |
| 151 | expect(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.asin64" { |
| 155 | 155 | const epsilon = 0.000001; |
| 156 | 156 | |
| 157 | assert(math.approxEq(f64, asin64(0.0), 0.0, epsilon)); | |
| 158 | assert(math.approxEq(f64, asin64(0.2), 0.201358, epsilon)); | |
| 159 | assert(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon)); | |
| 160 | assert(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon)); | |
| 161 | assert(math.approxEq(f64, asin64(0.5), 0.523599, epsilon)); | |
| 162 | assert(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon)); | |
| 157 | expect(math.approxEq(f64, asin64(0.0), 0.0, epsilon)); | |
| 158 | expect(math.approxEq(f64, asin64(0.2), 0.201358, epsilon)); | |
| 159 | expect(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon)); | |
| 160 | expect(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon)); | |
| 161 | expect(math.approxEq(f64, asin64(0.5), 0.523599, epsilon)); | |
| 162 | expect(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon)); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | test "math.asin32.special" { |
| 166 | assert(asin32(0.0) == 0.0); | |
| 167 | assert(asin32(-0.0) == -0.0); | |
| 168 | assert(math.isNan(asin32(-2))); | |
| 169 | assert(math.isNan(asin32(1.5))); | |
| 166 | expect(asin32(0.0) == 0.0); | |
| 167 | expect(asin32(-0.0) == -0.0); | |
| 168 | expect(math.isNan(asin32(-2))); | |
| 169 | expect(math.isNan(asin32(1.5))); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "math.asin64.special" { |
| 173 | assert(asin64(0.0) == 0.0); | |
| 174 | assert(asin64(-0.0) == -0.0); | |
| 175 | assert(math.isNan(asin64(-2))); | |
| 176 | assert(math.isNan(asin64(1.5))); | |
| 173 | expect(asin64(0.0) == 0.0); | |
| 174 | expect(asin64(-0.0) == -0.0); | |
| 175 | expect(math.isNan(asin64(-2))); | |
| 176 | expect(math.isNan(asin64(1.5))); | |
| 177 | 177 | } |
std/math/asinh.zig+27-27| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | const maxInt = std.math.maxInt; |
| 11 | 11 | |
| 12 | 12 | pub fn asinh(x: var) @typeOf(x) { |
| ... | ... | @@ -83,46 +83,46 @@ fn asinh64(x: f64) f64 { |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "math.asinh" { |
| 86 | assert(asinh(f32(0.0)) == asinh32(0.0)); | |
| 87 | assert(asinh(f64(0.0)) == asinh64(0.0)); | |
| 86 | expect(asinh(f32(0.0)) == asinh32(0.0)); | |
| 87 | expect(asinh(f64(0.0)) == asinh64(0.0)); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "math.asinh32" { |
| 91 | 91 | const epsilon = 0.000001; |
| 92 | 92 | |
| 93 | assert(math.approxEq(f32, asinh32(0.0), 0.0, epsilon)); | |
| 94 | assert(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon)); | |
| 95 | assert(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon)); | |
| 96 | assert(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon)); | |
| 97 | assert(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon)); | |
| 98 | assert(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon)); | |
| 99 | assert(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon)); | |
| 93 | expect(math.approxEq(f32, asinh32(0.0), 0.0, epsilon)); | |
| 94 | expect(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon)); | |
| 95 | expect(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon)); | |
| 96 | expect(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon)); | |
| 97 | expect(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon)); | |
| 98 | expect(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon)); | |
| 99 | expect(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon)); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "math.asinh64" { |
| 103 | 103 | const epsilon = 0.000001; |
| 104 | 104 | |
| 105 | assert(math.approxEq(f64, asinh64(0.0), 0.0, epsilon)); | |
| 106 | assert(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon)); | |
| 107 | assert(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon)); | |
| 108 | assert(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon)); | |
| 109 | assert(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon)); | |
| 110 | assert(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon)); | |
| 111 | assert(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon)); | |
| 105 | expect(math.approxEq(f64, asinh64(0.0), 0.0, epsilon)); | |
| 106 | expect(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon)); | |
| 107 | expect(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon)); | |
| 108 | expect(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon)); | |
| 109 | expect(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon)); | |
| 110 | expect(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon)); | |
| 111 | expect(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon)); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "math.asinh32.special" { |
| 115 | assert(asinh32(0.0) == 0.0); | |
| 116 | assert(asinh32(-0.0) == -0.0); | |
| 117 | assert(math.isPositiveInf(asinh32(math.inf(f32)))); | |
| 118 | assert(math.isNegativeInf(asinh32(-math.inf(f32)))); | |
| 119 | assert(math.isNan(asinh32(math.nan(f32)))); | |
| 115 | expect(asinh32(0.0) == 0.0); | |
| 116 | expect(asinh32(-0.0) == -0.0); | |
| 117 | expect(math.isPositiveInf(asinh32(math.inf(f32)))); | |
| 118 | expect(math.isNegativeInf(asinh32(-math.inf(f32)))); | |
| 119 | expect(math.isNan(asinh32(math.nan(f32)))); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "math.asinh64.special" { |
| 123 | assert(asinh64(0.0) == 0.0); | |
| 124 | assert(asinh64(-0.0) == -0.0); | |
| 125 | assert(math.isPositiveInf(asinh64(math.inf(f64)))); | |
| 126 | assert(math.isNegativeInf(asinh64(-math.inf(f64)))); | |
| 127 | assert(math.isNan(asinh64(math.nan(f64)))); | |
| 123 | expect(asinh64(0.0) == 0.0); | |
| 124 | expect(asinh64(-0.0) == -0.0); | |
| 125 | expect(math.isPositiveInf(asinh64(math.inf(f64)))); | |
| 126 | expect(math.isNegativeInf(asinh64(-math.inf(f64)))); | |
| 127 | expect(math.isNan(asinh64(math.nan(f64)))); | |
| 128 | 128 | } |
std/math/atan.zig+21-21| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | |
| 10 | 10 | pub fn atan(x: var) @typeOf(x) { |
| 11 | 11 | const T = @typeOf(x); |
| ... | ... | @@ -206,44 +206,44 @@ fn atan64(x_: f64) f64 { |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | test "math.atan" { |
| 209 | assert(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2))); | |
| 210 | assert(atan(f64(0.2)) == atan64(0.2)); | |
| 209 | expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2))); | |
| 210 | expect(atan(f64(0.2)) == atan64(0.2)); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | test "math.atan32" { |
| 214 | 214 | const epsilon = 0.000001; |
| 215 | 215 | |
| 216 | assert(math.approxEq(f32, atan32(0.2), 0.197396, epsilon)); | |
| 217 | assert(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon)); | |
| 218 | assert(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon)); | |
| 219 | assert(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon)); | |
| 220 | assert(math.approxEq(f32, atan32(1.5), 0.982794, epsilon)); | |
| 216 | expect(math.approxEq(f32, atan32(0.2), 0.197396, epsilon)); | |
| 217 | expect(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon)); | |
| 218 | expect(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon)); | |
| 219 | expect(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon)); | |
| 220 | expect(math.approxEq(f32, atan32(1.5), 0.982794, epsilon)); | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | test "math.atan64" { |
| 224 | 224 | const epsilon = 0.000001; |
| 225 | 225 | |
| 226 | assert(math.approxEq(f64, atan64(0.2), 0.197396, epsilon)); | |
| 227 | assert(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon)); | |
| 228 | assert(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon)); | |
| 229 | assert(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon)); | |
| 230 | assert(math.approxEq(f64, atan64(1.5), 0.982794, epsilon)); | |
| 226 | expect(math.approxEq(f64, atan64(0.2), 0.197396, epsilon)); | |
| 227 | expect(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon)); | |
| 228 | expect(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon)); | |
| 229 | expect(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon)); | |
| 230 | expect(math.approxEq(f64, atan64(1.5), 0.982794, epsilon)); | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | test "math.atan32.special" { |
| 234 | 234 | const epsilon = 0.000001; |
| 235 | 235 | |
| 236 | assert(atan32(0.0) == 0.0); | |
| 237 | assert(atan32(-0.0) == -0.0); | |
| 238 | assert(math.approxEq(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon)); | |
| 239 | assert(math.approxEq(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon)); | |
| 236 | expect(atan32(0.0) == 0.0); | |
| 237 | expect(atan32(-0.0) == -0.0); | |
| 238 | expect(math.approxEq(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon)); | |
| 239 | expect(math.approxEq(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon)); | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | test "math.atan64.special" { |
| 243 | 243 | const epsilon = 0.000001; |
| 244 | 244 | |
| 245 | assert(atan64(0.0) == 0.0); | |
| 246 | assert(atan64(-0.0) == -0.0); | |
| 247 | assert(math.approxEq(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon)); | |
| 248 | assert(math.approxEq(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon)); | |
| 245 | expect(atan64(0.0) == 0.0); | |
| 246 | expect(atan64(-0.0) == -0.0); | |
| 247 | expect(math.approxEq(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon)); | |
| 248 | expect(math.approxEq(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon)); | |
| 249 | 249 | } |
std/math/atan2.zig+55-55| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | |
| 21 | 21 | const std = @import("../index.zig"); |
| 22 | 22 | const math = std.math; |
| 23 | const assert = std.debug.assert; | |
| 23 | const expect = std.testing.expect; | |
| 24 | 24 | |
| 25 | 25 | pub fn atan2(comptime T: type, y: T, x: T) T { |
| 26 | 26 | return switch (T) { |
| ... | ... | @@ -206,78 +206,78 @@ fn atan2_64(y: f64, x: f64) f64 { |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | test "math.atan2" { |
| 209 | assert(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21)); | |
| 210 | assert(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21)); | |
| 209 | expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21)); | |
| 210 | expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21)); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | test "math.atan2_32" { |
| 214 | 214 | const epsilon = 0.000001; |
| 215 | 215 | |
| 216 | assert(math.approxEq(f32, atan2_32(0.0, 0.0), 0.0, epsilon)); | |
| 217 | assert(math.approxEq(f32, atan2_32(0.2, 0.2), 0.785398, epsilon)); | |
| 218 | assert(math.approxEq(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon)); | |
| 219 | assert(math.approxEq(f32, atan2_32(0.2, -0.2), 2.356194, epsilon)); | |
| 220 | assert(math.approxEq(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon)); | |
| 221 | assert(math.approxEq(f32, atan2_32(0.34, -0.4), 2.437099, epsilon)); | |
| 222 | assert(math.approxEq(f32, atan2_32(0.34, 1.243), 0.267001, epsilon)); | |
| 216 | expect(math.approxEq(f32, atan2_32(0.0, 0.0), 0.0, epsilon)); | |
| 217 | expect(math.approxEq(f32, atan2_32(0.2, 0.2), 0.785398, epsilon)); | |
| 218 | expect(math.approxEq(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon)); | |
| 219 | expect(math.approxEq(f32, atan2_32(0.2, -0.2), 2.356194, epsilon)); | |
| 220 | expect(math.approxEq(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon)); | |
| 221 | expect(math.approxEq(f32, atan2_32(0.34, -0.4), 2.437099, epsilon)); | |
| 222 | expect(math.approxEq(f32, atan2_32(0.34, 1.243), 0.267001, epsilon)); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | test "math.atan2_64" { |
| 226 | 226 | const epsilon = 0.000001; |
| 227 | 227 | |
| 228 | assert(math.approxEq(f64, atan2_64(0.0, 0.0), 0.0, epsilon)); | |
| 229 | assert(math.approxEq(f64, atan2_64(0.2, 0.2), 0.785398, epsilon)); | |
| 230 | assert(math.approxEq(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon)); | |
| 231 | assert(math.approxEq(f64, atan2_64(0.2, -0.2), 2.356194, epsilon)); | |
| 232 | assert(math.approxEq(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon)); | |
| 233 | assert(math.approxEq(f64, atan2_64(0.34, -0.4), 2.437099, epsilon)); | |
| 234 | assert(math.approxEq(f64, atan2_64(0.34, 1.243), 0.267001, epsilon)); | |
| 228 | expect(math.approxEq(f64, atan2_64(0.0, 0.0), 0.0, epsilon)); | |
| 229 | expect(math.approxEq(f64, atan2_64(0.2, 0.2), 0.785398, epsilon)); | |
| 230 | expect(math.approxEq(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon)); | |
| 231 | expect(math.approxEq(f64, atan2_64(0.2, -0.2), 2.356194, epsilon)); | |
| 232 | expect(math.approxEq(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon)); | |
| 233 | expect(math.approxEq(f64, atan2_64(0.34, -0.4), 2.437099, epsilon)); | |
| 234 | expect(math.approxEq(f64, atan2_64(0.34, 1.243), 0.267001, epsilon)); | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | test "math.atan2_32.special" { |
| 238 | 238 | const epsilon = 0.000001; |
| 239 | 239 | |
| 240 | assert(math.isNan(atan2_32(1.0, math.nan(f32)))); | |
| 241 | assert(math.isNan(atan2_32(math.nan(f32), 1.0))); | |
| 242 | assert(atan2_32(0.0, 5.0) == 0.0); | |
| 243 | assert(atan2_32(-0.0, 5.0) == -0.0); | |
| 244 | assert(math.approxEq(f32, atan2_32(0.0, -5.0), math.pi, epsilon)); | |
| 245 | //assert(math.approxEq(f32, atan2_32(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero? | |
| 246 | assert(math.approxEq(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 247 | assert(math.approxEq(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 248 | assert(math.approxEq(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 249 | assert(math.approxEq(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 250 | assert(math.approxEq(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon)); | |
| 251 | assert(math.approxEq(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon)); | |
| 252 | assert(math.approxEq(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon)); | |
| 253 | assert(math.approxEq(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon)); | |
| 254 | assert(atan2_32(1.0, math.inf(f32)) == 0.0); | |
| 255 | assert(math.approxEq(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon)); | |
| 256 | assert(math.approxEq(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon)); | |
| 257 | assert(math.approxEq(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon)); | |
| 258 | assert(math.approxEq(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon)); | |
| 240 | expect(math.isNan(atan2_32(1.0, math.nan(f32)))); | |
| 241 | expect(math.isNan(atan2_32(math.nan(f32), 1.0))); | |
| 242 | expect(atan2_32(0.0, 5.0) == 0.0); | |
| 243 | expect(atan2_32(-0.0, 5.0) == -0.0); | |
| 244 | expect(math.approxEq(f32, atan2_32(0.0, -5.0), math.pi, epsilon)); | |
| 245 | //expect(math.approxEq(f32, atan2_32(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero? | |
| 246 | expect(math.approxEq(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 247 | expect(math.approxEq(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 248 | expect(math.approxEq(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 249 | expect(math.approxEq(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 250 | expect(math.approxEq(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon)); | |
| 251 | expect(math.approxEq(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon)); | |
| 252 | expect(math.approxEq(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon)); | |
| 253 | expect(math.approxEq(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon)); | |
| 254 | expect(atan2_32(1.0, math.inf(f32)) == 0.0); | |
| 255 | expect(math.approxEq(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon)); | |
| 256 | expect(math.approxEq(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon)); | |
| 257 | expect(math.approxEq(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon)); | |
| 258 | expect(math.approxEq(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon)); | |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | test "math.atan2_64.special" { |
| 262 | 262 | const epsilon = 0.000001; |
| 263 | 263 | |
| 264 | assert(math.isNan(atan2_64(1.0, math.nan(f64)))); | |
| 265 | assert(math.isNan(atan2_64(math.nan(f64), 1.0))); | |
| 266 | assert(atan2_64(0.0, 5.0) == 0.0); | |
| 267 | assert(atan2_64(-0.0, 5.0) == -0.0); | |
| 268 | assert(math.approxEq(f64, atan2_64(0.0, -5.0), math.pi, epsilon)); | |
| 269 | //assert(math.approxEq(f64, atan2_64(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero? | |
| 270 | assert(math.approxEq(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 271 | assert(math.approxEq(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 272 | assert(math.approxEq(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 273 | assert(math.approxEq(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 274 | assert(math.approxEq(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon)); | |
| 275 | assert(math.approxEq(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon)); | |
| 276 | assert(math.approxEq(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon)); | |
| 277 | assert(math.approxEq(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon)); | |
| 278 | assert(atan2_64(1.0, math.inf(f64)) == 0.0); | |
| 279 | assert(math.approxEq(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon)); | |
| 280 | assert(math.approxEq(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon)); | |
| 281 | assert(math.approxEq(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon)); | |
| 282 | assert(math.approxEq(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon)); | |
| 264 | expect(math.isNan(atan2_64(1.0, math.nan(f64)))); | |
| 265 | expect(math.isNan(atan2_64(math.nan(f64), 1.0))); | |
| 266 | expect(atan2_64(0.0, 5.0) == 0.0); | |
| 267 | expect(atan2_64(-0.0, 5.0) == -0.0); | |
| 268 | expect(math.approxEq(f64, atan2_64(0.0, -5.0), math.pi, epsilon)); | |
| 269 | //expect(math.approxEq(f64, atan2_64(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero? | |
| 270 | expect(math.approxEq(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 271 | expect(math.approxEq(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 272 | expect(math.approxEq(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 273 | expect(math.approxEq(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 274 | expect(math.approxEq(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon)); | |
| 275 | expect(math.approxEq(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon)); | |
| 276 | expect(math.approxEq(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon)); | |
| 277 | expect(math.approxEq(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon)); | |
| 278 | expect(atan2_64(1.0, math.inf(f64)) == 0.0); | |
| 279 | expect(math.approxEq(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon)); | |
| 280 | expect(math.approxEq(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon)); | |
| 281 | expect(math.approxEq(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon)); | |
| 282 | expect(math.approxEq(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon)); | |
| 283 | 283 | } |
std/math/atanh.zig+19-19| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | const maxInt = std.math.maxInt; |
| 11 | 11 | |
| 12 | 12 | pub fn atanh(x: var) @typeOf(x) { |
| ... | ... | @@ -78,38 +78,38 @@ fn atanh_64(x: f64) f64 { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "math.atanh" { |
| 81 | assert(atanh(f32(0.0)) == atanh_32(0.0)); | |
| 82 | assert(atanh(f64(0.0)) == atanh_64(0.0)); | |
| 81 | expect(atanh(f32(0.0)) == atanh_32(0.0)); | |
| 82 | expect(atanh(f64(0.0)) == atanh_64(0.0)); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "math.atanh_32" { |
| 86 | 86 | const epsilon = 0.000001; |
| 87 | 87 | |
| 88 | assert(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon)); | |
| 89 | assert(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon)); | |
| 90 | assert(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon)); | |
| 88 | expect(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon)); | |
| 89 | expect(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon)); | |
| 90 | expect(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon)); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | test "math.atanh_64" { |
| 94 | 94 | const epsilon = 0.000001; |
| 95 | 95 | |
| 96 | assert(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon)); | |
| 97 | assert(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon)); | |
| 98 | assert(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon)); | |
| 96 | expect(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon)); | |
| 97 | expect(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon)); | |
| 98 | expect(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon)); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | test "math.atanh32.special" { |
| 102 | assert(math.isPositiveInf(atanh_32(1))); | |
| 103 | assert(math.isNegativeInf(atanh_32(-1))); | |
| 104 | assert(math.isSignalNan(atanh_32(1.5))); | |
| 105 | assert(math.isSignalNan(atanh_32(-1.5))); | |
| 106 | assert(math.isNan(atanh_32(math.nan(f32)))); | |
| 102 | expect(math.isPositiveInf(atanh_32(1))); | |
| 103 | expect(math.isNegativeInf(atanh_32(-1))); | |
| 104 | expect(math.isSignalNan(atanh_32(1.5))); | |
| 105 | expect(math.isSignalNan(atanh_32(-1.5))); | |
| 106 | expect(math.isNan(atanh_32(math.nan(f32)))); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "math.atanh64.special" { |
| 110 | assert(math.isPositiveInf(atanh_64(1))); | |
| 111 | assert(math.isNegativeInf(atanh_64(-1))); | |
| 112 | assert(math.isSignalNan(atanh_64(1.5))); | |
| 113 | assert(math.isSignalNan(atanh_64(-1.5))); | |
| 114 | assert(math.isNan(atanh_64(math.nan(f64)))); | |
| 110 | expect(math.isPositiveInf(atanh_64(1))); | |
| 111 | expect(math.isNegativeInf(atanh_64(-1))); | |
| 112 | expect(math.isSignalNan(atanh_64(1.5))); | |
| 113 | expect(math.isSignalNan(atanh_64(-1.5))); | |
| 114 | expect(math.isNan(atanh_64(math.nan(f64)))); | |
| 115 | 115 | } |
std/math/big/int.zig+180-187| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const debug = std.debug; |
| 4 | const testing = std.testing; | |
| 4 | 5 | const math = std.math; |
| 5 | 6 | const mem = std.mem; |
| 6 | 7 | const Allocator = mem.Allocator; |
| ... | ... | @@ -1086,44 +1087,40 @@ test "big.int comptime_int set" { |
| 1086 | 1087 | const result = Limb(s & maxInt(Limb)); |
| 1087 | 1088 | s >>= Limb.bit_count / 2; |
| 1088 | 1089 | s >>= Limb.bit_count / 2; |
| 1089 | debug.assert(a.limbs[i] == result); | |
| 1090 | testing.expect(a.limbs[i] == result); | |
| 1090 | 1091 | } |
| 1091 | 1092 | } |
| 1092 | 1093 | |
| 1093 | 1094 | test "big.int comptime_int set negative" { |
| 1094 | 1095 | var a = try Int.initSet(al, -10); |
| 1095 | 1096 | |
| 1096 | debug.assert(a.limbs[0] == 10); | |
| 1097 | debug.assert(a.positive == false); | |
| 1097 | testing.expect(a.limbs[0] == 10); | |
| 1098 | testing.expect(a.positive == false); | |
| 1098 | 1099 | } |
| 1099 | 1100 | |
| 1100 | 1101 | test "big.int int set unaligned small" { |
| 1101 | 1102 | var a = try Int.initSet(al, u7(45)); |
| 1102 | 1103 | |
| 1103 | debug.assert(a.limbs[0] == 45); | |
| 1104 | debug.assert(a.positive == true); | |
| 1104 | testing.expect(a.limbs[0] == 45); | |
| 1105 | testing.expect(a.positive == true); | |
| 1105 | 1106 | } |
| 1106 | 1107 | |
| 1107 | 1108 | test "big.int comptime_int to" { |
| 1108 | 1109 | const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab); |
| 1109 | 1110 | |
| 1110 | debug.assert((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab); | |
| 1111 | testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab); | |
| 1111 | 1112 | } |
| 1112 | 1113 | |
| 1113 | 1114 | test "big.int sub-limb to" { |
| 1114 | 1115 | const a = try Int.initSet(al, 10); |
| 1115 | 1116 | |
| 1116 | debug.assert((try a.to(u8)) == 10); | |
| 1117 | testing.expect((try a.to(u8)) == 10); | |
| 1117 | 1118 | } |
| 1118 | 1119 | |
| 1119 | 1120 | test "big.int to target too small error" { |
| 1120 | 1121 | const a = try Int.initSet(al, 0xffffffff); |
| 1121 | 1122 | |
| 1122 | if (a.to(u8)) |_| { | |
| 1123 | unreachable; | |
| 1124 | } else |err| { | |
| 1125 | debug.assert(err == error.TargetTooSmall); | |
| 1126 | } | |
| 1123 | testing.expectError(error.TargetTooSmall, a.to(u8)); | |
| 1127 | 1124 | } |
| 1128 | 1125 | |
| 1129 | 1126 | test "big.int norm1" { |
| ... | ... | @@ -1135,22 +1132,22 @@ test "big.int norm1" { |
| 1135 | 1132 | a.limbs[2] = 3; |
| 1136 | 1133 | a.limbs[3] = 0; |
| 1137 | 1134 | a.norm1(4); |
| 1138 | debug.assert(a.len == 3); | |
| 1135 | testing.expect(a.len == 3); | |
| 1139 | 1136 | |
| 1140 | 1137 | a.limbs[0] = 1; |
| 1141 | 1138 | a.limbs[1] = 2; |
| 1142 | 1139 | a.limbs[2] = 3; |
| 1143 | 1140 | a.norm1(3); |
| 1144 | debug.assert(a.len == 3); | |
| 1141 | testing.expect(a.len == 3); | |
| 1145 | 1142 | |
| 1146 | 1143 | a.limbs[0] = 0; |
| 1147 | 1144 | a.limbs[1] = 0; |
| 1148 | 1145 | a.norm1(2); |
| 1149 | debug.assert(a.len == 1); | |
| 1146 | testing.expect(a.len == 1); | |
| 1150 | 1147 | |
| 1151 | 1148 | a.limbs[0] = 0; |
| 1152 | 1149 | a.norm1(1); |
| 1153 | debug.assert(a.len == 1); | |
| 1150 | testing.expect(a.len == 1); | |
| 1154 | 1151 | } |
| 1155 | 1152 | |
| 1156 | 1153 | test "big.int normN" { |
| ... | ... | @@ -1162,144 +1159,144 @@ test "big.int normN" { |
| 1162 | 1159 | a.limbs[2] = 0; |
| 1163 | 1160 | a.limbs[3] = 0; |
| 1164 | 1161 | a.normN(4); |
| 1165 | debug.assert(a.len == 2); | |
| 1162 | testing.expect(a.len == 2); | |
| 1166 | 1163 | |
| 1167 | 1164 | a.limbs[0] = 1; |
| 1168 | 1165 | a.limbs[1] = 2; |
| 1169 | 1166 | a.limbs[2] = 3; |
| 1170 | 1167 | a.normN(3); |
| 1171 | debug.assert(a.len == 3); | |
| 1168 | testing.expect(a.len == 3); | |
| 1172 | 1169 | |
| 1173 | 1170 | a.limbs[0] = 0; |
| 1174 | 1171 | a.limbs[1] = 0; |
| 1175 | 1172 | a.limbs[2] = 0; |
| 1176 | 1173 | a.limbs[3] = 0; |
| 1177 | 1174 | a.normN(4); |
| 1178 | debug.assert(a.len == 1); | |
| 1175 | testing.expect(a.len == 1); | |
| 1179 | 1176 | |
| 1180 | 1177 | a.limbs[0] = 0; |
| 1181 | 1178 | a.normN(1); |
| 1182 | debug.assert(a.len == 1); | |
| 1179 | testing.expect(a.len == 1); | |
| 1183 | 1180 | } |
| 1184 | 1181 | |
| 1185 | 1182 | test "big.int parity" { |
| 1186 | 1183 | var a = try Int.init(al); |
| 1187 | 1184 | try a.set(0); |
| 1188 | debug.assert(a.isEven()); | |
| 1189 | debug.assert(!a.isOdd()); | |
| 1185 | testing.expect(a.isEven()); | |
| 1186 | testing.expect(!a.isOdd()); | |
| 1190 | 1187 | |
| 1191 | 1188 | try a.set(7); |
| 1192 | debug.assert(!a.isEven()); | |
| 1193 | debug.assert(a.isOdd()); | |
| 1189 | testing.expect(!a.isEven()); | |
| 1190 | testing.expect(a.isOdd()); | |
| 1194 | 1191 | } |
| 1195 | 1192 | |
| 1196 | 1193 | test "big.int bitcount + sizeInBase" { |
| 1197 | 1194 | var a = try Int.init(al); |
| 1198 | 1195 | |
| 1199 | 1196 | try a.set(0b100); |
| 1200 | debug.assert(a.bitCountAbs() == 3); | |
| 1201 | debug.assert(a.sizeInBase(2) >= 3); | |
| 1202 | debug.assert(a.sizeInBase(10) >= 1); | |
| 1197 | testing.expect(a.bitCountAbs() == 3); | |
| 1198 | testing.expect(a.sizeInBase(2) >= 3); | |
| 1199 | testing.expect(a.sizeInBase(10) >= 1); | |
| 1203 | 1200 | |
| 1204 | 1201 | a.negate(); |
| 1205 | debug.assert(a.bitCountAbs() == 3); | |
| 1206 | debug.assert(a.sizeInBase(2) >= 4); | |
| 1207 | debug.assert(a.sizeInBase(10) >= 2); | |
| 1202 | testing.expect(a.bitCountAbs() == 3); | |
| 1203 | testing.expect(a.sizeInBase(2) >= 4); | |
| 1204 | testing.expect(a.sizeInBase(10) >= 2); | |
| 1208 | 1205 | |
| 1209 | 1206 | try a.set(0xffffffff); |
| 1210 | debug.assert(a.bitCountAbs() == 32); | |
| 1211 | debug.assert(a.sizeInBase(2) >= 32); | |
| 1212 | debug.assert(a.sizeInBase(10) >= 10); | |
| 1207 | testing.expect(a.bitCountAbs() == 32); | |
| 1208 | testing.expect(a.sizeInBase(2) >= 32); | |
| 1209 | testing.expect(a.sizeInBase(10) >= 10); | |
| 1213 | 1210 | |
| 1214 | 1211 | try a.shiftLeft(a, 5000); |
| 1215 | debug.assert(a.bitCountAbs() == 5032); | |
| 1216 | debug.assert(a.sizeInBase(2) >= 5032); | |
| 1212 | testing.expect(a.bitCountAbs() == 5032); | |
| 1213 | testing.expect(a.sizeInBase(2) >= 5032); | |
| 1217 | 1214 | a.positive = false; |
| 1218 | 1215 | |
| 1219 | debug.assert(a.bitCountAbs() == 5032); | |
| 1220 | debug.assert(a.sizeInBase(2) >= 5033); | |
| 1216 | testing.expect(a.bitCountAbs() == 5032); | |
| 1217 | testing.expect(a.sizeInBase(2) >= 5033); | |
| 1221 | 1218 | } |
| 1222 | 1219 | |
| 1223 | 1220 | test "big.int bitcount/to" { |
| 1224 | 1221 | var a = try Int.init(al); |
| 1225 | 1222 | |
| 1226 | 1223 | try a.set(0); |
| 1227 | debug.assert(a.bitCountTwosComp() == 0); | |
| 1224 | testing.expect(a.bitCountTwosComp() == 0); | |
| 1228 | 1225 | |
| 1229 | 1226 | // TODO: stack smashing |
| 1230 | // debug.assert((try a.to(u0)) == 0); | |
| 1227 | // testing.expect((try a.to(u0)) == 0); | |
| 1231 | 1228 | // TODO: sigsegv |
| 1232 | // debug.assert((try a.to(i0)) == 0); | |
| 1229 | // testing.expect((try a.to(i0)) == 0); | |
| 1233 | 1230 | |
| 1234 | 1231 | try a.set(-1); |
| 1235 | debug.assert(a.bitCountTwosComp() == 1); | |
| 1236 | debug.assert((try a.to(i1)) == -1); | |
| 1232 | testing.expect(a.bitCountTwosComp() == 1); | |
| 1233 | testing.expect((try a.to(i1)) == -1); | |
| 1237 | 1234 | |
| 1238 | 1235 | try a.set(-8); |
| 1239 | debug.assert(a.bitCountTwosComp() == 4); | |
| 1240 | debug.assert((try a.to(i4)) == -8); | |
| 1236 | testing.expect(a.bitCountTwosComp() == 4); | |
| 1237 | testing.expect((try a.to(i4)) == -8); | |
| 1241 | 1238 | |
| 1242 | 1239 | try a.set(127); |
| 1243 | debug.assert(a.bitCountTwosComp() == 7); | |
| 1244 | debug.assert((try a.to(u7)) == 127); | |
| 1240 | testing.expect(a.bitCountTwosComp() == 7); | |
| 1241 | testing.expect((try a.to(u7)) == 127); | |
| 1245 | 1242 | |
| 1246 | 1243 | try a.set(-128); |
| 1247 | debug.assert(a.bitCountTwosComp() == 8); | |
| 1248 | debug.assert((try a.to(i8)) == -128); | |
| 1244 | testing.expect(a.bitCountTwosComp() == 8); | |
| 1245 | testing.expect((try a.to(i8)) == -128); | |
| 1249 | 1246 | |
| 1250 | 1247 | try a.set(-129); |
| 1251 | debug.assert(a.bitCountTwosComp() == 9); | |
| 1252 | debug.assert((try a.to(i9)) == -129); | |
| 1248 | testing.expect(a.bitCountTwosComp() == 9); | |
| 1249 | testing.expect((try a.to(i9)) == -129); | |
| 1253 | 1250 | } |
| 1254 | 1251 | |
| 1255 | 1252 | test "big.int fits" { |
| 1256 | 1253 | var a = try Int.init(al); |
| 1257 | 1254 | |
| 1258 | 1255 | try a.set(0); |
| 1259 | debug.assert(a.fits(u0)); | |
| 1260 | debug.assert(a.fits(i0)); | |
| 1256 | testing.expect(a.fits(u0)); | |
| 1257 | testing.expect(a.fits(i0)); | |
| 1261 | 1258 | |
| 1262 | 1259 | try a.set(255); |
| 1263 | debug.assert(!a.fits(u0)); | |
| 1264 | debug.assert(!a.fits(u1)); | |
| 1265 | debug.assert(!a.fits(i8)); | |
| 1266 | debug.assert(a.fits(u8)); | |
| 1267 | debug.assert(a.fits(u9)); | |
| 1268 | debug.assert(a.fits(i9)); | |
| 1260 | testing.expect(!a.fits(u0)); | |
| 1261 | testing.expect(!a.fits(u1)); | |
| 1262 | testing.expect(!a.fits(i8)); | |
| 1263 | testing.expect(a.fits(u8)); | |
| 1264 | testing.expect(a.fits(u9)); | |
| 1265 | testing.expect(a.fits(i9)); | |
| 1269 | 1266 | |
| 1270 | 1267 | try a.set(-128); |
| 1271 | debug.assert(!a.fits(i7)); | |
| 1272 | debug.assert(a.fits(i8)); | |
| 1273 | debug.assert(a.fits(i9)); | |
| 1274 | debug.assert(!a.fits(u9)); | |
| 1268 | testing.expect(!a.fits(i7)); | |
| 1269 | testing.expect(a.fits(i8)); | |
| 1270 | testing.expect(a.fits(i9)); | |
| 1271 | testing.expect(!a.fits(u9)); | |
| 1275 | 1272 | |
| 1276 | 1273 | try a.set(0x1ffffffffeeeeeeee); |
| 1277 | debug.assert(!a.fits(u32)); | |
| 1278 | debug.assert(!a.fits(u64)); | |
| 1279 | debug.assert(a.fits(u65)); | |
| 1274 | testing.expect(!a.fits(u32)); | |
| 1275 | testing.expect(!a.fits(u64)); | |
| 1276 | testing.expect(a.fits(u65)); | |
| 1280 | 1277 | } |
| 1281 | 1278 | |
| 1282 | 1279 | test "big.int string set" { |
| 1283 | 1280 | var a = try Int.init(al); |
| 1284 | 1281 | try a.setString(10, "120317241209124781241290847124"); |
| 1285 | 1282 | |
| 1286 | debug.assert((try a.to(u128)) == 120317241209124781241290847124); | |
| 1283 | testing.expect((try a.to(u128)) == 120317241209124781241290847124); | |
| 1287 | 1284 | } |
| 1288 | 1285 | |
| 1289 | 1286 | test "big.int string negative" { |
| 1290 | 1287 | var a = try Int.init(al); |
| 1291 | 1288 | try a.setString(10, "-1023"); |
| 1292 | debug.assert((try a.to(i32)) == -1023); | |
| 1289 | testing.expect((try a.to(i32)) == -1023); | |
| 1293 | 1290 | } |
| 1294 | 1291 | |
| 1295 | 1292 | test "big.int string set bad char error" { |
| 1296 | 1293 | var a = try Int.init(al); |
| 1297 | a.setString(10, "x") catch |err| debug.assert(err == error.InvalidCharForDigit); | |
| 1294 | testing.expectError(error.InvalidCharForDigit, a.setString(10, "x")); | |
| 1298 | 1295 | } |
| 1299 | 1296 | |
| 1300 | 1297 | test "big.int string set bad base error" { |
| 1301 | 1298 | var a = try Int.init(al); |
| 1302 | a.setString(45, "10") catch |err| debug.assert(err == error.InvalidBase); | |
| 1299 | testing.expectError(error.InvalidBase, a.setString(45, "10")); | |
| 1303 | 1300 | } |
| 1304 | 1301 | |
| 1305 | 1302 | test "big.int string to" { |
| ... | ... | @@ -1308,17 +1305,13 @@ test "big.int string to" { |
| 1308 | 1305 | const as = try a.toString(al, 10); |
| 1309 | 1306 | const es = "120317241209124781241290847124"; |
| 1310 | 1307 | |
| 1311 | debug.assert(mem.eql(u8, as, es)); | |
| 1308 | testing.expect(mem.eql(u8, as, es)); | |
| 1312 | 1309 | } |
| 1313 | 1310 | |
| 1314 | 1311 | test "big.int string to base base error" { |
| 1315 | 1312 | const a = try Int.initSet(al, 0xffffffff); |
| 1316 | 1313 | |
| 1317 | if (a.toString(al, 45)) |_| { | |
| 1318 | unreachable; | |
| 1319 | } else |err| { | |
| 1320 | debug.assert(err == error.InvalidBase); | |
| 1321 | } | |
| 1314 | testing.expectError(error.InvalidBase, a.toString(al, 45)); | |
| 1322 | 1315 | } |
| 1323 | 1316 | |
| 1324 | 1317 | test "big.int string to base 2" { |
| ... | ... | @@ -1327,7 +1320,7 @@ test "big.int string to base 2" { |
| 1327 | 1320 | const as = try a.toString(al, 2); |
| 1328 | 1321 | const es = "-1011"; |
| 1329 | 1322 | |
| 1330 | debug.assert(mem.eql(u8, as, es)); | |
| 1323 | testing.expect(mem.eql(u8, as, es)); | |
| 1331 | 1324 | } |
| 1332 | 1325 | |
| 1333 | 1326 | test "big.int string to base 16" { |
| ... | ... | @@ -1336,7 +1329,7 @@ test "big.int string to base 16" { |
| 1336 | 1329 | const as = try a.toString(al, 16); |
| 1337 | 1330 | const es = "efffffff00000001eeeeeeefaaaaaaab"; |
| 1338 | 1331 | |
| 1339 | debug.assert(mem.eql(u8, as, es)); | |
| 1332 | testing.expect(mem.eql(u8, as, es)); | |
| 1340 | 1333 | } |
| 1341 | 1334 | |
| 1342 | 1335 | test "big.int neg string to" { |
| ... | ... | @@ -1345,7 +1338,7 @@ test "big.int neg string to" { |
| 1345 | 1338 | const as = try a.toString(al, 10); |
| 1346 | 1339 | const es = "-123907434"; |
| 1347 | 1340 | |
| 1348 | debug.assert(mem.eql(u8, as, es)); | |
| 1341 | testing.expect(mem.eql(u8, as, es)); | |
| 1349 | 1342 | } |
| 1350 | 1343 | |
| 1351 | 1344 | test "big.int zero string to" { |
| ... | ... | @@ -1354,98 +1347,98 @@ test "big.int zero string to" { |
| 1354 | 1347 | const as = try a.toString(al, 10); |
| 1355 | 1348 | const es = "0"; |
| 1356 | 1349 | |
| 1357 | debug.assert(mem.eql(u8, as, es)); | |
| 1350 | testing.expect(mem.eql(u8, as, es)); | |
| 1358 | 1351 | } |
| 1359 | 1352 | |
| 1360 | 1353 | test "big.int clone" { |
| 1361 | 1354 | var a = try Int.initSet(al, 1234); |
| 1362 | 1355 | const b = try a.clone(); |
| 1363 | 1356 | |
| 1364 | debug.assert((try a.to(u32)) == 1234); | |
| 1365 | debug.assert((try b.to(u32)) == 1234); | |
| 1357 | testing.expect((try a.to(u32)) == 1234); | |
| 1358 | testing.expect((try b.to(u32)) == 1234); | |
| 1366 | 1359 | |
| 1367 | 1360 | try a.set(77); |
| 1368 | debug.assert((try a.to(u32)) == 77); | |
| 1369 | debug.assert((try b.to(u32)) == 1234); | |
| 1361 | testing.expect((try a.to(u32)) == 77); | |
| 1362 | testing.expect((try b.to(u32)) == 1234); | |
| 1370 | 1363 | } |
| 1371 | 1364 | |
| 1372 | 1365 | test "big.int swap" { |
| 1373 | 1366 | var a = try Int.initSet(al, 1234); |
| 1374 | 1367 | var b = try Int.initSet(al, 5678); |
| 1375 | 1368 | |
| 1376 | debug.assert((try a.to(u32)) == 1234); | |
| 1377 | debug.assert((try b.to(u32)) == 5678); | |
| 1369 | testing.expect((try a.to(u32)) == 1234); | |
| 1370 | testing.expect((try b.to(u32)) == 5678); | |
| 1378 | 1371 | |
| 1379 | 1372 | a.swap(&b); |
| 1380 | 1373 | |
| 1381 | debug.assert((try a.to(u32)) == 5678); | |
| 1382 | debug.assert((try b.to(u32)) == 1234); | |
| 1374 | testing.expect((try a.to(u32)) == 5678); | |
| 1375 | testing.expect((try b.to(u32)) == 1234); | |
| 1383 | 1376 | } |
| 1384 | 1377 | |
| 1385 | 1378 | test "big.int to negative" { |
| 1386 | 1379 | var a = try Int.initSet(al, -10); |
| 1387 | 1380 | |
| 1388 | debug.assert((try a.to(i32)) == -10); | |
| 1381 | testing.expect((try a.to(i32)) == -10); | |
| 1389 | 1382 | } |
| 1390 | 1383 | |
| 1391 | 1384 | test "big.int compare" { |
| 1392 | 1385 | var a = try Int.initSet(al, -11); |
| 1393 | 1386 | var b = try Int.initSet(al, 10); |
| 1394 | 1387 | |
| 1395 | debug.assert(a.cmpAbs(b) == 1); | |
| 1396 | debug.assert(a.cmp(b) == -1); | |
| 1388 | testing.expect(a.cmpAbs(b) == 1); | |
| 1389 | testing.expect(a.cmp(b) == -1); | |
| 1397 | 1390 | } |
| 1398 | 1391 | |
| 1399 | 1392 | test "big.int compare similar" { |
| 1400 | 1393 | var a = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeee); |
| 1401 | 1394 | var b = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeef); |
| 1402 | 1395 | |
| 1403 | debug.assert(a.cmpAbs(b) == -1); | |
| 1404 | debug.assert(b.cmpAbs(a) == 1); | |
| 1396 | testing.expect(a.cmpAbs(b) == -1); | |
| 1397 | testing.expect(b.cmpAbs(a) == 1); | |
| 1405 | 1398 | } |
| 1406 | 1399 | |
| 1407 | 1400 | test "big.int compare different limb size" { |
| 1408 | 1401 | var a = try Int.initSet(al, maxInt(Limb) + 1); |
| 1409 | 1402 | var b = try Int.initSet(al, 1); |
| 1410 | 1403 | |
| 1411 | debug.assert(a.cmpAbs(b) == 1); | |
| 1412 | debug.assert(b.cmpAbs(a) == -1); | |
| 1404 | testing.expect(a.cmpAbs(b) == 1); | |
| 1405 | testing.expect(b.cmpAbs(a) == -1); | |
| 1413 | 1406 | } |
| 1414 | 1407 | |
| 1415 | 1408 | test "big.int compare multi-limb" { |
| 1416 | 1409 | var a = try Int.initSet(al, -0x7777777799999999ffffeeeeffffeeeeffffeeeef); |
| 1417 | 1410 | var b = try Int.initSet(al, 0x7777777799999999ffffeeeeffffeeeeffffeeeee); |
| 1418 | 1411 | |
| 1419 | debug.assert(a.cmpAbs(b) == 1); | |
| 1420 | debug.assert(a.cmp(b) == -1); | |
| 1412 | testing.expect(a.cmpAbs(b) == 1); | |
| 1413 | testing.expect(a.cmp(b) == -1); | |
| 1421 | 1414 | } |
| 1422 | 1415 | |
| 1423 | 1416 | test "big.int equality" { |
| 1424 | 1417 | var a = try Int.initSet(al, 0xffffffff1); |
| 1425 | 1418 | var b = try Int.initSet(al, -0xffffffff1); |
| 1426 | 1419 | |
| 1427 | debug.assert(a.eqAbs(b)); | |
| 1428 | debug.assert(!a.eq(b)); | |
| 1420 | testing.expect(a.eqAbs(b)); | |
| 1421 | testing.expect(!a.eq(b)); | |
| 1429 | 1422 | } |
| 1430 | 1423 | |
| 1431 | 1424 | test "big.int abs" { |
| 1432 | 1425 | var a = try Int.initSet(al, -5); |
| 1433 | 1426 | |
| 1434 | 1427 | a.abs(); |
| 1435 | debug.assert((try a.to(u32)) == 5); | |
| 1428 | testing.expect((try a.to(u32)) == 5); | |
| 1436 | 1429 | |
| 1437 | 1430 | a.abs(); |
| 1438 | debug.assert((try a.to(u32)) == 5); | |
| 1431 | testing.expect((try a.to(u32)) == 5); | |
| 1439 | 1432 | } |
| 1440 | 1433 | |
| 1441 | 1434 | test "big.int negate" { |
| 1442 | 1435 | var a = try Int.initSet(al, 5); |
| 1443 | 1436 | |
| 1444 | 1437 | a.negate(); |
| 1445 | debug.assert((try a.to(i32)) == -5); | |
| 1438 | testing.expect((try a.to(i32)) == -5); | |
| 1446 | 1439 | |
| 1447 | 1440 | a.negate(); |
| 1448 | debug.assert((try a.to(i32)) == 5); | |
| 1441 | testing.expect((try a.to(i32)) == 5); | |
| 1449 | 1442 | } |
| 1450 | 1443 | |
| 1451 | 1444 | test "big.int add single-single" { |
| ... | ... | @@ -1455,7 +1448,7 @@ test "big.int add single-single" { |
| 1455 | 1448 | var c = try Int.init(al); |
| 1456 | 1449 | try c.add(a, b); |
| 1457 | 1450 | |
| 1458 | debug.assert((try c.to(u32)) == 55); | |
| 1451 | testing.expect((try c.to(u32)) == 55); | |
| 1459 | 1452 | } |
| 1460 | 1453 | |
| 1461 | 1454 | test "big.int add multi-single" { |
| ... | ... | @@ -1465,10 +1458,10 @@ test "big.int add multi-single" { |
| 1465 | 1458 | var c = try Int.init(al); |
| 1466 | 1459 | |
| 1467 | 1460 | try c.add(a, b); |
| 1468 | debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2); | |
| 1461 | testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2); | |
| 1469 | 1462 | |
| 1470 | 1463 | try c.add(b, a); |
| 1471 | debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2); | |
| 1464 | testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2); | |
| 1472 | 1465 | } |
| 1473 | 1466 | |
| 1474 | 1467 | test "big.int add multi-multi" { |
| ... | ... | @@ -1480,7 +1473,7 @@ test "big.int add multi-multi" { |
| 1480 | 1473 | var c = try Int.init(al); |
| 1481 | 1474 | try c.add(a, b); |
| 1482 | 1475 | |
| 1483 | debug.assert((try c.to(u128)) == op1 + op2); | |
| 1476 | testing.expect((try c.to(u128)) == op1 + op2); | |
| 1484 | 1477 | } |
| 1485 | 1478 | |
| 1486 | 1479 | test "big.int add zero-zero" { |
| ... | ... | @@ -1490,7 +1483,7 @@ test "big.int add zero-zero" { |
| 1490 | 1483 | var c = try Int.init(al); |
| 1491 | 1484 | try c.add(a, b); |
| 1492 | 1485 | |
| 1493 | debug.assert((try c.to(u32)) == 0); | |
| 1486 | testing.expect((try c.to(u32)) == 0); | |
| 1494 | 1487 | } |
| 1495 | 1488 | |
| 1496 | 1489 | test "big.int add alias multi-limb nonzero-zero" { |
| ... | ... | @@ -1500,7 +1493,7 @@ test "big.int add alias multi-limb nonzero-zero" { |
| 1500 | 1493 | |
| 1501 | 1494 | try a.add(a, b); |
| 1502 | 1495 | |
| 1503 | debug.assert((try a.to(u128)) == op1); | |
| 1496 | testing.expect((try a.to(u128)) == op1); | |
| 1504 | 1497 | } |
| 1505 | 1498 | |
| 1506 | 1499 | test "big.int add sign" { |
| ... | ... | @@ -1512,16 +1505,16 @@ test "big.int add sign" { |
| 1512 | 1505 | const neg_two = try Int.initSet(al, -2); |
| 1513 | 1506 | |
| 1514 | 1507 | try a.add(one, two); |
| 1515 | debug.assert((try a.to(i32)) == 3); | |
| 1508 | testing.expect((try a.to(i32)) == 3); | |
| 1516 | 1509 | |
| 1517 | 1510 | try a.add(neg_one, two); |
| 1518 | debug.assert((try a.to(i32)) == 1); | |
| 1511 | testing.expect((try a.to(i32)) == 1); | |
| 1519 | 1512 | |
| 1520 | 1513 | try a.add(one, neg_two); |
| 1521 | debug.assert((try a.to(i32)) == -1); | |
| 1514 | testing.expect((try a.to(i32)) == -1); | |
| 1522 | 1515 | |
| 1523 | 1516 | try a.add(neg_one, neg_two); |
| 1524 | debug.assert((try a.to(i32)) == -3); | |
| 1517 | testing.expect((try a.to(i32)) == -3); | |
| 1525 | 1518 | } |
| 1526 | 1519 | |
| 1527 | 1520 | test "big.int sub single-single" { |
| ... | ... | @@ -1531,7 +1524,7 @@ test "big.int sub single-single" { |
| 1531 | 1524 | var c = try Int.init(al); |
| 1532 | 1525 | try c.sub(a, b); |
| 1533 | 1526 | |
| 1534 | debug.assert((try c.to(u32)) == 45); | |
| 1527 | testing.expect((try c.to(u32)) == 45); | |
| 1535 | 1528 | } |
| 1536 | 1529 | |
| 1537 | 1530 | test "big.int sub multi-single" { |
| ... | ... | @@ -1541,7 +1534,7 @@ test "big.int sub multi-single" { |
| 1541 | 1534 | var c = try Int.init(al); |
| 1542 | 1535 | try c.sub(a, b); |
| 1543 | 1536 | |
| 1544 | debug.assert((try c.to(Limb)) == maxInt(Limb)); | |
| 1537 | testing.expect((try c.to(Limb)) == maxInt(Limb)); | |
| 1545 | 1538 | } |
| 1546 | 1539 | |
| 1547 | 1540 | test "big.int sub multi-multi" { |
| ... | ... | @@ -1554,7 +1547,7 @@ test "big.int sub multi-multi" { |
| 1554 | 1547 | var c = try Int.init(al); |
| 1555 | 1548 | try c.sub(a, b); |
| 1556 | 1549 | |
| 1557 | debug.assert((try c.to(u128)) == op1 - op2); | |
| 1550 | testing.expect((try c.to(u128)) == op1 - op2); | |
| 1558 | 1551 | } |
| 1559 | 1552 | |
| 1560 | 1553 | test "big.int sub equal" { |
| ... | ... | @@ -1564,7 +1557,7 @@ test "big.int sub equal" { |
| 1564 | 1557 | var c = try Int.init(al); |
| 1565 | 1558 | try c.sub(a, b); |
| 1566 | 1559 | |
| 1567 | debug.assert((try c.to(u32)) == 0); | |
| 1560 | testing.expect((try c.to(u32)) == 0); | |
| 1568 | 1561 | } |
| 1569 | 1562 | |
| 1570 | 1563 | test "big.int sub sign" { |
| ... | ... | @@ -1576,19 +1569,19 @@ test "big.int sub sign" { |
| 1576 | 1569 | const neg_two = try Int.initSet(al, -2); |
| 1577 | 1570 | |
| 1578 | 1571 | try a.sub(one, two); |
| 1579 | debug.assert((try a.to(i32)) == -1); | |
| 1572 | testing.expect((try a.to(i32)) == -1); | |
| 1580 | 1573 | |
| 1581 | 1574 | try a.sub(neg_one, two); |
| 1582 | debug.assert((try a.to(i32)) == -3); | |
| 1575 | testing.expect((try a.to(i32)) == -3); | |
| 1583 | 1576 | |
| 1584 | 1577 | try a.sub(one, neg_two); |
| 1585 | debug.assert((try a.to(i32)) == 3); | |
| 1578 | testing.expect((try a.to(i32)) == 3); | |
| 1586 | 1579 | |
| 1587 | 1580 | try a.sub(neg_one, neg_two); |
| 1588 | debug.assert((try a.to(i32)) == 1); | |
| 1581 | testing.expect((try a.to(i32)) == 1); | |
| 1589 | 1582 | |
| 1590 | 1583 | try a.sub(neg_two, neg_one); |
| 1591 | debug.assert((try a.to(i32)) == -1); | |
| 1584 | testing.expect((try a.to(i32)) == -1); | |
| 1592 | 1585 | } |
| 1593 | 1586 | |
| 1594 | 1587 | test "big.int mul single-single" { |
| ... | ... | @@ -1598,7 +1591,7 @@ test "big.int mul single-single" { |
| 1598 | 1591 | var c = try Int.init(al); |
| 1599 | 1592 | try c.mul(a, b); |
| 1600 | 1593 | |
| 1601 | debug.assert((try c.to(u64)) == 250); | |
| 1594 | testing.expect((try c.to(u64)) == 250); | |
| 1602 | 1595 | } |
| 1603 | 1596 | |
| 1604 | 1597 | test "big.int mul multi-single" { |
| ... | ... | @@ -1608,7 +1601,7 @@ test "big.int mul multi-single" { |
| 1608 | 1601 | var c = try Int.init(al); |
| 1609 | 1602 | try c.mul(a, b); |
| 1610 | 1603 | |
| 1611 | debug.assert((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1604 | testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1612 | 1605 | } |
| 1613 | 1606 | |
| 1614 | 1607 | test "big.int mul multi-multi" { |
| ... | ... | @@ -1620,7 +1613,7 @@ test "big.int mul multi-multi" { |
| 1620 | 1613 | var c = try Int.init(al); |
| 1621 | 1614 | try c.mul(a, b); |
| 1622 | 1615 | |
| 1623 | debug.assert((try c.to(u256)) == op1 * op2); | |
| 1616 | testing.expect((try c.to(u256)) == op1 * op2); | |
| 1624 | 1617 | } |
| 1625 | 1618 | |
| 1626 | 1619 | test "big.int mul alias r with a" { |
| ... | ... | @@ -1629,7 +1622,7 @@ test "big.int mul alias r with a" { |
| 1629 | 1622 | |
| 1630 | 1623 | try a.mul(a, b); |
| 1631 | 1624 | |
| 1632 | debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1625 | testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1633 | 1626 | } |
| 1634 | 1627 | |
| 1635 | 1628 | test "big.int mul alias r with b" { |
| ... | ... | @@ -1638,7 +1631,7 @@ test "big.int mul alias r with b" { |
| 1638 | 1631 | |
| 1639 | 1632 | try a.mul(b, a); |
| 1640 | 1633 | |
| 1641 | debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1634 | testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 1642 | 1635 | } |
| 1643 | 1636 | |
| 1644 | 1637 | test "big.int mul alias r with a and b" { |
| ... | ... | @@ -1646,7 +1639,7 @@ test "big.int mul alias r with a and b" { |
| 1646 | 1639 | |
| 1647 | 1640 | try a.mul(a, a); |
| 1648 | 1641 | |
| 1649 | debug.assert((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb)); | |
| 1642 | testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb)); | |
| 1650 | 1643 | } |
| 1651 | 1644 | |
| 1652 | 1645 | test "big.int mul a*0" { |
| ... | ... | @@ -1656,7 +1649,7 @@ test "big.int mul a*0" { |
| 1656 | 1649 | var c = try Int.init(al); |
| 1657 | 1650 | try c.mul(a, b); |
| 1658 | 1651 | |
| 1659 | debug.assert((try c.to(u32)) == 0); | |
| 1652 | testing.expect((try c.to(u32)) == 0); | |
| 1660 | 1653 | } |
| 1661 | 1654 | |
| 1662 | 1655 | test "big.int mul 0*0" { |
| ... | ... | @@ -1666,7 +1659,7 @@ test "big.int mul 0*0" { |
| 1666 | 1659 | var c = try Int.init(al); |
| 1667 | 1660 | try c.mul(a, b); |
| 1668 | 1661 | |
| 1669 | debug.assert((try c.to(u32)) == 0); | |
| 1662 | testing.expect((try c.to(u32)) == 0); | |
| 1670 | 1663 | } |
| 1671 | 1664 | |
| 1672 | 1665 | test "big.int div single-single no rem" { |
| ... | ... | @@ -1677,8 +1670,8 @@ test "big.int div single-single no rem" { |
| 1677 | 1670 | var r = try Int.init(al); |
| 1678 | 1671 | try Int.divTrunc(&q, &r, a, b); |
| 1679 | 1672 | |
| 1680 | debug.assert((try q.to(u32)) == 10); | |
| 1681 | debug.assert((try r.to(u32)) == 0); | |
| 1673 | testing.expect((try q.to(u32)) == 10); | |
| 1674 | testing.expect((try r.to(u32)) == 0); | |
| 1682 | 1675 | } |
| 1683 | 1676 | |
| 1684 | 1677 | test "big.int div single-single with rem" { |
| ... | ... | @@ -1689,8 +1682,8 @@ test "big.int div single-single with rem" { |
| 1689 | 1682 | var r = try Int.init(al); |
| 1690 | 1683 | try Int.divTrunc(&q, &r, a, b); |
| 1691 | 1684 | |
| 1692 | debug.assert((try q.to(u32)) == 9); | |
| 1693 | debug.assert((try r.to(u32)) == 4); | |
| 1685 | testing.expect((try q.to(u32)) == 9); | |
| 1686 | testing.expect((try r.to(u32)) == 4); | |
| 1694 | 1687 | } |
| 1695 | 1688 | |
| 1696 | 1689 | test "big.int div multi-single no rem" { |
| ... | ... | @@ -1704,8 +1697,8 @@ test "big.int div multi-single no rem" { |
| 1704 | 1697 | var r = try Int.init(al); |
| 1705 | 1698 | try Int.divTrunc(&q, &r, a, b); |
| 1706 | 1699 | |
| 1707 | debug.assert((try q.to(u64)) == op1 / op2); | |
| 1708 | debug.assert((try r.to(u64)) == 0); | |
| 1700 | testing.expect((try q.to(u64)) == op1 / op2); | |
| 1701 | testing.expect((try r.to(u64)) == 0); | |
| 1709 | 1702 | } |
| 1710 | 1703 | |
| 1711 | 1704 | test "big.int div multi-single with rem" { |
| ... | ... | @@ -1719,8 +1712,8 @@ test "big.int div multi-single with rem" { |
| 1719 | 1712 | var r = try Int.init(al); |
| 1720 | 1713 | try Int.divTrunc(&q, &r, a, b); |
| 1721 | 1714 | |
| 1722 | debug.assert((try q.to(u64)) == op1 / op2); | |
| 1723 | debug.assert((try r.to(u64)) == 3); | |
| 1715 | testing.expect((try q.to(u64)) == op1 / op2); | |
| 1716 | testing.expect((try r.to(u64)) == 3); | |
| 1724 | 1717 | } |
| 1725 | 1718 | |
| 1726 | 1719 | test "big.int div multi>2-single" { |
| ... | ... | @@ -1734,8 +1727,8 @@ test "big.int div multi>2-single" { |
| 1734 | 1727 | var r = try Int.init(al); |
| 1735 | 1728 | try Int.divTrunc(&q, &r, a, b); |
| 1736 | 1729 | |
| 1737 | debug.assert((try q.to(u128)) == op1 / op2); | |
| 1738 | debug.assert((try r.to(u32)) == 0x3e4e); | |
| 1730 | testing.expect((try q.to(u128)) == op1 / op2); | |
| 1731 | testing.expect((try r.to(u32)) == 0x3e4e); | |
| 1739 | 1732 | } |
| 1740 | 1733 | |
| 1741 | 1734 | test "big.int div single-single q < r" { |
| ... | ... | @@ -1746,8 +1739,8 @@ test "big.int div single-single q < r" { |
| 1746 | 1739 | var r = try Int.init(al); |
| 1747 | 1740 | try Int.divTrunc(&q, &r, a, b); |
| 1748 | 1741 | |
| 1749 | debug.assert((try q.to(u64)) == 0); | |
| 1750 | debug.assert((try r.to(u64)) == 0x0078f432); | |
| 1742 | testing.expect((try q.to(u64)) == 0); | |
| 1743 | testing.expect((try r.to(u64)) == 0x0078f432); | |
| 1751 | 1744 | } |
| 1752 | 1745 | |
| 1753 | 1746 | test "big.int div single-single q == r" { |
| ... | ... | @@ -1758,8 +1751,8 @@ test "big.int div single-single q == r" { |
| 1758 | 1751 | var r = try Int.init(al); |
| 1759 | 1752 | try Int.divTrunc(&q, &r, a, b); |
| 1760 | 1753 | |
| 1761 | debug.assert((try q.to(u64)) == 1); | |
| 1762 | debug.assert((try r.to(u64)) == 0); | |
| 1754 | testing.expect((try q.to(u64)) == 1); | |
| 1755 | testing.expect((try r.to(u64)) == 0); | |
| 1763 | 1756 | } |
| 1764 | 1757 | |
| 1765 | 1758 | test "big.int div q=0 alias" { |
| ... | ... | @@ -1768,8 +1761,8 @@ test "big.int div q=0 alias" { |
| 1768 | 1761 | |
| 1769 | 1762 | try Int.divTrunc(&a, &b, a, b); |
| 1770 | 1763 | |
| 1771 | debug.assert((try a.to(u64)) == 0); | |
| 1772 | debug.assert((try b.to(u64)) == 3); | |
| 1764 | testing.expect((try a.to(u64)) == 0); | |
| 1765 | testing.expect((try b.to(u64)) == 3); | |
| 1773 | 1766 | } |
| 1774 | 1767 | |
| 1775 | 1768 | test "big.int div multi-multi q < r" { |
| ... | ... | @@ -1782,8 +1775,8 @@ test "big.int div multi-multi q < r" { |
| 1782 | 1775 | var r = try Int.init(al); |
| 1783 | 1776 | try Int.divTrunc(&q, &r, a, b); |
| 1784 | 1777 | |
| 1785 | debug.assert((try q.to(u128)) == 0); | |
| 1786 | debug.assert((try r.to(u128)) == op1); | |
| 1778 | testing.expect((try q.to(u128)) == 0); | |
| 1779 | testing.expect((try r.to(u128)) == op1); | |
| 1787 | 1780 | } |
| 1788 | 1781 | |
| 1789 | 1782 | test "big.int div trunc single-single +/+" { |
| ... | ... | @@ -1802,8 +1795,8 @@ test "big.int div trunc single-single +/+" { |
| 1802 | 1795 | const eq = @divTrunc(u, v); |
| 1803 | 1796 | const er = @mod(u, v); |
| 1804 | 1797 | |
| 1805 | debug.assert((try q.to(i32)) == eq); | |
| 1806 | debug.assert((try r.to(i32)) == er); | |
| 1798 | testing.expect((try q.to(i32)) == eq); | |
| 1799 | testing.expect((try r.to(i32)) == er); | |
| 1807 | 1800 | } |
| 1808 | 1801 | |
| 1809 | 1802 | test "big.int div trunc single-single -/+" { |
| ... | ... | @@ -1822,8 +1815,8 @@ test "big.int div trunc single-single -/+" { |
| 1822 | 1815 | const eq = -1; |
| 1823 | 1816 | const er = -2; |
| 1824 | 1817 | |
| 1825 | debug.assert((try q.to(i32)) == eq); | |
| 1826 | debug.assert((try r.to(i32)) == er); | |
| 1818 | testing.expect((try q.to(i32)) == eq); | |
| 1819 | testing.expect((try r.to(i32)) == er); | |
| 1827 | 1820 | } |
| 1828 | 1821 | |
| 1829 | 1822 | test "big.int div trunc single-single +/-" { |
| ... | ... | @@ -1842,8 +1835,8 @@ test "big.int div trunc single-single +/-" { |
| 1842 | 1835 | const eq = -1; |
| 1843 | 1836 | const er = 2; |
| 1844 | 1837 | |
| 1845 | debug.assert((try q.to(i32)) == eq); | |
| 1846 | debug.assert((try r.to(i32)) == er); | |
| 1838 | testing.expect((try q.to(i32)) == eq); | |
| 1839 | testing.expect((try r.to(i32)) == er); | |
| 1847 | 1840 | } |
| 1848 | 1841 | |
| 1849 | 1842 | test "big.int div trunc single-single -/-" { |
| ... | ... | @@ -1862,8 +1855,8 @@ test "big.int div trunc single-single -/-" { |
| 1862 | 1855 | const eq = 1; |
| 1863 | 1856 | const er = -2; |
| 1864 | 1857 | |
| 1865 | debug.assert((try q.to(i32)) == eq); | |
| 1866 | debug.assert((try r.to(i32)) == er); | |
| 1858 | testing.expect((try q.to(i32)) == eq); | |
| 1859 | testing.expect((try r.to(i32)) == er); | |
| 1867 | 1860 | } |
| 1868 | 1861 | |
| 1869 | 1862 | test "big.int div floor single-single +/+" { |
| ... | ... | @@ -1882,8 +1875,8 @@ test "big.int div floor single-single +/+" { |
| 1882 | 1875 | const eq = 1; |
| 1883 | 1876 | const er = 2; |
| 1884 | 1877 | |
| 1885 | debug.assert((try q.to(i32)) == eq); | |
| 1886 | debug.assert((try r.to(i32)) == er); | |
| 1878 | testing.expect((try q.to(i32)) == eq); | |
| 1879 | testing.expect((try r.to(i32)) == er); | |
| 1887 | 1880 | } |
| 1888 | 1881 | |
| 1889 | 1882 | test "big.int div floor single-single -/+" { |
| ... | ... | @@ -1902,8 +1895,8 @@ test "big.int div floor single-single -/+" { |
| 1902 | 1895 | const eq = -2; |
| 1903 | 1896 | const er = 1; |
| 1904 | 1897 | |
| 1905 | debug.assert((try q.to(i32)) == eq); | |
| 1906 | debug.assert((try r.to(i32)) == er); | |
| 1898 | testing.expect((try q.to(i32)) == eq); | |
| 1899 | testing.expect((try r.to(i32)) == er); | |
| 1907 | 1900 | } |
| 1908 | 1901 | |
| 1909 | 1902 | test "big.int div floor single-single +/-" { |
| ... | ... | @@ -1922,8 +1915,8 @@ test "big.int div floor single-single +/-" { |
| 1922 | 1915 | const eq = -2; |
| 1923 | 1916 | const er = -1; |
| 1924 | 1917 | |
| 1925 | debug.assert((try q.to(i32)) == eq); | |
| 1926 | debug.assert((try r.to(i32)) == er); | |
| 1918 | testing.expect((try q.to(i32)) == eq); | |
| 1919 | testing.expect((try r.to(i32)) == er); | |
| 1927 | 1920 | } |
| 1928 | 1921 | |
| 1929 | 1922 | test "big.int div floor single-single -/-" { |
| ... | ... | @@ -1942,8 +1935,8 @@ test "big.int div floor single-single -/-" { |
| 1942 | 1935 | const eq = 1; |
| 1943 | 1936 | const er = -2; |
| 1944 | 1937 | |
| 1945 | debug.assert((try q.to(i32)) == eq); | |
| 1946 | debug.assert((try r.to(i32)) == er); | |
| 1938 | testing.expect((try q.to(i32)) == eq); | |
| 1939 | testing.expect((try r.to(i32)) == er); | |
| 1947 | 1940 | } |
| 1948 | 1941 | |
| 1949 | 1942 | test "big.int div multi-multi with rem" { |
| ... | ... | @@ -1954,8 +1947,8 @@ test "big.int div multi-multi with rem" { |
| 1954 | 1947 | var r = try Int.init(al); |
| 1955 | 1948 | try Int.divTrunc(&q, &r, a, b); |
| 1956 | 1949 | |
| 1957 | debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1958 | debug.assert((try r.to(u128)) == 0x28de0acacd806823638); | |
| 1950 | testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1951 | testing.expect((try r.to(u128)) == 0x28de0acacd806823638); | |
| 1959 | 1952 | } |
| 1960 | 1953 | |
| 1961 | 1954 | test "big.int div multi-multi no rem" { |
| ... | ... | @@ -1966,8 +1959,8 @@ test "big.int div multi-multi no rem" { |
| 1966 | 1959 | var r = try Int.init(al); |
| 1967 | 1960 | try Int.divTrunc(&q, &r, a, b); |
| 1968 | 1961 | |
| 1969 | debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1970 | debug.assert((try r.to(u128)) == 0); | |
| 1962 | testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1963 | testing.expect((try r.to(u128)) == 0); | |
| 1971 | 1964 | } |
| 1972 | 1965 | |
| 1973 | 1966 | test "big.int div multi-multi (2 branch)" { |
| ... | ... | @@ -1978,8 +1971,8 @@ test "big.int div multi-multi (2 branch)" { |
| 1978 | 1971 | var r = try Int.init(al); |
| 1979 | 1972 | try Int.divTrunc(&q, &r, a, b); |
| 1980 | 1973 | |
| 1981 | debug.assert((try q.to(u128)) == 0x10000000000000000); | |
| 1982 | debug.assert((try r.to(u128)) == 0x44444443444444431111111111111111); | |
| 1974 | testing.expect((try q.to(u128)) == 0x10000000000000000); | |
| 1975 | testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111); | |
| 1983 | 1976 | } |
| 1984 | 1977 | |
| 1985 | 1978 | test "big.int div multi-multi (3.1/3.3 branch)" { |
| ... | ... | @@ -1990,53 +1983,53 @@ test "big.int div multi-multi (3.1/3.3 branch)" { |
| 1990 | 1983 | var r = try Int.init(al); |
| 1991 | 1984 | try Int.divTrunc(&q, &r, a, b); |
| 1992 | 1985 | |
| 1993 | debug.assert((try q.to(u128)) == 0xfffffffffffffffffff); | |
| 1994 | debug.assert((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282); | |
| 1986 | testing.expect((try q.to(u128)) == 0xfffffffffffffffffff); | |
| 1987 | testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282); | |
| 1995 | 1988 | } |
| 1996 | 1989 | |
| 1997 | 1990 | test "big.int shift-right single" { |
| 1998 | 1991 | var a = try Int.initSet(al, 0xffff0000); |
| 1999 | 1992 | try a.shiftRight(a, 16); |
| 2000 | 1993 | |
| 2001 | debug.assert((try a.to(u32)) == 0xffff); | |
| 1994 | testing.expect((try a.to(u32)) == 0xffff); | |
| 2002 | 1995 | } |
| 2003 | 1996 | |
| 2004 | 1997 | test "big.int shift-right multi" { |
| 2005 | 1998 | var a = try Int.initSet(al, 0xffff0000eeee1111dddd2222cccc3333); |
| 2006 | 1999 | try a.shiftRight(a, 67); |
| 2007 | 2000 | |
| 2008 | debug.assert((try a.to(u64)) == 0x1fffe0001dddc222); | |
| 2001 | testing.expect((try a.to(u64)) == 0x1fffe0001dddc222); | |
| 2009 | 2002 | } |
| 2010 | 2003 | |
| 2011 | 2004 | test "big.int shift-left single" { |
| 2012 | 2005 | var a = try Int.initSet(al, 0xffff); |
| 2013 | 2006 | try a.shiftLeft(a, 16); |
| 2014 | 2007 | |
| 2015 | debug.assert((try a.to(u64)) == 0xffff0000); | |
| 2008 | testing.expect((try a.to(u64)) == 0xffff0000); | |
| 2016 | 2009 | } |
| 2017 | 2010 | |
| 2018 | 2011 | test "big.int shift-left multi" { |
| 2019 | 2012 | var a = try Int.initSet(al, 0x1fffe0001dddc222); |
| 2020 | 2013 | try a.shiftLeft(a, 67); |
| 2021 | 2014 | |
| 2022 | debug.assert((try a.to(u128)) == 0xffff0000eeee11100000000000000000); | |
| 2015 | testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000); | |
| 2023 | 2016 | } |
| 2024 | 2017 | |
| 2025 | 2018 | test "big.int shift-right negative" { |
| 2026 | 2019 | var a = try Int.init(al); |
| 2027 | 2020 | |
| 2028 | 2021 | try a.shiftRight(try Int.initSet(al, -20), 2); |
| 2029 | debug.assert((try a.to(i32)) == -20 >> 2); | |
| 2022 | testing.expect((try a.to(i32)) == -20 >> 2); | |
| 2030 | 2023 | |
| 2031 | 2024 | try a.shiftRight(try Int.initSet(al, -5), 10); |
| 2032 | debug.assert((try a.to(i32)) == -5 >> 10); | |
| 2025 | testing.expect((try a.to(i32)) == -5 >> 10); | |
| 2033 | 2026 | } |
| 2034 | 2027 | |
| 2035 | 2028 | test "big.int shift-left negative" { |
| 2036 | 2029 | var a = try Int.init(al); |
| 2037 | 2030 | |
| 2038 | 2031 | try a.shiftRight(try Int.initSet(al, -10), 1232); |
| 2039 | debug.assert((try a.to(i32)) == -10 >> 1232); | |
| 2032 | testing.expect((try a.to(i32)) == -10 >> 1232); | |
| 2040 | 2033 | } |
| 2041 | 2034 | |
| 2042 | 2035 | test "big.int bitwise and simple" { |
| ... | ... | @@ -2045,7 +2038,7 @@ test "big.int bitwise and simple" { |
| 2045 | 2038 | |
| 2046 | 2039 | try a.bitAnd(a, b); |
| 2047 | 2040 | |
| 2048 | debug.assert((try a.to(u64)) == 0xeeeeeeee00000000); | |
| 2041 | testing.expect((try a.to(u64)) == 0xeeeeeeee00000000); | |
| 2049 | 2042 | } |
| 2050 | 2043 | |
| 2051 | 2044 | test "big.int bitwise and multi-limb" { |
| ... | ... | @@ -2054,7 +2047,7 @@ test "big.int bitwise and multi-limb" { |
| 2054 | 2047 | |
| 2055 | 2048 | try a.bitAnd(a, b); |
| 2056 | 2049 | |
| 2057 | debug.assert((try a.to(u128)) == 0); | |
| 2050 | testing.expect((try a.to(u128)) == 0); | |
| 2058 | 2051 | } |
| 2059 | 2052 | |
| 2060 | 2053 | test "big.int bitwise xor simple" { |
| ... | ... | @@ -2063,7 +2056,7 @@ test "big.int bitwise xor simple" { |
| 2063 | 2056 | |
| 2064 | 2057 | try a.bitXor(a, b); |
| 2065 | 2058 | |
| 2066 | debug.assert((try a.to(u64)) == 0x1111111133333333); | |
| 2059 | testing.expect((try a.to(u64)) == 0x1111111133333333); | |
| 2067 | 2060 | } |
| 2068 | 2061 | |
| 2069 | 2062 | test "big.int bitwise xor multi-limb" { |
| ... | ... | @@ -2072,7 +2065,7 @@ test "big.int bitwise xor multi-limb" { |
| 2072 | 2065 | |
| 2073 | 2066 | try a.bitXor(a, b); |
| 2074 | 2067 | |
| 2075 | debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb)); | |
| 2068 | testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb)); | |
| 2076 | 2069 | } |
| 2077 | 2070 | |
| 2078 | 2071 | test "big.int bitwise or simple" { |
| ... | ... | @@ -2081,7 +2074,7 @@ test "big.int bitwise or simple" { |
| 2081 | 2074 | |
| 2082 | 2075 | try a.bitOr(a, b); |
| 2083 | 2076 | |
| 2084 | debug.assert((try a.to(u64)) == 0xffffffff33333333); | |
| 2077 | testing.expect((try a.to(u64)) == 0xffffffff33333333); | |
| 2085 | 2078 | } |
| 2086 | 2079 | |
| 2087 | 2080 | test "big.int bitwise or multi-limb" { |
| ... | ... | @@ -2091,15 +2084,15 @@ test "big.int bitwise or multi-limb" { |
| 2091 | 2084 | try a.bitOr(a, b); |
| 2092 | 2085 | |
| 2093 | 2086 | // TODO: big.int.cpp or is wrong on multi-limb. |
| 2094 | debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb)); | |
| 2087 | testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb)); | |
| 2095 | 2088 | } |
| 2096 | 2089 | |
| 2097 | 2090 | test "big.int var args" { |
| 2098 | 2091 | var a = try Int.initSet(al, 5); |
| 2099 | 2092 | |
| 2100 | 2093 | try a.add(a, try Int.initSet(al, 6)); |
| 2101 | debug.assert((try a.to(u64)) == 11); | |
| 2094 | testing.expect((try a.to(u64)) == 11); | |
| 2102 | 2095 | |
| 2103 | debug.assert(a.cmp(try Int.initSet(al, 11)) == 0); | |
| 2104 | debug.assert(a.cmp(try Int.initSet(al, 14)) <= 0); | |
| 2096 | testing.expect(a.cmp(try Int.initSet(al, 11)) == 0); | |
| 2097 | testing.expect(a.cmp(try Int.initSet(al, 14)) <= 0); | |
| 2105 | 2098 | } |
std/math/cbrt.zig+25-25| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | |
| 11 | 11 | pub fn cbrt(x: var) @typeOf(x) { |
| 12 | 12 | const T = @typeOf(x); |
| ... | ... | @@ -114,44 +114,44 @@ fn cbrt64(x: f64) f64 { |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | test "math.cbrt" { |
| 117 | assert(cbrt(f32(0.0)) == cbrt32(0.0)); | |
| 118 | assert(cbrt(f64(0.0)) == cbrt64(0.0)); | |
| 117 | expect(cbrt(f32(0.0)) == cbrt32(0.0)); | |
| 118 | expect(cbrt(f64(0.0)) == cbrt64(0.0)); | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | test "math.cbrt32" { |
| 122 | 122 | const epsilon = 0.000001; |
| 123 | 123 | |
| 124 | assert(cbrt32(0.0) == 0.0); | |
| 125 | assert(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon)); | |
| 126 | assert(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon)); | |
| 127 | assert(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon)); | |
| 128 | assert(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon)); | |
| 129 | assert(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon)); | |
| 124 | expect(cbrt32(0.0) == 0.0); | |
| 125 | expect(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon)); | |
| 126 | expect(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon)); | |
| 127 | expect(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon)); | |
| 128 | expect(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon)); | |
| 129 | expect(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon)); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "math.cbrt64" { |
| 133 | 133 | const epsilon = 0.000001; |
| 134 | 134 | |
| 135 | assert(cbrt64(0.0) == 0.0); | |
| 136 | assert(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon)); | |
| 137 | assert(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon)); | |
| 138 | assert(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon)); | |
| 139 | assert(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon)); | |
| 140 | assert(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon)); | |
| 135 | expect(cbrt64(0.0) == 0.0); | |
| 136 | expect(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon)); | |
| 137 | expect(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon)); | |
| 138 | expect(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon)); | |
| 139 | expect(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon)); | |
| 140 | expect(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon)); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "math.cbrt.special" { |
| 144 | assert(cbrt32(0.0) == 0.0); | |
| 145 | assert(cbrt32(-0.0) == -0.0); | |
| 146 | assert(math.isPositiveInf(cbrt32(math.inf(f32)))); | |
| 147 | assert(math.isNegativeInf(cbrt32(-math.inf(f32)))); | |
| 148 | assert(math.isNan(cbrt32(math.nan(f32)))); | |
| 144 | expect(cbrt32(0.0) == 0.0); | |
| 145 | expect(cbrt32(-0.0) == -0.0); | |
| 146 | expect(math.isPositiveInf(cbrt32(math.inf(f32)))); | |
| 147 | expect(math.isNegativeInf(cbrt32(-math.inf(f32)))); | |
| 148 | expect(math.isNan(cbrt32(math.nan(f32)))); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "math.cbrt64.special" { |
| 152 | assert(cbrt64(0.0) == 0.0); | |
| 153 | assert(cbrt64(-0.0) == -0.0); | |
| 154 | assert(math.isPositiveInf(cbrt64(math.inf(f64)))); | |
| 155 | assert(math.isNegativeInf(cbrt64(-math.inf(f64)))); | |
| 156 | assert(math.isNan(cbrt64(math.nan(f64)))); | |
| 152 | expect(cbrt64(0.0) == 0.0); | |
| 153 | expect(cbrt64(-0.0) == -0.0); | |
| 154 | expect(math.isPositiveInf(cbrt64(math.inf(f64)))); | |
| 155 | expect(math.isNegativeInf(cbrt64(-math.inf(f64)))); | |
| 156 | expect(math.isNan(cbrt64(math.nan(f64)))); | |
| 157 | 157 | } |
std/math/ceil.zig+19-19| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | |
| 12 | 12 | pub fn ceil(x: var) @typeOf(x) { |
| 13 | 13 | const T = @typeOf(x); |
| ... | ... | @@ -81,34 +81,34 @@ fn ceil64(x: f64) f64 { |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "math.ceil" { |
| 84 | assert(ceil(f32(0.0)) == ceil32(0.0)); | |
| 85 | assert(ceil(f64(0.0)) == ceil64(0.0)); | |
| 84 | expect(ceil(f32(0.0)) == ceil32(0.0)); | |
| 85 | expect(ceil(f64(0.0)) == ceil64(0.0)); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | test "math.ceil32" { |
| 89 | assert(ceil32(1.3) == 2.0); | |
| 90 | assert(ceil32(-1.3) == -1.0); | |
| 91 | assert(ceil32(0.2) == 1.0); | |
| 89 | expect(ceil32(1.3) == 2.0); | |
| 90 | expect(ceil32(-1.3) == -1.0); | |
| 91 | expect(ceil32(0.2) == 1.0); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "math.ceil64" { |
| 95 | assert(ceil64(1.3) == 2.0); | |
| 96 | assert(ceil64(-1.3) == -1.0); | |
| 97 | assert(ceil64(0.2) == 1.0); | |
| 95 | expect(ceil64(1.3) == 2.0); | |
| 96 | expect(ceil64(-1.3) == -1.0); | |
| 97 | expect(ceil64(0.2) == 1.0); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "math.ceil32.special" { |
| 101 | assert(ceil32(0.0) == 0.0); | |
| 102 | assert(ceil32(-0.0) == -0.0); | |
| 103 | assert(math.isPositiveInf(ceil32(math.inf(f32)))); | |
| 104 | assert(math.isNegativeInf(ceil32(-math.inf(f32)))); | |
| 105 | assert(math.isNan(ceil32(math.nan(f32)))); | |
| 101 | expect(ceil32(0.0) == 0.0); | |
| 102 | expect(ceil32(-0.0) == -0.0); | |
| 103 | expect(math.isPositiveInf(ceil32(math.inf(f32)))); | |
| 104 | expect(math.isNegativeInf(ceil32(-math.inf(f32)))); | |
| 105 | expect(math.isNan(ceil32(math.nan(f32)))); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | test "math.ceil64.special" { |
| 109 | assert(ceil64(0.0) == 0.0); | |
| 110 | assert(ceil64(-0.0) == -0.0); | |
| 111 | assert(math.isPositiveInf(ceil64(math.inf(f64)))); | |
| 112 | assert(math.isNegativeInf(ceil64(-math.inf(f64)))); | |
| 113 | assert(math.isNan(ceil64(math.nan(f64)))); | |
| 109 | expect(ceil64(0.0) == 0.0); | |
| 110 | expect(ceil64(-0.0) == -0.0); | |
| 111 | expect(math.isPositiveInf(ceil64(math.inf(f64)))); | |
| 112 | expect(math.isNegativeInf(ceil64(-math.inf(f64)))); | |
| 113 | expect(math.isNan(ceil64(math.nan(f64)))); | |
| 114 | 114 | } |
std/math/complex/abs.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -14,5 +14,5 @@ const epsilon = 0.0001; |
| 14 | 14 | test "complex.cabs" { |
| 15 | 15 | const a = Complex(f32).new(5, 3); |
| 16 | 16 | const c = abs(a); |
| 17 | debug.assert(math.approxEq(f32, c, 5.83095, epsilon)); | |
| 17 | testing.expect(math.approxEq(f32, c, 5.83095, epsilon)); | |
| 18 | 18 | } |
std/math/complex/acos.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -16,6 +16,6 @@ test "complex.cacos" { |
| 16 | 16 | const a = Complex(f32).new(5, 3); |
| 17 | 17 | const c = acos(a); |
| 18 | 18 | |
| 19 | debug.assert(math.approxEq(f32, c.re, 0.546975, epsilon)); | |
| 20 | debug.assert(math.approxEq(f32, c.im, -2.452914, epsilon)); | |
| 19 | testing.expect(math.approxEq(f32, c.re, 0.546975, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.im, -2.452914, epsilon)); | |
| 21 | 21 | } |
std/math/complex/acosh.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -16,6 +16,6 @@ test "complex.cacosh" { |
| 16 | 16 | const a = Complex(f32).new(5, 3); |
| 17 | 17 | const c = acosh(a); |
| 18 | 18 | |
| 19 | debug.assert(math.approxEq(f32, c.re, 2.452914, epsilon)); | |
| 20 | debug.assert(math.approxEq(f32, c.im, 0.546975, epsilon)); | |
| 19 | testing.expect(math.approxEq(f32, c.re, 2.452914, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.im, 0.546975, epsilon)); | |
| 21 | 21 | } |
std/math/complex/arg.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -14,5 +14,5 @@ const epsilon = 0.0001; |
| 14 | 14 | test "complex.carg" { |
| 15 | 15 | const a = Complex(f32).new(5, 3); |
| 16 | 16 | const c = arg(a); |
| 17 | debug.assert(math.approxEq(f32, c, 0.540420, epsilon)); | |
| 17 | testing.expect(math.approxEq(f32, c, 0.540420, epsilon)); | |
| 18 | 18 | } |
std/math/complex/asin.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -22,6 +22,6 @@ test "complex.casin" { |
| 22 | 22 | const a = Complex(f32).new(5, 3); |
| 23 | 23 | const c = asin(a); |
| 24 | 24 | |
| 25 | debug.assert(math.approxEq(f32, c.re, 1.023822, epsilon)); | |
| 26 | debug.assert(math.approxEq(f32, c.im, 2.452914, epsilon)); | |
| 25 | testing.expect(math.approxEq(f32, c.re, 1.023822, epsilon)); | |
| 26 | testing.expect(math.approxEq(f32, c.im, 2.452914, epsilon)); | |
| 27 | 27 | } |
std/math/complex/asinh.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -17,6 +17,6 @@ test "complex.casinh" { |
| 17 | 17 | const a = Complex(f32).new(5, 3); |
| 18 | 18 | const c = asinh(a); |
| 19 | 19 | |
| 20 | debug.assert(math.approxEq(f32, c.re, 2.459831, epsilon)); | |
| 21 | debug.assert(math.approxEq(f32, c.im, 0.533999, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.re, 2.459831, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.im, 0.533999, epsilon)); | |
| 22 | 22 | } |
std/math/complex/atan.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -117,14 +117,14 @@ test "complex.catan32" { |
| 117 | 117 | const a = Complex(f32).new(5, 3); |
| 118 | 118 | const c = atan(a); |
| 119 | 119 | |
| 120 | debug.assert(math.approxEq(f32, c.re, 1.423679, epsilon)); | |
| 121 | debug.assert(math.approxEq(f32, c.im, 0.086569, epsilon)); | |
| 120 | testing.expect(math.approxEq(f32, c.re, 1.423679, epsilon)); | |
| 121 | testing.expect(math.approxEq(f32, c.im, 0.086569, epsilon)); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | test "complex.catan64" { |
| 125 | 125 | const a = Complex(f64).new(5, 3); |
| 126 | 126 | const c = atan(a); |
| 127 | 127 | |
| 128 | debug.assert(math.approxEq(f64, c.re, 1.423679, epsilon)); | |
| 129 | debug.assert(math.approxEq(f64, c.im, 0.086569, epsilon)); | |
| 128 | testing.expect(math.approxEq(f64, c.re, 1.423679, epsilon)); | |
| 129 | testing.expect(math.approxEq(f64, c.im, 0.086569, epsilon)); | |
| 130 | 130 | } |
std/math/complex/atanh.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -17,6 +17,6 @@ test "complex.catanh" { |
| 17 | 17 | const a = Complex(f32).new(5, 3); |
| 18 | 18 | const c = atanh(a); |
| 19 | 19 | |
| 20 | debug.assert(math.approxEq(f32, c.re, 0.146947, epsilon)); | |
| 21 | debug.assert(math.approxEq(f32, c.im, 1.480870, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.re, 0.146947, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.im, 1.480870, epsilon)); | |
| 22 | 22 | } |
std/math/complex/conj.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -13,5 +13,5 @@ test "complex.conj" { |
| 13 | 13 | const a = Complex(f32).new(5, 3); |
| 14 | 14 | const c = a.conjugate(); |
| 15 | 15 | |
| 16 | debug.assert(c.re == 5 and c.im == -3); | |
| 16 | testing.expect(c.re == 5 and c.im == -3); | |
| 17 | 17 | } |
std/math/complex/cos.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -16,6 +16,6 @@ test "complex.ccos" { |
| 16 | 16 | const a = Complex(f32).new(5, 3); |
| 17 | 17 | const c = cos(a); |
| 18 | 18 | |
| 19 | debug.assert(math.approxEq(f32, c.re, 2.855815, epsilon)); | |
| 20 | debug.assert(math.approxEq(f32, c.im, 9.606383, epsilon)); | |
| 19 | testing.expect(math.approxEq(f32, c.re, 2.855815, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.im, 9.606383, epsilon)); | |
| 21 | 21 | } |
std/math/complex/cosh.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -152,14 +152,14 @@ test "complex.ccosh32" { |
| 152 | 152 | const a = Complex(f32).new(5, 3); |
| 153 | 153 | const c = cosh(a); |
| 154 | 154 | |
| 155 | debug.assert(math.approxEq(f32, c.re, -73.467300, epsilon)); | |
| 156 | debug.assert(math.approxEq(f32, c.im, 10.471557, epsilon)); | |
| 155 | testing.expect(math.approxEq(f32, c.re, -73.467300, epsilon)); | |
| 156 | testing.expect(math.approxEq(f32, c.im, 10.471557, epsilon)); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "complex.ccosh64" { |
| 160 | 160 | const a = Complex(f64).new(5, 3); |
| 161 | 161 | const c = cosh(a); |
| 162 | 162 | |
| 163 | debug.assert(math.approxEq(f64, c.re, -73.467300, epsilon)); | |
| 164 | debug.assert(math.approxEq(f64, c.im, 10.471557, epsilon)); | |
| 163 | testing.expect(math.approxEq(f64, c.re, -73.467300, epsilon)); | |
| 164 | testing.expect(math.approxEq(f64, c.im, 10.471557, epsilon)); | |
| 165 | 165 | } |
std/math/complex/exp.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -118,14 +118,14 @@ test "complex.cexp32" { |
| 118 | 118 | const a = Complex(f32).new(5, 3); |
| 119 | 119 | const c = exp(a); |
| 120 | 120 | |
| 121 | debug.assert(math.approxEq(f32, c.re, -146.927917, epsilon)); | |
| 122 | debug.assert(math.approxEq(f32, c.im, 20.944065, epsilon)); | |
| 121 | testing.expect(math.approxEq(f32, c.re, -146.927917, epsilon)); | |
| 122 | testing.expect(math.approxEq(f32, c.im, 20.944065, epsilon)); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "complex.cexp64" { |
| 126 | 126 | const a = Complex(f64).new(5, 3); |
| 127 | 127 | const c = exp(a); |
| 128 | 128 | |
| 129 | debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon)); | |
| 130 | debug.assert(math.approxEq(f64, c.im, 20.944065, epsilon)); | |
| 129 | testing.expect(math.approxEq(f64, c.re, -146.927917, epsilon)); | |
| 130 | testing.expect(math.approxEq(f64, c.im, 20.944065, epsilon)); | |
| 131 | 131 | } |
std/math/complex/index.zig+8-8| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | |
| 5 | 5 | pub const abs = @import("abs.zig").abs; |
| ... | ... | @@ -97,7 +97,7 @@ test "complex.add" { |
| 97 | 97 | const b = Complex(f32).new(2, 7); |
| 98 | 98 | const c = a.add(b); |
| 99 | 99 | |
| 100 | debug.assert(c.re == 7 and c.im == 10); | |
| 100 | testing.expect(c.re == 7 and c.im == 10); | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | test "complex.sub" { |
| ... | ... | @@ -105,7 +105,7 @@ test "complex.sub" { |
| 105 | 105 | const b = Complex(f32).new(2, 7); |
| 106 | 106 | const c = a.sub(b); |
| 107 | 107 | |
| 108 | debug.assert(c.re == 3 and c.im == -4); | |
| 108 | testing.expect(c.re == 3 and c.im == -4); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | test "complex.mul" { |
| ... | ... | @@ -113,7 +113,7 @@ test "complex.mul" { |
| 113 | 113 | const b = Complex(f32).new(2, 7); |
| 114 | 114 | const c = a.mul(b); |
| 115 | 115 | |
| 116 | debug.assert(c.re == -11 and c.im == 41); | |
| 116 | testing.expect(c.re == -11 and c.im == 41); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "complex.div" { |
| ... | ... | @@ -121,7 +121,7 @@ test "complex.div" { |
| 121 | 121 | const b = Complex(f32).new(2, 7); |
| 122 | 122 | const c = a.div(b); |
| 123 | 123 | |
| 124 | debug.assert(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and | |
| 124 | testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and | |
| 125 | 125 | math.approxEq(f32, c.im, f32(-29) / 53, epsilon)); |
| 126 | 126 | } |
| 127 | 127 | |
| ... | ... | @@ -129,14 +129,14 @@ test "complex.conjugate" { |
| 129 | 129 | const a = Complex(f32).new(5, 3); |
| 130 | 130 | const c = a.conjugate(); |
| 131 | 131 | |
| 132 | debug.assert(c.re == 5 and c.im == -3); | |
| 132 | testing.expect(c.re == 5 and c.im == -3); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | test "complex.reciprocal" { |
| 136 | 136 | const a = Complex(f32).new(5, 3); |
| 137 | 137 | const c = a.reciprocal(); |
| 138 | 138 | |
| 139 | debug.assert(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and | |
| 139 | testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and | |
| 140 | 140 | math.approxEq(f32, c.im, f32(-3) / 34, epsilon)); |
| 141 | 141 | } |
| 142 | 142 | |
| ... | ... | @@ -144,7 +144,7 @@ test "complex.magnitude" { |
| 144 | 144 | const a = Complex(f32).new(5, 3); |
| 145 | 145 | const c = a.magnitude(); |
| 146 | 146 | |
| 147 | debug.assert(math.approxEq(f32, c, 5.83095, epsilon)); | |
| 147 | testing.expect(math.approxEq(f32, c, 5.83095, epsilon)); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "complex.cmath" { |
std/math/complex/log.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -18,6 +18,6 @@ test "complex.clog" { |
| 18 | 18 | const a = Complex(f32).new(5, 3); |
| 19 | 19 | const c = log(a); |
| 20 | 20 | |
| 21 | debug.assert(math.approxEq(f32, c.re, 1.763180, epsilon)); | |
| 22 | debug.assert(math.approxEq(f32, c.im, 0.540419, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.re, 1.763180, epsilon)); | |
| 22 | testing.expect(math.approxEq(f32, c.im, 0.540419, epsilon)); | |
| 23 | 23 | } |
std/math/complex/pow.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -17,6 +17,6 @@ test "complex.cpow" { |
| 17 | 17 | const b = Complex(f32).new(2.3, -1.3); |
| 18 | 18 | const c = pow(Complex(f32), a, b); |
| 19 | 19 | |
| 20 | debug.assert(math.approxEq(f32, c.re, 58.049110, epsilon)); | |
| 21 | debug.assert(math.approxEq(f32, c.im, -101.003433, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.re, 58.049110, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.im, -101.003433, epsilon)); | |
| 22 | 22 | } |
std/math/complex/proj.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -20,5 +20,5 @@ test "complex.cproj" { |
| 20 | 20 | const a = Complex(f32).new(5, 3); |
| 21 | 21 | const c = proj(a); |
| 22 | 22 | |
| 23 | debug.assert(c.re == 5 and c.im == 3); | |
| 23 | testing.expect(c.re == 5 and c.im == 3); | |
| 24 | 24 | } |
std/math/complex/sin.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -17,6 +17,6 @@ test "complex.csin" { |
| 17 | 17 | const a = Complex(f32).new(5, 3); |
| 18 | 18 | const c = sin(a); |
| 19 | 19 | |
| 20 | debug.assert(math.approxEq(f32, c.re, -9.654126, epsilon)); | |
| 21 | debug.assert(math.approxEq(f32, c.im, 2.841692, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.re, -9.654126, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.im, 2.841692, epsilon)); | |
| 22 | 22 | } |
std/math/complex/sinh.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -151,14 +151,14 @@ test "complex.csinh32" { |
| 151 | 151 | const a = Complex(f32).new(5, 3); |
| 152 | 152 | const c = sinh(a); |
| 153 | 153 | |
| 154 | debug.assert(math.approxEq(f32, c.re, -73.460617, epsilon)); | |
| 155 | debug.assert(math.approxEq(f32, c.im, 10.472508, epsilon)); | |
| 154 | testing.expect(math.approxEq(f32, c.re, -73.460617, epsilon)); | |
| 155 | testing.expect(math.approxEq(f32, c.im, 10.472508, epsilon)); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | test "complex.csinh64" { |
| 159 | 159 | const a = Complex(f64).new(5, 3); |
| 160 | 160 | const c = sinh(a); |
| 161 | 161 | |
| 162 | debug.assert(math.approxEq(f64, c.re, -73.460617, epsilon)); | |
| 163 | debug.assert(math.approxEq(f64, c.im, 10.472508, epsilon)); | |
| 162 | testing.expect(math.approxEq(f64, c.re, -73.460617, epsilon)); | |
| 163 | testing.expect(math.approxEq(f64, c.im, 10.472508, epsilon)); | |
| 164 | 164 | } |
std/math/complex/sqrt.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -125,14 +125,14 @@ test "complex.csqrt32" { |
| 125 | 125 | const a = Complex(f32).new(5, 3); |
| 126 | 126 | const c = sqrt(a); |
| 127 | 127 | |
| 128 | debug.assert(math.approxEq(f32, c.re, 2.327117, epsilon)); | |
| 129 | debug.assert(math.approxEq(f32, c.im, 0.644574, epsilon)); | |
| 128 | testing.expect(math.approxEq(f32, c.re, 2.327117, epsilon)); | |
| 129 | testing.expect(math.approxEq(f32, c.im, 0.644574, epsilon)); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "complex.csqrt64" { |
| 133 | 133 | const a = Complex(f64).new(5, 3); |
| 134 | 134 | const c = sqrt(a); |
| 135 | 135 | |
| 136 | debug.assert(math.approxEq(f64, c.re, 2.3271175190399496, epsilon)); | |
| 137 | debug.assert(math.approxEq(f64, c.im, 0.6445742373246469, epsilon)); | |
| 136 | testing.expect(math.approxEq(f64, c.re, 2.3271175190399496, epsilon)); | |
| 137 | testing.expect(math.approxEq(f64, c.im, 0.6445742373246469, epsilon)); | |
| 138 | 138 | } |
std/math/complex/tan.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -17,6 +17,6 @@ test "complex.ctan" { |
| 17 | 17 | const a = Complex(f32).new(5, 3); |
| 18 | 18 | const c = tan(a); |
| 19 | 19 | |
| 20 | debug.assert(math.approxEq(f32, c.re, -0.002708233, epsilon)); | |
| 21 | debug.assert(math.approxEq(f32, c.im, 1.004165, epsilon)); | |
| 20 | testing.expect(math.approxEq(f32, c.re, -0.002708233, epsilon)); | |
| 21 | testing.expect(math.approxEq(f32, c.im, 1.004165, epsilon)); | |
| 22 | 22 | } |
std/math/complex/tanh.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | const debug = std.debug; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| ... | ... | @@ -100,14 +100,14 @@ test "complex.ctanh32" { |
| 100 | 100 | const a = Complex(f32).new(5, 3); |
| 101 | 101 | const c = tanh(a); |
| 102 | 102 | |
| 103 | debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon)); | |
| 104 | debug.assert(math.approxEq(f32, c.im, -0.000025, epsilon)); | |
| 103 | testing.expect(math.approxEq(f32, c.re, 0.999913, epsilon)); | |
| 104 | testing.expect(math.approxEq(f32, c.im, -0.000025, epsilon)); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | test "complex.ctanh64" { |
| 108 | 108 | const a = Complex(f64).new(5, 3); |
| 109 | 109 | const c = tanh(a); |
| 110 | 110 | |
| 111 | debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon)); | |
| 112 | debug.assert(math.approxEq(f64, c.im, -0.000025, epsilon)); | |
| 111 | testing.expect(math.approxEq(f64, c.re, 0.999913, epsilon)); | |
| 112 | testing.expect(math.approxEq(f64, c.im, -0.000025, epsilon)); | |
| 113 | 113 | } |
std/math/copysign.zig+16-16| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn copysign(comptime T: type, x: T, y: T) T { |
| ... | ... | @@ -40,28 +40,28 @@ fn copysign64(x: f64, y: f64) f64 { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | test "math.copysign" { |
| 43 | assert(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0)); | |
| 44 | assert(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0)); | |
| 45 | assert(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0)); | |
| 43 | expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0)); | |
| 44 | expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0)); | |
| 45 | expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0)); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | test "math.copysign16" { |
| 49 | assert(copysign16(5.0, 1.0) == 5.0); | |
| 50 | assert(copysign16(5.0, -1.0) == -5.0); | |
| 51 | assert(copysign16(-5.0, -1.0) == -5.0); | |
| 52 | assert(copysign16(-5.0, 1.0) == 5.0); | |
| 49 | expect(copysign16(5.0, 1.0) == 5.0); | |
| 50 | expect(copysign16(5.0, -1.0) == -5.0); | |
| 51 | expect(copysign16(-5.0, -1.0) == -5.0); | |
| 52 | expect(copysign16(-5.0, 1.0) == 5.0); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "math.copysign32" { |
| 56 | assert(copysign32(5.0, 1.0) == 5.0); | |
| 57 | assert(copysign32(5.0, -1.0) == -5.0); | |
| 58 | assert(copysign32(-5.0, -1.0) == -5.0); | |
| 59 | assert(copysign32(-5.0, 1.0) == 5.0); | |
| 56 | expect(copysign32(5.0, 1.0) == 5.0); | |
| 57 | expect(copysign32(5.0, -1.0) == -5.0); | |
| 58 | expect(copysign32(-5.0, -1.0) == -5.0); | |
| 59 | expect(copysign32(-5.0, 1.0) == 5.0); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | test "math.copysign64" { |
| 63 | assert(copysign64(5.0, 1.0) == 5.0); | |
| 64 | assert(copysign64(5.0, -1.0) == -5.0); | |
| 65 | assert(copysign64(-5.0, -1.0) == -5.0); | |
| 66 | assert(copysign64(-5.0, 1.0) == 5.0); | |
| 63 | expect(copysign64(5.0, 1.0) == 5.0); | |
| 64 | expect(copysign64(5.0, -1.0) == -5.0); | |
| 65 | expect(copysign64(-5.0, -1.0) == -5.0); | |
| 66 | expect(copysign64(-5.0, 1.0) == 5.0); | |
| 67 | 67 | } |
std/math/cos.zig+21-21| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | const builtin = @import("builtin"); |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | |
| 11 | 11 | pub fn cos(x: var) @typeOf(x) { |
| 12 | 12 | const T = @typeOf(x); |
| ... | ... | @@ -139,40 +139,40 @@ fn cos64(x_: f64) f64 { |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "math.cos" { |
| 142 | assert(cos(f32(0.0)) == cos32(0.0)); | |
| 143 | assert(cos(f64(0.0)) == cos64(0.0)); | |
| 142 | expect(cos(f32(0.0)) == cos32(0.0)); | |
| 143 | expect(cos(f64(0.0)) == cos64(0.0)); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | test "math.cos32" { |
| 147 | 147 | const epsilon = 0.000001; |
| 148 | 148 | |
| 149 | assert(math.approxEq(f32, cos32(0.0), 1.0, epsilon)); | |
| 150 | assert(math.approxEq(f32, cos32(0.2), 0.980067, epsilon)); | |
| 151 | assert(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon)); | |
| 152 | assert(math.approxEq(f32, cos32(1.5), 0.070737, epsilon)); | |
| 153 | assert(math.approxEq(f32, cos32(37.45), 0.969132, epsilon)); | |
| 154 | assert(math.approxEq(f32, cos32(89.123), 0.400798, epsilon)); | |
| 149 | expect(math.approxEq(f32, cos32(0.0), 1.0, epsilon)); | |
| 150 | expect(math.approxEq(f32, cos32(0.2), 0.980067, epsilon)); | |
| 151 | expect(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon)); | |
| 152 | expect(math.approxEq(f32, cos32(1.5), 0.070737, epsilon)); | |
| 153 | expect(math.approxEq(f32, cos32(37.45), 0.969132, epsilon)); | |
| 154 | expect(math.approxEq(f32, cos32(89.123), 0.400798, epsilon)); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | test "math.cos64" { |
| 158 | 158 | const epsilon = 0.000001; |
| 159 | 159 | |
| 160 | assert(math.approxEq(f64, cos64(0.0), 1.0, epsilon)); | |
| 161 | assert(math.approxEq(f64, cos64(0.2), 0.980067, epsilon)); | |
| 162 | assert(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon)); | |
| 163 | assert(math.approxEq(f64, cos64(1.5), 0.070737, epsilon)); | |
| 164 | assert(math.approxEq(f64, cos64(37.45), 0.969132, epsilon)); | |
| 165 | assert(math.approxEq(f64, cos64(89.123), 0.40080, epsilon)); | |
| 160 | expect(math.approxEq(f64, cos64(0.0), 1.0, epsilon)); | |
| 161 | expect(math.approxEq(f64, cos64(0.2), 0.980067, epsilon)); | |
| 162 | expect(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon)); | |
| 163 | expect(math.approxEq(f64, cos64(1.5), 0.070737, epsilon)); | |
| 164 | expect(math.approxEq(f64, cos64(37.45), 0.969132, epsilon)); | |
| 165 | expect(math.approxEq(f64, cos64(89.123), 0.40080, epsilon)); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | test "math.cos32.special" { |
| 169 | assert(math.isNan(cos32(math.inf(f32)))); | |
| 170 | assert(math.isNan(cos32(-math.inf(f32)))); | |
| 171 | assert(math.isNan(cos32(math.nan(f32)))); | |
| 169 | expect(math.isNan(cos32(math.inf(f32)))); | |
| 170 | expect(math.isNan(cos32(-math.inf(f32)))); | |
| 171 | expect(math.isNan(cos32(math.nan(f32)))); | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | test "math.cos64.special" { |
| 175 | assert(math.isNan(cos64(math.inf(f64)))); | |
| 176 | assert(math.isNan(cos64(-math.inf(f64)))); | |
| 177 | assert(math.isNan(cos64(math.nan(f64)))); | |
| 175 | expect(math.isNan(cos64(math.inf(f64)))); | |
| 176 | expect(math.isNan(cos64(-math.inf(f64)))); | |
| 177 | expect(math.isNan(cos64(math.nan(f64)))); | |
| 178 | 178 | } |
std/math/cosh.zig+21-21| ... | ... | @@ -8,7 +8,7 @@ const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | 10 | const expo2 = @import("expo2.zig").expo2; |
| 11 | const assert = std.debug.assert; | |
| 11 | const expect = std.testing.expect; | |
| 12 | 12 | const maxInt = std.math.maxInt; |
| 13 | 13 | |
| 14 | 14 | pub fn cosh(x: var) @typeOf(x) { |
| ... | ... | @@ -82,40 +82,40 @@ fn cosh64(x: f64) f64 { |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | test "math.cosh" { |
| 85 | assert(cosh(f32(1.5)) == cosh32(1.5)); | |
| 86 | assert(cosh(f64(1.5)) == cosh64(1.5)); | |
| 85 | expect(cosh(f32(1.5)) == cosh32(1.5)); | |
| 86 | expect(cosh(f64(1.5)) == cosh64(1.5)); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "math.cosh32" { |
| 90 | 90 | const epsilon = 0.000001; |
| 91 | 91 | |
| 92 | assert(math.approxEq(f32, cosh32(0.0), 1.0, epsilon)); | |
| 93 | assert(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon)); | |
| 94 | assert(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon)); | |
| 95 | assert(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon)); | |
| 92 | expect(math.approxEq(f32, cosh32(0.0), 1.0, epsilon)); | |
| 93 | expect(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon)); | |
| 94 | expect(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon)); | |
| 95 | expect(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon)); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "math.cosh64" { |
| 99 | 99 | const epsilon = 0.000001; |
| 100 | 100 | |
| 101 | assert(math.approxEq(f64, cosh64(0.0), 1.0, epsilon)); | |
| 102 | assert(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon)); | |
| 103 | assert(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon)); | |
| 104 | assert(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon)); | |
| 101 | expect(math.approxEq(f64, cosh64(0.0), 1.0, epsilon)); | |
| 102 | expect(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon)); | |
| 103 | expect(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon)); | |
| 104 | expect(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon)); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | test "math.cosh32.special" { |
| 108 | assert(cosh32(0.0) == 1.0); | |
| 109 | assert(cosh32(-0.0) == 1.0); | |
| 110 | assert(math.isPositiveInf(cosh32(math.inf(f32)))); | |
| 111 | assert(math.isPositiveInf(cosh32(-math.inf(f32)))); | |
| 112 | assert(math.isNan(cosh32(math.nan(f32)))); | |
| 108 | expect(cosh32(0.0) == 1.0); | |
| 109 | expect(cosh32(-0.0) == 1.0); | |
| 110 | expect(math.isPositiveInf(cosh32(math.inf(f32)))); | |
| 111 | expect(math.isPositiveInf(cosh32(-math.inf(f32)))); | |
| 112 | expect(math.isNan(cosh32(math.nan(f32)))); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "math.cosh64.special" { |
| 116 | assert(cosh64(0.0) == 1.0); | |
| 117 | assert(cosh64(-0.0) == 1.0); | |
| 118 | assert(math.isPositiveInf(cosh64(math.inf(f64)))); | |
| 119 | assert(math.isPositiveInf(cosh64(-math.inf(f64)))); | |
| 120 | assert(math.isNan(cosh64(math.nan(f64)))); | |
| 116 | expect(cosh64(0.0) == 1.0); | |
| 117 | expect(cosh64(-0.0) == 1.0); | |
| 118 | expect(math.isPositiveInf(cosh64(math.inf(f64)))); | |
| 119 | expect(math.isPositiveInf(cosh64(-math.inf(f64)))); | |
| 120 | expect(math.isNan(cosh64(math.nan(f64)))); | |
| 121 | 121 | } |
std/math/exp2.zig+16-16| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | |
| 10 | 10 | pub fn exp2(x: var) @typeOf(x) { |
| 11 | 11 | const T = @typeOf(x); |
| ... | ... | @@ -415,35 +415,35 @@ fn exp2_64(x: f64) f64 { |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | test "math.exp2" { |
| 418 | assert(exp2(f32(0.8923)) == exp2_32(0.8923)); | |
| 419 | assert(exp2(f64(0.8923)) == exp2_64(0.8923)); | |
| 418 | expect(exp2(f32(0.8923)) == exp2_32(0.8923)); | |
| 419 | expect(exp2(f64(0.8923)) == exp2_64(0.8923)); | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | test "math.exp2_32" { |
| 423 | 423 | const epsilon = 0.000001; |
| 424 | 424 | |
| 425 | assert(exp2_32(0.0) == 1.0); | |
| 426 | assert(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon)); | |
| 427 | assert(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon)); | |
| 428 | assert(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon)); | |
| 429 | assert(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon)); | |
| 425 | expect(exp2_32(0.0) == 1.0); | |
| 426 | expect(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon)); | |
| 427 | expect(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon)); | |
| 428 | expect(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon)); | |
| 429 | expect(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon)); | |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | test "math.exp2_64" { |
| 433 | 433 | const epsilon = 0.000001; |
| 434 | 434 | |
| 435 | assert(exp2_64(0.0) == 1.0); | |
| 436 | assert(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon)); | |
| 437 | assert(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon)); | |
| 438 | assert(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon)); | |
| 435 | expect(exp2_64(0.0) == 1.0); | |
| 436 | expect(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon)); | |
| 437 | expect(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon)); | |
| 438 | expect(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon)); | |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | test "math.exp2_32.special" { |
| 442 | assert(math.isPositiveInf(exp2_32(math.inf(f32)))); | |
| 443 | assert(math.isNan(exp2_32(math.nan(f32)))); | |
| 442 | expect(math.isPositiveInf(exp2_32(math.inf(f32)))); | |
| 443 | expect(math.isNan(exp2_32(math.nan(f32)))); | |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | test "math.exp2_64.special" { |
| 447 | assert(math.isPositiveInf(exp2_64(math.inf(f64)))); | |
| 448 | assert(math.isNan(exp2_64(math.nan(f64)))); | |
| 447 | expect(math.isPositiveInf(exp2_64(math.inf(f64)))); | |
| 448 | expect(math.isNan(exp2_64(math.nan(f64)))); | |
| 449 | 449 | } |
std/math/expm1.zig+19-19| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | |
| 12 | 12 | pub fn expm1(x: var) @typeOf(x) { |
| 13 | 13 | const T = @typeOf(x); |
| ... | ... | @@ -278,42 +278,42 @@ fn expm1_64(x_: f64) f64 { |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | test "math.exp1m" { |
| 281 | assert(expm1(f32(0.0)) == expm1_32(0.0)); | |
| 282 | assert(expm1(f64(0.0)) == expm1_64(0.0)); | |
| 281 | expect(expm1(f32(0.0)) == expm1_32(0.0)); | |
| 282 | expect(expm1(f64(0.0)) == expm1_64(0.0)); | |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | test "math.expm1_32" { |
| 286 | 286 | const epsilon = 0.000001; |
| 287 | 287 | |
| 288 | assert(expm1_32(0.0) == 0.0); | |
| 289 | assert(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon)); | |
| 290 | assert(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon)); | |
| 291 | assert(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon)); | |
| 292 | assert(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon)); | |
| 288 | expect(expm1_32(0.0) == 0.0); | |
| 289 | expect(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon)); | |
| 290 | expect(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon)); | |
| 291 | expect(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon)); | |
| 292 | expect(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon)); | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | test "math.expm1_64" { |
| 296 | 296 | const epsilon = 0.000001; |
| 297 | 297 | |
| 298 | assert(expm1_64(0.0) == 0.0); | |
| 299 | assert(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon)); | |
| 300 | assert(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon)); | |
| 301 | assert(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon)); | |
| 302 | assert(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon)); | |
| 298 | expect(expm1_64(0.0) == 0.0); | |
| 299 | expect(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon)); | |
| 300 | expect(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon)); | |
| 301 | expect(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon)); | |
| 302 | expect(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon)); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | test "math.expm1_32.special" { |
| 306 | 306 | const epsilon = 0.000001; |
| 307 | 307 | |
| 308 | assert(math.isPositiveInf(expm1_32(math.inf(f32)))); | |
| 309 | assert(expm1_32(-math.inf(f32)) == -1.0); | |
| 310 | assert(math.isNan(expm1_32(math.nan(f32)))); | |
| 308 | expect(math.isPositiveInf(expm1_32(math.inf(f32)))); | |
| 309 | expect(expm1_32(-math.inf(f32)) == -1.0); | |
| 310 | expect(math.isNan(expm1_32(math.nan(f32)))); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | test "math.expm1_64.special" { |
| 314 | 314 | const epsilon = 0.000001; |
| 315 | 315 | |
| 316 | assert(math.isPositiveInf(expm1_64(math.inf(f64)))); | |
| 317 | assert(expm1_64(-math.inf(f64)) == -1.0); | |
| 318 | assert(math.isNan(expm1_64(math.nan(f64)))); | |
| 316 | expect(math.isPositiveInf(expm1_64(math.inf(f64)))); | |
| 317 | expect(expm1_64(-math.inf(f64)) == -1.0); | |
| 318 | expect(math.isNan(expm1_64(math.nan(f64)))); | |
| 319 | 319 | } |
std/math/fabs.zig+19-19| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | const maxInt = std.math.maxInt; |
| 10 | 10 | |
| 11 | 11 | pub fn fabs(x: var) @typeOf(x) { |
| ... | ... | @@ -37,40 +37,40 @@ fn fabs64(x: f64) f64 { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "math.fabs" { |
| 40 | assert(fabs(f16(1.0)) == fabs16(1.0)); | |
| 41 | assert(fabs(f32(1.0)) == fabs32(1.0)); | |
| 42 | assert(fabs(f64(1.0)) == fabs64(1.0)); | |
| 40 | expect(fabs(f16(1.0)) == fabs16(1.0)); | |
| 41 | expect(fabs(f32(1.0)) == fabs32(1.0)); | |
| 42 | expect(fabs(f64(1.0)) == fabs64(1.0)); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | test "math.fabs16" { |
| 46 | assert(fabs16(1.0) == 1.0); | |
| 47 | assert(fabs16(-1.0) == 1.0); | |
| 46 | expect(fabs16(1.0) == 1.0); | |
| 47 | expect(fabs16(-1.0) == 1.0); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "math.fabs32" { |
| 51 | assert(fabs32(1.0) == 1.0); | |
| 52 | assert(fabs32(-1.0) == 1.0); | |
| 51 | expect(fabs32(1.0) == 1.0); | |
| 52 | expect(fabs32(-1.0) == 1.0); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "math.fabs64" { |
| 56 | assert(fabs64(1.0) == 1.0); | |
| 57 | assert(fabs64(-1.0) == 1.0); | |
| 56 | expect(fabs64(1.0) == 1.0); | |
| 57 | expect(fabs64(-1.0) == 1.0); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | test "math.fabs16.special" { |
| 61 | assert(math.isPositiveInf(fabs(math.inf(f16)))); | |
| 62 | assert(math.isPositiveInf(fabs(-math.inf(f16)))); | |
| 63 | assert(math.isNan(fabs(math.nan(f16)))); | |
| 61 | expect(math.isPositiveInf(fabs(math.inf(f16)))); | |
| 62 | expect(math.isPositiveInf(fabs(-math.inf(f16)))); | |
| 63 | expect(math.isNan(fabs(math.nan(f16)))); | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | test "math.fabs32.special" { |
| 67 | assert(math.isPositiveInf(fabs(math.inf(f32)))); | |
| 68 | assert(math.isPositiveInf(fabs(-math.inf(f32)))); | |
| 69 | assert(math.isNan(fabs(math.nan(f32)))); | |
| 67 | expect(math.isPositiveInf(fabs(math.inf(f32)))); | |
| 68 | expect(math.isPositiveInf(fabs(-math.inf(f32)))); | |
| 69 | expect(math.isNan(fabs(math.nan(f32)))); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | test "math.fabs64.special" { |
| 73 | assert(math.isPositiveInf(fabs(math.inf(f64)))); | |
| 74 | assert(math.isPositiveInf(fabs(-math.inf(f64)))); | |
| 75 | assert(math.isNan(fabs(math.nan(f64)))); | |
| 73 | expect(math.isPositiveInf(fabs(math.inf(f64)))); | |
| 74 | expect(math.isPositiveInf(fabs(-math.inf(f64)))); | |
| 75 | expect(math.isNan(fabs(math.nan(f64)))); | |
| 76 | 76 | } |
std/math/floor.zig+28-28| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // - floor(nan) = nan |
| 6 | 6 | |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | const std = @import("../index.zig"); |
| 10 | 10 | const math = std.math; |
| 11 | 11 | |
| ... | ... | @@ -117,49 +117,49 @@ fn floor64(x: f64) f64 { |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "math.floor" { |
| 120 | assert(floor(f16(1.3)) == floor16(1.3)); | |
| 121 | assert(floor(f32(1.3)) == floor32(1.3)); | |
| 122 | assert(floor(f64(1.3)) == floor64(1.3)); | |
| 120 | expect(floor(f16(1.3)) == floor16(1.3)); | |
| 121 | expect(floor(f32(1.3)) == floor32(1.3)); | |
| 122 | expect(floor(f64(1.3)) == floor64(1.3)); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "math.floor16" { |
| 126 | assert(floor16(1.3) == 1.0); | |
| 127 | assert(floor16(-1.3) == -2.0); | |
| 128 | assert(floor16(0.2) == 0.0); | |
| 126 | expect(floor16(1.3) == 1.0); | |
| 127 | expect(floor16(-1.3) == -2.0); | |
| 128 | expect(floor16(0.2) == 0.0); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.floor32" { |
| 132 | assert(floor32(1.3) == 1.0); | |
| 133 | assert(floor32(-1.3) == -2.0); | |
| 134 | assert(floor32(0.2) == 0.0); | |
| 132 | expect(floor32(1.3) == 1.0); | |
| 133 | expect(floor32(-1.3) == -2.0); | |
| 134 | expect(floor32(0.2) == 0.0); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | test "math.floor64" { |
| 138 | assert(floor64(1.3) == 1.0); | |
| 139 | assert(floor64(-1.3) == -2.0); | |
| 140 | assert(floor64(0.2) == 0.0); | |
| 138 | expect(floor64(1.3) == 1.0); | |
| 139 | expect(floor64(-1.3) == -2.0); | |
| 140 | expect(floor64(0.2) == 0.0); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "math.floor16.special" { |
| 144 | assert(floor16(0.0) == 0.0); | |
| 145 | assert(floor16(-0.0) == -0.0); | |
| 146 | assert(math.isPositiveInf(floor16(math.inf(f16)))); | |
| 147 | assert(math.isNegativeInf(floor16(-math.inf(f16)))); | |
| 148 | assert(math.isNan(floor16(math.nan(f16)))); | |
| 144 | expect(floor16(0.0) == 0.0); | |
| 145 | expect(floor16(-0.0) == -0.0); | |
| 146 | expect(math.isPositiveInf(floor16(math.inf(f16)))); | |
| 147 | expect(math.isNegativeInf(floor16(-math.inf(f16)))); | |
| 148 | expect(math.isNan(floor16(math.nan(f16)))); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "math.floor32.special" { |
| 152 | assert(floor32(0.0) == 0.0); | |
| 153 | assert(floor32(-0.0) == -0.0); | |
| 154 | assert(math.isPositiveInf(floor32(math.inf(f32)))); | |
| 155 | assert(math.isNegativeInf(floor32(-math.inf(f32)))); | |
| 156 | assert(math.isNan(floor32(math.nan(f32)))); | |
| 152 | expect(floor32(0.0) == 0.0); | |
| 153 | expect(floor32(-0.0) == -0.0); | |
| 154 | expect(math.isPositiveInf(floor32(math.inf(f32)))); | |
| 155 | expect(math.isNegativeInf(floor32(-math.inf(f32)))); | |
| 156 | expect(math.isNan(floor32(math.nan(f32)))); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "math.floor64.special" { |
| 160 | assert(floor64(0.0) == 0.0); | |
| 161 | assert(floor64(-0.0) == -0.0); | |
| 162 | assert(math.isPositiveInf(floor64(math.inf(f64)))); | |
| 163 | assert(math.isNegativeInf(floor64(-math.inf(f64)))); | |
| 164 | assert(math.isNan(floor64(math.nan(f64)))); | |
| 160 | expect(floor64(0.0) == 0.0); | |
| 161 | expect(floor64(-0.0) == -0.0); | |
| 162 | expect(math.isPositiveInf(floor64(math.inf(f64)))); | |
| 163 | expect(math.isNegativeInf(floor64(-math.inf(f64)))); | |
| 164 | expect(math.isNan(floor64(math.nan(f64)))); | |
| 165 | 165 | } |
std/math/fma.zig+17-17| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | pub fn fma(comptime T: type, x: T, y: T, z: T) T { |
| 6 | 6 | return switch (T) { |
| ... | ... | @@ -135,30 +135,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 { |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | test "math.fma" { |
| 138 | assert(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0)); | |
| 139 | assert(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0)); | |
| 138 | expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0)); | |
| 139 | expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0)); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | test "math.fma32" { |
| 143 | 143 | const epsilon = 0.000001; |
| 144 | 144 | |
| 145 | assert(math.approxEq(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 146 | assert(math.approxEq(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 147 | assert(math.approxEq(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 148 | assert(math.approxEq(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 149 | assert(math.approxEq(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon)); | |
| 150 | assert(math.approxEq(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon)); | |
| 151 | assert(math.approxEq(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 145 | expect(math.approxEq(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 146 | expect(math.approxEq(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 147 | expect(math.approxEq(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 148 | expect(math.approxEq(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 149 | expect(math.approxEq(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon)); | |
| 150 | expect(math.approxEq(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon)); | |
| 151 | expect(math.approxEq(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.fma64" { |
| 155 | 155 | const epsilon = 0.000001; |
| 156 | 156 | |
| 157 | assert(math.approxEq(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 158 | assert(math.approxEq(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 159 | assert(math.approxEq(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 160 | assert(math.approxEq(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 161 | assert(math.approxEq(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon)); | |
| 162 | assert(math.approxEq(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon)); | |
| 163 | assert(math.approxEq(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 157 | expect(math.approxEq(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 158 | expect(math.approxEq(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 159 | expect(math.approxEq(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 160 | expect(math.approxEq(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 161 | expect(math.approxEq(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon)); | |
| 162 | expect(math.approxEq(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon)); | |
| 163 | expect(math.approxEq(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 164 | 164 | } |
std/math/frexp.zig+17-17| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | |
| 11 | 11 | fn frexp_result(comptime T: type) type { |
| 12 | 12 | return struct { |
| ... | ... | @@ -103,11 +103,11 @@ fn frexp64(x: f64) frexp64_result { |
| 103 | 103 | test "math.frexp" { |
| 104 | 104 | const a = frexp(f32(1.3)); |
| 105 | 105 | const b = frexp32(1.3); |
| 106 | assert(a.significand == b.significand and a.exponent == b.exponent); | |
| 106 | expect(a.significand == b.significand and a.exponent == b.exponent); | |
| 107 | 107 | |
| 108 | 108 | const c = frexp(f64(1.3)); |
| 109 | 109 | const d = frexp64(1.3); |
| 110 | assert(c.significand == d.significand and c.exponent == d.exponent); | |
| 110 | expect(c.significand == d.significand and c.exponent == d.exponent); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "math.frexp32" { |
| ... | ... | @@ -115,10 +115,10 @@ test "math.frexp32" { |
| 115 | 115 | var r: frexp32_result = undefined; |
| 116 | 116 | |
| 117 | 117 | r = frexp32(1.3); |
| 118 | assert(math.approxEq(f32, r.significand, 0.65, epsilon) and r.exponent == 1); | |
| 118 | expect(math.approxEq(f32, r.significand, 0.65, epsilon) and r.exponent == 1); | |
| 119 | 119 | |
| 120 | 120 | r = frexp32(78.0234); |
| 121 | assert(math.approxEq(f32, r.significand, 0.609558, epsilon) and r.exponent == 7); | |
| 121 | expect(math.approxEq(f32, r.significand, 0.609558, epsilon) and r.exponent == 7); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | test "math.frexp64" { |
| ... | ... | @@ -126,46 +126,46 @@ test "math.frexp64" { |
| 126 | 126 | var r: frexp64_result = undefined; |
| 127 | 127 | |
| 128 | 128 | r = frexp64(1.3); |
| 129 | assert(math.approxEq(f64, r.significand, 0.65, epsilon) and r.exponent == 1); | |
| 129 | expect(math.approxEq(f64, r.significand, 0.65, epsilon) and r.exponent == 1); | |
| 130 | 130 | |
| 131 | 131 | r = frexp64(78.0234); |
| 132 | assert(math.approxEq(f64, r.significand, 0.609558, epsilon) and r.exponent == 7); | |
| 132 | expect(math.approxEq(f64, r.significand, 0.609558, epsilon) and r.exponent == 7); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | test "math.frexp32.special" { |
| 136 | 136 | var r: frexp32_result = undefined; |
| 137 | 137 | |
| 138 | 138 | r = frexp32(0.0); |
| 139 | assert(r.significand == 0.0 and r.exponent == 0); | |
| 139 | expect(r.significand == 0.0 and r.exponent == 0); | |
| 140 | 140 | |
| 141 | 141 | r = frexp32(-0.0); |
| 142 | assert(r.significand == -0.0 and r.exponent == 0); | |
| 142 | expect(r.significand == -0.0 and r.exponent == 0); | |
| 143 | 143 | |
| 144 | 144 | r = frexp32(math.inf(f32)); |
| 145 | assert(math.isPositiveInf(r.significand) and r.exponent == 0); | |
| 145 | expect(math.isPositiveInf(r.significand) and r.exponent == 0); | |
| 146 | 146 | |
| 147 | 147 | r = frexp32(-math.inf(f32)); |
| 148 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); | |
| 148 | expect(math.isNegativeInf(r.significand) and r.exponent == 0); | |
| 149 | 149 | |
| 150 | 150 | r = frexp32(math.nan(f32)); |
| 151 | assert(math.isNan(r.significand)); | |
| 151 | expect(math.isNan(r.significand)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.frexp64.special" { |
| 155 | 155 | var r: frexp64_result = undefined; |
| 156 | 156 | |
| 157 | 157 | r = frexp64(0.0); |
| 158 | assert(r.significand == 0.0 and r.exponent == 0); | |
| 158 | expect(r.significand == 0.0 and r.exponent == 0); | |
| 159 | 159 | |
| 160 | 160 | r = frexp64(-0.0); |
| 161 | assert(r.significand == -0.0 and r.exponent == 0); | |
| 161 | expect(r.significand == -0.0 and r.exponent == 0); | |
| 162 | 162 | |
| 163 | 163 | r = frexp64(math.inf(f64)); |
| 164 | assert(math.isPositiveInf(r.significand) and r.exponent == 0); | |
| 164 | expect(math.isPositiveInf(r.significand) and r.exponent == 0); | |
| 165 | 165 | |
| 166 | 166 | r = frexp64(-math.inf(f64)); |
| 167 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); | |
| 167 | expect(math.isNegativeInf(r.significand) and r.exponent == 0); | |
| 168 | 168 | |
| 169 | 169 | r = frexp64(math.nan(f64)); |
| 170 | assert(math.isNan(r.significand)); | |
| 170 | expect(math.isNan(r.significand)); | |
| 171 | 171 | } |
std/math/hypot.zig+29-29| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const maxInt = std.math.maxInt; |
| 12 | 12 | |
| 13 | 13 | pub fn hypot(comptime T: type, x: T, y: T) T { |
| ... | ... | @@ -115,48 +115,48 @@ fn hypot64(x: f64, y: f64) f64 { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "math.hypot" { |
| 118 | assert(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2)); | |
| 119 | assert(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2)); | |
| 118 | expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2)); | |
| 119 | expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2)); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "math.hypot32" { |
| 123 | 123 | const epsilon = 0.000001; |
| 124 | 124 | |
| 125 | assert(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon)); | |
| 126 | assert(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon)); | |
| 127 | assert(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon)); | |
| 128 | assert(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon)); | |
| 129 | assert(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon)); | |
| 130 | assert(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon)); | |
| 131 | assert(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon)); | |
| 125 | expect(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon)); | |
| 126 | expect(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon)); | |
| 127 | expect(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon)); | |
| 128 | expect(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon)); | |
| 129 | expect(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon)); | |
| 130 | expect(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon)); | |
| 131 | expect(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon)); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | test "math.hypot64" { |
| 135 | 135 | const epsilon = 0.000001; |
| 136 | 136 | |
| 137 | assert(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon)); | |
| 138 | assert(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon)); | |
| 139 | assert(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon)); | |
| 140 | assert(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon)); | |
| 141 | assert(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon)); | |
| 142 | assert(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon)); | |
| 143 | assert(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon)); | |
| 137 | expect(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon)); | |
| 138 | expect(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon)); | |
| 139 | expect(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon)); | |
| 140 | expect(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon)); | |
| 141 | expect(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon)); | |
| 142 | expect(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon)); | |
| 143 | expect(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon)); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | test "math.hypot32.special" { |
| 147 | assert(math.isPositiveInf(hypot32(math.inf(f32), 0.0))); | |
| 148 | assert(math.isPositiveInf(hypot32(-math.inf(f32), 0.0))); | |
| 149 | assert(math.isPositiveInf(hypot32(0.0, math.inf(f32)))); | |
| 150 | assert(math.isPositiveInf(hypot32(0.0, -math.inf(f32)))); | |
| 151 | assert(math.isNan(hypot32(math.nan(f32), 0.0))); | |
| 152 | assert(math.isNan(hypot32(0.0, math.nan(f32)))); | |
| 147 | expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0))); | |
| 148 | expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0))); | |
| 149 | expect(math.isPositiveInf(hypot32(0.0, math.inf(f32)))); | |
| 150 | expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32)))); | |
| 151 | expect(math.isNan(hypot32(math.nan(f32), 0.0))); | |
| 152 | expect(math.isNan(hypot32(0.0, math.nan(f32)))); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | test "math.hypot64.special" { |
| 156 | assert(math.isPositiveInf(hypot64(math.inf(f64), 0.0))); | |
| 157 | assert(math.isPositiveInf(hypot64(-math.inf(f64), 0.0))); | |
| 158 | assert(math.isPositiveInf(hypot64(0.0, math.inf(f64)))); | |
| 159 | assert(math.isPositiveInf(hypot64(0.0, -math.inf(f64)))); | |
| 160 | assert(math.isNan(hypot64(math.nan(f64), 0.0))); | |
| 161 | assert(math.isNan(hypot64(0.0, math.nan(f64)))); | |
| 156 | expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0))); | |
| 157 | expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0))); | |
| 158 | expect(math.isPositiveInf(hypot64(0.0, math.inf(f64)))); | |
| 159 | expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64)))); | |
| 160 | expect(math.isNan(hypot64(math.nan(f64), 0.0))); | |
| 161 | expect(math.isNan(hypot64(0.0, math.nan(f64)))); | |
| 162 | 162 | } |
std/math/ilogb.zig+23-23| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | const maxInt = std.math.maxInt; |
| 11 | 11 | const minInt = std.math.minInt; |
| 12 | 12 | |
| ... | ... | @@ -95,38 +95,38 @@ fn ilogb64(x: f64) i32 { |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | test "math.ilogb" { |
| 98 | assert(ilogb(f32(0.2)) == ilogb32(0.2)); | |
| 99 | assert(ilogb(f64(0.2)) == ilogb64(0.2)); | |
| 98 | expect(ilogb(f32(0.2)) == ilogb32(0.2)); | |
| 99 | expect(ilogb(f64(0.2)) == ilogb64(0.2)); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "math.ilogb32" { |
| 103 | assert(ilogb32(0.0) == fp_ilogb0); | |
| 104 | assert(ilogb32(0.5) == -1); | |
| 105 | assert(ilogb32(0.8923) == -1); | |
| 106 | assert(ilogb32(10.0) == 3); | |
| 107 | assert(ilogb32(-123984) == 16); | |
| 108 | assert(ilogb32(2398.23) == 11); | |
| 103 | expect(ilogb32(0.0) == fp_ilogb0); | |
| 104 | expect(ilogb32(0.5) == -1); | |
| 105 | expect(ilogb32(0.8923) == -1); | |
| 106 | expect(ilogb32(10.0) == 3); | |
| 107 | expect(ilogb32(-123984) == 16); | |
| 108 | expect(ilogb32(2398.23) == 11); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | test "math.ilogb64" { |
| 112 | assert(ilogb64(0.0) == fp_ilogb0); | |
| 113 | assert(ilogb64(0.5) == -1); | |
| 114 | assert(ilogb64(0.8923) == -1); | |
| 115 | assert(ilogb64(10.0) == 3); | |
| 116 | assert(ilogb64(-123984) == 16); | |
| 117 | assert(ilogb64(2398.23) == 11); | |
| 112 | expect(ilogb64(0.0) == fp_ilogb0); | |
| 113 | expect(ilogb64(0.5) == -1); | |
| 114 | expect(ilogb64(0.8923) == -1); | |
| 115 | expect(ilogb64(10.0) == 3); | |
| 116 | expect(ilogb64(-123984) == 16); | |
| 117 | expect(ilogb64(2398.23) == 11); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "math.ilogb32.special" { |
| 121 | assert(ilogb32(math.inf(f32)) == maxInt(i32)); | |
| 122 | assert(ilogb32(-math.inf(f32)) == maxInt(i32)); | |
| 123 | assert(ilogb32(0.0) == minInt(i32)); | |
| 124 | assert(ilogb32(math.nan(f32)) == maxInt(i32)); | |
| 121 | expect(ilogb32(math.inf(f32)) == maxInt(i32)); | |
| 122 | expect(ilogb32(-math.inf(f32)) == maxInt(i32)); | |
| 123 | expect(ilogb32(0.0) == minInt(i32)); | |
| 124 | expect(ilogb32(math.nan(f32)) == maxInt(i32)); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | test "math.ilogb64.special" { |
| 128 | assert(ilogb64(math.inf(f64)) == maxInt(i32)); | |
| 129 | assert(ilogb64(-math.inf(f64)) == maxInt(i32)); | |
| 130 | assert(ilogb64(0.0) == minInt(i32)); | |
| 131 | assert(ilogb64(math.nan(f64)) == maxInt(i32)); | |
| 128 | expect(ilogb64(math.inf(f64)) == maxInt(i32)); | |
| 129 | expect(ilogb64(-math.inf(f64)) == maxInt(i32)); | |
| 130 | expect(ilogb64(0.0) == minInt(i32)); | |
| 131 | expect(ilogb64(math.nan(f64)) == maxInt(i32)); | |
| 132 | 132 | } |
std/math/index.zig+172-171| ... | ... | @@ -2,6 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("../index.zig"); |
| 3 | 3 | const TypeId = builtin.TypeId; |
| 4 | 4 | const assert = std.debug.assert; |
| 5 | const testing = std.testing; | |
| 5 | 6 | |
| 6 | 7 | pub const e = 2.71828182845904523536028747135266249775724709369995; |
| 7 | 8 | pub const pi = 3.14159265358979323846264338327950288419716939937510; |
| ... | ... | @@ -240,7 +241,7 @@ pub fn min(x: var, y: var) @typeOf(x + y) { |
| 240 | 241 | } |
| 241 | 242 | |
| 242 | 243 | test "math.min" { |
| 243 | assert(min(i32(-1), i32(2)) == -1); | |
| 244 | testing.expect(min(i32(-1), i32(2)) == -1); | |
| 244 | 245 | } |
| 245 | 246 | |
| 246 | 247 | pub fn max(x: var, y: var) @typeOf(x + y) { |
| ... | ... | @@ -248,7 +249,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) { |
| 248 | 249 | } |
| 249 | 250 | |
| 250 | 251 | test "math.max" { |
| 251 | assert(max(i32(-1), i32(2)) == 2); | |
| 252 | testing.expect(max(i32(-1), i32(2)) == 2); | |
| 252 | 253 | } |
| 253 | 254 | |
| 254 | 255 | pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { |
| ... | ... | @@ -293,10 +294,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { |
| 293 | 294 | } |
| 294 | 295 | |
| 295 | 296 | test "math.shl" { |
| 296 | assert(shl(u8, 0b11111111, usize(3)) == 0b11111000); | |
| 297 | assert(shl(u8, 0b11111111, usize(8)) == 0); | |
| 298 | assert(shl(u8, 0b11111111, usize(9)) == 0); | |
| 299 | assert(shl(u8, 0b11111111, isize(-2)) == 0b00111111); | |
| 297 | testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000); | |
| 298 | testing.expect(shl(u8, 0b11111111, usize(8)) == 0); | |
| 299 | testing.expect(shl(u8, 0b11111111, usize(9)) == 0); | |
| 300 | testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111); | |
| 300 | 301 | } |
| 301 | 302 | |
| 302 | 303 | /// Shifts right. Overflowed bits are truncated. |
| ... | ... | @@ -317,10 +318,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T { |
| 317 | 318 | } |
| 318 | 319 | |
| 319 | 320 | test "math.shr" { |
| 320 | assert(shr(u8, 0b11111111, usize(3)) == 0b00011111); | |
| 321 | assert(shr(u8, 0b11111111, usize(8)) == 0); | |
| 322 | assert(shr(u8, 0b11111111, usize(9)) == 0); | |
| 323 | assert(shr(u8, 0b11111111, isize(-2)) == 0b11111100); | |
| 321 | testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111); | |
| 322 | testing.expect(shr(u8, 0b11111111, usize(8)) == 0); | |
| 323 | testing.expect(shr(u8, 0b11111111, usize(9)) == 0); | |
| 324 | testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100); | |
| 324 | 325 | } |
| 325 | 326 | |
| 326 | 327 | /// Rotates right. Only unsigned values can be rotated. |
| ... | ... | @@ -335,11 +336,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T { |
| 335 | 336 | } |
| 336 | 337 | |
| 337 | 338 | test "math.rotr" { |
| 338 | assert(rotr(u8, 0b00000001, usize(0)) == 0b00000001); | |
| 339 | assert(rotr(u8, 0b00000001, usize(9)) == 0b10000000); | |
| 340 | assert(rotr(u8, 0b00000001, usize(8)) == 0b00000001); | |
| 341 | assert(rotr(u8, 0b00000001, usize(4)) == 0b00010000); | |
| 342 | assert(rotr(u8, 0b00000001, isize(-1)) == 0b00000010); | |
| 339 | testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001); | |
| 340 | testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000); | |
| 341 | testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001); | |
| 342 | testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000); | |
| 343 | testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010); | |
| 343 | 344 | } |
| 344 | 345 | |
| 345 | 346 | /// Rotates left. Only unsigned values can be rotated. |
| ... | ... | @@ -354,11 +355,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T { |
| 354 | 355 | } |
| 355 | 356 | |
| 356 | 357 | test "math.rotl" { |
| 357 | assert(rotl(u8, 0b00000001, usize(0)) == 0b00000001); | |
| 358 | assert(rotl(u8, 0b00000001, usize(9)) == 0b00000010); | |
| 359 | assert(rotl(u8, 0b00000001, usize(8)) == 0b00000001); | |
| 360 | assert(rotl(u8, 0b00000001, usize(4)) == 0b00010000); | |
| 361 | assert(rotl(u8, 0b00000001, isize(-1)) == 0b10000000); | |
| 358 | testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001); | |
| 359 | testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010); | |
| 360 | testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001); | |
| 361 | testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000); | |
| 362 | testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000); | |
| 362 | 363 | } |
| 363 | 364 | |
| 364 | 365 | pub fn Log2Int(comptime T: type) type { |
| ... | ... | @@ -389,50 +390,50 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t |
| 389 | 390 | } |
| 390 | 391 | |
| 391 | 392 | test "math.IntFittingRange" { |
| 392 | assert(IntFittingRange(0, 0) == u0); | |
| 393 | assert(IntFittingRange(0, 1) == u1); | |
| 394 | assert(IntFittingRange(0, 2) == u2); | |
| 395 | assert(IntFittingRange(0, 3) == u2); | |
| 396 | assert(IntFittingRange(0, 4) == u3); | |
| 397 | assert(IntFittingRange(0, 7) == u3); | |
| 398 | assert(IntFittingRange(0, 8) == u4); | |
| 399 | assert(IntFittingRange(0, 9) == u4); | |
| 400 | assert(IntFittingRange(0, 15) == u4); | |
| 401 | assert(IntFittingRange(0, 16) == u5); | |
| 402 | assert(IntFittingRange(0, 17) == u5); | |
| 403 | assert(IntFittingRange(0, 4095) == u12); | |
| 404 | assert(IntFittingRange(2000, 4095) == u12); | |
| 405 | assert(IntFittingRange(0, 4096) == u13); | |
| 406 | assert(IntFittingRange(2000, 4096) == u13); | |
| 407 | assert(IntFittingRange(0, 4097) == u13); | |
| 408 | assert(IntFittingRange(2000, 4097) == u13); | |
| 409 | assert(IntFittingRange(0, 123456789123456798123456789) == u87); | |
| 410 | assert(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177); | |
| 411 | ||
| 412 | assert(IntFittingRange(-1, -1) == i1); | |
| 413 | assert(IntFittingRange(-1, 0) == i1); | |
| 414 | assert(IntFittingRange(-1, 1) == i2); | |
| 415 | assert(IntFittingRange(-2, -2) == i2); | |
| 416 | assert(IntFittingRange(-2, -1) == i2); | |
| 417 | assert(IntFittingRange(-2, 0) == i2); | |
| 418 | assert(IntFittingRange(-2, 1) == i2); | |
| 419 | assert(IntFittingRange(-2, 2) == i3); | |
| 420 | assert(IntFittingRange(-1, 2) == i3); | |
| 421 | assert(IntFittingRange(-1, 3) == i3); | |
| 422 | assert(IntFittingRange(-1, 4) == i4); | |
| 423 | assert(IntFittingRange(-1, 7) == i4); | |
| 424 | assert(IntFittingRange(-1, 8) == i5); | |
| 425 | assert(IntFittingRange(-1, 9) == i5); | |
| 426 | assert(IntFittingRange(-1, 15) == i5); | |
| 427 | assert(IntFittingRange(-1, 16) == i6); | |
| 428 | assert(IntFittingRange(-1, 17) == i6); | |
| 429 | assert(IntFittingRange(-1, 4095) == i13); | |
| 430 | assert(IntFittingRange(-4096, 4095) == i13); | |
| 431 | assert(IntFittingRange(-1, 4096) == i14); | |
| 432 | assert(IntFittingRange(-4097, 4095) == i14); | |
| 433 | assert(IntFittingRange(-1, 4097) == i14); | |
| 434 | assert(IntFittingRange(-1, 123456789123456798123456789) == i88); | |
| 435 | assert(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178); | |
| 393 | testing.expect(IntFittingRange(0, 0) == u0); | |
| 394 | testing.expect(IntFittingRange(0, 1) == u1); | |
| 395 | testing.expect(IntFittingRange(0, 2) == u2); | |
| 396 | testing.expect(IntFittingRange(0, 3) == u2); | |
| 397 | testing.expect(IntFittingRange(0, 4) == u3); | |
| 398 | testing.expect(IntFittingRange(0, 7) == u3); | |
| 399 | testing.expect(IntFittingRange(0, 8) == u4); | |
| 400 | testing.expect(IntFittingRange(0, 9) == u4); | |
| 401 | testing.expect(IntFittingRange(0, 15) == u4); | |
| 402 | testing.expect(IntFittingRange(0, 16) == u5); | |
| 403 | testing.expect(IntFittingRange(0, 17) == u5); | |
| 404 | testing.expect(IntFittingRange(0, 4095) == u12); | |
| 405 | testing.expect(IntFittingRange(2000, 4095) == u12); | |
| 406 | testing.expect(IntFittingRange(0, 4096) == u13); | |
| 407 | testing.expect(IntFittingRange(2000, 4096) == u13); | |
| 408 | testing.expect(IntFittingRange(0, 4097) == u13); | |
| 409 | testing.expect(IntFittingRange(2000, 4097) == u13); | |
| 410 | testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87); | |
| 411 | testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177); | |
| 412 | ||
| 413 | testing.expect(IntFittingRange(-1, -1) == i1); | |
| 414 | testing.expect(IntFittingRange(-1, 0) == i1); | |
| 415 | testing.expect(IntFittingRange(-1, 1) == i2); | |
| 416 | testing.expect(IntFittingRange(-2, -2) == i2); | |
| 417 | testing.expect(IntFittingRange(-2, -1) == i2); | |
| 418 | testing.expect(IntFittingRange(-2, 0) == i2); | |
| 419 | testing.expect(IntFittingRange(-2, 1) == i2); | |
| 420 | testing.expect(IntFittingRange(-2, 2) == i3); | |
| 421 | testing.expect(IntFittingRange(-1, 2) == i3); | |
| 422 | testing.expect(IntFittingRange(-1, 3) == i3); | |
| 423 | testing.expect(IntFittingRange(-1, 4) == i4); | |
| 424 | testing.expect(IntFittingRange(-1, 7) == i4); | |
| 425 | testing.expect(IntFittingRange(-1, 8) == i5); | |
| 426 | testing.expect(IntFittingRange(-1, 9) == i5); | |
| 427 | testing.expect(IntFittingRange(-1, 15) == i5); | |
| 428 | testing.expect(IntFittingRange(-1, 16) == i6); | |
| 429 | testing.expect(IntFittingRange(-1, 17) == i6); | |
| 430 | testing.expect(IntFittingRange(-1, 4095) == i13); | |
| 431 | testing.expect(IntFittingRange(-4096, 4095) == i13); | |
| 432 | testing.expect(IntFittingRange(-1, 4096) == i14); | |
| 433 | testing.expect(IntFittingRange(-4097, 4095) == i14); | |
| 434 | testing.expect(IntFittingRange(-1, 4097) == i14); | |
| 435 | testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88); | |
| 436 | testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178); | |
| 436 | 437 | } |
| 437 | 438 | |
| 438 | 439 | test "math overflow functions" { |
| ... | ... | @@ -441,10 +442,10 @@ test "math overflow functions" { |
| 441 | 442 | } |
| 442 | 443 | |
| 443 | 444 | fn testOverflow() void { |
| 444 | assert((mul(i32, 3, 4) catch unreachable) == 12); | |
| 445 | assert((add(i32, 3, 4) catch unreachable) == 7); | |
| 446 | assert((sub(i32, 3, 4) catch unreachable) == -1); | |
| 447 | assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | |
| 445 | testing.expect((mul(i32, 3, 4) catch unreachable) == 12); | |
| 446 | testing.expect((add(i32, 3, 4) catch unreachable) == 7); | |
| 447 | testing.expect((sub(i32, 3, 4) catch unreachable) == -1); | |
| 448 | testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | |
| 448 | 449 | } |
| 449 | 450 | |
| 450 | 451 | pub fn absInt(x: var) !@typeOf(x) { |
| ... | ... | @@ -465,8 +466,8 @@ test "math.absInt" { |
| 465 | 466 | comptime testAbsInt(); |
| 466 | 467 | } |
| 467 | 468 | fn testAbsInt() void { |
| 468 | assert((absInt(i32(-10)) catch unreachable) == 10); | |
| 469 | assert((absInt(i32(10)) catch unreachable) == 10); | |
| 469 | testing.expect((absInt(i32(-10)) catch unreachable) == 10); | |
| 470 | testing.expect((absInt(i32(10)) catch unreachable) == 10); | |
| 470 | 471 | } |
| 471 | 472 | |
| 472 | 473 | pub const absFloat = @import("fabs.zig").fabs; |
| ... | ... | @@ -483,13 +484,13 @@ test "math.divTrunc" { |
| 483 | 484 | comptime testDivTrunc(); |
| 484 | 485 | } |
| 485 | 486 | fn testDivTrunc() void { |
| 486 | assert((divTrunc(i32, 5, 3) catch unreachable) == 1); | |
| 487 | assert((divTrunc(i32, -5, 3) catch unreachable) == -1); | |
| 488 | if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 489 | if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); | |
| 487 | testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1); | |
| 488 | testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1); | |
| 489 | testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0)); | |
| 490 | testing.expectError(error.Overflow, divTrunc(i8, -128, -1)); | |
| 490 | 491 | |
| 491 | assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 492 | assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); | |
| 492 | testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 493 | testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); | |
| 493 | 494 | } |
| 494 | 495 | |
| 495 | 496 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { |
| ... | ... | @@ -504,13 +505,13 @@ test "math.divFloor" { |
| 504 | 505 | comptime testDivFloor(); |
| 505 | 506 | } |
| 506 | 507 | fn testDivFloor() void { |
| 507 | assert((divFloor(i32, 5, 3) catch unreachable) == 1); | |
| 508 | assert((divFloor(i32, -5, 3) catch unreachable) == -2); | |
| 509 | if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 510 | if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); | |
| 508 | testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1); | |
| 509 | testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2); | |
| 510 | testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0)); | |
| 511 | testing.expectError(error.Overflow, divFloor(i8, -128, -1)); | |
| 511 | 512 | |
| 512 | assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 513 | assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); | |
| 513 | testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 514 | testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); | |
| 514 | 515 | } |
| 515 | 516 | |
| 516 | 517 | pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { |
| ... | ... | @@ -527,15 +528,15 @@ test "math.divExact" { |
| 527 | 528 | comptime testDivExact(); |
| 528 | 529 | } |
| 529 | 530 | fn testDivExact() void { |
| 530 | assert((divExact(i32, 10, 5) catch unreachable) == 2); | |
| 531 | assert((divExact(i32, -10, 5) catch unreachable) == -2); | |
| 532 | if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 533 | if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); | |
| 534 | if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder); | |
| 531 | testing.expect((divExact(i32, 10, 5) catch unreachable) == 2); | |
| 532 | testing.expect((divExact(i32, -10, 5) catch unreachable) == -2); | |
| 533 | testing.expectError(error.DivisionByZero, divExact(i8, -5, 0)); | |
| 534 | testing.expectError(error.Overflow, divExact(i8, -128, -1)); | |
| 535 | testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2)); | |
| 535 | 536 | |
| 536 | assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0); | |
| 537 | assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0); | |
| 538 | if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder); | |
| 537 | testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0); | |
| 538 | testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0); | |
| 539 | testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0)); | |
| 539 | 540 | } |
| 540 | 541 | |
| 541 | 542 | pub fn mod(comptime T: type, numerator: T, denominator: T) !T { |
| ... | ... | @@ -550,15 +551,15 @@ test "math.mod" { |
| 550 | 551 | comptime testMod(); |
| 551 | 552 | } |
| 552 | 553 | fn testMod() void { |
| 553 | assert((mod(i32, -5, 3) catch unreachable) == 1); | |
| 554 | assert((mod(i32, 5, 3) catch unreachable) == 2); | |
| 555 | if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | |
| 556 | if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 554 | testing.expect((mod(i32, -5, 3) catch unreachable) == 1); | |
| 555 | testing.expect((mod(i32, 5, 3) catch unreachable) == 2); | |
| 556 | testing.expectError(error.NegativeDenominator, mod(i32, 10, -1)); | |
| 557 | testing.expectError(error.DivisionByZero, mod(i32, 10, 0)); | |
| 557 | 558 | |
| 558 | assert((mod(f32, -5, 3) catch unreachable) == 1); | |
| 559 | assert((mod(f32, 5, 3) catch unreachable) == 2); | |
| 560 | if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | |
| 561 | if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 559 | testing.expect((mod(f32, -5, 3) catch unreachable) == 1); | |
| 560 | testing.expect((mod(f32, 5, 3) catch unreachable) == 2); | |
| 561 | testing.expectError(error.NegativeDenominator, mod(f32, 10, -1)); | |
| 562 | testing.expectError(error.DivisionByZero, mod(f32, 10, 0)); | |
| 562 | 563 | } |
| 563 | 564 | |
| 564 | 565 | pub fn rem(comptime T: type, numerator: T, denominator: T) !T { |
| ... | ... | @@ -573,15 +574,15 @@ test "math.rem" { |
| 573 | 574 | comptime testRem(); |
| 574 | 575 | } |
| 575 | 576 | fn testRem() void { |
| 576 | assert((rem(i32, -5, 3) catch unreachable) == -2); | |
| 577 | assert((rem(i32, 5, 3) catch unreachable) == 2); | |
| 578 | if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | |
| 579 | if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 577 | testing.expect((rem(i32, -5, 3) catch unreachable) == -2); | |
| 578 | testing.expect((rem(i32, 5, 3) catch unreachable) == 2); | |
| 579 | testing.expectError(error.NegativeDenominator, rem(i32, 10, -1)); | |
| 580 | testing.expectError(error.DivisionByZero, rem(i32, 10, 0)); | |
| 580 | 581 | |
| 581 | assert((rem(f32, -5, 3) catch unreachable) == -2); | |
| 582 | assert((rem(f32, 5, 3) catch unreachable) == 2); | |
| 583 | if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | |
| 584 | if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | |
| 582 | testing.expect((rem(f32, -5, 3) catch unreachable) == -2); | |
| 583 | testing.expect((rem(f32, 5, 3) catch unreachable) == 2); | |
| 584 | testing.expectError(error.NegativeDenominator, rem(f32, 10, -1)); | |
| 585 | testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); | |
| 585 | 586 | } |
| 586 | 587 | |
| 587 | 588 | /// Returns the absolute value of the integer parameter. |
| ... | ... | @@ -594,14 +595,14 @@ pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) { |
| 594 | 595 | } |
| 595 | 596 | |
| 596 | 597 | test "math.absCast" { |
| 597 | assert(absCast(i32(-999)) == 999); | |
| 598 | assert(@typeOf(absCast(i32(-999))) == u32); | |
| 598 | testing.expect(absCast(i32(-999)) == 999); | |
| 599 | testing.expect(@typeOf(absCast(i32(-999))) == u32); | |
| 599 | 600 | |
| 600 | assert(absCast(i32(999)) == 999); | |
| 601 | assert(@typeOf(absCast(i32(999))) == u32); | |
| 601 | testing.expect(absCast(i32(999)) == 999); | |
| 602 | testing.expect(@typeOf(absCast(i32(999))) == u32); | |
| 602 | 603 | |
| 603 | assert(absCast(i32(minInt(i32))) == -minInt(i32)); | |
| 604 | assert(@typeOf(absCast(i32(minInt(i32)))) == u32); | |
| 604 | testing.expect(absCast(i32(minInt(i32))) == -minInt(i32)); | |
| 605 | testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32); | |
| 605 | 606 | } |
| 606 | 607 | |
| 607 | 608 | /// Returns the negation of the integer parameter. |
| ... | ... | @@ -618,13 +619,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { |
| 618 | 619 | } |
| 619 | 620 | |
| 620 | 621 | test "math.negateCast" { |
| 621 | assert((negateCast(u32(999)) catch unreachable) == -999); | |
| 622 | assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32); | |
| 622 | testing.expect((negateCast(u32(999)) catch unreachable) == -999); | |
| 623 | testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32); | |
| 623 | 624 | |
| 624 | assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32)); | |
| 625 | assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32); | |
| 625 | testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32)); | |
| 626 | testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32); | |
| 626 | 627 | |
| 627 | if (negateCast(u32(maxInt(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow); | |
| 628 | testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10))); | |
| 628 | 629 | } |
| 629 | 630 | |
| 630 | 631 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| ... | ... | @@ -642,13 +643,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { |
| 642 | 643 | } |
| 643 | 644 | |
| 644 | 645 | test "math.cast" { |
| 645 | if (cast(u8, u32(300))) |_| @panic("fail") else |err| assert(err == error.Overflow); | |
| 646 | if (cast(i8, i32(-200))) |_| @panic("fail") else |err| assert(err == error.Overflow); | |
| 647 | if (cast(u8, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow); | |
| 648 | if (cast(u64, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow); | |
| 646 | testing.expectError(error.Overflow, cast(u8, u32(300))); | |
| 647 | testing.expectError(error.Overflow, cast(i8, i32(-200))); | |
| 648 | testing.expectError(error.Overflow, cast(u8, i8(-1))); | |
| 649 | testing.expectError(error.Overflow, cast(u64, i8(-1))); | |
| 649 | 650 | |
| 650 | assert((try cast(u8, u32(255))) == u8(255)); | |
| 651 | assert(@typeOf(try cast(u8, u32(255))) == u8); | |
| 651 | testing.expect((try cast(u8, u32(255))) == u8(255)); | |
| 652 | testing.expect(@typeOf(try cast(u8, u32(255))) == u8); | |
| 652 | 653 | } |
| 653 | 654 | |
| 654 | 655 | pub const AlignCastError = error{UnalignedMemory}; |
| ... | ... | @@ -692,25 +693,25 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) { |
| 692 | 693 | } |
| 693 | 694 | |
| 694 | 695 | test "std.math.log2_int_ceil" { |
| 695 | assert(log2_int_ceil(u32, 1) == 0); | |
| 696 | assert(log2_int_ceil(u32, 2) == 1); | |
| 697 | assert(log2_int_ceil(u32, 3) == 2); | |
| 698 | assert(log2_int_ceil(u32, 4) == 2); | |
| 699 | assert(log2_int_ceil(u32, 5) == 3); | |
| 700 | assert(log2_int_ceil(u32, 6) == 3); | |
| 701 | assert(log2_int_ceil(u32, 7) == 3); | |
| 702 | assert(log2_int_ceil(u32, 8) == 3); | |
| 703 | assert(log2_int_ceil(u32, 9) == 4); | |
| 704 | assert(log2_int_ceil(u32, 10) == 4); | |
| 696 | testing.expect(log2_int_ceil(u32, 1) == 0); | |
| 697 | testing.expect(log2_int_ceil(u32, 2) == 1); | |
| 698 | testing.expect(log2_int_ceil(u32, 3) == 2); | |
| 699 | testing.expect(log2_int_ceil(u32, 4) == 2); | |
| 700 | testing.expect(log2_int_ceil(u32, 5) == 3); | |
| 701 | testing.expect(log2_int_ceil(u32, 6) == 3); | |
| 702 | testing.expect(log2_int_ceil(u32, 7) == 3); | |
| 703 | testing.expect(log2_int_ceil(u32, 8) == 3); | |
| 704 | testing.expect(log2_int_ceil(u32, 9) == 4); | |
| 705 | testing.expect(log2_int_ceil(u32, 10) == 4); | |
| 705 | 706 | } |
| 706 | 707 | |
| 707 | 708 | fn testFloorPowerOfTwo() void { |
| 708 | assert(floorPowerOfTwo(u32, 63) == 32); | |
| 709 | assert(floorPowerOfTwo(u32, 64) == 64); | |
| 710 | assert(floorPowerOfTwo(u32, 65) == 64); | |
| 711 | assert(floorPowerOfTwo(u4, 7) == 4); | |
| 712 | assert(floorPowerOfTwo(u4, 8) == 8); | |
| 713 | assert(floorPowerOfTwo(u4, 9) == 8); | |
| 709 | testing.expect(floorPowerOfTwo(u32, 63) == 32); | |
| 710 | testing.expect(floorPowerOfTwo(u32, 64) == 64); | |
| 711 | testing.expect(floorPowerOfTwo(u32, 65) == 64); | |
| 712 | testing.expect(floorPowerOfTwo(u4, 7) == 4); | |
| 713 | testing.expect(floorPowerOfTwo(u4, 8) == 8); | |
| 714 | testing.expect(floorPowerOfTwo(u4, 9) == 8); | |
| 714 | 715 | } |
| 715 | 716 | |
| 716 | 717 | pub fn lossyCast(comptime T: type, value: var) T { |
| ... | ... | @@ -726,7 +727,7 @@ pub fn lossyCast(comptime T: type, value: var) T { |
| 726 | 727 | test "math.f64_min" { |
| 727 | 728 | const f64_min_u64 = 0x0010000000000000; |
| 728 | 729 | const fmin: f64 = f64_min; |
| 729 | assert(@bitCast(u64, fmin) == f64_min_u64); | |
| 730 | testing.expect(@bitCast(u64, fmin) == f64_min_u64); | |
| 730 | 731 | } |
| 731 | 732 | |
| 732 | 733 | pub fn maxInt(comptime T: type) comptime_int { |
| ... | ... | @@ -745,36 +746,36 @@ pub fn minInt(comptime T: type) comptime_int { |
| 745 | 746 | } |
| 746 | 747 | |
| 747 | 748 | test "minInt and maxInt" { |
| 748 | assert(maxInt(u0) == 0); | |
| 749 | assert(maxInt(u1) == 1); | |
| 750 | assert(maxInt(u8) == 255); | |
| 751 | assert(maxInt(u16) == 65535); | |
| 752 | assert(maxInt(u32) == 4294967295); | |
| 753 | assert(maxInt(u64) == 18446744073709551615); | |
| 754 | ||
| 755 | assert(maxInt(i0) == 0); | |
| 756 | assert(maxInt(i1) == 0); | |
| 757 | assert(maxInt(i8) == 127); | |
| 758 | assert(maxInt(i16) == 32767); | |
| 759 | assert(maxInt(i32) == 2147483647); | |
| 760 | assert(maxInt(i63) == 4611686018427387903); | |
| 761 | assert(maxInt(i64) == 9223372036854775807); | |
| 762 | ||
| 763 | assert(minInt(u0) == 0); | |
| 764 | assert(minInt(u1) == 0); | |
| 765 | assert(minInt(u8) == 0); | |
| 766 | assert(minInt(u16) == 0); | |
| 767 | assert(minInt(u32) == 0); | |
| 768 | assert(minInt(u63) == 0); | |
| 769 | assert(minInt(u64) == 0); | |
| 770 | ||
| 771 | assert(minInt(i0) == 0); | |
| 772 | assert(minInt(i1) == -1); | |
| 773 | assert(minInt(i8) == -128); | |
| 774 | assert(minInt(i16) == -32768); | |
| 775 | assert(minInt(i32) == -2147483648); | |
| 776 | assert(minInt(i63) == -4611686018427387904); | |
| 777 | assert(minInt(i64) == -9223372036854775808); | |
| 749 | testing.expect(maxInt(u0) == 0); | |
| 750 | testing.expect(maxInt(u1) == 1); | |
| 751 | testing.expect(maxInt(u8) == 255); | |
| 752 | testing.expect(maxInt(u16) == 65535); | |
| 753 | testing.expect(maxInt(u32) == 4294967295); | |
| 754 | testing.expect(maxInt(u64) == 18446744073709551615); | |
| 755 | ||
| 756 | testing.expect(maxInt(i0) == 0); | |
| 757 | testing.expect(maxInt(i1) == 0); | |
| 758 | testing.expect(maxInt(i8) == 127); | |
| 759 | testing.expect(maxInt(i16) == 32767); | |
| 760 | testing.expect(maxInt(i32) == 2147483647); | |
| 761 | testing.expect(maxInt(i63) == 4611686018427387903); | |
| 762 | testing.expect(maxInt(i64) == 9223372036854775807); | |
| 763 | ||
| 764 | testing.expect(minInt(u0) == 0); | |
| 765 | testing.expect(minInt(u1) == 0); | |
| 766 | testing.expect(minInt(u8) == 0); | |
| 767 | testing.expect(minInt(u16) == 0); | |
| 768 | testing.expect(minInt(u32) == 0); | |
| 769 | testing.expect(minInt(u63) == 0); | |
| 770 | testing.expect(minInt(u64) == 0); | |
| 771 | ||
| 772 | testing.expect(minInt(i0) == 0); | |
| 773 | testing.expect(minInt(i1) == -1); | |
| 774 | testing.expect(minInt(i8) == -128); | |
| 775 | testing.expect(minInt(i16) == -32768); | |
| 776 | testing.expect(minInt(i32) == -2147483648); | |
| 777 | testing.expect(minInt(i63) == -4611686018427387904); | |
| 778 | testing.expect(minInt(i64) == -9223372036854775808); | |
| 778 | 779 | } |
| 779 | 780 | |
| 780 | 781 | test "max value type" { |
| ... | ... | @@ -782,5 +783,5 @@ test "max value type" { |
| 782 | 783 | // u32 would not work. But since the value is a number literal, |
| 783 | 784 | // it works fine. |
| 784 | 785 | const x: u32 = maxInt(i32); |
| 785 | assert(x == 2147483647); | |
| 786 | testing.expect(x == 2147483647); | |
| 786 | 787 | } |
std/math/isfinite.zig+13-13| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn isFinite(x: var) bool { |
| ... | ... | @@ -25,16 +25,16 @@ pub fn isFinite(x: var) bool { |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | test "math.isFinite" { |
| 28 | assert(isFinite(f16(0.0))); | |
| 29 | assert(isFinite(f16(-0.0))); | |
| 30 | assert(isFinite(f32(0.0))); | |
| 31 | assert(isFinite(f32(-0.0))); | |
| 32 | assert(isFinite(f64(0.0))); | |
| 33 | assert(isFinite(f64(-0.0))); | |
| 34 | assert(!isFinite(math.inf(f16))); | |
| 35 | assert(!isFinite(-math.inf(f16))); | |
| 36 | assert(!isFinite(math.inf(f32))); | |
| 37 | assert(!isFinite(-math.inf(f32))); | |
| 38 | assert(!isFinite(math.inf(f64))); | |
| 39 | assert(!isFinite(-math.inf(f64))); | |
| 28 | expect(isFinite(f16(0.0))); | |
| 29 | expect(isFinite(f16(-0.0))); | |
| 30 | expect(isFinite(f32(0.0))); | |
| 31 | expect(isFinite(f32(-0.0))); | |
| 32 | expect(isFinite(f64(0.0))); | |
| 33 | expect(isFinite(f64(-0.0))); | |
| 34 | expect(!isFinite(math.inf(f16))); | |
| 35 | expect(!isFinite(-math.inf(f16))); | |
| 36 | expect(!isFinite(math.inf(f32))); | |
| 37 | expect(!isFinite(-math.inf(f32))); | |
| 38 | expect(!isFinite(math.inf(f64))); | |
| 39 | expect(!isFinite(-math.inf(f64))); | |
| 40 | 40 | } |
std/math/isinf.zig+37-37| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn isInf(x: var) bool { |
| ... | ... | @@ -61,46 +61,46 @@ pub fn isNegativeInf(x: var) bool { |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "math.isInf" { |
| 64 | assert(!isInf(f16(0.0))); | |
| 65 | assert(!isInf(f16(-0.0))); | |
| 66 | assert(!isInf(f32(0.0))); | |
| 67 | assert(!isInf(f32(-0.0))); | |
| 68 | assert(!isInf(f64(0.0))); | |
| 69 | assert(!isInf(f64(-0.0))); | |
| 70 | assert(isInf(math.inf(f16))); | |
| 71 | assert(isInf(-math.inf(f16))); | |
| 72 | assert(isInf(math.inf(f32))); | |
| 73 | assert(isInf(-math.inf(f32))); | |
| 74 | assert(isInf(math.inf(f64))); | |
| 75 | assert(isInf(-math.inf(f64))); | |
| 64 | expect(!isInf(f16(0.0))); | |
| 65 | expect(!isInf(f16(-0.0))); | |
| 66 | expect(!isInf(f32(0.0))); | |
| 67 | expect(!isInf(f32(-0.0))); | |
| 68 | expect(!isInf(f64(0.0))); | |
| 69 | expect(!isInf(f64(-0.0))); | |
| 70 | expect(isInf(math.inf(f16))); | |
| 71 | expect(isInf(-math.inf(f16))); | |
| 72 | expect(isInf(math.inf(f32))); | |
| 73 | expect(isInf(-math.inf(f32))); | |
| 74 | expect(isInf(math.inf(f64))); | |
| 75 | expect(isInf(-math.inf(f64))); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "math.isPositiveInf" { |
| 79 | assert(!isPositiveInf(f16(0.0))); | |
| 80 | assert(!isPositiveInf(f16(-0.0))); | |
| 81 | assert(!isPositiveInf(f32(0.0))); | |
| 82 | assert(!isPositiveInf(f32(-0.0))); | |
| 83 | assert(!isPositiveInf(f64(0.0))); | |
| 84 | assert(!isPositiveInf(f64(-0.0))); | |
| 85 | assert(isPositiveInf(math.inf(f16))); | |
| 86 | assert(!isPositiveInf(-math.inf(f16))); | |
| 87 | assert(isPositiveInf(math.inf(f32))); | |
| 88 | assert(!isPositiveInf(-math.inf(f32))); | |
| 89 | assert(isPositiveInf(math.inf(f64))); | |
| 90 | assert(!isPositiveInf(-math.inf(f64))); | |
| 79 | expect(!isPositiveInf(f16(0.0))); | |
| 80 | expect(!isPositiveInf(f16(-0.0))); | |
| 81 | expect(!isPositiveInf(f32(0.0))); | |
| 82 | expect(!isPositiveInf(f32(-0.0))); | |
| 83 | expect(!isPositiveInf(f64(0.0))); | |
| 84 | expect(!isPositiveInf(f64(-0.0))); | |
| 85 | expect(isPositiveInf(math.inf(f16))); | |
| 86 | expect(!isPositiveInf(-math.inf(f16))); | |
| 87 | expect(isPositiveInf(math.inf(f32))); | |
| 88 | expect(!isPositiveInf(-math.inf(f32))); | |
| 89 | expect(isPositiveInf(math.inf(f64))); | |
| 90 | expect(!isPositiveInf(-math.inf(f64))); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | test "math.isNegativeInf" { |
| 94 | assert(!isNegativeInf(f16(0.0))); | |
| 95 | assert(!isNegativeInf(f16(-0.0))); | |
| 96 | assert(!isNegativeInf(f32(0.0))); | |
| 97 | assert(!isNegativeInf(f32(-0.0))); | |
| 98 | assert(!isNegativeInf(f64(0.0))); | |
| 99 | assert(!isNegativeInf(f64(-0.0))); | |
| 100 | assert(!isNegativeInf(math.inf(f16))); | |
| 101 | assert(isNegativeInf(-math.inf(f16))); | |
| 102 | assert(!isNegativeInf(math.inf(f32))); | |
| 103 | assert(isNegativeInf(-math.inf(f32))); | |
| 104 | assert(!isNegativeInf(math.inf(f64))); | |
| 105 | assert(isNegativeInf(-math.inf(f64))); | |
| 94 | expect(!isNegativeInf(f16(0.0))); | |
| 95 | expect(!isNegativeInf(f16(-0.0))); | |
| 96 | expect(!isNegativeInf(f32(0.0))); | |
| 97 | expect(!isNegativeInf(f32(-0.0))); | |
| 98 | expect(!isNegativeInf(f64(0.0))); | |
| 99 | expect(!isNegativeInf(f64(-0.0))); | |
| 100 | expect(!isNegativeInf(math.inf(f16))); | |
| 101 | expect(isNegativeInf(-math.inf(f16))); | |
| 102 | expect(!isNegativeInf(math.inf(f32))); | |
| 103 | expect(isNegativeInf(-math.inf(f32))); | |
| 104 | expect(!isNegativeInf(math.inf(f64))); | |
| 105 | expect(isNegativeInf(-math.inf(f64))); | |
| 106 | 106 | } |
std/math/isnan.zig+7-7| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn isNan(x: var) bool { |
| ... | ... | @@ -31,10 +31,10 @@ pub fn isSignalNan(x: var) bool { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | test "math.isNan" { |
| 34 | assert(isNan(math.nan(f16))); | |
| 35 | assert(isNan(math.nan(f32))); | |
| 36 | assert(isNan(math.nan(f64))); | |
| 37 | assert(!isNan(f16(1.0))); | |
| 38 | assert(!isNan(f32(1.0))); | |
| 39 | assert(!isNan(f64(1.0))); | |
| 34 | expect(isNan(math.nan(f16))); | |
| 35 | expect(isNan(math.nan(f32))); | |
| 36 | expect(isNan(math.nan(f64))); | |
| 37 | expect(!isNan(f16(1.0))); | |
| 38 | expect(!isNan(f32(1.0))); | |
| 39 | expect(!isNan(f64(1.0))); | |
| 40 | 40 | } |
std/math/isnormal.zig+10-10| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn isNormal(x: var) bool { |
| ... | ... | @@ -25,13 +25,13 @@ pub fn isNormal(x: var) bool { |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | test "math.isNormal" { |
| 28 | assert(!isNormal(math.nan(f16))); | |
| 29 | assert(!isNormal(math.nan(f32))); | |
| 30 | assert(!isNormal(math.nan(f64))); | |
| 31 | assert(!isNormal(f16(0))); | |
| 32 | assert(!isNormal(f32(0))); | |
| 33 | assert(!isNormal(f64(0))); | |
| 34 | assert(isNormal(f16(1.0))); | |
| 35 | assert(isNormal(f32(1.0))); | |
| 36 | assert(isNormal(f64(1.0))); | |
| 28 | expect(!isNormal(math.nan(f16))); | |
| 29 | expect(!isNormal(math.nan(f32))); | |
| 30 | expect(!isNormal(math.nan(f64))); | |
| 31 | expect(!isNormal(f16(0))); | |
| 32 | expect(!isNormal(f32(0))); | |
| 33 | expect(!isNormal(f64(0))); | |
| 34 | expect(isNormal(f16(1.0))); | |
| 35 | expect(isNormal(f32(1.0))); | |
| 36 | expect(isNormal(f64(1.0))); | |
| 37 | 37 | } |
std/math/ln.zig+23-23| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const builtin = @import("builtin"); |
| 12 | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | |
| ... | ... | @@ -143,42 +143,42 @@ pub fn ln_64(x_: f64) f64 { |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "math.ln" { |
| 146 | assert(ln(f32(0.2)) == ln_32(0.2)); | |
| 147 | assert(ln(f64(0.2)) == ln_64(0.2)); | |
| 146 | expect(ln(f32(0.2)) == ln_32(0.2)); | |
| 147 | expect(ln(f64(0.2)) == ln_64(0.2)); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "math.ln32" { |
| 151 | 151 | const epsilon = 0.000001; |
| 152 | 152 | |
| 153 | assert(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon)); | |
| 154 | assert(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon)); | |
| 155 | assert(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon)); | |
| 156 | assert(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon)); | |
| 157 | assert(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon)); | |
| 158 | assert(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon)); | |
| 153 | expect(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon)); | |
| 154 | expect(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon)); | |
| 155 | expect(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon)); | |
| 156 | expect(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon)); | |
| 157 | expect(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon)); | |
| 158 | expect(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon)); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | test "math.ln64" { |
| 162 | 162 | const epsilon = 0.000001; |
| 163 | 163 | |
| 164 | assert(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon)); | |
| 165 | assert(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon)); | |
| 166 | assert(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon)); | |
| 167 | assert(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon)); | |
| 168 | assert(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon)); | |
| 169 | assert(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon)); | |
| 164 | expect(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon)); | |
| 165 | expect(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon)); | |
| 166 | expect(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon)); | |
| 167 | expect(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon)); | |
| 168 | expect(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon)); | |
| 169 | expect(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon)); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "math.ln32.special" { |
| 173 | assert(math.isPositiveInf(ln_32(math.inf(f32)))); | |
| 174 | assert(math.isNegativeInf(ln_32(0.0))); | |
| 175 | assert(math.isNan(ln_32(-1.0))); | |
| 176 | assert(math.isNan(ln_32(math.nan(f32)))); | |
| 173 | expect(math.isPositiveInf(ln_32(math.inf(f32)))); | |
| 174 | expect(math.isNegativeInf(ln_32(0.0))); | |
| 175 | expect(math.isNan(ln_32(-1.0))); | |
| 176 | expect(math.isNan(ln_32(math.nan(f32)))); | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | test "math.ln64.special" { |
| 180 | assert(math.isPositiveInf(ln_64(math.inf(f64)))); | |
| 181 | assert(math.isNegativeInf(ln_64(0.0))); | |
| 182 | assert(math.isNan(ln_64(-1.0))); | |
| 183 | assert(math.isNan(ln_64(math.nan(f64)))); | |
| 180 | expect(math.isPositiveInf(ln_64(math.inf(f64)))); | |
| 181 | expect(math.isNegativeInf(ln_64(0.0))); | |
| 182 | expect(math.isNan(ln_64(-1.0))); | |
| 183 | expect(math.isNan(ln_64(math.nan(f64)))); | |
| 184 | 184 | } |
std/math/log.zig+13-13| ... | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | const TypeId = builtin.TypeId; |
| 5 | const assert = std.debug.assert; | |
| 5 | const expect = std.testing.expect; | |
| 6 | 6 | |
| 7 | 7 | pub fn log(comptime T: type, base: T, x: T) T { |
| 8 | 8 | if (base == 2) { |
| ... | ... | @@ -41,25 +41,25 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | test "math.log integer" { |
| 44 | assert(log(u8, 2, 0x1) == 0); | |
| 45 | assert(log(u8, 2, 0x2) == 1); | |
| 46 | assert(log(i16, 2, 0x72) == 6); | |
| 47 | assert(log(u32, 2, 0xFFFFFF) == 23); | |
| 48 | assert(log(u64, 2, 0x7FF0123456789ABC) == 62); | |
| 44 | expect(log(u8, 2, 0x1) == 0); | |
| 45 | expect(log(u8, 2, 0x2) == 1); | |
| 46 | expect(log(i16, 2, 0x72) == 6); | |
| 47 | expect(log(u32, 2, 0xFFFFFF) == 23); | |
| 48 | expect(log(u64, 2, 0x7FF0123456789ABC) == 62); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | test "math.log float" { |
| 52 | 52 | const epsilon = 0.000001; |
| 53 | 53 | |
| 54 | assert(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon)); | |
| 55 | assert(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon)); | |
| 56 | assert(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon)); | |
| 54 | expect(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon)); | |
| 55 | expect(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon)); | |
| 56 | expect(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon)); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | test "math.log float_special" { |
| 60 | assert(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974))); | |
| 61 | assert(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974))); | |
| 60 | expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974))); | |
| 61 | expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974))); | |
| 62 | 62 | |
| 63 | assert(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993))); | |
| 64 | assert(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993))); | |
| 63 | expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993))); | |
| 64 | expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993))); | |
| 65 | 65 | } |
std/math/log10.zig+23-23| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const testing = std.testing; | |
| 11 | 11 | const builtin = @import("builtin"); |
| 12 | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | const maxInt = std.math.maxInt; |
| ... | ... | @@ -171,42 +171,42 @@ pub fn log10_64(x_: f64) f64 { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | test "math.log10" { |
| 174 | assert(log10(f32(0.2)) == log10_32(0.2)); | |
| 175 | assert(log10(f64(0.2)) == log10_64(0.2)); | |
| 174 | testing.expect(log10(f32(0.2)) == log10_32(0.2)); | |
| 175 | testing.expect(log10(f64(0.2)) == log10_64(0.2)); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | test "math.log10_32" { |
| 179 | 179 | const epsilon = 0.000001; |
| 180 | 180 | |
| 181 | assert(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon)); | |
| 182 | assert(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon)); | |
| 183 | assert(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon)); | |
| 184 | assert(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon)); | |
| 185 | assert(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon)); | |
| 186 | assert(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon)); | |
| 181 | testing.expect(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon)); | |
| 182 | testing.expect(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon)); | |
| 183 | testing.expect(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon)); | |
| 184 | testing.expect(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon)); | |
| 185 | testing.expect(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon)); | |
| 186 | testing.expect(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon)); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "math.log10_64" { |
| 190 | 190 | const epsilon = 0.000001; |
| 191 | 191 | |
| 192 | assert(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon)); | |
| 193 | assert(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon)); | |
| 194 | assert(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon)); | |
| 195 | assert(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon)); | |
| 196 | assert(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon)); | |
| 197 | assert(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon)); | |
| 192 | testing.expect(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon)); | |
| 193 | testing.expect(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon)); | |
| 194 | testing.expect(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon)); | |
| 195 | testing.expect(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon)); | |
| 196 | testing.expect(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon)); | |
| 197 | testing.expect(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon)); | |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | test "math.log10_32.special" { |
| 201 | assert(math.isPositiveInf(log10_32(math.inf(f32)))); | |
| 202 | assert(math.isNegativeInf(log10_32(0.0))); | |
| 203 | assert(math.isNan(log10_32(-1.0))); | |
| 204 | assert(math.isNan(log10_32(math.nan(f32)))); | |
| 201 | testing.expect(math.isPositiveInf(log10_32(math.inf(f32)))); | |
| 202 | testing.expect(math.isNegativeInf(log10_32(0.0))); | |
| 203 | testing.expect(math.isNan(log10_32(-1.0))); | |
| 204 | testing.expect(math.isNan(log10_32(math.nan(f32)))); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | test "math.log10_64.special" { |
| 208 | assert(math.isPositiveInf(log10_64(math.inf(f64)))); | |
| 209 | assert(math.isNegativeInf(log10_64(0.0))); | |
| 210 | assert(math.isNan(log10_64(-1.0))); | |
| 211 | assert(math.isNan(log10_64(math.nan(f64)))); | |
| 208 | testing.expect(math.isPositiveInf(log10_64(math.inf(f64)))); | |
| 209 | testing.expect(math.isNegativeInf(log10_64(0.0))); | |
| 210 | testing.expect(math.isNan(log10_64(-1.0))); | |
| 211 | testing.expect(math.isNan(log10_64(math.nan(f64)))); | |
| 212 | 212 | } |
std/math/log1p.zig+29-29| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | const builtin = @import("builtin"); |
| 10 | 10 | const std = @import("../index.zig"); |
| 11 | 11 | const math = std.math; |
| 12 | const assert = std.debug.assert; | |
| 12 | const expect = std.testing.expect; | |
| 13 | 13 | |
| 14 | 14 | pub fn log1p(x: var) @typeOf(x) { |
| 15 | 15 | const T = @typeOf(x); |
| ... | ... | @@ -177,48 +177,48 @@ fn log1p_64(x: f64) f64 { |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | test "math.log1p" { |
| 180 | assert(log1p(f32(0.0)) == log1p_32(0.0)); | |
| 181 | assert(log1p(f64(0.0)) == log1p_64(0.0)); | |
| 180 | expect(log1p(f32(0.0)) == log1p_32(0.0)); | |
| 181 | expect(log1p(f64(0.0)) == log1p_64(0.0)); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | test "math.log1p_32" { |
| 185 | 185 | const epsilon = 0.000001; |
| 186 | 186 | |
| 187 | assert(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon)); | |
| 188 | assert(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon)); | |
| 189 | assert(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon)); | |
| 190 | assert(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon)); | |
| 191 | assert(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon)); | |
| 192 | assert(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon)); | |
| 193 | assert(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon)); | |
| 187 | expect(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon)); | |
| 188 | expect(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon)); | |
| 189 | expect(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon)); | |
| 190 | expect(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon)); | |
| 191 | expect(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon)); | |
| 192 | expect(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon)); | |
| 193 | expect(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon)); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | test "math.log1p_64" { |
| 197 | 197 | const epsilon = 0.000001; |
| 198 | 198 | |
| 199 | assert(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon)); | |
| 200 | assert(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon)); | |
| 201 | assert(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon)); | |
| 202 | assert(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon)); | |
| 203 | assert(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon)); | |
| 204 | assert(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon)); | |
| 205 | assert(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon)); | |
| 199 | expect(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon)); | |
| 200 | expect(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon)); | |
| 201 | expect(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon)); | |
| 202 | expect(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon)); | |
| 203 | expect(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon)); | |
| 204 | expect(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon)); | |
| 205 | expect(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon)); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | test "math.log1p_32.special" { |
| 209 | assert(math.isPositiveInf(log1p_32(math.inf(f32)))); | |
| 210 | assert(log1p_32(0.0) == 0.0); | |
| 211 | assert(log1p_32(-0.0) == -0.0); | |
| 212 | assert(math.isNegativeInf(log1p_32(-1.0))); | |
| 213 | assert(math.isNan(log1p_32(-2.0))); | |
| 214 | assert(math.isNan(log1p_32(math.nan(f32)))); | |
| 209 | expect(math.isPositiveInf(log1p_32(math.inf(f32)))); | |
| 210 | expect(log1p_32(0.0) == 0.0); | |
| 211 | expect(log1p_32(-0.0) == -0.0); | |
| 212 | expect(math.isNegativeInf(log1p_32(-1.0))); | |
| 213 | expect(math.isNan(log1p_32(-2.0))); | |
| 214 | expect(math.isNan(log1p_32(math.nan(f32)))); | |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | test "math.log1p_64.special" { |
| 218 | assert(math.isPositiveInf(log1p_64(math.inf(f64)))); | |
| 219 | assert(log1p_64(0.0) == 0.0); | |
| 220 | assert(log1p_64(-0.0) == -0.0); | |
| 221 | assert(math.isNegativeInf(log1p_64(-1.0))); | |
| 222 | assert(math.isNan(log1p_64(-2.0))); | |
| 223 | assert(math.isNan(log1p_64(math.nan(f64)))); | |
| 218 | expect(math.isPositiveInf(log1p_64(math.inf(f64)))); | |
| 219 | expect(log1p_64(0.0) == 0.0); | |
| 220 | expect(log1p_64(-0.0) == -0.0); | |
| 221 | expect(math.isNegativeInf(log1p_64(-1.0))); | |
| 222 | expect(math.isNan(log1p_64(-2.0))); | |
| 223 | expect(math.isNan(log1p_64(math.nan(f64)))); | |
| 224 | 224 | } |
std/math/log2.zig+21-21| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const builtin = @import("builtin"); |
| 12 | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | const maxInt = std.math.maxInt; |
| ... | ... | @@ -169,40 +169,40 @@ pub fn log2_64(x_: f64) f64 { |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "math.log2" { |
| 172 | assert(log2(f32(0.2)) == log2_32(0.2)); | |
| 173 | assert(log2(f64(0.2)) == log2_64(0.2)); | |
| 172 | expect(log2(f32(0.2)) == log2_32(0.2)); | |
| 173 | expect(log2(f64(0.2)) == log2_64(0.2)); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "math.log2_32" { |
| 177 | 177 | const epsilon = 0.000001; |
| 178 | 178 | |
| 179 | assert(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon)); | |
| 180 | assert(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon)); | |
| 181 | assert(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon)); | |
| 182 | assert(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon)); | |
| 183 | assert(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon)); | |
| 179 | expect(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon)); | |
| 180 | expect(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon)); | |
| 181 | expect(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon)); | |
| 182 | expect(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon)); | |
| 183 | expect(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon)); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | test "math.log2_64" { |
| 187 | 187 | const epsilon = 0.000001; |
| 188 | 188 | |
| 189 | assert(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon)); | |
| 190 | assert(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon)); | |
| 191 | assert(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon)); | |
| 192 | assert(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon)); | |
| 193 | assert(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon)); | |
| 189 | expect(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon)); | |
| 190 | expect(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon)); | |
| 191 | expect(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon)); | |
| 192 | expect(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon)); | |
| 193 | expect(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon)); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | test "math.log2_32.special" { |
| 197 | assert(math.isPositiveInf(log2_32(math.inf(f32)))); | |
| 198 | assert(math.isNegativeInf(log2_32(0.0))); | |
| 199 | assert(math.isNan(log2_32(-1.0))); | |
| 200 | assert(math.isNan(log2_32(math.nan(f32)))); | |
| 197 | expect(math.isPositiveInf(log2_32(math.inf(f32)))); | |
| 198 | expect(math.isNegativeInf(log2_32(0.0))); | |
| 199 | expect(math.isNan(log2_32(-1.0))); | |
| 200 | expect(math.isNan(log2_32(math.nan(f32)))); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | test "math.log2_64.special" { |
| 204 | assert(math.isPositiveInf(log2_64(math.inf(f64)))); | |
| 205 | assert(math.isNegativeInf(log2_64(0.0))); | |
| 206 | assert(math.isNan(log2_64(-1.0))); | |
| 207 | assert(math.isNan(log2_64(math.nan(f64)))); | |
| 204 | expect(math.isPositiveInf(log2_64(math.inf(f64)))); | |
| 205 | expect(math.isNegativeInf(log2_64(0.0))); | |
| 206 | expect(math.isNan(log2_64(-1.0))); | |
| 207 | expect(math.isNan(log2_64(math.nan(f64)))); | |
| 208 | 208 | } |
std/math/modf.zig+29-29| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | const std = @import("../index.zig"); |
| 7 | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | const maxInt = std.math.maxInt; |
| 10 | 10 | |
| 11 | 11 | fn modf_result(comptime T: type) type { |
| ... | ... | @@ -119,11 +119,11 @@ test "math.modf" { |
| 119 | 119 | const a = modf(f32(1.0)); |
| 120 | 120 | const b = modf32(1.0); |
| 121 | 121 | // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. |
| 122 | assert(a.ipart == b.ipart and a.fpart == b.fpart); | |
| 122 | expect(a.ipart == b.ipart and a.fpart == b.fpart); | |
| 123 | 123 | |
| 124 | 124 | const c = modf(f64(1.0)); |
| 125 | 125 | const d = modf64(1.0); |
| 126 | assert(a.ipart == b.ipart and a.fpart == b.fpart); | |
| 126 | expect(a.ipart == b.ipart and a.fpart == b.fpart); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | test "math.modf32" { |
| ... | ... | @@ -131,24 +131,24 @@ test "math.modf32" { |
| 131 | 131 | var r: modf32_result = undefined; |
| 132 | 132 | |
| 133 | 133 | r = modf32(1.0); |
| 134 | assert(math.approxEq(f32, r.ipart, 1.0, epsilon)); | |
| 135 | assert(math.approxEq(f32, r.fpart, 0.0, epsilon)); | |
| 134 | expect(math.approxEq(f32, r.ipart, 1.0, epsilon)); | |
| 135 | expect(math.approxEq(f32, r.fpart, 0.0, epsilon)); | |
| 136 | 136 | |
| 137 | 137 | r = modf32(2.545); |
| 138 | assert(math.approxEq(f32, r.ipart, 2.0, epsilon)); | |
| 139 | assert(math.approxEq(f32, r.fpart, 0.545, epsilon)); | |
| 138 | expect(math.approxEq(f32, r.ipart, 2.0, epsilon)); | |
| 139 | expect(math.approxEq(f32, r.fpart, 0.545, epsilon)); | |
| 140 | 140 | |
| 141 | 141 | r = modf32(3.978123); |
| 142 | assert(math.approxEq(f32, r.ipart, 3.0, epsilon)); | |
| 143 | assert(math.approxEq(f32, r.fpart, 0.978123, epsilon)); | |
| 142 | expect(math.approxEq(f32, r.ipart, 3.0, epsilon)); | |
| 143 | expect(math.approxEq(f32, r.fpart, 0.978123, epsilon)); | |
| 144 | 144 | |
| 145 | 145 | r = modf32(43874.3); |
| 146 | assert(math.approxEq(f32, r.ipart, 43874, epsilon)); | |
| 147 | assert(math.approxEq(f32, r.fpart, 0.300781, epsilon)); | |
| 146 | expect(math.approxEq(f32, r.ipart, 43874, epsilon)); | |
| 147 | expect(math.approxEq(f32, r.fpart, 0.300781, epsilon)); | |
| 148 | 148 | |
| 149 | 149 | r = modf32(1234.340780); |
| 150 | assert(math.approxEq(f32, r.ipart, 1234, epsilon)); | |
| 151 | assert(math.approxEq(f32, r.fpart, 0.340820, epsilon)); | |
| 150 | expect(math.approxEq(f32, r.ipart, 1234, epsilon)); | |
| 151 | expect(math.approxEq(f32, r.fpart, 0.340820, epsilon)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.modf64" { |
| ... | ... | @@ -156,48 +156,48 @@ test "math.modf64" { |
| 156 | 156 | var r: modf64_result = undefined; |
| 157 | 157 | |
| 158 | 158 | r = modf64(1.0); |
| 159 | assert(math.approxEq(f64, r.ipart, 1.0, epsilon)); | |
| 160 | assert(math.approxEq(f64, r.fpart, 0.0, epsilon)); | |
| 159 | expect(math.approxEq(f64, r.ipart, 1.0, epsilon)); | |
| 160 | expect(math.approxEq(f64, r.fpart, 0.0, epsilon)); | |
| 161 | 161 | |
| 162 | 162 | r = modf64(2.545); |
| 163 | assert(math.approxEq(f64, r.ipart, 2.0, epsilon)); | |
| 164 | assert(math.approxEq(f64, r.fpart, 0.545, epsilon)); | |
| 163 | expect(math.approxEq(f64, r.ipart, 2.0, epsilon)); | |
| 164 | expect(math.approxEq(f64, r.fpart, 0.545, epsilon)); | |
| 165 | 165 | |
| 166 | 166 | r = modf64(3.978123); |
| 167 | assert(math.approxEq(f64, r.ipart, 3.0, epsilon)); | |
| 168 | assert(math.approxEq(f64, r.fpart, 0.978123, epsilon)); | |
| 167 | expect(math.approxEq(f64, r.ipart, 3.0, epsilon)); | |
| 168 | expect(math.approxEq(f64, r.fpart, 0.978123, epsilon)); | |
| 169 | 169 | |
| 170 | 170 | r = modf64(43874.3); |
| 171 | assert(math.approxEq(f64, r.ipart, 43874, epsilon)); | |
| 172 | assert(math.approxEq(f64, r.fpart, 0.3, epsilon)); | |
| 171 | expect(math.approxEq(f64, r.ipart, 43874, epsilon)); | |
| 172 | expect(math.approxEq(f64, r.fpart, 0.3, epsilon)); | |
| 173 | 173 | |
| 174 | 174 | r = modf64(1234.340780); |
| 175 | assert(math.approxEq(f64, r.ipart, 1234, epsilon)); | |
| 176 | assert(math.approxEq(f64, r.fpart, 0.340780, epsilon)); | |
| 175 | expect(math.approxEq(f64, r.ipart, 1234, epsilon)); | |
| 176 | expect(math.approxEq(f64, r.fpart, 0.340780, epsilon)); | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | test "math.modf32.special" { |
| 180 | 180 | var r: modf32_result = undefined; |
| 181 | 181 | |
| 182 | 182 | r = modf32(math.inf(f32)); |
| 183 | assert(math.isPositiveInf(r.ipart) and math.isNan(r.fpart)); | |
| 183 | expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart)); | |
| 184 | 184 | |
| 185 | 185 | r = modf32(-math.inf(f32)); |
| 186 | assert(math.isNegativeInf(r.ipart) and math.isNan(r.fpart)); | |
| 186 | expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart)); | |
| 187 | 187 | |
| 188 | 188 | r = modf32(math.nan(f32)); |
| 189 | assert(math.isNan(r.ipart) and math.isNan(r.fpart)); | |
| 189 | expect(math.isNan(r.ipart) and math.isNan(r.fpart)); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | test "math.modf64.special" { |
| 193 | 193 | var r: modf64_result = undefined; |
| 194 | 194 | |
| 195 | 195 | r = modf64(math.inf(f64)); |
| 196 | assert(math.isPositiveInf(r.ipart) and math.isNan(r.fpart)); | |
| 196 | expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart)); | |
| 197 | 197 | |
| 198 | 198 | r = modf64(-math.inf(f64)); |
| 199 | assert(math.isNegativeInf(r.ipart) and math.isNan(r.fpart)); | |
| 199 | expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart)); | |
| 200 | 200 | |
| 201 | 201 | r = modf64(math.nan(f64)); |
| 202 | assert(math.isNan(r.ipart) and math.isNan(r.fpart)); | |
| 202 | expect(math.isNan(r.ipart) and math.isNan(r.fpart)); | |
| 203 | 203 | } |
std/math/pow.zig+48-48| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | const builtin = @import("builtin"); |
| 25 | 25 | const std = @import("../index.zig"); |
| 26 | 26 | const math = std.math; |
| 27 | const assert = std.debug.assert; | |
| 27 | const expect = std.testing.expect; | |
| 28 | 28 | |
| 29 | 29 | // This implementation is taken from the go stlib, musl is a bit more complex. |
| 30 | 30 | pub fn pow(comptime T: type, x: T, y: T) T { |
| ... | ... | @@ -179,56 +179,56 @@ fn isOddInteger(x: f64) bool { |
| 179 | 179 | test "math.pow" { |
| 180 | 180 | const epsilon = 0.000001; |
| 181 | 181 | |
| 182 | assert(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon)); | |
| 183 | assert(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon)); | |
| 184 | assert(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon)); | |
| 185 | assert(math.approxEq(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon)); | |
| 186 | assert(math.approxEq(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon)); | |
| 187 | assert(math.approxEq(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon)); | |
| 188 | ||
| 189 | assert(math.approxEq(f64, pow(f64, 0.0, 3.3), 0.0, epsilon)); | |
| 190 | assert(math.approxEq(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon)); | |
| 191 | assert(math.approxEq(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon)); | |
| 192 | assert(math.approxEq(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon)); | |
| 193 | assert(math.approxEq(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon)); | |
| 194 | assert(math.approxEq(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon)); | |
| 182 | expect(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon)); | |
| 183 | expect(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon)); | |
| 184 | expect(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon)); | |
| 185 | expect(math.approxEq(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon)); | |
| 186 | expect(math.approxEq(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon)); | |
| 187 | expect(math.approxEq(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon)); | |
| 188 | ||
| 189 | expect(math.approxEq(f64, pow(f64, 0.0, 3.3), 0.0, epsilon)); | |
| 190 | expect(math.approxEq(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon)); | |
| 191 | expect(math.approxEq(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon)); | |
| 192 | expect(math.approxEq(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon)); | |
| 193 | expect(math.approxEq(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon)); | |
| 194 | expect(math.approxEq(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon)); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | test "math.pow.special" { |
| 198 | 198 | const epsilon = 0.000001; |
| 199 | 199 | |
| 200 | assert(pow(f32, 4, 0.0) == 1.0); | |
| 201 | assert(pow(f32, 7, -0.0) == 1.0); | |
| 202 | assert(pow(f32, 45, 1.0) == 45); | |
| 203 | assert(pow(f32, -45, 1.0) == -45); | |
| 204 | assert(math.isNan(pow(f32, math.nan(f32), 5.0))); | |
| 205 | assert(math.isNan(pow(f32, 5.0, math.nan(f32)))); | |
| 206 | assert(math.isPositiveInf(pow(f32, 0.0, -1.0))); | |
| 207 | //assert(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required? | |
| 208 | assert(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32)))); | |
| 209 | assert(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32)))); | |
| 210 | assert(pow(f32, 0.0, math.inf(f32)) == 0.0); | |
| 211 | assert(pow(f32, -0.0, math.inf(f32)) == 0.0); | |
| 212 | assert(math.isPositiveInf(pow(f32, 0.0, -2.0))); | |
| 213 | assert(math.isPositiveInf(pow(f32, -0.0, -2.0))); | |
| 214 | assert(pow(f32, 0.0, 1.0) == 0.0); | |
| 215 | assert(pow(f32, -0.0, 1.0) == -0.0); | |
| 216 | assert(pow(f32, 0.0, 2.0) == 0.0); | |
| 217 | assert(pow(f32, -0.0, 2.0) == 0.0); | |
| 218 | assert(math.approxEq(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon)); | |
| 219 | assert(math.approxEq(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon)); | |
| 220 | assert(math.isPositiveInf(pow(f32, 1.2, math.inf(f32)))); | |
| 221 | assert(math.isPositiveInf(pow(f32, -1.2, math.inf(f32)))); | |
| 222 | assert(pow(f32, 1.2, -math.inf(f32)) == 0.0); | |
| 223 | assert(pow(f32, -1.2, -math.inf(f32)) == 0.0); | |
| 224 | assert(pow(f32, 0.2, math.inf(f32)) == 0.0); | |
| 225 | assert(pow(f32, -0.2, math.inf(f32)) == 0.0); | |
| 226 | assert(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32)))); | |
| 227 | assert(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32)))); | |
| 228 | assert(math.isPositiveInf(pow(f32, math.inf(f32), 1.0))); | |
| 229 | assert(pow(f32, math.inf(f32), -1.0) == 0.0); | |
| 230 | //assert(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0? | |
| 231 | assert(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2)); | |
| 232 | assert(math.isNan(pow(f32, -1.0, 1.2))); | |
| 233 | assert(math.isNan(pow(f32, -12.4, 78.5))); | |
| 200 | expect(pow(f32, 4, 0.0) == 1.0); | |
| 201 | expect(pow(f32, 7, -0.0) == 1.0); | |
| 202 | expect(pow(f32, 45, 1.0) == 45); | |
| 203 | expect(pow(f32, -45, 1.0) == -45); | |
| 204 | expect(math.isNan(pow(f32, math.nan(f32), 5.0))); | |
| 205 | expect(math.isNan(pow(f32, 5.0, math.nan(f32)))); | |
| 206 | expect(math.isPositiveInf(pow(f32, 0.0, -1.0))); | |
| 207 | //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required? | |
| 208 | expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32)))); | |
| 209 | expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32)))); | |
| 210 | expect(pow(f32, 0.0, math.inf(f32)) == 0.0); | |
| 211 | expect(pow(f32, -0.0, math.inf(f32)) == 0.0); | |
| 212 | expect(math.isPositiveInf(pow(f32, 0.0, -2.0))); | |
| 213 | expect(math.isPositiveInf(pow(f32, -0.0, -2.0))); | |
| 214 | expect(pow(f32, 0.0, 1.0) == 0.0); | |
| 215 | expect(pow(f32, -0.0, 1.0) == -0.0); | |
| 216 | expect(pow(f32, 0.0, 2.0) == 0.0); | |
| 217 | expect(pow(f32, -0.0, 2.0) == 0.0); | |
| 218 | expect(math.approxEq(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon)); | |
| 219 | expect(math.approxEq(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon)); | |
| 220 | expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32)))); | |
| 221 | expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32)))); | |
| 222 | expect(pow(f32, 1.2, -math.inf(f32)) == 0.0); | |
| 223 | expect(pow(f32, -1.2, -math.inf(f32)) == 0.0); | |
| 224 | expect(pow(f32, 0.2, math.inf(f32)) == 0.0); | |
| 225 | expect(pow(f32, -0.2, math.inf(f32)) == 0.0); | |
| 226 | expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32)))); | |
| 227 | expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32)))); | |
| 228 | expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0))); | |
| 229 | expect(pow(f32, math.inf(f32), -1.0) == 0.0); | |
| 230 | //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0? | |
| 231 | expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2)); | |
| 232 | expect(math.isNan(pow(f32, -1.0, 1.2))); | |
| 233 | expect(math.isNan(pow(f32, -12.4, 78.5))); | |
| 234 | 234 | } |
std/math/powi.zig+69-69| ... | ... | @@ -12,7 +12,7 @@ const builtin = @import("builtin"); |
| 12 | 12 | const std = @import("../index.zig"); |
| 13 | 13 | const math = std.math; |
| 14 | 14 | const assert = std.debug.assert; |
| 15 | const assertError = std.debug.assertError; | |
| 15 | const testing = std.testing; | |
| 16 | 16 | |
| 17 | 17 | // This implementation is based on that from the rust stlib |
| 18 | 18 | pub fn powi(comptime T: type, x: T, y: T) (error{ |
| ... | ... | @@ -103,75 +103,75 @@ pub fn powi(comptime T: type, x: T, y: T) (error{ |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "math.powi" { |
| 106 | assertError(powi(i8, -66, 6), error.Underflow); | |
| 107 | assertError(powi(i16, -13, 13), error.Underflow); | |
| 108 | assertError(powi(i32, -32, 21), error.Underflow); | |
| 109 | assertError(powi(i64, -24, 61), error.Underflow); | |
| 110 | assertError(powi(i17, -15, 15), error.Underflow); | |
| 111 | assertError(powi(i42, -6, 40), error.Underflow); | |
| 112 | ||
| 113 | assert((try powi(i8, -5, 3)) == -125); | |
| 114 | assert((try powi(i16, -16, 3)) == -4096); | |
| 115 | assert((try powi(i32, -91, 3)) == -753571); | |
| 116 | assert((try powi(i64, -36, 6)) == 2176782336); | |
| 117 | assert((try powi(i17, -2, 15)) == -32768); | |
| 118 | assert((try powi(i42, -5, 7)) == -78125); | |
| 119 | ||
| 120 | assert((try powi(u8, 6, 2)) == 36); | |
| 121 | assert((try powi(u16, 5, 4)) == 625); | |
| 122 | assert((try powi(u32, 12, 6)) == 2985984); | |
| 123 | assert((try powi(u64, 34, 2)) == 1156); | |
| 124 | assert((try powi(u17, 16, 3)) == 4096); | |
| 125 | assert((try powi(u42, 34, 6)) == 1544804416); | |
| 126 | ||
| 127 | assertError(powi(i8, 120, 7), error.Overflow); | |
| 128 | assertError(powi(i16, 73, 15), error.Overflow); | |
| 129 | assertError(powi(i32, 23, 31), error.Overflow); | |
| 130 | assertError(powi(i64, 68, 61), error.Overflow); | |
| 131 | assertError(powi(i17, 15, 15), error.Overflow); | |
| 132 | assertError(powi(i42, 121312, 41), error.Overflow); | |
| 133 | ||
| 134 | assertError(powi(u8, 123, 7), error.Overflow); | |
| 135 | assertError(powi(u16, 2313, 15), error.Overflow); | |
| 136 | assertError(powi(u32, 8968, 31), error.Overflow); | |
| 137 | assertError(powi(u64, 2342, 63), error.Overflow); | |
| 138 | assertError(powi(u17, 2723, 16), error.Overflow); | |
| 139 | assertError(powi(u42, 8234, 41), error.Overflow); | |
| 106 | testing.expectError(error.Underflow, powi(i8, -66, 6)); | |
| 107 | testing.expectError(error.Underflow, powi(i16, -13, 13)); | |
| 108 | testing.expectError(error.Underflow, powi(i32, -32, 21)); | |
| 109 | testing.expectError(error.Underflow, powi(i64, -24, 61)); | |
| 110 | testing.expectError(error.Underflow, powi(i17, -15, 15)); | |
| 111 | testing.expectError(error.Underflow, powi(i42, -6, 40)); | |
| 112 | ||
| 113 | testing.expect((try powi(i8, -5, 3)) == -125); | |
| 114 | testing.expect((try powi(i16, -16, 3)) == -4096); | |
| 115 | testing.expect((try powi(i32, -91, 3)) == -753571); | |
| 116 | testing.expect((try powi(i64, -36, 6)) == 2176782336); | |
| 117 | testing.expect((try powi(i17, -2, 15)) == -32768); | |
| 118 | testing.expect((try powi(i42, -5, 7)) == -78125); | |
| 119 | ||
| 120 | testing.expect((try powi(u8, 6, 2)) == 36); | |
| 121 | testing.expect((try powi(u16, 5, 4)) == 625); | |
| 122 | testing.expect((try powi(u32, 12, 6)) == 2985984); | |
| 123 | testing.expect((try powi(u64, 34, 2)) == 1156); | |
| 124 | testing.expect((try powi(u17, 16, 3)) == 4096); | |
| 125 | testing.expect((try powi(u42, 34, 6)) == 1544804416); | |
| 126 | ||
| 127 | testing.expectError(error.Overflow, powi(i8, 120, 7)); | |
| 128 | testing.expectError(error.Overflow, powi(i16, 73, 15)); | |
| 129 | testing.expectError(error.Overflow, powi(i32, 23, 31)); | |
| 130 | testing.expectError(error.Overflow, powi(i64, 68, 61)); | |
| 131 | testing.expectError(error.Overflow, powi(i17, 15, 15)); | |
| 132 | testing.expectError(error.Overflow, powi(i42, 121312, 41)); | |
| 133 | ||
| 134 | testing.expectError(error.Overflow, powi(u8, 123, 7)); | |
| 135 | testing.expectError(error.Overflow, powi(u16, 2313, 15)); | |
| 136 | testing.expectError(error.Overflow, powi(u32, 8968, 31)); | |
| 137 | testing.expectError(error.Overflow, powi(u64, 2342, 63)); | |
| 138 | testing.expectError(error.Overflow, powi(u17, 2723, 16)); | |
| 139 | testing.expectError(error.Overflow, powi(u42, 8234, 41)); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | test "math.powi.special" { |
| 143 | assertError(powi(i8, -2, 8), error.Underflow); | |
| 144 | assertError(powi(i16, -2, 16), error.Underflow); | |
| 145 | assertError(powi(i32, -2, 32), error.Underflow); | |
| 146 | assertError(powi(i64, -2, 64), error.Underflow); | |
| 147 | assertError(powi(i17, -2, 17), error.Underflow); | |
| 148 | assertError(powi(i42, -2, 42), error.Underflow); | |
| 149 | ||
| 150 | assert((try powi(i8, -1, 3)) == -1); | |
| 151 | assert((try powi(i16, -1, 2)) == 1); | |
| 152 | assert((try powi(i32, -1, 16)) == 1); | |
| 153 | assert((try powi(i64, -1, 6)) == 1); | |
| 154 | assert((try powi(i17, -1, 15)) == -1); | |
| 155 | assert((try powi(i42, -1, 7)) == -1); | |
| 156 | ||
| 157 | assert((try powi(u8, 1, 2)) == 1); | |
| 158 | assert((try powi(u16, 1, 4)) == 1); | |
| 159 | assert((try powi(u32, 1, 6)) == 1); | |
| 160 | assert((try powi(u64, 1, 2)) == 1); | |
| 161 | assert((try powi(u17, 1, 3)) == 1); | |
| 162 | assert((try powi(u42, 1, 6)) == 1); | |
| 163 | ||
| 164 | assertError(powi(i8, 2, 7), error.Overflow); | |
| 165 | assertError(powi(i16, 2, 15), error.Overflow); | |
| 166 | assertError(powi(i32, 2, 31), error.Overflow); | |
| 167 | assertError(powi(i64, 2, 63), error.Overflow); | |
| 168 | assertError(powi(i17, 2, 16), error.Overflow); | |
| 169 | assertError(powi(i42, 2, 41), error.Overflow); | |
| 170 | ||
| 171 | assertError(powi(u8, 2, 8), error.Overflow); | |
| 172 | assertError(powi(u16, 2, 16), error.Overflow); | |
| 173 | assertError(powi(u32, 2, 32), error.Overflow); | |
| 174 | assertError(powi(u64, 2, 64), error.Overflow); | |
| 175 | assertError(powi(u17, 2, 17), error.Overflow); | |
| 176 | assertError(powi(u42, 2, 42), error.Overflow); | |
| 143 | testing.expectError(error.Underflow, powi(i8, -2, 8)); | |
| 144 | testing.expectError(error.Underflow, powi(i16, -2, 16)); | |
| 145 | testing.expectError(error.Underflow, powi(i32, -2, 32)); | |
| 146 | testing.expectError(error.Underflow, powi(i64, -2, 64)); | |
| 147 | testing.expectError(error.Underflow, powi(i17, -2, 17)); | |
| 148 | testing.expectError(error.Underflow, powi(i42, -2, 42)); | |
| 149 | ||
| 150 | testing.expect((try powi(i8, -1, 3)) == -1); | |
| 151 | testing.expect((try powi(i16, -1, 2)) == 1); | |
| 152 | testing.expect((try powi(i32, -1, 16)) == 1); | |
| 153 | testing.expect((try powi(i64, -1, 6)) == 1); | |
| 154 | testing.expect((try powi(i17, -1, 15)) == -1); | |
| 155 | testing.expect((try powi(i42, -1, 7)) == -1); | |
| 156 | ||
| 157 | testing.expect((try powi(u8, 1, 2)) == 1); | |
| 158 | testing.expect((try powi(u16, 1, 4)) == 1); | |
| 159 | testing.expect((try powi(u32, 1, 6)) == 1); | |
| 160 | testing.expect((try powi(u64, 1, 2)) == 1); | |
| 161 | testing.expect((try powi(u17, 1, 3)) == 1); | |
| 162 | testing.expect((try powi(u42, 1, 6)) == 1); | |
| 163 | ||
| 164 | testing.expectError(error.Overflow, powi(i8, 2, 7)); | |
| 165 | testing.expectError(error.Overflow, powi(i16, 2, 15)); | |
| 166 | testing.expectError(error.Overflow, powi(i32, 2, 31)); | |
| 167 | testing.expectError(error.Overflow, powi(i64, 2, 63)); | |
| 168 | testing.expectError(error.Overflow, powi(i17, 2, 16)); | |
| 169 | testing.expectError(error.Overflow, powi(i42, 2, 41)); | |
| 170 | ||
| 171 | testing.expectError(error.Overflow, powi(u8, 2, 8)); | |
| 172 | testing.expectError(error.Overflow, powi(u16, 2, 16)); | |
| 173 | testing.expectError(error.Overflow, powi(u32, 2, 32)); | |
| 174 | testing.expectError(error.Overflow, powi(u64, 2, 64)); | |
| 175 | testing.expectError(error.Overflow, powi(u17, 2, 17)); | |
| 176 | testing.expectError(error.Overflow, powi(u42, 2, 42)); | |
| 177 | 177 | } |
std/math/round.zig+21-21| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // - round(nan) = nan |
| 6 | 6 | |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | const assert = std.debug.assert; | |
| 8 | const expect = std.testing.expect; | |
| 9 | 9 | const std = @import("../index.zig"); |
| 10 | 10 | const math = std.math; |
| 11 | 11 | |
| ... | ... | @@ -85,36 +85,36 @@ fn round64(x_: f64) f64 { |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | test "math.round" { |
| 88 | assert(round(f32(1.3)) == round32(1.3)); | |
| 89 | assert(round(f64(1.3)) == round64(1.3)); | |
| 88 | expect(round(f32(1.3)) == round32(1.3)); | |
| 89 | expect(round(f64(1.3)) == round64(1.3)); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | test "math.round32" { |
| 93 | assert(round32(1.3) == 1.0); | |
| 94 | assert(round32(-1.3) == -1.0); | |
| 95 | assert(round32(0.2) == 0.0); | |
| 96 | assert(round32(1.8) == 2.0); | |
| 93 | expect(round32(1.3) == 1.0); | |
| 94 | expect(round32(-1.3) == -1.0); | |
| 95 | expect(round32(0.2) == 0.0); | |
| 96 | expect(round32(1.8) == 2.0); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test "math.round64" { |
| 100 | assert(round64(1.3) == 1.0); | |
| 101 | assert(round64(-1.3) == -1.0); | |
| 102 | assert(round64(0.2) == 0.0); | |
| 103 | assert(round64(1.8) == 2.0); | |
| 100 | expect(round64(1.3) == 1.0); | |
| 101 | expect(round64(-1.3) == -1.0); | |
| 102 | expect(round64(0.2) == 0.0); | |
| 103 | expect(round64(1.8) == 2.0); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | test "math.round32.special" { |
| 107 | assert(round32(0.0) == 0.0); | |
| 108 | assert(round32(-0.0) == -0.0); | |
| 109 | assert(math.isPositiveInf(round32(math.inf(f32)))); | |
| 110 | assert(math.isNegativeInf(round32(-math.inf(f32)))); | |
| 111 | assert(math.isNan(round32(math.nan(f32)))); | |
| 107 | expect(round32(0.0) == 0.0); | |
| 108 | expect(round32(-0.0) == -0.0); | |
| 109 | expect(math.isPositiveInf(round32(math.inf(f32)))); | |
| 110 | expect(math.isNegativeInf(round32(-math.inf(f32)))); | |
| 111 | expect(math.isNan(round32(math.nan(f32)))); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "math.round64.special" { |
| 115 | assert(round64(0.0) == 0.0); | |
| 116 | assert(round64(-0.0) == -0.0); | |
| 117 | assert(math.isPositiveInf(round64(math.inf(f64)))); | |
| 118 | assert(math.isNegativeInf(round64(-math.inf(f64)))); | |
| 119 | assert(math.isNan(round64(math.nan(f64)))); | |
| 115 | expect(round64(0.0) == 0.0); | |
| 116 | expect(round64(-0.0) == -0.0); | |
| 117 | expect(math.isPositiveInf(round64(math.inf(f64)))); | |
| 118 | expect(math.isNegativeInf(round64(-math.inf(f64)))); | |
| 119 | expect(math.isNan(round64(math.nan(f64)))); | |
| 120 | 120 | } |
std/math/scalbn.zig+5-5| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | pub fn scalbn(x: var, n: i32) @typeOf(x) { |
| 6 | 6 | const T = @typeOf(x); |
| ... | ... | @@ -72,14 +72,14 @@ fn scalbn64(x: f64, n_: i32) f64 { |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "math.scalbn" { |
| 75 | assert(scalbn(f32(1.5), 4) == scalbn32(1.5, 4)); | |
| 76 | assert(scalbn(f64(1.5), 4) == scalbn64(1.5, 4)); | |
| 75 | expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4)); | |
| 76 | expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4)); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | test "math.scalbn32" { |
| 80 | assert(scalbn32(1.5, 4) == 24.0); | |
| 80 | expect(scalbn32(1.5, 4) == 24.0); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "math.scalbn64" { |
| 84 | assert(scalbn64(1.5, 4) == 24.0); | |
| 84 | expect(scalbn64(1.5, 4) == 24.0); | |
| 85 | 85 | } |
std/math/signbit.zig+10-10| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | pub fn signbit(x: var) bool { |
| 6 | 6 | const T = @typeOf(x); |
| ... | ... | @@ -28,22 +28,22 @@ fn signbit64(x: f64) bool { |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | test "math.signbit" { |
| 31 | assert(signbit(f16(4.0)) == signbit16(4.0)); | |
| 32 | assert(signbit(f32(4.0)) == signbit32(4.0)); | |
| 33 | assert(signbit(f64(4.0)) == signbit64(4.0)); | |
| 31 | expect(signbit(f16(4.0)) == signbit16(4.0)); | |
| 32 | expect(signbit(f32(4.0)) == signbit32(4.0)); | |
| 33 | expect(signbit(f64(4.0)) == signbit64(4.0)); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | test "math.signbit16" { |
| 37 | assert(!signbit16(4.0)); | |
| 38 | assert(signbit16(-3.0)); | |
| 37 | expect(!signbit16(4.0)); | |
| 38 | expect(signbit16(-3.0)); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | test "math.signbit32" { |
| 42 | assert(!signbit32(4.0)); | |
| 43 | assert(signbit32(-3.0)); | |
| 42 | expect(!signbit32(4.0)); | |
| 43 | expect(signbit32(-3.0)); | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | test "math.signbit64" { |
| 47 | assert(!signbit64(4.0)); | |
| 48 | assert(signbit64(-3.0)); | |
| 47 | expect(!signbit64(4.0)); | |
| 48 | expect(signbit64(-3.0)); | |
| 49 | 49 | } |
std/math/sin.zig+26-26| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | |
| 12 | 12 | pub fn sin(x: var) @typeOf(x) { |
| 13 | 13 | const T = @typeOf(x); |
| ... | ... | @@ -142,45 +142,45 @@ fn sin64(x_: f64) f64 { |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "math.sin" { |
| 145 | assert(sin(f32(0.0)) == sin32(0.0)); | |
| 146 | assert(sin(f64(0.0)) == sin64(0.0)); | |
| 147 | assert(comptime (math.sin(f64(2))) == math.sin(f64(2))); | |
| 145 | expect(sin(f32(0.0)) == sin32(0.0)); | |
| 146 | expect(sin(f64(0.0)) == sin64(0.0)); | |
| 147 | expect(comptime (math.sin(f64(2))) == math.sin(f64(2))); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "math.sin32" { |
| 151 | 151 | const epsilon = 0.000001; |
| 152 | 152 | |
| 153 | assert(math.approxEq(f32, sin32(0.0), 0.0, epsilon)); | |
| 154 | assert(math.approxEq(f32, sin32(0.2), 0.198669, epsilon)); | |
| 155 | assert(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon)); | |
| 156 | assert(math.approxEq(f32, sin32(1.5), 0.997495, epsilon)); | |
| 157 | assert(math.approxEq(f32, sin32(37.45), -0.246544, epsilon)); | |
| 158 | assert(math.approxEq(f32, sin32(89.123), 0.916166, epsilon)); | |
| 153 | expect(math.approxEq(f32, sin32(0.0), 0.0, epsilon)); | |
| 154 | expect(math.approxEq(f32, sin32(0.2), 0.198669, epsilon)); | |
| 155 | expect(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon)); | |
| 156 | expect(math.approxEq(f32, sin32(1.5), 0.997495, epsilon)); | |
| 157 | expect(math.approxEq(f32, sin32(37.45), -0.246544, epsilon)); | |
| 158 | expect(math.approxEq(f32, sin32(89.123), 0.916166, epsilon)); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | test "math.sin64" { |
| 162 | 162 | const epsilon = 0.000001; |
| 163 | 163 | |
| 164 | assert(math.approxEq(f64, sin64(0.0), 0.0, epsilon)); | |
| 165 | assert(math.approxEq(f64, sin64(0.2), 0.198669, epsilon)); | |
| 166 | assert(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon)); | |
| 167 | assert(math.approxEq(f64, sin64(1.5), 0.997495, epsilon)); | |
| 168 | assert(math.approxEq(f64, sin64(37.45), -0.246543, epsilon)); | |
| 169 | assert(math.approxEq(f64, sin64(89.123), 0.916166, epsilon)); | |
| 164 | expect(math.approxEq(f64, sin64(0.0), 0.0, epsilon)); | |
| 165 | expect(math.approxEq(f64, sin64(0.2), 0.198669, epsilon)); | |
| 166 | expect(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon)); | |
| 167 | expect(math.approxEq(f64, sin64(1.5), 0.997495, epsilon)); | |
| 168 | expect(math.approxEq(f64, sin64(37.45), -0.246543, epsilon)); | |
| 169 | expect(math.approxEq(f64, sin64(89.123), 0.916166, epsilon)); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "math.sin32.special" { |
| 173 | assert(sin32(0.0) == 0.0); | |
| 174 | assert(sin32(-0.0) == -0.0); | |
| 175 | assert(math.isNan(sin32(math.inf(f32)))); | |
| 176 | assert(math.isNan(sin32(-math.inf(f32)))); | |
| 177 | assert(math.isNan(sin32(math.nan(f32)))); | |
| 173 | expect(sin32(0.0) == 0.0); | |
| 174 | expect(sin32(-0.0) == -0.0); | |
| 175 | expect(math.isNan(sin32(math.inf(f32)))); | |
| 176 | expect(math.isNan(sin32(-math.inf(f32)))); | |
| 177 | expect(math.isNan(sin32(math.nan(f32)))); | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | test "math.sin64.special" { |
| 181 | assert(sin64(0.0) == 0.0); | |
| 182 | assert(sin64(-0.0) == -0.0); | |
| 183 | assert(math.isNan(sin64(math.inf(f64)))); | |
| 184 | assert(math.isNan(sin64(-math.inf(f64)))); | |
| 185 | assert(math.isNan(sin64(math.nan(f64)))); | |
| 181 | expect(sin64(0.0) == 0.0); | |
| 182 | expect(sin64(-0.0) == -0.0); | |
| 183 | expect(math.isNan(sin64(math.inf(f64)))); | |
| 184 | expect(math.isNan(sin64(-math.inf(f64)))); | |
| 185 | expect(math.isNan(sin64(math.nan(f64)))); | |
| 186 | 186 | } |
std/math/sinh.zig+21-21| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | 12 | const maxInt = std.math.maxInt; |
| 13 | 13 | |
| ... | ... | @@ -87,40 +87,40 @@ fn sinh64(x: f64) f64 { |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "math.sinh" { |
| 90 | assert(sinh(f32(1.5)) == sinh32(1.5)); | |
| 91 | assert(sinh(f64(1.5)) == sinh64(1.5)); | |
| 90 | expect(sinh(f32(1.5)) == sinh32(1.5)); | |
| 91 | expect(sinh(f64(1.5)) == sinh64(1.5)); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "math.sinh32" { |
| 95 | 95 | const epsilon = 0.000001; |
| 96 | 96 | |
| 97 | assert(math.approxEq(f32, sinh32(0.0), 0.0, epsilon)); | |
| 98 | assert(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon)); | |
| 99 | assert(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon)); | |
| 100 | assert(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon)); | |
| 97 | expect(math.approxEq(f32, sinh32(0.0), 0.0, epsilon)); | |
| 98 | expect(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon)); | |
| 99 | expect(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon)); | |
| 100 | expect(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon)); | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | test "math.sinh64" { |
| 104 | 104 | const epsilon = 0.000001; |
| 105 | 105 | |
| 106 | assert(math.approxEq(f64, sinh64(0.0), 0.0, epsilon)); | |
| 107 | assert(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon)); | |
| 108 | assert(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon)); | |
| 109 | assert(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon)); | |
| 106 | expect(math.approxEq(f64, sinh64(0.0), 0.0, epsilon)); | |
| 107 | expect(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon)); | |
| 108 | expect(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon)); | |
| 109 | expect(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon)); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "math.sinh32.special" { |
| 113 | assert(sinh32(0.0) == 0.0); | |
| 114 | assert(sinh32(-0.0) == -0.0); | |
| 115 | assert(math.isPositiveInf(sinh32(math.inf(f32)))); | |
| 116 | assert(math.isNegativeInf(sinh32(-math.inf(f32)))); | |
| 117 | assert(math.isNan(sinh32(math.nan(f32)))); | |
| 113 | expect(sinh32(0.0) == 0.0); | |
| 114 | expect(sinh32(-0.0) == -0.0); | |
| 115 | expect(math.isPositiveInf(sinh32(math.inf(f32)))); | |
| 116 | expect(math.isNegativeInf(sinh32(-math.inf(f32)))); | |
| 117 | expect(math.isNan(sinh32(math.nan(f32)))); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "math.sinh64.special" { |
| 121 | assert(sinh64(0.0) == 0.0); | |
| 122 | assert(sinh64(-0.0) == -0.0); | |
| 123 | assert(math.isPositiveInf(sinh64(math.inf(f64)))); | |
| 124 | assert(math.isNegativeInf(sinh64(-math.inf(f64)))); | |
| 125 | assert(math.isNan(sinh64(math.nan(f64)))); | |
| 121 | expect(sinh64(0.0) == 0.0); | |
| 122 | expect(sinh64(-0.0) == -0.0); | |
| 123 | expect(math.isPositiveInf(sinh64(math.inf(f64)))); | |
| 124 | expect(math.isNegativeInf(sinh64(-math.inf(f64)))); | |
| 125 | expect(math.isNan(sinh64(math.nan(f64)))); | |
| 126 | 126 | } |
std/math/sqrt.zig+52-52| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const builtin = @import("builtin"); |
| 12 | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | const maxInt = std.math.maxInt; |
| ... | ... | @@ -32,75 +32,75 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "math.sqrt" { |
| 35 | assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); | |
| 36 | assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); | |
| 37 | assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); | |
| 35 | expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); | |
| 36 | expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); | |
| 37 | expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "math.sqrt16" { |
| 41 | 41 | const epsilon = 0.000001; |
| 42 | 42 | |
| 43 | assert(@sqrt(f16, 0.0) == 0.0); | |
| 44 | assert(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon)); | |
| 45 | assert(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon)); | |
| 46 | assert(@sqrt(f16, 4.0) == 2.0); | |
| 47 | assert(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon)); | |
| 48 | assert(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon)); | |
| 49 | assert(@sqrt(f16, 64.0) == 8.0); | |
| 50 | assert(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon)); | |
| 51 | assert(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon)); | |
| 43 | expect(@sqrt(f16, 0.0) == 0.0); | |
| 44 | expect(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon)); | |
| 45 | expect(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon)); | |
| 46 | expect(@sqrt(f16, 4.0) == 2.0); | |
| 47 | expect(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon)); | |
| 48 | expect(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon)); | |
| 49 | expect(@sqrt(f16, 64.0) == 8.0); | |
| 50 | expect(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon)); | |
| 51 | expect(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon)); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "math.sqrt32" { |
| 55 | 55 | const epsilon = 0.000001; |
| 56 | 56 | |
| 57 | assert(@sqrt(f32, 0.0) == 0.0); | |
| 58 | assert(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon)); | |
| 59 | assert(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon)); | |
| 60 | assert(@sqrt(f32, 4.0) == 2.0); | |
| 61 | assert(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon)); | |
| 62 | assert(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon)); | |
| 63 | assert(@sqrt(f32, 64.0) == 8.0); | |
| 64 | assert(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon)); | |
| 65 | assert(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon)); | |
| 57 | expect(@sqrt(f32, 0.0) == 0.0); | |
| 58 | expect(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon)); | |
| 59 | expect(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon)); | |
| 60 | expect(@sqrt(f32, 4.0) == 2.0); | |
| 61 | expect(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon)); | |
| 62 | expect(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon)); | |
| 63 | expect(@sqrt(f32, 64.0) == 8.0); | |
| 64 | expect(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon)); | |
| 65 | expect(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon)); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "math.sqrt64" { |
| 69 | 69 | const epsilon = 0.000001; |
| 70 | 70 | |
| 71 | assert(@sqrt(f64, 0.0) == 0.0); | |
| 72 | assert(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon)); | |
| 73 | assert(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon)); | |
| 74 | assert(@sqrt(f64, 4.0) == 2.0); | |
| 75 | assert(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon)); | |
| 76 | assert(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon)); | |
| 77 | assert(@sqrt(f64, 64.0) == 8.0); | |
| 78 | assert(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon)); | |
| 79 | assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon)); | |
| 71 | expect(@sqrt(f64, 0.0) == 0.0); | |
| 72 | expect(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon)); | |
| 73 | expect(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon)); | |
| 74 | expect(@sqrt(f64, 4.0) == 2.0); | |
| 75 | expect(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon)); | |
| 76 | expect(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon)); | |
| 77 | expect(@sqrt(f64, 64.0) == 8.0); | |
| 78 | expect(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon)); | |
| 79 | expect(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon)); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | test "math.sqrt16.special" { |
| 83 | assert(math.isPositiveInf(@sqrt(f16, math.inf(f16)))); | |
| 84 | assert(@sqrt(f16, 0.0) == 0.0); | |
| 85 | assert(@sqrt(f16, -0.0) == -0.0); | |
| 86 | assert(math.isNan(@sqrt(f16, -1.0))); | |
| 87 | assert(math.isNan(@sqrt(f16, math.nan(f16)))); | |
| 83 | expect(math.isPositiveInf(@sqrt(f16, math.inf(f16)))); | |
| 84 | expect(@sqrt(f16, 0.0) == 0.0); | |
| 85 | expect(@sqrt(f16, -0.0) == -0.0); | |
| 86 | expect(math.isNan(@sqrt(f16, -1.0))); | |
| 87 | expect(math.isNan(@sqrt(f16, math.nan(f16)))); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "math.sqrt32.special" { |
| 91 | assert(math.isPositiveInf(@sqrt(f32, math.inf(f32)))); | |
| 92 | assert(@sqrt(f32, 0.0) == 0.0); | |
| 93 | assert(@sqrt(f32, -0.0) == -0.0); | |
| 94 | assert(math.isNan(@sqrt(f32, -1.0))); | |
| 95 | assert(math.isNan(@sqrt(f32, math.nan(f32)))); | |
| 91 | expect(math.isPositiveInf(@sqrt(f32, math.inf(f32)))); | |
| 92 | expect(@sqrt(f32, 0.0) == 0.0); | |
| 93 | expect(@sqrt(f32, -0.0) == -0.0); | |
| 94 | expect(math.isNan(@sqrt(f32, -1.0))); | |
| 95 | expect(math.isNan(@sqrt(f32, math.nan(f32)))); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "math.sqrt64.special" { |
| 99 | assert(math.isPositiveInf(@sqrt(f64, math.inf(f64)))); | |
| 100 | assert(@sqrt(f64, 0.0) == 0.0); | |
| 101 | assert(@sqrt(f64, -0.0) == -0.0); | |
| 102 | assert(math.isNan(@sqrt(f64, -1.0))); | |
| 103 | assert(math.isNan(@sqrt(f64, math.nan(f64)))); | |
| 99 | expect(math.isPositiveInf(@sqrt(f64, math.inf(f64)))); | |
| 100 | expect(@sqrt(f64, 0.0) == 0.0); | |
| 101 | expect(@sqrt(f64, -0.0) == -0.0); | |
| 102 | expect(math.isNan(@sqrt(f64, -1.0))); | |
| 103 | expect(math.isNan(@sqrt(f64, math.nan(f64)))); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) { |
| ... | ... | @@ -127,10 +127,10 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) { |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | test "math.sqrt_int" { |
| 130 | assert(sqrt_int(u32, 3) == 1); | |
| 131 | assert(sqrt_int(u32, 4) == 2); | |
| 132 | assert(sqrt_int(u32, 5) == 2); | |
| 133 | assert(sqrt_int(u32, 8) == 2); | |
| 134 | assert(sqrt_int(u32, 9) == 3); | |
| 135 | assert(sqrt_int(u32, 10) == 3); | |
| 130 | expect(sqrt_int(u32, 3) == 1); | |
| 131 | expect(sqrt_int(u32, 4) == 2); | |
| 132 | expect(sqrt_int(u32, 5) == 2); | |
| 133 | expect(sqrt_int(u32, 8) == 2); | |
| 134 | expect(sqrt_int(u32, 9) == 3); | |
| 135 | expect(sqrt_int(u32, 10) == 3); | |
| 136 | 136 | } |
std/math/tan.zig+25-25| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | |
| 12 | 12 | pub fn tan(x: var) @typeOf(x) { |
| 13 | 13 | const T = @typeOf(x); |
| ... | ... | @@ -129,44 +129,44 @@ fn tan64(x_: f64) f64 { |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.tan" { |
| 132 | assert(tan(f32(0.0)) == tan32(0.0)); | |
| 133 | assert(tan(f64(0.0)) == tan64(0.0)); | |
| 132 | expect(tan(f32(0.0)) == tan32(0.0)); | |
| 133 | expect(tan(f64(0.0)) == tan64(0.0)); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "math.tan32" { |
| 137 | 137 | const epsilon = 0.000001; |
| 138 | 138 | |
| 139 | assert(math.approxEq(f32, tan32(0.0), 0.0, epsilon)); | |
| 140 | assert(math.approxEq(f32, tan32(0.2), 0.202710, epsilon)); | |
| 141 | assert(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon)); | |
| 142 | assert(math.approxEq(f32, tan32(1.5), 14.101420, epsilon)); | |
| 143 | assert(math.approxEq(f32, tan32(37.45), -0.254397, epsilon)); | |
| 144 | assert(math.approxEq(f32, tan32(89.123), 2.285852, epsilon)); | |
| 139 | expect(math.approxEq(f32, tan32(0.0), 0.0, epsilon)); | |
| 140 | expect(math.approxEq(f32, tan32(0.2), 0.202710, epsilon)); | |
| 141 | expect(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon)); | |
| 142 | expect(math.approxEq(f32, tan32(1.5), 14.101420, epsilon)); | |
| 143 | expect(math.approxEq(f32, tan32(37.45), -0.254397, epsilon)); | |
| 144 | expect(math.approxEq(f32, tan32(89.123), 2.285852, epsilon)); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | test "math.tan64" { |
| 148 | 148 | const epsilon = 0.000001; |
| 149 | 149 | |
| 150 | assert(math.approxEq(f64, tan64(0.0), 0.0, epsilon)); | |
| 151 | assert(math.approxEq(f64, tan64(0.2), 0.202710, epsilon)); | |
| 152 | assert(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon)); | |
| 153 | assert(math.approxEq(f64, tan64(1.5), 14.101420, epsilon)); | |
| 154 | assert(math.approxEq(f64, tan64(37.45), -0.254397, epsilon)); | |
| 155 | assert(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon)); | |
| 150 | expect(math.approxEq(f64, tan64(0.0), 0.0, epsilon)); | |
| 151 | expect(math.approxEq(f64, tan64(0.2), 0.202710, epsilon)); | |
| 152 | expect(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon)); | |
| 153 | expect(math.approxEq(f64, tan64(1.5), 14.101420, epsilon)); | |
| 154 | expect(math.approxEq(f64, tan64(37.45), -0.254397, epsilon)); | |
| 155 | expect(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon)); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | test "math.tan32.special" { |
| 159 | assert(tan32(0.0) == 0.0); | |
| 160 | assert(tan32(-0.0) == -0.0); | |
| 161 | assert(math.isNan(tan32(math.inf(f32)))); | |
| 162 | assert(math.isNan(tan32(-math.inf(f32)))); | |
| 163 | assert(math.isNan(tan32(math.nan(f32)))); | |
| 159 | expect(tan32(0.0) == 0.0); | |
| 160 | expect(tan32(-0.0) == -0.0); | |
| 161 | expect(math.isNan(tan32(math.inf(f32)))); | |
| 162 | expect(math.isNan(tan32(-math.inf(f32)))); | |
| 163 | expect(math.isNan(tan32(math.nan(f32)))); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | test "math.tan64.special" { |
| 167 | assert(tan64(0.0) == 0.0); | |
| 168 | assert(tan64(-0.0) == -0.0); | |
| 169 | assert(math.isNan(tan64(math.inf(f64)))); | |
| 170 | assert(math.isNan(tan64(-math.inf(f64)))); | |
| 171 | assert(math.isNan(tan64(math.nan(f64)))); | |
| 167 | expect(tan64(0.0) == 0.0); | |
| 168 | expect(tan64(-0.0) == -0.0); | |
| 169 | expect(math.isNan(tan64(math.inf(f64)))); | |
| 170 | expect(math.isNan(tan64(-math.inf(f64)))); | |
| 171 | expect(math.isNan(tan64(math.nan(f64)))); | |
| 172 | 172 | } |
std/math/tanh.zig+23-23| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | const builtin = @import("builtin"); |
| 8 | 8 | const std = @import("../index.zig"); |
| 9 | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | |
| 10 | const expect = std.testing.expect; | |
| 11 | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | 12 | const maxInt = std.math.maxInt; |
| 13 | 13 | |
| ... | ... | @@ -113,42 +113,42 @@ fn tanh64(x: f64) f64 { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "math.tanh" { |
| 116 | assert(tanh(f32(1.5)) == tanh32(1.5)); | |
| 117 | assert(tanh(f64(1.5)) == tanh64(1.5)); | |
| 116 | expect(tanh(f32(1.5)) == tanh32(1.5)); | |
| 117 | expect(tanh(f64(1.5)) == tanh64(1.5)); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "math.tanh32" { |
| 121 | 121 | const epsilon = 0.000001; |
| 122 | 122 | |
| 123 | assert(math.approxEq(f32, tanh32(0.0), 0.0, epsilon)); | |
| 124 | assert(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon)); | |
| 125 | assert(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon)); | |
| 126 | assert(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon)); | |
| 127 | assert(math.approxEq(f32, tanh32(37.45), 1.0, epsilon)); | |
| 123 | expect(math.approxEq(f32, tanh32(0.0), 0.0, epsilon)); | |
| 124 | expect(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon)); | |
| 125 | expect(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon)); | |
| 126 | expect(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon)); | |
| 127 | expect(math.approxEq(f32, tanh32(37.45), 1.0, epsilon)); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | test "math.tanh64" { |
| 131 | 131 | const epsilon = 0.000001; |
| 132 | 132 | |
| 133 | assert(math.approxEq(f64, tanh64(0.0), 0.0, epsilon)); | |
| 134 | assert(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon)); | |
| 135 | assert(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon)); | |
| 136 | assert(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon)); | |
| 137 | assert(math.approxEq(f64, tanh64(37.45), 1.0, epsilon)); | |
| 133 | expect(math.approxEq(f64, tanh64(0.0), 0.0, epsilon)); | |
| 134 | expect(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon)); | |
| 135 | expect(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon)); | |
| 136 | expect(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon)); | |
| 137 | expect(math.approxEq(f64, tanh64(37.45), 1.0, epsilon)); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | test "math.tanh32.special" { |
| 141 | assert(tanh32(0.0) == 0.0); | |
| 142 | assert(tanh32(-0.0) == -0.0); | |
| 143 | assert(tanh32(math.inf(f32)) == 1.0); | |
| 144 | assert(tanh32(-math.inf(f32)) == -1.0); | |
| 145 | assert(math.isNan(tanh32(math.nan(f32)))); | |
| 141 | expect(tanh32(0.0) == 0.0); | |
| 142 | expect(tanh32(-0.0) == -0.0); | |
| 143 | expect(tanh32(math.inf(f32)) == 1.0); | |
| 144 | expect(tanh32(-math.inf(f32)) == -1.0); | |
| 145 | expect(math.isNan(tanh32(math.nan(f32)))); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "math.tanh64.special" { |
| 149 | assert(tanh64(0.0) == 0.0); | |
| 150 | assert(tanh64(-0.0) == -0.0); | |
| 151 | assert(tanh64(math.inf(f64)) == 1.0); | |
| 152 | assert(tanh64(-math.inf(f64)) == -1.0); | |
| 153 | assert(math.isNan(tanh64(math.nan(f64)))); | |
| 149 | expect(tanh64(0.0) == 0.0); | |
| 150 | expect(tanh64(-0.0) == -0.0); | |
| 151 | expect(tanh64(math.inf(f64)) == 1.0); | |
| 152 | expect(tanh64(-math.inf(f64)) == -1.0); | |
| 153 | expect(math.isNan(tanh64(math.nan(f64)))); | |
| 154 | 154 | } |
std/math/trunc.zig+19-19| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../index.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | |
| 9 | const expect = std.testing.expect; | |
| 10 | 10 | const maxInt = std.math.maxInt; |
| 11 | 11 | |
| 12 | 12 | pub fn trunc(x: var) @typeOf(x) { |
| ... | ... | @@ -61,34 +61,34 @@ fn trunc64(x: f64) f64 { |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "math.trunc" { |
| 64 | assert(trunc(f32(1.3)) == trunc32(1.3)); | |
| 65 | assert(trunc(f64(1.3)) == trunc64(1.3)); | |
| 64 | expect(trunc(f32(1.3)) == trunc32(1.3)); | |
| 65 | expect(trunc(f64(1.3)) == trunc64(1.3)); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "math.trunc32" { |
| 69 | assert(trunc32(1.3) == 1.0); | |
| 70 | assert(trunc32(-1.3) == -1.0); | |
| 71 | assert(trunc32(0.2) == 0.0); | |
| 69 | expect(trunc32(1.3) == 1.0); | |
| 70 | expect(trunc32(-1.3) == -1.0); | |
| 71 | expect(trunc32(0.2) == 0.0); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "math.trunc64" { |
| 75 | assert(trunc64(1.3) == 1.0); | |
| 76 | assert(trunc64(-1.3) == -1.0); | |
| 77 | assert(trunc64(0.2) == 0.0); | |
| 75 | expect(trunc64(1.3) == 1.0); | |
| 76 | expect(trunc64(-1.3) == -1.0); | |
| 77 | expect(trunc64(0.2) == 0.0); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "math.trunc32.special" { |
| 81 | assert(trunc32(0.0) == 0.0); // 0x3F800000 | |
| 82 | assert(trunc32(-0.0) == -0.0); | |
| 83 | assert(math.isPositiveInf(trunc32(math.inf(f32)))); | |
| 84 | assert(math.isNegativeInf(trunc32(-math.inf(f32)))); | |
| 85 | assert(math.isNan(trunc32(math.nan(f32)))); | |
| 81 | expect(trunc32(0.0) == 0.0); // 0x3F800000 | |
| 82 | expect(trunc32(-0.0) == -0.0); | |
| 83 | expect(math.isPositiveInf(trunc32(math.inf(f32)))); | |
| 84 | expect(math.isNegativeInf(trunc32(-math.inf(f32)))); | |
| 85 | expect(math.isNan(trunc32(math.nan(f32)))); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | test "math.trunc64.special" { |
| 89 | assert(trunc64(0.0) == 0.0); | |
| 90 | assert(trunc64(-0.0) == -0.0); | |
| 91 | assert(math.isPositiveInf(trunc64(math.inf(f64)))); | |
| 92 | assert(math.isNegativeInf(trunc64(-math.inf(f64)))); | |
| 93 | assert(math.isNan(trunc64(math.nan(f64)))); | |
| 89 | expect(trunc64(0.0) == 0.0); | |
| 90 | expect(trunc64(-0.0) == -0.0); | |
| 91 | expect(math.isPositiveInf(trunc64(math.inf(f64)))); | |
| 92 | expect(math.isNegativeInf(trunc64(-math.inf(f64)))); | |
| 93 | expect(math.isNan(trunc64(math.nan(f64)))); | |
| 94 | 94 | } |
std/mem.zig+160-159| ... | ... | @@ -6,6 +6,7 @@ const builtin = @import("builtin"); |
| 6 | 6 | const mem = @This(); |
| 7 | 7 | const meta = std.meta; |
| 8 | 8 | const trait = meta.trait; |
| 9 | const testing = std.testing; | |
| 9 | 10 | |
| 10 | 11 | pub const Allocator = struct { |
| 11 | 12 | pub const Error = error{OutOfMemory}; |
| ... | ... | @@ -181,7 +182,7 @@ test "mem.secureZero" { |
| 181 | 182 | set(u8, a[0..], 0); |
| 182 | 183 | secureZero(u8, b[0..]); |
| 183 | 184 | |
| 184 | assert(eql(u8, a[0..], b[0..])); | |
| 185 | testing.expectEqualSlices(u8, a[0..], b[0..]); | |
| 185 | 186 | } |
| 186 | 187 | |
| 187 | 188 | pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare { |
| ... | ... | @@ -210,11 +211,11 @@ pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare { |
| 210 | 211 | } |
| 211 | 212 | |
| 212 | 213 | test "mem.compare" { |
| 213 | assert(compare(u8, "abcd", "bee") == Compare.LessThan); | |
| 214 | assert(compare(u8, "abc", "abc") == Compare.Equal); | |
| 215 | assert(compare(u8, "abc", "abc0") == Compare.LessThan); | |
| 216 | assert(compare(u8, "", "") == Compare.Equal); | |
| 217 | assert(compare(u8, "", "a") == Compare.LessThan); | |
| 214 | testing.expect(compare(u8, "abcd", "bee") == Compare.LessThan); | |
| 215 | testing.expect(compare(u8, "abc", "abc") == Compare.Equal); | |
| 216 | testing.expect(compare(u8, "abc", "abc0") == Compare.LessThan); | |
| 217 | testing.expect(compare(u8, "", "") == Compare.Equal); | |
| 218 | testing.expect(compare(u8, "", "a") == Compare.LessThan); | |
| 218 | 219 | } |
| 219 | 220 | |
| 220 | 221 | /// Returns true if lhs < rhs, false otherwise |
| ... | ... | @@ -227,11 +228,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool { |
| 227 | 228 | } |
| 228 | 229 | |
| 229 | 230 | test "mem.lessThan" { |
| 230 | assert(lessThan(u8, "abcd", "bee")); | |
| 231 | assert(!lessThan(u8, "abc", "abc")); | |
| 232 | assert(lessThan(u8, "abc", "abc0")); | |
| 233 | assert(!lessThan(u8, "", "")); | |
| 234 | assert(lessThan(u8, "", "a")); | |
| 231 | testing.expect(lessThan(u8, "abcd", "bee")); | |
| 232 | testing.expect(!lessThan(u8, "abc", "abc")); | |
| 233 | testing.expect(lessThan(u8, "abc", "abc0")); | |
| 234 | testing.expect(!lessThan(u8, "", "")); | |
| 235 | testing.expect(lessThan(u8, "", "a")); | |
| 235 | 236 | } |
| 236 | 237 | |
| 237 | 238 | /// Compares two slices and returns whether they are equal. |
| ... | ... | @@ -296,10 +297,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co |
| 296 | 297 | } |
| 297 | 298 | |
| 298 | 299 | test "mem.trim" { |
| 299 | assert(eql(u8, trimLeft(u8, " foo\n ", " \n"), "foo\n ")); | |
| 300 | assert(eql(u8, trimRight(u8, " foo\n ", " \n"), " foo")); | |
| 301 | assert(eql(u8, trim(u8, " foo\n ", " \n"), "foo")); | |
| 302 | assert(eql(u8, trim(u8, "foo", " \n"), "foo")); | |
| 300 | testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); | |
| 301 | testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); | |
| 302 | testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); | |
| 303 | testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n")); | |
| 303 | 304 | } |
| 304 | 305 | |
| 305 | 306 | /// Linear search for the index of a scalar value inside a slice. |
| ... | ... | @@ -380,20 +381,20 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee |
| 380 | 381 | } |
| 381 | 382 | |
| 382 | 383 | test "mem.indexOf" { |
| 383 | assert(indexOf(u8, "one two three four", "four").? == 14); | |
| 384 | assert(lastIndexOf(u8, "one two three two four", "two").? == 14); | |
| 385 | assert(indexOf(u8, "one two three four", "gour") == null); | |
| 386 | assert(lastIndexOf(u8, "one two three four", "gour") == null); | |
| 387 | assert(indexOf(u8, "foo", "foo").? == 0); | |
| 388 | assert(lastIndexOf(u8, "foo", "foo").? == 0); | |
| 389 | assert(indexOf(u8, "foo", "fool") == null); | |
| 390 | assert(lastIndexOf(u8, "foo", "lfoo") == null); | |
| 391 | assert(lastIndexOf(u8, "foo", "fool") == null); | |
| 392 | ||
| 393 | assert(indexOf(u8, "foo foo", "foo").? == 0); | |
| 394 | assert(lastIndexOf(u8, "foo foo", "foo").? == 4); | |
| 395 | assert(lastIndexOfAny(u8, "boo, cat", "abo").? == 6); | |
| 396 | assert(lastIndexOfScalar(u8, "boo", 'o').? == 2); | |
| 384 | testing.expect(indexOf(u8, "one two three four", "four").? == 14); | |
| 385 | testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14); | |
| 386 | testing.expect(indexOf(u8, "one two three four", "gour") == null); | |
| 387 | testing.expect(lastIndexOf(u8, "one two three four", "gour") == null); | |
| 388 | testing.expect(indexOf(u8, "foo", "foo").? == 0); | |
| 389 | testing.expect(lastIndexOf(u8, "foo", "foo").? == 0); | |
| 390 | testing.expect(indexOf(u8, "foo", "fool") == null); | |
| 391 | testing.expect(lastIndexOf(u8, "foo", "lfoo") == null); | |
| 392 | testing.expect(lastIndexOf(u8, "foo", "fool") == null); | |
| 393 | ||
| 394 | testing.expect(indexOf(u8, "foo foo", "foo").? == 0); | |
| 395 | testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4); | |
| 396 | testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6); | |
| 397 | testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2); | |
| 397 | 398 | } |
| 398 | 399 | |
| 399 | 400 | /// Reads an integer from memory with size equal to bytes.len. |
| ... | ... | @@ -504,34 +505,34 @@ test "comptime read/write int" { |
| 504 | 505 | var bytes: [2]u8 = undefined; |
| 505 | 506 | std.mem.writeIntLittle(u16, &bytes, 0x1234); |
| 506 | 507 | const result = std.mem.readIntBig(u16, &bytes); |
| 507 | std.debug.assert(result == 0x3412); | |
| 508 | testing.expect(result == 0x3412); | |
| 508 | 509 | } |
| 509 | 510 | comptime { |
| 510 | 511 | var bytes: [2]u8 = undefined; |
| 511 | 512 | std.mem.writeIntBig(u16, &bytes, 0x1234); |
| 512 | 513 | const result = std.mem.readIntLittle(u16, &bytes); |
| 513 | std.debug.assert(result == 0x3412); | |
| 514 | testing.expect(result == 0x3412); | |
| 514 | 515 | } |
| 515 | 516 | } |
| 516 | 517 | |
| 517 | 518 | test "readIntBig and readIntLittle" { |
| 518 | assert(readIntSliceBig(u0, []u8{}) == 0x0); | |
| 519 | assert(readIntSliceLittle(u0, []u8{}) == 0x0); | |
| 519 | testing.expect(readIntSliceBig(u0, []u8{}) == 0x0); | |
| 520 | testing.expect(readIntSliceLittle(u0, []u8{}) == 0x0); | |
| 520 | 521 | |
| 521 | assert(readIntSliceBig(u8, []u8{0x32}) == 0x32); | |
| 522 | assert(readIntSliceLittle(u8, []u8{0x12}) == 0x12); | |
| 522 | testing.expect(readIntSliceBig(u8, []u8{0x32}) == 0x32); | |
| 523 | testing.expect(readIntSliceLittle(u8, []u8{0x12}) == 0x12); | |
| 523 | 524 | |
| 524 | assert(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234); | |
| 525 | assert(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412); | |
| 525 | testing.expect(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234); | |
| 526 | testing.expect(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412); | |
| 526 | 527 | |
| 527 | assert(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); | |
| 528 | assert(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); | |
| 528 | testing.expect(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); | |
| 529 | testing.expect(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); | |
| 529 | 530 | |
| 530 | assert(readIntSliceBig(i8, []u8{0xff}) == -1); | |
| 531 | assert(readIntSliceLittle(i8, []u8{0xfe}) == -2); | |
| 531 | testing.expect(readIntSliceBig(i8, []u8{0xff}) == -1); | |
| 532 | testing.expect(readIntSliceLittle(i8, []u8{0xfe}) == -2); | |
| 532 | 533 | |
| 533 | assert(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3); | |
| 534 | assert(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4); | |
| 534 | testing.expect(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3); | |
| 535 | testing.expect(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4); | |
| 535 | 536 | } |
| 536 | 537 | |
| 537 | 538 | /// Writes an integer to memory, storing it in twos-complement. |
| ... | ... | @@ -645,34 +646,34 @@ test "writeIntBig and writeIntLittle" { |
| 645 | 646 | var buf9: [9]u8 = undefined; |
| 646 | 647 | |
| 647 | 648 | writeIntBig(u0, &buf0, 0x0); |
| 648 | assert(eql_slice_u8(buf0[0..], []u8{})); | |
| 649 | testing.expect(eql_slice_u8(buf0[0..], []u8{})); | |
| 649 | 650 | writeIntLittle(u0, &buf0, 0x0); |
| 650 | assert(eql_slice_u8(buf0[0..], []u8{})); | |
| 651 | testing.expect(eql_slice_u8(buf0[0..], []u8{})); | |
| 651 | 652 | |
| 652 | 653 | writeIntBig(u8, &buf1, 0x12); |
| 653 | assert(eql_slice_u8(buf1[0..], []u8{0x12})); | |
| 654 | testing.expect(eql_slice_u8(buf1[0..], []u8{0x12})); | |
| 654 | 655 | writeIntLittle(u8, &buf1, 0x34); |
| 655 | assert(eql_slice_u8(buf1[0..], []u8{0x34})); | |
| 656 | testing.expect(eql_slice_u8(buf1[0..], []u8{0x34})); | |
| 656 | 657 | |
| 657 | 658 | writeIntBig(u16, &buf2, 0x1234); |
| 658 | assert(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 })); | |
| 659 | testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 })); | |
| 659 | 660 | writeIntLittle(u16, &buf2, 0x5678); |
| 660 | assert(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 })); | |
| 661 | testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 })); | |
| 661 | 662 | |
| 662 | 663 | writeIntBig(u72, &buf9, 0x123456789abcdef024); |
| 663 | assert(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 664 | testing.expect(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 664 | 665 | writeIntLittle(u72, &buf9, 0xfedcba9876543210ec); |
| 665 | assert(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 666 | testing.expect(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 666 | 667 | |
| 667 | 668 | writeIntBig(i8, &buf1, -1); |
| 668 | assert(eql_slice_u8(buf1[0..], []u8{0xff})); | |
| 669 | testing.expect(eql_slice_u8(buf1[0..], []u8{0xff})); | |
| 669 | 670 | writeIntLittle(i8, &buf1, -2); |
| 670 | assert(eql_slice_u8(buf1[0..], []u8{0xfe})); | |
| 671 | testing.expect(eql_slice_u8(buf1[0..], []u8{0xfe})); | |
| 671 | 672 | |
| 672 | 673 | writeIntBig(i16, &buf2, -3); |
| 673 | assert(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd })); | |
| 674 | testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd })); | |
| 674 | 675 | writeIntLittle(i16, &buf2, -4); |
| 675 | assert(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff })); | |
| 676 | testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff })); | |
| 676 | 677 | } |
| 677 | 678 | |
| 678 | 679 | pub fn hash_slice_u8(k: []const u8) u32 { |
| ... | ... | @@ -706,46 +707,46 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator { |
| 706 | 707 | |
| 707 | 708 | test "mem.tokenize" { |
| 708 | 709 | var it = tokenize(" abc def ghi ", " "); |
| 709 | assert(eql(u8, it.next().?, "abc")); | |
| 710 | assert(eql(u8, it.next().?, "def")); | |
| 711 | assert(eql(u8, it.next().?, "ghi")); | |
| 712 | assert(it.next() == null); | |
| 710 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 711 | testing.expect(eql(u8, it.next().?, "def")); | |
| 712 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 713 | testing.expect(it.next() == null); | |
| 713 | 714 | |
| 714 | 715 | it = tokenize("..\\bob", "\\"); |
| 715 | assert(eql(u8, it.next().?, "..")); | |
| 716 | assert(eql(u8, "..", "..\\bob"[0..it.index])); | |
| 717 | assert(eql(u8, it.next().?, "bob")); | |
| 718 | assert(it.next() == null); | |
| 716 | testing.expect(eql(u8, it.next().?, "..")); | |
| 717 | testing.expect(eql(u8, "..", "..\\bob"[0..it.index])); | |
| 718 | testing.expect(eql(u8, it.next().?, "bob")); | |
| 719 | testing.expect(it.next() == null); | |
| 719 | 720 | |
| 720 | 721 | it = tokenize("//a/b", "/"); |
| 721 | assert(eql(u8, it.next().?, "a")); | |
| 722 | assert(eql(u8, it.next().?, "b")); | |
| 723 | assert(eql(u8, "//a/b", "//a/b"[0..it.index])); | |
| 724 | assert(it.next() == null); | |
| 722 | testing.expect(eql(u8, it.next().?, "a")); | |
| 723 | testing.expect(eql(u8, it.next().?, "b")); | |
| 724 | testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index])); | |
| 725 | testing.expect(it.next() == null); | |
| 725 | 726 | |
| 726 | 727 | it = tokenize("|", "|"); |
| 727 | assert(it.next() == null); | |
| 728 | testing.expect(it.next() == null); | |
| 728 | 729 | |
| 729 | 730 | it = tokenize("", "|"); |
| 730 | assert(it.next() == null); | |
| 731 | testing.expect(it.next() == null); | |
| 731 | 732 | |
| 732 | 733 | it = tokenize("hello", ""); |
| 733 | assert(eql(u8, it.next().?, "hello")); | |
| 734 | assert(it.next() == null); | |
| 734 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 735 | testing.expect(it.next() == null); | |
| 735 | 736 | |
| 736 | 737 | it = tokenize("hello", " "); |
| 737 | assert(eql(u8, it.next().?, "hello")); | |
| 738 | assert(it.next() == null); | |
| 738 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 739 | testing.expect(it.next() == null); | |
| 739 | 740 | } |
| 740 | 741 | |
| 741 | 742 | test "mem.tokenize (multibyte)" { |
| 742 | 743 | var it = tokenize("a|b,c/d e", " /,|"); |
| 743 | assert(eql(u8, it.next().?, "a")); | |
| 744 | assert(eql(u8, it.next().?, "b")); | |
| 745 | assert(eql(u8, it.next().?, "c")); | |
| 746 | assert(eql(u8, it.next().?, "d")); | |
| 747 | assert(eql(u8, it.next().?, "e")); | |
| 748 | assert(it.next() == null); | |
| 744 | testing.expect(eql(u8, it.next().?, "a")); | |
| 745 | testing.expect(eql(u8, it.next().?, "b")); | |
| 746 | testing.expect(eql(u8, it.next().?, "c")); | |
| 747 | testing.expect(eql(u8, it.next().?, "d")); | |
| 748 | testing.expect(eql(u8, it.next().?, "e")); | |
| 749 | testing.expect(it.next() == null); | |
| 749 | 750 | } |
| 750 | 751 | |
| 751 | 752 | /// Returns an iterator that iterates over the slices of `buffer` that |
| ... | ... | @@ -769,34 +770,34 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator { |
| 769 | 770 | |
| 770 | 771 | test "mem.separate" { |
| 771 | 772 | var it = separate("abc|def||ghi", "|"); |
| 772 | assert(eql(u8, it.next().?, "abc")); | |
| 773 | assert(eql(u8, it.next().?, "def")); | |
| 774 | assert(eql(u8, it.next().?, "")); | |
| 775 | assert(eql(u8, it.next().?, "ghi")); | |
| 776 | assert(it.next() == null); | |
| 773 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 774 | testing.expect(eql(u8, it.next().?, "def")); | |
| 775 | testing.expect(eql(u8, it.next().?, "")); | |
| 776 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 777 | testing.expect(it.next() == null); | |
| 777 | 778 | |
| 778 | 779 | it = separate("", "|"); |
| 779 | assert(eql(u8, it.next().?, "")); | |
| 780 | assert(it.next() == null); | |
| 780 | testing.expect(eql(u8, it.next().?, "")); | |
| 781 | testing.expect(it.next() == null); | |
| 781 | 782 | |
| 782 | 783 | it = separate("|", "|"); |
| 783 | assert(eql(u8, it.next().?, "")); | |
| 784 | assert(eql(u8, it.next().?, "")); | |
| 785 | assert(it.next() == null); | |
| 784 | testing.expect(eql(u8, it.next().?, "")); | |
| 785 | testing.expect(eql(u8, it.next().?, "")); | |
| 786 | testing.expect(it.next() == null); | |
| 786 | 787 | |
| 787 | 788 | it = separate("hello", " "); |
| 788 | assert(eql(u8, it.next().?, "hello")); | |
| 789 | assert(it.next() == null); | |
| 789 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 790 | testing.expect(it.next() == null); | |
| 790 | 791 | } |
| 791 | 792 | |
| 792 | 793 | test "mem.separate (multibyte)" { |
| 793 | 794 | var it = separate("a, b ,, c, d, e", ", "); |
| 794 | assert(eql(u8, it.next().?, "a")); | |
| 795 | assert(eql(u8, it.next().?, "b ,")); | |
| 796 | assert(eql(u8, it.next().?, "c")); | |
| 797 | assert(eql(u8, it.next().?, "d")); | |
| 798 | assert(eql(u8, it.next().?, "e")); | |
| 799 | assert(it.next() == null); | |
| 795 | testing.expect(eql(u8, it.next().?, "a")); | |
| 796 | testing.expect(eql(u8, it.next().?, "b ,")); | |
| 797 | testing.expect(eql(u8, it.next().?, "c")); | |
| 798 | testing.expect(eql(u8, it.next().?, "d")); | |
| 799 | testing.expect(eql(u8, it.next().?, "e")); | |
| 800 | testing.expect(it.next() == null); | |
| 800 | 801 | } |
| 801 | 802 | |
| 802 | 803 | pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| ... | ... | @@ -804,8 +805,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool |
| 804 | 805 | } |
| 805 | 806 | |
| 806 | 807 | test "mem.startsWith" { |
| 807 | assert(startsWith(u8, "Bob", "Bo")); | |
| 808 | assert(!startsWith(u8, "Needle in haystack", "haystack")); | |
| 808 | testing.expect(startsWith(u8, "Bob", "Bo")); | |
| 809 | testing.expect(!startsWith(u8, "Needle in haystack", "haystack")); | |
| 809 | 810 | } |
| 810 | 811 | |
| 811 | 812 | pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| ... | ... | @@ -813,8 +814,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| 813 | 814 | } |
| 814 | 815 | |
| 815 | 816 | test "mem.endsWith" { |
| 816 | assert(endsWith(u8, "Needle in haystack", "haystack")); | |
| 817 | assert(!endsWith(u8, "Bob", "Bo")); | |
| 817 | testing.expect(endsWith(u8, "Needle in haystack", "haystack")); | |
| 818 | testing.expect(!endsWith(u8, "Bob", "Bo")); | |
| 818 | 819 | } |
| 819 | 820 | |
| 820 | 821 | pub const TokenIterator = struct { |
| ... | ... | @@ -913,15 +914,15 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons |
| 913 | 914 | test "mem.join" { |
| 914 | 915 | var buf: [1024]u8 = undefined; |
| 915 | 916 | const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; |
| 916 | assert(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c")); | |
| 917 | assert(eql(u8, try join(a, ",", [][]const u8{"a"}), "a")); | |
| 918 | assert(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c")); | |
| 917 | testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c")); | |
| 918 | testing.expect(eql(u8, try join(a, ",", [][]const u8{"a"}), "a")); | |
| 919 | testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c")); | |
| 919 | 920 | } |
| 920 | 921 | |
| 921 | 922 | test "testStringEquality" { |
| 922 | assert(eql(u8, "abcd", "abcd")); | |
| 923 | assert(!eql(u8, "abcdef", "abZdef")); | |
| 924 | assert(!eql(u8, "abcdefg", "abcdef")); | |
| 923 | testing.expect(eql(u8, "abcd", "abcd")); | |
| 924 | testing.expect(!eql(u8, "abcdef", "abZdef")); | |
| 925 | testing.expect(!eql(u8, "abcdefg", "abcdef")); | |
| 925 | 926 | } |
| 926 | 927 | |
| 927 | 928 | test "testReadInt" { |
| ... | ... | @@ -936,12 +937,12 @@ fn testReadIntImpl() void { |
| 936 | 937 | 0x56, |
| 937 | 938 | 0x78, |
| 938 | 939 | }; |
| 939 | assert(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678); | |
| 940 | assert(readIntBig(u32, &bytes) == 0x12345678); | |
| 941 | assert(readIntBig(i32, &bytes) == 0x12345678); | |
| 942 | assert(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412); | |
| 943 | assert(readIntLittle(u32, &bytes) == 0x78563412); | |
| 944 | assert(readIntLittle(i32, &bytes) == 0x78563412); | |
| 940 | testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678); | |
| 941 | testing.expect(readIntBig(u32, &bytes) == 0x12345678); | |
| 942 | testing.expect(readIntBig(i32, &bytes) == 0x12345678); | |
| 943 | testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412); | |
| 944 | testing.expect(readIntLittle(u32, &bytes) == 0x78563412); | |
| 945 | testing.expect(readIntLittle(i32, &bytes) == 0x78563412); | |
| 945 | 946 | } |
| 946 | 947 | { |
| 947 | 948 | const buf = []u8{ |
| ... | ... | @@ -951,7 +952,7 @@ fn testReadIntImpl() void { |
| 951 | 952 | 0x34, |
| 952 | 953 | }; |
| 953 | 954 | const answer = readInt(u32, &buf, builtin.Endian.Big); |
| 954 | assert(answer == 0x00001234); | |
| 955 | testing.expect(answer == 0x00001234); | |
| 955 | 956 | } |
| 956 | 957 | { |
| 957 | 958 | const buf = []u8{ |
| ... | ... | @@ -961,17 +962,17 @@ fn testReadIntImpl() void { |
| 961 | 962 | 0x00, |
| 962 | 963 | }; |
| 963 | 964 | const answer = readInt(u32, &buf, builtin.Endian.Little); |
| 964 | assert(answer == 0x00003412); | |
| 965 | testing.expect(answer == 0x00003412); | |
| 965 | 966 | } |
| 966 | 967 | { |
| 967 | 968 | const bytes = []u8{ |
| 968 | 969 | 0xff, |
| 969 | 970 | 0xfe, |
| 970 | 971 | }; |
| 971 | assert(readIntBig(u16, &bytes) == 0xfffe); | |
| 972 | assert(readIntBig(i16, &bytes) == -0x0002); | |
| 973 | assert(readIntLittle(u16, &bytes) == 0xfeff); | |
| 974 | assert(readIntLittle(i16, &bytes) == -0x0101); | |
| 972 | testing.expect(readIntBig(u16, &bytes) == 0xfffe); | |
| 973 | testing.expect(readIntBig(i16, &bytes) == -0x0002); | |
| 974 | testing.expect(readIntLittle(u16, &bytes) == 0xfeff); | |
| 975 | testing.expect(readIntLittle(i16, &bytes) == -0x0101); | |
| 975 | 976 | } |
| 976 | 977 | } |
| 977 | 978 | |
| ... | ... | @@ -983,19 +984,19 @@ fn testWriteIntImpl() void { |
| 983 | 984 | var bytes: [8]u8 = undefined; |
| 984 | 985 | |
| 985 | 986 | writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big); |
| 986 | assert(eql(u8, bytes, []u8{ | |
| 987 | testing.expect(eql(u8, bytes, []u8{ | |
| 987 | 988 | 0x00, 0x00, 0x00, 0x00, |
| 988 | 989 | 0x00, 0x00, 0x00, 0x00, |
| 989 | 990 | })); |
| 990 | 991 | |
| 991 | 992 | writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little); |
| 992 | assert(eql(u8, bytes, []u8{ | |
| 993 | testing.expect(eql(u8, bytes, []u8{ | |
| 993 | 994 | 0x00, 0x00, 0x00, 0x00, |
| 994 | 995 | 0x00, 0x00, 0x00, 0x00, |
| 995 | 996 | })); |
| 996 | 997 | |
| 997 | 998 | writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big); |
| 998 | assert(eql(u8, bytes, []u8{ | |
| 999 | testing.expect(eql(u8, bytes, []u8{ | |
| 999 | 1000 | 0x12, |
| 1000 | 1001 | 0x34, |
| 1001 | 1002 | 0x56, |
| ... | ... | @@ -1007,7 +1008,7 @@ fn testWriteIntImpl() void { |
| 1007 | 1008 | })); |
| 1008 | 1009 | |
| 1009 | 1010 | writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little); |
| 1010 | assert(eql(u8, bytes, []u8{ | |
| 1011 | testing.expect(eql(u8, bytes, []u8{ | |
| 1011 | 1012 | 0x12, |
| 1012 | 1013 | 0x34, |
| 1013 | 1014 | 0x56, |
| ... | ... | @@ -1019,7 +1020,7 @@ fn testWriteIntImpl() void { |
| 1019 | 1020 | })); |
| 1020 | 1021 | |
| 1021 | 1022 | writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big); |
| 1022 | assert(eql(u8, bytes, []u8{ | |
| 1023 | testing.expect(eql(u8, bytes, []u8{ | |
| 1023 | 1024 | 0x00, |
| 1024 | 1025 | 0x00, |
| 1025 | 1026 | 0x00, |
| ... | ... | @@ -1031,7 +1032,7 @@ fn testWriteIntImpl() void { |
| 1031 | 1032 | })); |
| 1032 | 1033 | |
| 1033 | 1034 | writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little); |
| 1034 | assert(eql(u8, bytes, []u8{ | |
| 1035 | testing.expect(eql(u8, bytes, []u8{ | |
| 1035 | 1036 | 0x12, |
| 1036 | 1037 | 0x34, |
| 1037 | 1038 | 0x56, |
| ... | ... | @@ -1043,7 +1044,7 @@ fn testWriteIntImpl() void { |
| 1043 | 1044 | })); |
| 1044 | 1045 | |
| 1045 | 1046 | writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big); |
| 1046 | assert(eql(u8, bytes, []u8{ | |
| 1047 | testing.expect(eql(u8, bytes, []u8{ | |
| 1047 | 1048 | 0x00, |
| 1048 | 1049 | 0x00, |
| 1049 | 1050 | 0x00, |
| ... | ... | @@ -1055,7 +1056,7 @@ fn testWriteIntImpl() void { |
| 1055 | 1056 | })); |
| 1056 | 1057 | |
| 1057 | 1058 | writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little); |
| 1058 | assert(eql(u8, bytes, []u8{ | |
| 1059 | testing.expect(eql(u8, bytes, []u8{ | |
| 1059 | 1060 | 0x34, |
| 1060 | 1061 | 0x12, |
| 1061 | 1062 | 0x00, |
| ... | ... | @@ -1076,7 +1077,7 @@ pub fn min(comptime T: type, slice: []const T) T { |
| 1076 | 1077 | } |
| 1077 | 1078 | |
| 1078 | 1079 | test "mem.min" { |
| 1079 | assert(min(u8, "abcdefg") == 'a'); | |
| 1080 | testing.expect(min(u8, "abcdefg") == 'a'); | |
| 1080 | 1081 | } |
| 1081 | 1082 | |
| 1082 | 1083 | pub fn max(comptime T: type, slice: []const T) T { |
| ... | ... | @@ -1088,7 +1089,7 @@ pub fn max(comptime T: type, slice: []const T) T { |
| 1088 | 1089 | } |
| 1089 | 1090 | |
| 1090 | 1091 | test "mem.max" { |
| 1091 | assert(max(u8, "abcdefg") == 'g'); | |
| 1092 | testing.expect(max(u8, "abcdefg") == 'g'); | |
| 1092 | 1093 | } |
| 1093 | 1094 | |
| 1094 | 1095 | pub fn swap(comptime T: type, a: *T, b: *T) void { |
| ... | ... | @@ -1116,7 +1117,7 @@ test "std.mem.reverse" { |
| 1116 | 1117 | }; |
| 1117 | 1118 | reverse(i32, arr[0..]); |
| 1118 | 1119 | |
| 1119 | assert(eql(i32, arr, []i32{ | |
| 1120 | testing.expect(eql(i32, arr, []i32{ | |
| 1120 | 1121 | 4, |
| 1121 | 1122 | 2, |
| 1122 | 1123 | 1, |
| ... | ... | @@ -1143,7 +1144,7 @@ test "std.mem.rotate" { |
| 1143 | 1144 | }; |
| 1144 | 1145 | rotate(i32, arr[0..], 2); |
| 1145 | 1146 | |
| 1146 | assert(eql(i32, arr, []i32{ | |
| 1147 | testing.expect(eql(i32, arr, []i32{ | |
| 1147 | 1148 | 1, |
| 1148 | 1149 | 2, |
| 1149 | 1150 | 4, |
| ... | ... | @@ -1225,12 +1226,12 @@ test "std.mem.asBytes" { |
| 1225 | 1226 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| 1226 | 1227 | }; |
| 1227 | 1228 | |
| 1228 | debug.assert(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | |
| 1229 | testing.expect(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | |
| 1229 | 1230 | |
| 1230 | 1231 | var codeface = u32(0xC0DEFACE); |
| 1231 | 1232 | for (asBytes(&codeface).*) |*b| |
| 1232 | 1233 | b.* = 0; |
| 1233 | debug.assert(codeface == 0); | |
| 1234 | testing.expect(codeface == 0); | |
| 1234 | 1235 | |
| 1235 | 1236 | const S = packed struct { |
| 1236 | 1237 | a: u8, |
| ... | ... | @@ -1245,7 +1246,7 @@ test "std.mem.asBytes" { |
| 1245 | 1246 | .c = 0xDE, |
| 1246 | 1247 | .d = 0xA1, |
| 1247 | 1248 | }; |
| 1248 | debug.assert(std.mem.eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | |
| 1249 | testing.expect(std.mem.eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | |
| 1249 | 1250 | } |
| 1250 | 1251 | |
| 1251 | 1252 | ///Given any value, returns a copy of its bytes in an array. |
| ... | ... | @@ -1256,14 +1257,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { |
| 1256 | 1257 | test "std.mem.toBytes" { |
| 1257 | 1258 | var my_bytes = toBytes(u32(0x12345678)); |
| 1258 | 1259 | switch (builtin.endian) { |
| 1259 | builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x12\x34\x56\x78")), | |
| 1260 | builtin.Endian.Little => debug.assert(std.mem.eql(u8, my_bytes, "\x78\x56\x34\x12")), | |
| 1260 | builtin.Endian.Big => testing.expect(std.mem.eql(u8, my_bytes, "\x12\x34\x56\x78")), | |
| 1261 | builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x78\x56\x34\x12")), | |
| 1261 | 1262 | } |
| 1262 | 1263 | |
| 1263 | 1264 | my_bytes[0] = '\x99'; |
| 1264 | 1265 | switch (builtin.endian) { |
| 1265 | builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x99\x34\x56\x78")), | |
| 1266 | builtin.Endian.Little => debug.assert(std.mem.eql(u8, my_bytes, "\x99\x56\x34\x12")), | |
| 1266 | builtin.Endian.Big => testing.expect(std.mem.eql(u8, my_bytes, "\x99\x34\x56\x78")), | |
| 1267 | builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x99\x56\x34\x12")), | |
| 1267 | 1268 | } |
| 1268 | 1269 | } |
| 1269 | 1270 | |
| ... | ... | @@ -1292,17 +1293,17 @@ test "std.mem.bytesAsValue" { |
| 1292 | 1293 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", |
| 1293 | 1294 | }; |
| 1294 | 1295 | |
| 1295 | debug.assert(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*); | |
| 1296 | testing.expect(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*); | |
| 1296 | 1297 | |
| 1297 | 1298 | var codeface_bytes = switch (builtin.endian) { |
| 1298 | 1299 | builtin.Endian.Big => "\xC0\xDE\xFA\xCE", |
| 1299 | 1300 | builtin.Endian.Little => "\xCE\xFA\xDE\xC0", |
| 1300 | 1301 | }; |
| 1301 | 1302 | var codeface = bytesAsValue(u32, &codeface_bytes); |
| 1302 | debug.assert(codeface.* == 0xC0DEFACE); | |
| 1303 | testing.expect(codeface.* == 0xC0DEFACE); | |
| 1303 | 1304 | codeface.* = 0; |
| 1304 | 1305 | for (codeface_bytes) |b| |
| 1305 | debug.assert(b == 0); | |
| 1306 | testing.expect(b == 0); | |
| 1306 | 1307 | |
| 1307 | 1308 | const S = packed struct { |
| 1308 | 1309 | a: u8, |
| ... | ... | @@ -1319,7 +1320,7 @@ test "std.mem.bytesAsValue" { |
| 1319 | 1320 | }; |
| 1320 | 1321 | const inst_bytes = "\xBE\xEF\xDE\xA1"; |
| 1321 | 1322 | const inst2 = bytesAsValue(S, &inst_bytes); |
| 1322 | debug.assert(meta.eql(inst, inst2.*)); | |
| 1323 | testing.expect(meta.eql(inst, inst2.*)); | |
| 1323 | 1324 | } |
| 1324 | 1325 | |
| 1325 | 1326 | ///Given a pointer to an array of bytes, returns a value of the specified type backed by a |
| ... | ... | @@ -1334,7 +1335,7 @@ test "std.mem.bytesToValue" { |
| 1334 | 1335 | }; |
| 1335 | 1336 | |
| 1336 | 1337 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
| 1337 | debug.assert(deadbeef == u32(0xDEADBEEF)); | |
| 1338 | testing.expect(deadbeef == u32(0xDEADBEEF)); | |
| 1338 | 1339 | } |
| 1339 | 1340 | |
| 1340 | 1341 | fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { |
| ... | ... | @@ -1345,7 +1346,7 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { |
| 1345 | 1346 | |
| 1346 | 1347 | ///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness. |
| 1347 | 1348 | pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) { |
| 1348 | debug.assert(start + length <= ptr.*.len); | |
| 1349 | assert(start + length <= ptr.*.len); | |
| 1349 | 1350 | |
| 1350 | 1351 | const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length); |
| 1351 | 1352 | const T = meta.Child(meta.Child(@typeOf(ptr))); |
| ... | ... | @@ -1355,14 +1356,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA |
| 1355 | 1356 | test "std.mem.subArrayPtr" { |
| 1356 | 1357 | const a1 = "abcdef"; |
| 1357 | 1358 | const sub1 = subArrayPtr(&a1, 2, 3); |
| 1358 | debug.assert(std.mem.eql(u8, sub1.*, "cde")); | |
| 1359 | testing.expect(std.mem.eql(u8, sub1.*, "cde")); | |
| 1359 | 1360 | |
| 1360 | 1361 | var a2 = "abcdef"; |
| 1361 | 1362 | var sub2 = subArrayPtr(&a2, 2, 3); |
| 1362 | 1363 | |
| 1363 | debug.assert(std.mem.eql(u8, sub2, "cde")); | |
| 1364 | testing.expect(std.mem.eql(u8, sub2, "cde")); | |
| 1364 | 1365 | sub2[1] = 'X'; |
| 1365 | debug.assert(std.mem.eql(u8, a2, "abcXef")); | |
| 1366 | testing.expect(std.mem.eql(u8, a2, "abcXef")); | |
| 1366 | 1367 | } |
| 1367 | 1368 | |
| 1368 | 1369 | /// Round an address up to the nearest aligned address |
| ... | ... | @@ -1371,16 +1372,16 @@ pub fn alignForward(addr: usize, alignment: usize) usize { |
| 1371 | 1372 | } |
| 1372 | 1373 | |
| 1373 | 1374 | test "std.mem.alignForward" { |
| 1374 | debug.assertOrPanic(alignForward(1, 1) == 1); | |
| 1375 | debug.assertOrPanic(alignForward(2, 1) == 2); | |
| 1376 | debug.assertOrPanic(alignForward(1, 2) == 2); | |
| 1377 | debug.assertOrPanic(alignForward(2, 2) == 2); | |
| 1378 | debug.assertOrPanic(alignForward(3, 2) == 4); | |
| 1379 | debug.assertOrPanic(alignForward(4, 2) == 4); | |
| 1380 | debug.assertOrPanic(alignForward(7, 8) == 8); | |
| 1381 | debug.assertOrPanic(alignForward(8, 8) == 8); | |
| 1382 | debug.assertOrPanic(alignForward(9, 8) == 16); | |
| 1383 | debug.assertOrPanic(alignForward(15, 8) == 16); | |
| 1384 | debug.assertOrPanic(alignForward(16, 8) == 16); | |
| 1385 | debug.assertOrPanic(alignForward(17, 8) == 24); | |
| 1375 | testing.expect(alignForward(1, 1) == 1); | |
| 1376 | testing.expect(alignForward(2, 1) == 2); | |
| 1377 | testing.expect(alignForward(1, 2) == 2); | |
| 1378 | testing.expect(alignForward(2, 2) == 2); | |
| 1379 | testing.expect(alignForward(3, 2) == 4); | |
| 1380 | testing.expect(alignForward(4, 2) == 4); | |
| 1381 | testing.expect(alignForward(7, 8) == 8); | |
| 1382 | testing.expect(alignForward(8, 8) == 8); | |
| 1383 | testing.expect(alignForward(9, 8) == 16); | |
| 1384 | testing.expect(alignForward(15, 8) == 16); | |
| 1385 | testing.expect(alignForward(16, 8) == 16); | |
| 1386 | testing.expect(alignForward(17, 8) == 24); | |
| 1386 | 1387 | } |
std/meta/index.zig+76-75| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const debug = std.debug; |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const math = std.math; |
| 6 | const testing = std.testing; | |
| 6 | 7 | |
| 7 | 8 | pub const trait = @import("trait.zig"); |
| 8 | 9 | |
| ... | ... | @@ -64,16 +65,16 @@ test "std.meta.tagName" { |
| 64 | 65 | var u2a = U2{ .C = 0 }; |
| 65 | 66 | var u2b = U2{ .D = 0 }; |
| 66 | 67 | |
| 67 | debug.assert(mem.eql(u8, tagName(E1.A), "A")); | |
| 68 | debug.assert(mem.eql(u8, tagName(E1.B), "B")); | |
| 69 | debug.assert(mem.eql(u8, tagName(E2.C), "C")); | |
| 70 | debug.assert(mem.eql(u8, tagName(E2.D), "D")); | |
| 71 | debug.assert(mem.eql(u8, tagName(error.E), "E")); | |
| 72 | debug.assert(mem.eql(u8, tagName(error.F), "F")); | |
| 73 | debug.assert(mem.eql(u8, tagName(u1g), "G")); | |
| 74 | debug.assert(mem.eql(u8, tagName(u1h), "H")); | |
| 75 | debug.assert(mem.eql(u8, tagName(u2a), "C")); | |
| 76 | debug.assert(mem.eql(u8, tagName(u2b), "D")); | |
| 68 | testing.expect(mem.eql(u8, tagName(E1.A), "A")); | |
| 69 | testing.expect(mem.eql(u8, tagName(E1.B), "B")); | |
| 70 | testing.expect(mem.eql(u8, tagName(E2.C), "C")); | |
| 71 | testing.expect(mem.eql(u8, tagName(E2.D), "D")); | |
| 72 | testing.expect(mem.eql(u8, tagName(error.E), "E")); | |
| 73 | testing.expect(mem.eql(u8, tagName(error.F), "F")); | |
| 74 | testing.expect(mem.eql(u8, tagName(u1g), "G")); | |
| 75 | testing.expect(mem.eql(u8, tagName(u1h), "H")); | |
| 76 | testing.expect(mem.eql(u8, tagName(u2a), "C")); | |
| 77 | testing.expect(mem.eql(u8, tagName(u2b), "D")); | |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | pub fn stringToEnum(comptime T: type, str: []const u8) ?T { |
| ... | ... | @@ -90,9 +91,9 @@ test "std.meta.stringToEnum" { |
| 90 | 91 | A, |
| 91 | 92 | B, |
| 92 | 93 | }; |
| 93 | debug.assert(E1.A == stringToEnum(E1, "A").?); | |
| 94 | debug.assert(E1.B == stringToEnum(E1, "B").?); | |
| 95 | debug.assert(null == stringToEnum(E1, "C")); | |
| 94 | testing.expect(E1.A == stringToEnum(E1, "A").?); | |
| 95 | testing.expect(E1.B == stringToEnum(E1, "B").?); | |
| 96 | testing.expect(null == stringToEnum(E1, "C")); | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | pub fn bitCount(comptime T: type) comptime_int { |
| ... | ... | @@ -104,8 +105,8 @@ pub fn bitCount(comptime T: type) comptime_int { |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | test "std.meta.bitCount" { |
| 107 | debug.assert(bitCount(u8) == 8); | |
| 108 | debug.assert(bitCount(f32) == 32); | |
| 108 | testing.expect(bitCount(u8) == 8); | |
| 109 | testing.expect(bitCount(f32) == 32); | |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | 112 | pub fn alignment(comptime T: type) comptime_int { |
| ... | ... | @@ -115,11 +116,11 @@ pub fn alignment(comptime T: type) comptime_int { |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | test "std.meta.alignment" { |
| 118 | debug.assert(alignment(u8) == 1); | |
| 119 | debug.assert(alignment(*align(1) u8) == 1); | |
| 120 | debug.assert(alignment(*align(2) u8) == 2); | |
| 121 | debug.assert(alignment([]align(1) u8) == 1); | |
| 122 | debug.assert(alignment([]align(2) u8) == 2); | |
| 119 | testing.expect(alignment(u8) == 1); | |
| 120 | testing.expect(alignment(*align(1) u8) == 1); | |
| 121 | testing.expect(alignment(*align(2) u8) == 2); | |
| 122 | testing.expect(alignment([]align(1) u8) == 1); | |
| 123 | testing.expect(alignment([]align(2) u8) == 2); | |
| 123 | 124 | } |
| 124 | 125 | |
| 125 | 126 | pub fn Child(comptime T: type) type { |
| ... | ... | @@ -133,11 +134,11 @@ pub fn Child(comptime T: type) type { |
| 133 | 134 | } |
| 134 | 135 | |
| 135 | 136 | test "std.meta.Child" { |
| 136 | debug.assert(Child([1]u8) == u8); | |
| 137 | debug.assert(Child(*u8) == u8); | |
| 138 | debug.assert(Child([]u8) == u8); | |
| 139 | debug.assert(Child(?u8) == u8); | |
| 140 | debug.assert(Child(promise->u8) == u8); | |
| 137 | testing.expect(Child([1]u8) == u8); | |
| 138 | testing.expect(Child(*u8) == u8); | |
| 139 | testing.expect(Child([]u8) == u8); | |
| 140 | testing.expect(Child(?u8) == u8); | |
| 141 | testing.expect(Child(promise->u8) == u8); | |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout { |
| ... | ... | @@ -172,15 +173,15 @@ test "std.meta.containerLayout" { |
| 172 | 173 | a: u8, |
| 173 | 174 | }; |
| 174 | 175 | |
| 175 | debug.assert(containerLayout(E1) == TypeInfo.ContainerLayout.Auto); | |
| 176 | debug.assert(containerLayout(E2) == TypeInfo.ContainerLayout.Packed); | |
| 177 | debug.assert(containerLayout(E3) == TypeInfo.ContainerLayout.Extern); | |
| 178 | debug.assert(containerLayout(S1) == TypeInfo.ContainerLayout.Auto); | |
| 179 | debug.assert(containerLayout(S2) == TypeInfo.ContainerLayout.Packed); | |
| 180 | debug.assert(containerLayout(S3) == TypeInfo.ContainerLayout.Extern); | |
| 181 | debug.assert(containerLayout(U1) == TypeInfo.ContainerLayout.Auto); | |
| 182 | debug.assert(containerLayout(U2) == TypeInfo.ContainerLayout.Packed); | |
| 183 | debug.assert(containerLayout(U3) == TypeInfo.ContainerLayout.Extern); | |
| 176 | testing.expect(containerLayout(E1) == TypeInfo.ContainerLayout.Auto); | |
| 177 | testing.expect(containerLayout(E2) == TypeInfo.ContainerLayout.Packed); | |
| 178 | testing.expect(containerLayout(E3) == TypeInfo.ContainerLayout.Extern); | |
| 179 | testing.expect(containerLayout(S1) == TypeInfo.ContainerLayout.Auto); | |
| 180 | testing.expect(containerLayout(S2) == TypeInfo.ContainerLayout.Packed); | |
| 181 | testing.expect(containerLayout(S3) == TypeInfo.ContainerLayout.Extern); | |
| 182 | testing.expect(containerLayout(U1) == TypeInfo.ContainerLayout.Auto); | |
| 183 | testing.expect(containerLayout(U2) == TypeInfo.ContainerLayout.Packed); | |
| 184 | testing.expect(containerLayout(U3) == TypeInfo.ContainerLayout.Extern); | |
| 184 | 185 | } |
| 185 | 186 | |
| 186 | 187 | pub fn definitions(comptime T: type) []TypeInfo.Definition { |
| ... | ... | @@ -214,8 +215,8 @@ test "std.meta.definitions" { |
| 214 | 215 | }; |
| 215 | 216 | |
| 216 | 217 | inline for (defs) |def| { |
| 217 | debug.assert(def.len == 1); | |
| 218 | debug.assert(comptime mem.eql(u8, def[0].name, "a")); | |
| 218 | testing.expect(def.len == 1); | |
| 219 | testing.expect(comptime mem.eql(u8, def[0].name, "a")); | |
| 219 | 220 | } |
| 220 | 221 | } |
| 221 | 222 | |
| ... | ... | @@ -250,8 +251,8 @@ test "std.meta.definitionInfo" { |
| 250 | 251 | }; |
| 251 | 252 | |
| 252 | 253 | inline for (infos) |info| { |
| 253 | debug.assert(comptime mem.eql(u8, info.name, "a")); | |
| 254 | debug.assert(!info.is_pub); | |
| 254 | testing.expect(comptime mem.eql(u8, info.name, "a")); | |
| 255 | testing.expect(!info.is_pub); | |
| 255 | 256 | } |
| 256 | 257 | } |
| 257 | 258 | |
| ... | ... | @@ -288,16 +289,16 @@ test "std.meta.fields" { |
| 288 | 289 | const sf = comptime fields(S1); |
| 289 | 290 | const uf = comptime fields(U1); |
| 290 | 291 | |
| 291 | debug.assert(e1f.len == 1); | |
| 292 | debug.assert(e2f.len == 1); | |
| 293 | debug.assert(sf.len == 1); | |
| 294 | debug.assert(uf.len == 1); | |
| 295 | debug.assert(mem.eql(u8, e1f[0].name, "A")); | |
| 296 | debug.assert(mem.eql(u8, e2f[0].name, "A")); | |
| 297 | debug.assert(mem.eql(u8, sf[0].name, "a")); | |
| 298 | debug.assert(mem.eql(u8, uf[0].name, "a")); | |
| 299 | debug.assert(comptime sf[0].field_type == u8); | |
| 300 | debug.assert(comptime uf[0].field_type == u8); | |
| 292 | testing.expect(e1f.len == 1); | |
| 293 | testing.expect(e2f.len == 1); | |
| 294 | testing.expect(sf.len == 1); | |
| 295 | testing.expect(uf.len == 1); | |
| 296 | testing.expect(mem.eql(u8, e1f[0].name, "A")); | |
| 297 | testing.expect(mem.eql(u8, e2f[0].name, "A")); | |
| 298 | testing.expect(mem.eql(u8, sf[0].name, "a")); | |
| 299 | testing.expect(mem.eql(u8, uf[0].name, "a")); | |
| 300 | testing.expect(comptime sf[0].field_type == u8); | |
| 301 | testing.expect(comptime uf[0].field_type == u8); | |
| 301 | 302 | } |
| 302 | 303 | |
| 303 | 304 | pub fn fieldInfo(comptime T: type, comptime field_name: []const u8) switch (@typeInfo(T)) { |
| ... | ... | @@ -332,12 +333,12 @@ test "std.meta.fieldInfo" { |
| 332 | 333 | const sf = comptime fieldInfo(S1, "a"); |
| 333 | 334 | const uf = comptime fieldInfo(U1, "a"); |
| 334 | 335 | |
| 335 | debug.assert(mem.eql(u8, e1f.name, "A")); | |
| 336 | debug.assert(mem.eql(u8, e2f.name, "A")); | |
| 337 | debug.assert(mem.eql(u8, sf.name, "a")); | |
| 338 | debug.assert(mem.eql(u8, uf.name, "a")); | |
| 339 | debug.assert(comptime sf.field_type == u8); | |
| 340 | debug.assert(comptime uf.field_type == u8); | |
| 336 | testing.expect(mem.eql(u8, e1f.name, "A")); | |
| 337 | testing.expect(mem.eql(u8, e2f.name, "A")); | |
| 338 | testing.expect(mem.eql(u8, sf.name, "a")); | |
| 339 | testing.expect(mem.eql(u8, uf.name, "a")); | |
| 340 | testing.expect(comptime sf.field_type == u8); | |
| 341 | testing.expect(comptime uf.field_type == u8); | |
| 341 | 342 | } |
| 342 | 343 | |
| 343 | 344 | pub fn TagType(comptime T: type) type { |
| ... | ... | @@ -358,8 +359,8 @@ test "std.meta.TagType" { |
| 358 | 359 | D: u16, |
| 359 | 360 | }; |
| 360 | 361 | |
| 361 | debug.assert(TagType(E) == u8); | |
| 362 | debug.assert(TagType(U) == E); | |
| 362 | testing.expect(TagType(E) == u8); | |
| 363 | testing.expect(TagType(U) == E); | |
| 363 | 364 | } |
| 364 | 365 | |
| 365 | 366 | ///Returns the active tag of a tagged union |
| ... | ... | @@ -380,18 +381,18 @@ test "std.meta.activeTag" { |
| 380 | 381 | }; |
| 381 | 382 | |
| 382 | 383 | var u = U{ .Int = 32 }; |
| 383 | debug.assert(activeTag(u) == UE.Int); | |
| 384 | testing.expect(activeTag(u) == UE.Int); | |
| 384 | 385 | |
| 385 | 386 | u = U{ .Float = 112.9876 }; |
| 386 | debug.assert(activeTag(u) == UE.Float); | |
| 387 | testing.expect(activeTag(u) == UE.Float); | |
| 387 | 388 | } |
| 388 | 389 | |
| 389 | 390 | ///Given a tagged union type, and an enum, return the type of the union |
| 390 | 391 | /// field corresponding to the enum tag. |
| 391 | 392 | pub fn TagPayloadType(comptime U: type, tag: var) type { |
| 392 | 393 | const Tag = @typeOf(tag); |
| 393 | debug.assert(trait.is(builtin.TypeId.Union)(U)); | |
| 394 | debug.assert(trait.is(builtin.TypeId.Enum)(Tag)); | |
| 394 | testing.expect(trait.is(builtin.TypeId.Union)(U)); | |
| 395 | testing.expect(trait.is(builtin.TypeId.Enum)(Tag)); | |
| 395 | 396 | |
| 396 | 397 | const info = @typeInfo(U).Union; |
| 397 | 398 | |
| ... | ... | @@ -410,7 +411,7 @@ test "std.meta.TagPayloadType" { |
| 410 | 411 | }; |
| 411 | 412 | const MovedEvent = TagPayloadType(Event, Event.Moved); |
| 412 | 413 | var e: Event = undefined; |
| 413 | debug.assert(MovedEvent == @typeOf(e.Moved)); | |
| 414 | testing.expect(MovedEvent == @typeOf(e.Moved)); | |
| 414 | 415 | } |
| 415 | 416 | |
| 416 | 417 | ///Compares two of any type for equality. Containers are compared on a field-by-field basis, |
| ... | ... | @@ -509,19 +510,19 @@ test "std.meta.eql" { |
| 509 | 510 | const u_2 = U{ .s = s_1 }; |
| 510 | 511 | const u_3 = U{ .f = 24 }; |
| 511 | 512 | |
| 512 | debug.assert(eql(s_1, s_3)); | |
| 513 | debug.assert(eql(&s_1, &s_1)); | |
| 514 | debug.assert(!eql(&s_1, &s_3)); | |
| 515 | debug.assert(eql(u_1, u_3)); | |
| 516 | debug.assert(!eql(u_1, u_2)); | |
| 513 | testing.expect(eql(s_1, s_3)); | |
| 514 | testing.expect(eql(&s_1, &s_1)); | |
| 515 | testing.expect(!eql(&s_1, &s_3)); | |
| 516 | testing.expect(eql(u_1, u_3)); | |
| 517 | testing.expect(!eql(u_1, u_2)); | |
| 517 | 518 | |
| 518 | 519 | var a1 = "abcdef"; |
| 519 | 520 | var a2 = "abcdef"; |
| 520 | 521 | var a3 = "ghijkl"; |
| 521 | 522 | |
| 522 | debug.assert(eql(a1, a2)); | |
| 523 | debug.assert(!eql(a1, a3)); | |
| 524 | debug.assert(!eql(a1[0..], a2[0..])); | |
| 523 | testing.expect(eql(a1, a2)); | |
| 524 | testing.expect(!eql(a1, a3)); | |
| 525 | testing.expect(!eql(a1[0..], a2[0..])); | |
| 525 | 526 | |
| 526 | 527 | const EU = struct { |
| 527 | 528 | fn tst(err: bool) !u8 { |
| ... | ... | @@ -530,9 +531,9 @@ test "std.meta.eql" { |
| 530 | 531 | } |
| 531 | 532 | }; |
| 532 | 533 | |
| 533 | debug.assert(eql(EU.tst(true), EU.tst(true))); | |
| 534 | debug.assert(eql(EU.tst(false), EU.tst(false))); | |
| 535 | debug.assert(!eql(EU.tst(false), EU.tst(true))); | |
| 534 | testing.expect(eql(EU.tst(true), EU.tst(true))); | |
| 535 | testing.expect(eql(EU.tst(false), EU.tst(false))); | |
| 536 | testing.expect(!eql(EU.tst(false), EU.tst(true))); | |
| 536 | 537 | } |
| 537 | 538 | |
| 538 | 539 | test "intToEnum with error return" { |
| ... | ... | @@ -546,9 +547,9 @@ test "intToEnum with error return" { |
| 546 | 547 | |
| 547 | 548 | var zero: u8 = 0; |
| 548 | 549 | var one: u16 = 1; |
| 549 | debug.assert(intToEnum(E1, zero) catch unreachable == E1.A); | |
| 550 | debug.assert(intToEnum(E2, one) catch unreachable == E2.B); | |
| 551 | debug.assertError(intToEnum(E1, one), error.InvalidEnumTag); | |
| 550 | testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); | |
| 551 | testing.expect(intToEnum(E2, one) catch unreachable == E2.B); | |
| 552 | testing.expectError(error.InvalidEnumTag, intToEnum(E1, one)); | |
| 552 | 553 | } |
| 553 | 554 | |
| 554 | 555 | pub const IntToEnumError = error{InvalidEnumTag}; |
std/meta/trait.zig+67-66| ... | ... | @@ -2,6 +2,7 @@ const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const debug = std.debug; |
| 5 | const testing = std.testing; | |
| 5 | 6 | const warn = debug.warn; |
| 6 | 7 | |
| 7 | 8 | const meta = @import("index.zig"); |
| ... | ... | @@ -50,8 +51,8 @@ test "std.meta.trait.multiTrait" { |
| 50 | 51 | hasField("x"), |
| 51 | 52 | hasField("y"), |
| 52 | 53 | }); |
| 53 | debug.assert(isVector(Vector2)); | |
| 54 | debug.assert(!isVector(u8)); | |
| 54 | testing.expect(isVector(Vector2)); | |
| 55 | testing.expect(!isVector(u8)); | |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | /// |
| ... | ... | @@ -85,12 +86,12 @@ test "std.meta.trait.hasDef" { |
| 85 | 86 | const value = u8(16); |
| 86 | 87 | }; |
| 87 | 88 | |
| 88 | debug.assert(hasDef("value")(TestStruct)); | |
| 89 | debug.assert(!hasDef("value")(TestStructFail)); | |
| 90 | debug.assert(!hasDef("value")(*TestStruct)); | |
| 91 | debug.assert(!hasDef("value")(**TestStructFail)); | |
| 92 | debug.assert(!hasDef("x")(TestStruct)); | |
| 93 | debug.assert(!hasDef("value")(u8)); | |
| 89 | testing.expect(hasDef("value")(TestStruct)); | |
| 90 | testing.expect(!hasDef("value")(TestStructFail)); | |
| 91 | testing.expect(!hasDef("value")(*TestStruct)); | |
| 92 | testing.expect(!hasDef("value")(**TestStructFail)); | |
| 93 | testing.expect(!hasDef("x")(TestStruct)); | |
| 94 | testing.expect(!hasDef("value")(u8)); | |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | 97 | /// |
| ... | ... | @@ -111,9 +112,9 @@ test "std.meta.trait.hasFn" { |
| 111 | 112 | pub fn useless() void {} |
| 112 | 113 | }; |
| 113 | 114 | |
| 114 | debug.assert(hasFn("useless")(TestStruct)); | |
| 115 | debug.assert(!hasFn("append")(TestStruct)); | |
| 116 | debug.assert(!hasFn("useless")(u8)); | |
| 115 | testing.expect(hasFn("useless")(TestStruct)); | |
| 116 | testing.expect(!hasFn("append")(TestStruct)); | |
| 117 | testing.expect(!hasFn("useless")(u8)); | |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | 120 | /// |
| ... | ... | @@ -143,11 +144,11 @@ test "std.meta.trait.hasField" { |
| 143 | 144 | value: u32, |
| 144 | 145 | }; |
| 145 | 146 | |
| 146 | debug.assert(hasField("value")(TestStruct)); | |
| 147 | debug.assert(!hasField("value")(*TestStruct)); | |
| 148 | debug.assert(!hasField("x")(TestStruct)); | |
| 149 | debug.assert(!hasField("x")(**TestStruct)); | |
| 150 | debug.assert(!hasField("value")(u8)); | |
| 147 | testing.expect(hasField("value")(TestStruct)); | |
| 148 | testing.expect(!hasField("value")(*TestStruct)); | |
| 149 | testing.expect(!hasField("x")(TestStruct)); | |
| 150 | testing.expect(!hasField("x")(**TestStruct)); | |
| 151 | testing.expect(!hasField("value")(u8)); | |
| 151 | 152 | } |
| 152 | 153 | |
| 153 | 154 | /// |
| ... | ... | @@ -161,11 +162,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn { |
| 161 | 162 | } |
| 162 | 163 | |
| 163 | 164 | test "std.meta.trait.is" { |
| 164 | debug.assert(is(builtin.TypeId.Int)(u8)); | |
| 165 | debug.assert(!is(builtin.TypeId.Int)(f32)); | |
| 166 | debug.assert(is(builtin.TypeId.Pointer)(*u8)); | |
| 167 | debug.assert(is(builtin.TypeId.Void)(void)); | |
| 168 | debug.assert(!is(builtin.TypeId.Optional)(anyerror)); | |
| 165 | testing.expect(is(builtin.TypeId.Int)(u8)); | |
| 166 | testing.expect(!is(builtin.TypeId.Int)(f32)); | |
| 167 | testing.expect(is(builtin.TypeId.Pointer)(*u8)); | |
| 168 | testing.expect(is(builtin.TypeId.Void)(void)); | |
| 169 | testing.expect(!is(builtin.TypeId.Optional)(anyerror)); | |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | 172 | /// |
| ... | ... | @@ -180,9 +181,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn { |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | 183 | test "std.meta.trait.isPtrTo" { |
| 183 | debug.assert(!isPtrTo(builtin.TypeId.Struct)(struct {})); | |
| 184 | debug.assert(isPtrTo(builtin.TypeId.Struct)(*struct {})); | |
| 185 | debug.assert(!isPtrTo(builtin.TypeId.Struct)(**struct {})); | |
| 184 | testing.expect(!isPtrTo(builtin.TypeId.Struct)(struct {})); | |
| 185 | testing.expect(isPtrTo(builtin.TypeId.Struct)(*struct {})); | |
| 186 | testing.expect(!isPtrTo(builtin.TypeId.Struct)(**struct {})); | |
| 186 | 187 | } |
| 187 | 188 | |
| 188 | 189 | ///////////Strait trait Fns |
| ... | ... | @@ -205,9 +206,9 @@ test "std.meta.trait.isExtern" { |
| 205 | 206 | const TestExStruct = extern struct {}; |
| 206 | 207 | const TestStruct = struct {}; |
| 207 | 208 | |
| 208 | debug.assert(isExtern(TestExStruct)); | |
| 209 | debug.assert(!isExtern(TestStruct)); | |
| 210 | debug.assert(!isExtern(u8)); | |
| 209 | testing.expect(isExtern(TestExStruct)); | |
| 210 | testing.expect(!isExtern(TestStruct)); | |
| 211 | testing.expect(!isExtern(u8)); | |
| 211 | 212 | } |
| 212 | 213 | |
| 213 | 214 | /// |
| ... | ... | @@ -226,9 +227,9 @@ test "std.meta.trait.isPacked" { |
| 226 | 227 | const TestPStruct = packed struct {}; |
| 227 | 228 | const TestStruct = struct {}; |
| 228 | 229 | |
| 229 | debug.assert(isPacked(TestPStruct)); | |
| 230 | debug.assert(!isPacked(TestStruct)); | |
| 231 | debug.assert(!isPacked(u8)); | |
| 230 | testing.expect(isPacked(TestPStruct)); | |
| 231 | testing.expect(!isPacked(TestStruct)); | |
| 232 | testing.expect(!isPacked(u8)); | |
| 232 | 233 | } |
| 233 | 234 | |
| 234 | 235 | /// |
| ... | ... | @@ -240,10 +241,10 @@ pub fn isUnsignedInt(comptime T: type) bool { |
| 240 | 241 | } |
| 241 | 242 | |
| 242 | 243 | test "isUnsignedInt" { |
| 243 | debug.assert(isUnsignedInt(u32) == true); | |
| 244 | debug.assert(isUnsignedInt(comptime_int) == false); | |
| 245 | debug.assert(isUnsignedInt(i64) == false); | |
| 246 | debug.assert(isUnsignedInt(f64) == false); | |
| 244 | testing.expect(isUnsignedInt(u32) == true); | |
| 245 | testing.expect(isUnsignedInt(comptime_int) == false); | |
| 246 | testing.expect(isUnsignedInt(i64) == false); | |
| 247 | testing.expect(isUnsignedInt(f64) == false); | |
| 247 | 248 | } |
| 248 | 249 | |
| 249 | 250 | /// |
| ... | ... | @@ -256,10 +257,10 @@ pub fn isSignedInt(comptime T: type) bool { |
| 256 | 257 | } |
| 257 | 258 | |
| 258 | 259 | test "isSignedInt" { |
| 259 | debug.assert(isSignedInt(u32) == false); | |
| 260 | debug.assert(isSignedInt(comptime_int) == true); | |
| 261 | debug.assert(isSignedInt(i64) == true); | |
| 262 | debug.assert(isSignedInt(f64) == false); | |
| 260 | testing.expect(isSignedInt(u32) == false); | |
| 261 | testing.expect(isSignedInt(comptime_int) == true); | |
| 262 | testing.expect(isSignedInt(i64) == true); | |
| 263 | testing.expect(isSignedInt(f64) == false); | |
| 263 | 264 | } |
| 264 | 265 | |
| 265 | 266 | /// |
| ... | ... | @@ -273,9 +274,9 @@ pub fn isSingleItemPtr(comptime T: type) bool { |
| 273 | 274 | |
| 274 | 275 | test "std.meta.trait.isSingleItemPtr" { |
| 275 | 276 | const array = []u8{0} ** 10; |
| 276 | debug.assert(isSingleItemPtr(@typeOf(&array[0]))); | |
| 277 | debug.assert(!isSingleItemPtr(@typeOf(array))); | |
| 278 | debug.assert(!isSingleItemPtr(@typeOf(array[0..1]))); | |
| 277 | testing.expect(isSingleItemPtr(@typeOf(&array[0]))); | |
| 278 | testing.expect(!isSingleItemPtr(@typeOf(array))); | |
| 279 | testing.expect(!isSingleItemPtr(@typeOf(array[0..1]))); | |
| 279 | 280 | } |
| 280 | 281 | |
| 281 | 282 | /// |
| ... | ... | @@ -290,9 +291,9 @@ pub fn isManyItemPtr(comptime T: type) bool { |
| 290 | 291 | test "std.meta.trait.isManyItemPtr" { |
| 291 | 292 | const array = []u8{0} ** 10; |
| 292 | 293 | const mip = @ptrCast([*]const u8, &array[0]); |
| 293 | debug.assert(isManyItemPtr(@typeOf(mip))); | |
| 294 | debug.assert(!isManyItemPtr(@typeOf(array))); | |
| 295 | debug.assert(!isManyItemPtr(@typeOf(array[0..1]))); | |
| 294 | testing.expect(isManyItemPtr(@typeOf(mip))); | |
| 295 | testing.expect(!isManyItemPtr(@typeOf(array))); | |
| 296 | testing.expect(!isManyItemPtr(@typeOf(array[0..1]))); | |
| 296 | 297 | } |
| 297 | 298 | |
| 298 | 299 | /// |
| ... | ... | @@ -306,9 +307,9 @@ pub fn isSlice(comptime T: type) bool { |
| 306 | 307 | |
| 307 | 308 | test "std.meta.trait.isSlice" { |
| 308 | 309 | const array = []u8{0} ** 10; |
| 309 | debug.assert(isSlice(@typeOf(array[0..]))); | |
| 310 | debug.assert(!isSlice(@typeOf(array))); | |
| 311 | debug.assert(!isSlice(@typeOf(&array[0]))); | |
| 310 | testing.expect(isSlice(@typeOf(array[0..]))); | |
| 311 | testing.expect(!isSlice(@typeOf(array))); | |
| 312 | testing.expect(!isSlice(@typeOf(&array[0]))); | |
| 312 | 313 | } |
| 313 | 314 | |
| 314 | 315 | /// |
| ... | ... | @@ -328,10 +329,10 @@ test "std.meta.trait.isIndexable" { |
| 328 | 329 | const array = []u8{0} ** 10; |
| 329 | 330 | const slice = array[0..]; |
| 330 | 331 | |
| 331 | debug.assert(isIndexable(@typeOf(array))); | |
| 332 | debug.assert(isIndexable(@typeOf(&array))); | |
| 333 | debug.assert(isIndexable(@typeOf(slice))); | |
| 334 | debug.assert(!isIndexable(meta.Child(@typeOf(slice)))); | |
| 332 | testing.expect(isIndexable(@typeOf(array))); | |
| 333 | testing.expect(isIndexable(@typeOf(&array))); | |
| 334 | testing.expect(isIndexable(@typeOf(slice))); | |
| 335 | testing.expect(!isIndexable(meta.Child(@typeOf(slice)))); | |
| 335 | 336 | } |
| 336 | 337 | |
| 337 | 338 | /// |
| ... | ... | @@ -347,13 +348,13 @@ test "std.meta.trait.isNumber" { |
| 347 | 348 | number: u8, |
| 348 | 349 | }; |
| 349 | 350 | |
| 350 | debug.assert(isNumber(u32)); | |
| 351 | debug.assert(isNumber(f32)); | |
| 352 | debug.assert(isNumber(u64)); | |
| 353 | debug.assert(isNumber(@typeOf(102))); | |
| 354 | debug.assert(isNumber(@typeOf(102.123))); | |
| 355 | debug.assert(!isNumber([]u8)); | |
| 356 | debug.assert(!isNumber(NotANumber)); | |
| 351 | testing.expect(isNumber(u32)); | |
| 352 | testing.expect(isNumber(f32)); | |
| 353 | testing.expect(isNumber(u64)); | |
| 354 | testing.expect(isNumber(@typeOf(102))); | |
| 355 | testing.expect(isNumber(@typeOf(102.123))); | |
| 356 | testing.expect(!isNumber([]u8)); | |
| 357 | testing.expect(!isNumber(NotANumber)); | |
| 357 | 358 | } |
| 358 | 359 | |
| 359 | 360 | /// |
| ... | ... | @@ -366,10 +367,10 @@ pub fn isConstPtr(comptime T: type) bool { |
| 366 | 367 | test "std.meta.trait.isConstPtr" { |
| 367 | 368 | var t = u8(0); |
| 368 | 369 | const c = u8(0); |
| 369 | debug.assert(isConstPtr(*const @typeOf(t))); | |
| 370 | debug.assert(isConstPtr(@typeOf(&c))); | |
| 371 | debug.assert(!isConstPtr(*@typeOf(t))); | |
| 372 | debug.assert(!isConstPtr(@typeOf(6))); | |
| 370 | testing.expect(isConstPtr(*const @typeOf(t))); | |
| 371 | testing.expect(isConstPtr(@typeOf(&c))); | |
| 372 | testing.expect(!isConstPtr(*@typeOf(t))); | |
| 373 | testing.expect(!isConstPtr(@typeOf(6))); | |
| 373 | 374 | } |
| 374 | 375 | |
| 375 | 376 | /// |
| ... | ... | @@ -393,8 +394,8 @@ test "std.meta.trait.isContainer" { |
| 393 | 394 | B, |
| 394 | 395 | }; |
| 395 | 396 | |
| 396 | debug.assert(isContainer(TestStruct)); | |
| 397 | debug.assert(isContainer(TestUnion)); | |
| 398 | debug.assert(isContainer(TestEnum)); | |
| 399 | debug.assert(!isContainer(u8)); | |
| 397 | testing.expect(isContainer(TestStruct)); | |
| 398 | testing.expect(isContainer(TestUnion)); | |
| 399 | testing.expect(isContainer(TestEnum)); | |
| 400 | testing.expect(!isContainer(u8)); | |
| 400 | 401 | } |
std/mutex.zig+3-3| ... | ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const AtomicOrder = builtin.AtomicOrder; |
| 4 | 4 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | const assert = std.debug.assert; | |
| 5 | const testing = std.testing; | |
| 6 | 6 | const SpinLock = std.SpinLock; |
| 7 | 7 | const linux = std.os.linux; |
| 8 | 8 | const windows = std.os.windows; |
| ... | ... | @@ -149,7 +149,7 @@ test "std.Mutex" { |
| 149 | 149 | |
| 150 | 150 | if (builtin.single_threaded) { |
| 151 | 151 | worker(&context); |
| 152 | std.debug.assertOrPanic(context.data == TestContext.incr_count); | |
| 152 | testing.expect(context.data == TestContext.incr_count); | |
| 153 | 153 | } else { |
| 154 | 154 | const thread_count = 10; |
| 155 | 155 | var threads: [thread_count]*std.os.Thread = undefined; |
| ... | ... | @@ -159,7 +159,7 @@ test "std.Mutex" { |
| 159 | 159 | for (threads) |t| |
| 160 | 160 | t.wait(); |
| 161 | 161 | |
| 162 | std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count); | |
| 162 | testing.expect(context.data == thread_count * TestContext.incr_count); | |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 |
std/os/child_process.zig-1| ... | ... | @@ -7,7 +7,6 @@ const posix = os.posix; |
| 7 | 7 | const windows = os.windows; |
| 8 | 8 | const mem = std.mem; |
| 9 | 9 | const debug = std.debug; |
| 10 | const assert = debug.assert; | |
| 11 | 10 | const BufMap = std.BufMap; |
| 12 | 11 | const Buffer = std.Buffer; |
| 13 | 12 | const builtin = @import("builtin"); |
std/os/index.zig+5-4| ... | ... | @@ -91,6 +91,7 @@ pub const GetAppDataDirError = @import("get_app_data_dir.zig").GetAppDataDirErro |
| 91 | 91 | |
| 92 | 92 | const debug = std.debug; |
| 93 | 93 | const assert = debug.assert; |
| 94 | const testing = std.testing; | |
| 94 | 95 | |
| 95 | 96 | const c = std.c; |
| 96 | 97 | |
| ... | ... | @@ -172,7 +173,7 @@ test "os.getRandomBytes" { |
| 172 | 173 | try getRandomBytes(buf_b[0..]); |
| 173 | 174 | |
| 174 | 175 | // Check if random (not 100% conclusive) |
| 175 | assert(!mem.eql(u8, buf_a, buf_b)); | |
| 176 | testing.expect(!mem.eql(u8, buf_a, buf_b)); | |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 179 | /// Raises a signal in the current kernel thread, ending its execution. |
| ... | ... | @@ -828,7 +829,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned |
| 828 | 829 | |
| 829 | 830 | test "os.getEnvVarOwned" { |
| 830 | 831 | var ga = debug.global_allocator; |
| 831 | debug.assertError(getEnvVarOwned(ga, "BADENV"), error.EnvironmentVariableNotFound); | |
| 832 | testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV")); | |
| 832 | 833 | } |
| 833 | 834 | |
| 834 | 835 | /// Caller must free the returned memory. |
| ... | ... | @@ -2219,9 +2220,9 @@ fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []cons |
| 2219 | 2220 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 2220 | 2221 | for (expected_args) |expected_arg| { |
| 2221 | 2222 | const arg = it.next(debug.global_allocator).? catch unreachable; |
| 2222 | assert(mem.eql(u8, arg, expected_arg)); | |
| 2223 | testing.expectEqualSlices(u8, expected_arg, arg); | |
| 2223 | 2224 | } |
| 2224 | assert(it.next(debug.global_allocator) == null); | |
| 2225 | testing.expect(it.next(debug.global_allocator) == null); | |
| 2225 | 2226 | } |
| 2226 | 2227 | |
| 2227 | 2228 | // TODO make this a build variable that you can set |
std/os/linux/test.zig+6-6| ... | ... | @@ -1,19 +1,19 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const linux = std.os.linux; |
| 4 | const assert = std.debug.assert; | |
| 4 | const expect = std.testing.expect; | |
| 5 | 5 | |
| 6 | 6 | test "getpid" { |
| 7 | assert(linux.getpid() != 0); | |
| 7 | expect(linux.getpid() != 0); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | test "timer" { |
| 11 | 11 | const epoll_fd = linux.epoll_create(); |
| 12 | 12 | var err = linux.getErrno(epoll_fd); |
| 13 | assert(err == 0); | |
| 13 | expect(err == 0); | |
| 14 | 14 | |
| 15 | 15 | const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); |
| 16 | assert(linux.getErrno(timer_fd) == 0); | |
| 16 | expect(linux.getErrno(timer_fd) == 0); | |
| 17 | 17 | |
| 18 | 18 | const time_interval = linux.timespec{ |
| 19 | 19 | .tv_sec = 0, |
| ... | ... | @@ -26,7 +26,7 @@ test "timer" { |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | 28 | err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null); |
| 29 | assert(err == 0); | |
| 29 | expect(err == 0); | |
| 30 | 30 | |
| 31 | 31 | var event = linux.epoll_event{ |
| 32 | 32 | .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, |
| ... | ... | @@ -34,7 +34,7 @@ test "timer" { |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event); |
| 37 | assert(err == 0); | |
| 37 | expect(err == 0); | |
| 38 | 38 | |
| 39 | 39 | const events_one: linux.epoll_event = undefined; |
| 40 | 40 | var events = []linux.epoll_event{events_one} ** 8; |
std/os/path.zig+58-57| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const Os = builtin.Os; |
| 4 | 4 | const debug = std.debug; |
| 5 | 5 | const assert = debug.assert; |
| 6 | const testing = std.testing; | |
| 6 | 7 | const mem = std.mem; |
| 7 | 8 | const fmt = std.fmt; |
| 8 | 9 | const Allocator = mem.Allocator; |
| ... | ... | @@ -94,14 +95,14 @@ fn testJoinWindows(paths: []const []const u8, expected: []const u8) void { |
| 94 | 95 | var buf: [1024]u8 = undefined; |
| 95 | 96 | const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; |
| 96 | 97 | const actual = joinWindows(a, paths) catch @panic("fail"); |
| 97 | debug.assertOrPanic(mem.eql(u8, actual, expected)); | |
| 98 | testing.expectEqualSlices(u8, expected, actual); | |
| 98 | 99 | } |
| 99 | 100 | |
| 100 | 101 | fn testJoinPosix(paths: []const []const u8, expected: []const u8) void { |
| 101 | 102 | var buf: [1024]u8 = undefined; |
| 102 | 103 | const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; |
| 103 | 104 | const actual = joinPosix(a, paths) catch @panic("fail"); |
| 104 | debug.assertOrPanic(mem.eql(u8, actual, expected)); | |
| 105 | testing.expectEqualSlices(u8, expected, actual); | |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | 108 | test "os.path.join" { |
| ... | ... | @@ -193,11 +194,11 @@ test "os.path.isAbsolutePosix" { |
| 193 | 194 | } |
| 194 | 195 | |
| 195 | 196 | fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void { |
| 196 | assert(isAbsoluteWindows(path) == expected_result); | |
| 197 | testing.expectEqual(expected_result, isAbsoluteWindows(path)); | |
| 197 | 198 | } |
| 198 | 199 | |
| 199 | 200 | fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void { |
| 200 | assert(isAbsolutePosix(path) == expected_result); | |
| 201 | testing.expectEqual(expected_result, isAbsolutePosix(path)); | |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | 204 | pub const WindowsPath = struct { |
| ... | ... | @@ -281,33 +282,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 281 | 282 | test "os.path.windowsParsePath" { |
| 282 | 283 | { |
| 283 | 284 | const parsed = windowsParsePath("//a/b"); |
| 284 | assert(parsed.is_abs); | |
| 285 | assert(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 286 | assert(mem.eql(u8, parsed.disk_designator, "//a/b")); | |
| 285 | testing.expect(parsed.is_abs); | |
| 286 | testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 287 | testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b")); | |
| 287 | 288 | } |
| 288 | 289 | { |
| 289 | 290 | const parsed = windowsParsePath("\\\\a\\b"); |
| 290 | assert(parsed.is_abs); | |
| 291 | assert(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 292 | assert(mem.eql(u8, parsed.disk_designator, "\\\\a\\b")); | |
| 291 | testing.expect(parsed.is_abs); | |
| 292 | testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 293 | testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b")); | |
| 293 | 294 | } |
| 294 | 295 | { |
| 295 | 296 | const parsed = windowsParsePath("\\\\a\\"); |
| 296 | assert(!parsed.is_abs); | |
| 297 | assert(parsed.kind == WindowsPath.Kind.None); | |
| 298 | assert(mem.eql(u8, parsed.disk_designator, "")); | |
| 297 | testing.expect(!parsed.is_abs); | |
| 298 | testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 299 | testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 299 | 300 | } |
| 300 | 301 | { |
| 301 | 302 | const parsed = windowsParsePath("/usr/local"); |
| 302 | assert(parsed.is_abs); | |
| 303 | assert(parsed.kind == WindowsPath.Kind.None); | |
| 304 | assert(mem.eql(u8, parsed.disk_designator, "")); | |
| 303 | testing.expect(parsed.is_abs); | |
| 304 | testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 305 | testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 305 | 306 | } |
| 306 | 307 | { |
| 307 | 308 | const parsed = windowsParsePath("c:../"); |
| 308 | assert(!parsed.is_abs); | |
| 309 | assert(parsed.kind == WindowsPath.Kind.Drive); | |
| 310 | assert(mem.eql(u8, parsed.disk_designator, "c:")); | |
| 309 | testing.expect(!parsed.is_abs); | |
| 310 | testing.expect(parsed.kind == WindowsPath.Kind.Drive); | |
| 311 | testing.expect(mem.eql(u8, parsed.disk_designator, "c:")); | |
| 311 | 312 | } |
| 312 | 313 | } |
| 313 | 314 | |
| ... | ... | @@ -642,10 +643,10 @@ test "os.path.resolve" { |
| 642 | 643 | if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) { |
| 643 | 644 | cwd[0] = asciiUpper(cwd[0]); |
| 644 | 645 | } |
| 645 | assert(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd)); | |
| 646 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd)); | |
| 646 | 647 | } else { |
| 647 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd)); | |
| 648 | assert(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd)); | |
| 648 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd)); | |
| 649 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd)); | |
| 649 | 650 | } |
| 650 | 651 | } |
| 651 | 652 | |
| ... | ... | @@ -662,7 +663,7 @@ test "os.path.resolveWindows" { |
| 662 | 663 | if (parsed_cwd.kind == WindowsPath.Kind.Drive) { |
| 663 | 664 | expected[0] = asciiUpper(parsed_cwd.disk_designator[0]); |
| 664 | 665 | } |
| 665 | assert(mem.eql(u8, result, expected)); | |
| 666 | testing.expect(mem.eql(u8, result, expected)); | |
| 666 | 667 | } |
| 667 | 668 | { |
| 668 | 669 | const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" }); |
| ... | ... | @@ -673,36 +674,36 @@ test "os.path.resolveWindows" { |
| 673 | 674 | if (parsed_cwd.kind == WindowsPath.Kind.Drive) { |
| 674 | 675 | expected[0] = asciiUpper(parsed_cwd.disk_designator[0]); |
| 675 | 676 | } |
| 676 | assert(mem.eql(u8, result, expected)); | |
| 677 | testing.expect(mem.eql(u8, result, expected)); | |
| 677 | 678 | } |
| 678 | 679 | } |
| 679 | 680 | |
| 680 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok")); | |
| 681 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a")); | |
| 682 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a")); | |
| 683 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe")); | |
| 684 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file")); | |
| 685 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir")); | |
| 686 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative")); | |
| 687 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\")); | |
| 688 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir")); | |
| 689 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\")); | |
| 690 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\")); | |
| 691 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir")); | |
| 692 | assert(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js")); | |
| 681 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok")); | |
| 682 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a")); | |
| 683 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a")); | |
| 684 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe")); | |
| 685 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file")); | |
| 686 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir")); | |
| 687 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative")); | |
| 688 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\")); | |
| 689 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir")); | |
| 690 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\")); | |
| 691 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\")); | |
| 692 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir")); | |
| 693 | testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js")); | |
| 693 | 694 | } |
| 694 | 695 | |
| 695 | 696 | test "os.path.resolvePosix" { |
| 696 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c")); | |
| 697 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e")); | |
| 698 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a")); | |
| 699 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/")); | |
| 700 | assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c")); | |
| 701 | ||
| 702 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file")); | |
| 703 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file")); | |
| 704 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute")); | |
| 705 | assert(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js")); | |
| 697 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c")); | |
| 698 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e")); | |
| 699 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a")); | |
| 700 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/")); | |
| 701 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c")); | |
| 702 | ||
| 703 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file")); | |
| 704 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file")); | |
| 705 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute")); | |
| 706 | testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js")); | |
| 706 | 707 | } |
| 707 | 708 | |
| 708 | 709 | fn testResolveWindows(paths: []const []const u8) []u8 { |
| ... | ... | @@ -833,17 +834,17 @@ test "os.path.dirnameWindows" { |
| 833 | 834 | |
| 834 | 835 | fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void { |
| 835 | 836 | if (dirnamePosix(input)) |output| { |
| 836 | assert(mem.eql(u8, output, expected_output.?)); | |
| 837 | testing.expect(mem.eql(u8, output, expected_output.?)); | |
| 837 | 838 | } else { |
| 838 | assert(expected_output == null); | |
| 839 | testing.expect(expected_output == null); | |
| 839 | 840 | } |
| 840 | 841 | } |
| 841 | 842 | |
| 842 | 843 | fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void { |
| 843 | 844 | if (dirnameWindows(input)) |output| { |
| 844 | assert(mem.eql(u8, output, expected_output.?)); | |
| 845 | testing.expect(mem.eql(u8, output, expected_output.?)); | |
| 845 | 846 | } else { |
| 846 | assert(expected_output == null); | |
| 847 | testing.expect(expected_output == null); | |
| 847 | 848 | } |
| 848 | 849 | } |
| 849 | 850 | |
| ... | ... | @@ -948,15 +949,15 @@ test "os.path.basename" { |
| 948 | 949 | } |
| 949 | 950 | |
| 950 | 951 | fn testBasename(input: []const u8, expected_output: []const u8) void { |
| 951 | assert(mem.eql(u8, basename(input), expected_output)); | |
| 952 | testing.expectEqualSlices(u8, expected_output, basename(input)); | |
| 952 | 953 | } |
| 953 | 954 | |
| 954 | 955 | fn testBasenamePosix(input: []const u8, expected_output: []const u8) void { |
| 955 | assert(mem.eql(u8, basenamePosix(input), expected_output)); | |
| 956 | testing.expectEqualSlices(u8, expected_output, basenamePosix(input)); | |
| 956 | 957 | } |
| 957 | 958 | |
| 958 | 959 | fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { |
| 959 | assert(mem.eql(u8, basenameWindows(input), expected_output)); | |
| 960 | testing.expectEqualSlices(u8, expected_output, basenameWindows(input)); | |
| 960 | 961 | } |
| 961 | 962 | |
| 962 | 963 | /// Returns the relative path from `from` to `to`. If `from` and `to` each |
| ... | ... | @@ -1131,12 +1132,12 @@ test "os.path.relative" { |
| 1131 | 1132 | |
| 1132 | 1133 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void { |
| 1133 | 1134 | const result = relativePosix(debug.global_allocator, from, to) catch unreachable; |
| 1134 | assert(mem.eql(u8, result, expected_output)); | |
| 1135 | testing.expectEqualSlices(u8, expected_output, result); | |
| 1135 | 1136 | } |
| 1136 | 1137 | |
| 1137 | 1138 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void { |
| 1138 | 1139 | const result = relativeWindows(debug.global_allocator, from, to) catch unreachable; |
| 1139 | assert(mem.eql(u8, result, expected_output)); | |
| 1140 | testing.expectEqualSlices(u8, expected_output, result); | |
| 1140 | 1141 | } |
| 1141 | 1142 | |
| 1142 | 1143 | pub const RealError = error{ |
| ... | ... | @@ -1283,5 +1284,5 @@ pub fn realAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 { |
| 1283 | 1284 | test "os.path.real" { |
| 1284 | 1285 | // at least call it so it gets compiled |
| 1285 | 1286 | var buf: [os.MAX_PATH_BYTES]u8 = undefined; |
| 1286 | std.debug.assertError(real(&buf, "definitely_bogus_does_not_exist1234"), error.FileNotFound); | |
| 1287 | testing.expectError(error.FileNotFound, real(&buf, "definitely_bogus_does_not_exist1234")); | |
| 1287 | 1288 | } |
std/os/test.zig+8-8| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const os = std.os; |
| 3 | const assert = std.debug.assert; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | const io = std.io; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | |
| ... | ... | @@ -18,7 +18,7 @@ test "makePath, put some files in it, deleteTree" { |
| 18 | 18 | if (os.Dir.open(a, "os_test_tmp")) |dir| { |
| 19 | 19 | @panic("expected error"); |
| 20 | 20 | } else |err| { |
| 21 | assert(err == error.FileNotFound); | |
| 21 | expect(err == error.FileNotFound); | |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| ... | ... | @@ -27,7 +27,7 @@ test "access file" { |
| 27 | 27 | if (os.File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt")) |ok| { |
| 28 | 28 | @panic("expected error"); |
| 29 | 29 | } else |err| { |
| 30 | assert(err == error.FileNotFound); | |
| 30 | expect(err == error.FileNotFound); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", ""); |
| ... | ... | @@ -47,9 +47,9 @@ test "std.os.Thread.getCurrentId" { |
| 47 | 47 | const thread_id = thread.handle(); |
| 48 | 48 | thread.wait(); |
| 49 | 49 | switch (builtin.os) { |
| 50 | builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id), | |
| 50 | builtin.Os.windows => expect(os.Thread.getCurrentId() != thread_current_id), | |
| 51 | 51 | else => { |
| 52 | assert(thread_current_id == thread_id); | |
| 52 | expect(thread_current_id == thread_id); | |
| 53 | 53 | }, |
| 54 | 54 | } |
| 55 | 55 | } |
| ... | ... | @@ -69,7 +69,7 @@ test "spawn threads" { |
| 69 | 69 | thread3.wait(); |
| 70 | 70 | thread4.wait(); |
| 71 | 71 | |
| 72 | assert(shared_ctx == 4); | |
| 72 | expect(shared_ctx == 4); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | fn start1(ctx: void) u8 { |
| ... | ... | @@ -83,7 +83,7 @@ fn start2(ctx: *i32) u8 { |
| 83 | 83 | |
| 84 | 84 | test "cpu count" { |
| 85 | 85 | const cpu_count = try std.os.cpuCount(a); |
| 86 | assert(cpu_count >= 1); | |
| 86 | expect(cpu_count >= 1); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "AtomicFile" { |
| ... | ... | @@ -101,7 +101,7 @@ test "AtomicFile" { |
| 101 | 101 | try af.finish(); |
| 102 | 102 | } |
| 103 | 103 | const content = try io.readFileAlloc(allocator, test_out_file); |
| 104 | assert(mem.eql(u8, content, test_content)); | |
| 104 | expect(mem.eql(u8, content, test_content)); | |
| 105 | 105 | |
| 106 | 106 | try os.deleteFile(test_out_file); |
| 107 | 107 | } |
std/os/time.zig+5-4| ... | ... | @@ -2,6 +2,7 @@ const std = @import("../index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const Os = builtin.Os; |
| 4 | 4 | const debug = std.debug; |
| 5 | const testing = std.testing; | |
| 5 | 6 | |
| 6 | 7 | const windows = std.os.windows; |
| 7 | 8 | const linux = std.os.linux; |
| ... | ... | @@ -270,7 +271,7 @@ test "os.time.timestamp" { |
| 270 | 271 | sleep(ns_per_ms); |
| 271 | 272 | const time_1 = milliTimestamp(); |
| 272 | 273 | const interval = time_1 - time_0; |
| 273 | debug.assert(interval > 0 and interval < margin); | |
| 274 | testing.expect(interval > 0 and interval < margin); | |
| 274 | 275 | } |
| 275 | 276 | |
| 276 | 277 | test "os.time.Timer" { |
| ... | ... | @@ -280,11 +281,11 @@ test "os.time.Timer" { |
| 280 | 281 | var timer = try Timer.start(); |
| 281 | 282 | sleep(10 * ns_per_ms); |
| 282 | 283 | const time_0 = timer.read(); |
| 283 | debug.assert(time_0 > 0 and time_0 < margin); | |
| 284 | testing.expect(time_0 > 0 and time_0 < margin); | |
| 284 | 285 | |
| 285 | 286 | const time_1 = timer.lap(); |
| 286 | debug.assert(time_1 >= time_0); | |
| 287 | testing.expect(time_1 >= time_0); | |
| 287 | 288 | |
| 288 | 289 | timer.reset(); |
| 289 | debug.assert(timer.read() < time_1); | |
| 290 | testing.expect(timer.read() < time_1); | |
| 290 | 291 | } |
std/rand/index.zig+81-80| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | const std = @import("../index.zig"); |
| 18 | 18 | const builtin = @import("builtin"); |
| 19 | 19 | const assert = std.debug.assert; |
| 20 | const expect = std.testing.expect; | |
| 20 | 21 | const mem = std.mem; |
| 21 | 22 | const math = std.math; |
| 22 | 23 | const ziggurat = @import("ziggurat.zig"); |
| ... | ... | @@ -316,43 +317,43 @@ test "Random int" { |
| 316 | 317 | fn testRandomInt() void { |
| 317 | 318 | var r = SequentialPrng.init(); |
| 318 | 319 | |
| 319 | assert(r.random.int(u0) == 0); | |
| 320 | expect(r.random.int(u0) == 0); | |
| 320 | 321 | |
| 321 | 322 | r.next_value = 0; |
| 322 | assert(r.random.int(u1) == 0); | |
| 323 | assert(r.random.int(u1) == 1); | |
| 324 | assert(r.random.int(u2) == 2); | |
| 325 | assert(r.random.int(u2) == 3); | |
| 326 | assert(r.random.int(u2) == 0); | |
| 323 | expect(r.random.int(u1) == 0); | |
| 324 | expect(r.random.int(u1) == 1); | |
| 325 | expect(r.random.int(u2) == 2); | |
| 326 | expect(r.random.int(u2) == 3); | |
| 327 | expect(r.random.int(u2) == 0); | |
| 327 | 328 | |
| 328 | 329 | r.next_value = 0xff; |
| 329 | assert(r.random.int(u8) == 0xff); | |
| 330 | expect(r.random.int(u8) == 0xff); | |
| 330 | 331 | r.next_value = 0x11; |
| 331 | assert(r.random.int(u8) == 0x11); | |
| 332 | expect(r.random.int(u8) == 0x11); | |
| 332 | 333 | |
| 333 | 334 | r.next_value = 0xff; |
| 334 | assert(r.random.int(u32) == 0xffffffff); | |
| 335 | expect(r.random.int(u32) == 0xffffffff); | |
| 335 | 336 | r.next_value = 0x11; |
| 336 | assert(r.random.int(u32) == 0x11111111); | |
| 337 | expect(r.random.int(u32) == 0x11111111); | |
| 337 | 338 | |
| 338 | 339 | r.next_value = 0xff; |
| 339 | assert(r.random.int(i32) == -1); | |
| 340 | expect(r.random.int(i32) == -1); | |
| 340 | 341 | r.next_value = 0x11; |
| 341 | assert(r.random.int(i32) == 0x11111111); | |
| 342 | expect(r.random.int(i32) == 0x11111111); | |
| 342 | 343 | |
| 343 | 344 | r.next_value = 0xff; |
| 344 | assert(r.random.int(i8) == -1); | |
| 345 | expect(r.random.int(i8) == -1); | |
| 345 | 346 | r.next_value = 0x11; |
| 346 | assert(r.random.int(i8) == 0x11); | |
| 347 | expect(r.random.int(i8) == 0x11); | |
| 347 | 348 | |
| 348 | 349 | r.next_value = 0xff; |
| 349 | assert(r.random.int(u33) == 0x1ffffffff); | |
| 350 | expect(r.random.int(u33) == 0x1ffffffff); | |
| 350 | 351 | r.next_value = 0xff; |
| 351 | assert(r.random.int(i1) == -1); | |
| 352 | expect(r.random.int(i1) == -1); | |
| 352 | 353 | r.next_value = 0xff; |
| 353 | assert(r.random.int(i2) == -1); | |
| 354 | expect(r.random.int(i2) == -1); | |
| 354 | 355 | r.next_value = 0xff; |
| 355 | assert(r.random.int(i33) == -1); | |
| 356 | expect(r.random.int(i33) == -1); | |
| 356 | 357 | } |
| 357 | 358 | |
| 358 | 359 | test "Random boolean" { |
| ... | ... | @@ -361,10 +362,10 @@ test "Random boolean" { |
| 361 | 362 | } |
| 362 | 363 | fn testRandomBoolean() void { |
| 363 | 364 | var r = SequentialPrng.init(); |
| 364 | assert(r.random.boolean() == false); | |
| 365 | assert(r.random.boolean() == true); | |
| 366 | assert(r.random.boolean() == false); | |
| 367 | assert(r.random.boolean() == true); | |
| 365 | expect(r.random.boolean() == false); | |
| 366 | expect(r.random.boolean() == true); | |
| 367 | expect(r.random.boolean() == false); | |
| 368 | expect(r.random.boolean() == true); | |
| 368 | 369 | } |
| 369 | 370 | |
| 370 | 371 | test "Random intLessThan" { |
| ... | ... | @@ -375,36 +376,36 @@ test "Random intLessThan" { |
| 375 | 376 | fn testRandomIntLessThan() void { |
| 376 | 377 | var r = SequentialPrng.init(); |
| 377 | 378 | r.next_value = 0xff; |
| 378 | assert(r.random.uintLessThan(u8, 4) == 3); | |
| 379 | assert(r.next_value == 0); | |
| 380 | assert(r.random.uintLessThan(u8, 4) == 0); | |
| 381 | assert(r.next_value == 1); | |
| 379 | expect(r.random.uintLessThan(u8, 4) == 3); | |
| 380 | expect(r.next_value == 0); | |
| 381 | expect(r.random.uintLessThan(u8, 4) == 0); | |
| 382 | expect(r.next_value == 1); | |
| 382 | 383 | |
| 383 | 384 | r.next_value = 0; |
| 384 | assert(r.random.uintLessThan(u64, 32) == 0); | |
| 385 | expect(r.random.uintLessThan(u64, 32) == 0); | |
| 385 | 386 | |
| 386 | 387 | // trigger the bias rejection code path |
| 387 | 388 | r.next_value = 0; |
| 388 | assert(r.random.uintLessThan(u8, 3) == 0); | |
| 389 | expect(r.random.uintLessThan(u8, 3) == 0); | |
| 389 | 390 | // verify we incremented twice |
| 390 | assert(r.next_value == 2); | |
| 391 | expect(r.next_value == 2); | |
| 391 | 392 | |
| 392 | 393 | r.next_value = 0xff; |
| 393 | assert(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f); | |
| 394 | expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f); | |
| 394 | 395 | r.next_value = 0xff; |
| 395 | assert(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe); | |
| 396 | expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe); | |
| 396 | 397 | |
| 397 | 398 | r.next_value = 0xff; |
| 398 | assert(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f); | |
| 399 | expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f); | |
| 399 | 400 | r.next_value = 0xff; |
| 400 | assert(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f); | |
| 401 | expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f); | |
| 401 | 402 | r.next_value = 0xff; |
| 402 | assert(r.random.intRangeLessThan(i8, -0x80, 0) == -1); | |
| 403 | expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1); | |
| 403 | 404 | |
| 404 | 405 | r.next_value = 0xff; |
| 405 | assert(r.random.intRangeLessThan(i3, -4, 0) == -1); | |
| 406 | expect(r.random.intRangeLessThan(i3, -4, 0) == -1); | |
| 406 | 407 | r.next_value = 0xff; |
| 407 | assert(r.random.intRangeLessThan(i3, -2, 2) == 1); | |
| 408 | expect(r.random.intRangeLessThan(i3, -2, 2) == 1); | |
| 408 | 409 | } |
| 409 | 410 | |
| 410 | 411 | test "Random intAtMost" { |
| ... | ... | @@ -415,34 +416,34 @@ test "Random intAtMost" { |
| 415 | 416 | fn testRandomIntAtMost() void { |
| 416 | 417 | var r = SequentialPrng.init(); |
| 417 | 418 | r.next_value = 0xff; |
| 418 | assert(r.random.uintAtMost(u8, 3) == 3); | |
| 419 | assert(r.next_value == 0); | |
| 420 | assert(r.random.uintAtMost(u8, 3) == 0); | |
| 419 | expect(r.random.uintAtMost(u8, 3) == 3); | |
| 420 | expect(r.next_value == 0); | |
| 421 | expect(r.random.uintAtMost(u8, 3) == 0); | |
| 421 | 422 | |
| 422 | 423 | // trigger the bias rejection code path |
| 423 | 424 | r.next_value = 0; |
| 424 | assert(r.random.uintAtMost(u8, 2) == 0); | |
| 425 | expect(r.random.uintAtMost(u8, 2) == 0); | |
| 425 | 426 | // verify we incremented twice |
| 426 | assert(r.next_value == 2); | |
| 427 | expect(r.next_value == 2); | |
| 427 | 428 | |
| 428 | 429 | r.next_value = 0xff; |
| 429 | assert(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f); | |
| 430 | expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f); | |
| 430 | 431 | r.next_value = 0xff; |
| 431 | assert(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe); | |
| 432 | expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe); | |
| 432 | 433 | |
| 433 | 434 | r.next_value = 0xff; |
| 434 | assert(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f); | |
| 435 | expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f); | |
| 435 | 436 | r.next_value = 0xff; |
| 436 | assert(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f); | |
| 437 | expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f); | |
| 437 | 438 | r.next_value = 0xff; |
| 438 | assert(r.random.intRangeAtMost(i8, -0x80, -1) == -1); | |
| 439 | expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1); | |
| 439 | 440 | |
| 440 | 441 | r.next_value = 0xff; |
| 441 | assert(r.random.intRangeAtMost(i3, -4, -1) == -1); | |
| 442 | expect(r.random.intRangeAtMost(i3, -4, -1) == -1); | |
| 442 | 443 | r.next_value = 0xff; |
| 443 | assert(r.random.intRangeAtMost(i3, -2, 1) == 1); | |
| 444 | expect(r.random.intRangeAtMost(i3, -2, 1) == 1); | |
| 444 | 445 | |
| 445 | assert(r.random.uintAtMost(u0, 0) == 0); | |
| 446 | expect(r.random.uintAtMost(u0, 0) == 0); | |
| 446 | 447 | } |
| 447 | 448 | |
| 448 | 449 | test "Random Biased" { |
| ... | ... | @@ -450,30 +451,30 @@ test "Random Biased" { |
| 450 | 451 | // Not thoroughly checking the logic here. |
| 451 | 452 | // Just want to execute all the paths with different types. |
| 452 | 453 | |
| 453 | assert(r.random.uintLessThanBiased(u1, 1) == 0); | |
| 454 | assert(r.random.uintLessThanBiased(u32, 10) < 10); | |
| 455 | assert(r.random.uintLessThanBiased(u64, 20) < 20); | |
| 454 | expect(r.random.uintLessThanBiased(u1, 1) == 0); | |
| 455 | expect(r.random.uintLessThanBiased(u32, 10) < 10); | |
| 456 | expect(r.random.uintLessThanBiased(u64, 20) < 20); | |
| 456 | 457 | |
| 457 | assert(r.random.uintAtMostBiased(u0, 0) == 0); | |
| 458 | assert(r.random.uintAtMostBiased(u1, 0) <= 0); | |
| 459 | assert(r.random.uintAtMostBiased(u32, 10) <= 10); | |
| 460 | assert(r.random.uintAtMostBiased(u64, 20) <= 20); | |
| 458 | expect(r.random.uintAtMostBiased(u0, 0) == 0); | |
| 459 | expect(r.random.uintAtMostBiased(u1, 0) <= 0); | |
| 460 | expect(r.random.uintAtMostBiased(u32, 10) <= 10); | |
| 461 | expect(r.random.uintAtMostBiased(u64, 20) <= 20); | |
| 461 | 462 | |
| 462 | assert(r.random.intRangeLessThanBiased(u1, 0, 1) == 0); | |
| 463 | assert(r.random.intRangeLessThanBiased(i1, -1, 0) == -1); | |
| 464 | assert(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10); | |
| 465 | assert(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10); | |
| 466 | assert(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20); | |
| 467 | assert(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20); | |
| 463 | expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0); | |
| 464 | expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1); | |
| 465 | expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10); | |
| 466 | expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10); | |
| 467 | expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20); | |
| 468 | expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20); | |
| 468 | 469 | |
| 469 | 470 | // uncomment for broken module error: |
| 470 | //assert(r.random.intRangeAtMostBiased(u0, 0, 0) == 0); | |
| 471 | assert(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0); | |
| 472 | assert(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1); | |
| 473 | assert(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10); | |
| 474 | assert(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10); | |
| 475 | assert(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20); | |
| 476 | assert(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20); | |
| 471 | //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0); | |
| 472 | expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0); | |
| 473 | expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1); | |
| 474 | expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10); | |
| 475 | expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10); | |
| 476 | expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20); | |
| 477 | expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20); | |
| 477 | 478 | } |
| 478 | 479 | |
| 479 | 480 | // Generator to extend 64-bit seed values into longer sequences. |
| ... | ... | @@ -510,7 +511,7 @@ test "splitmix64 sequence" { |
| 510 | 511 | }; |
| 511 | 512 | |
| 512 | 513 | for (seq) |s| { |
| 513 | std.debug.assert(s == r.next()); | |
| 514 | expect(s == r.next()); | |
| 514 | 515 | } |
| 515 | 516 | } |
| 516 | 517 | |
| ... | ... | @@ -603,7 +604,7 @@ test "pcg sequence" { |
| 603 | 604 | }; |
| 604 | 605 | |
| 605 | 606 | for (seq) |s| { |
| 606 | std.debug.assert(s == r.next()); | |
| 607 | expect(s == r.next()); | |
| 607 | 608 | } |
| 608 | 609 | } |
| 609 | 610 | |
| ... | ... | @@ -712,7 +713,7 @@ test "xoroshiro sequence" { |
| 712 | 713 | }; |
| 713 | 714 | |
| 714 | 715 | for (seq1) |s| { |
| 715 | std.debug.assert(s == r.next()); | |
| 716 | expect(s == r.next()); | |
| 716 | 717 | } |
| 717 | 718 | |
| 718 | 719 | r.jump(); |
| ... | ... | @@ -727,7 +728,7 @@ test "xoroshiro sequence" { |
| 727 | 728 | }; |
| 728 | 729 | |
| 729 | 730 | for (seq2) |s| { |
| 730 | std.debug.assert(s == r.next()); | |
| 731 | expect(s == r.next()); | |
| 731 | 732 | } |
| 732 | 733 | } |
| 733 | 734 | |
| ... | ... | @@ -930,7 +931,7 @@ test "isaac64 sequence" { |
| 930 | 931 | }; |
| 931 | 932 | |
| 932 | 933 | for (seq) |s| { |
| 933 | std.debug.assert(s == r.next()); | |
| 934 | expect(s == r.next()); | |
| 934 | 935 | } |
| 935 | 936 | } |
| 936 | 937 | |
| ... | ... | @@ -941,12 +942,12 @@ test "Random float" { |
| 941 | 942 | var i: usize = 0; |
| 942 | 943 | while (i < 1000) : (i += 1) { |
| 943 | 944 | const val1 = prng.random.float(f32); |
| 944 | std.debug.assert(val1 >= 0.0); | |
| 945 | std.debug.assert(val1 < 1.0); | |
| 945 | expect(val1 >= 0.0); | |
| 946 | expect(val1 < 1.0); | |
| 946 | 947 | |
| 947 | 948 | const val2 = prng.random.float(f64); |
| 948 | std.debug.assert(val2 >= 0.0); | |
| 949 | std.debug.assert(val2 < 1.0); | |
| 949 | expect(val2 >= 0.0); | |
| 950 | expect(val2 < 1.0); | |
| 950 | 951 | } |
| 951 | 952 | } |
| 952 | 953 | |
| ... | ... | @@ -960,12 +961,12 @@ test "Random shuffle" { |
| 960 | 961 | while (i < 1000) : (i += 1) { |
| 961 | 962 | prng.random.shuffle(u8, seq[0..]); |
| 962 | 963 | seen[seq[0]] = true; |
| 963 | std.debug.assert(sumArray(seq[0..]) == 10); | |
| 964 | expect(sumArray(seq[0..]) == 10); | |
| 964 | 965 | } |
| 965 | 966 | |
| 966 | 967 | // we should see every entry at the head at least once |
| 967 | 968 | for (seen) |e| { |
| 968 | std.debug.assert(e == true); | |
| 969 | expect(e == true); | |
| 969 | 970 | } |
| 970 | 971 | } |
| 971 | 972 |
std/rb.zig+3-2| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const mem = std.mem; // For mem.Compare |
| 4 | 5 | |
| 5 | 6 | const Color = enum(u1) { |
| ... | ... | @@ -533,13 +534,13 @@ test "rb" { |
| 533 | 534 | _ = tree.insert(&ns[8].node); |
| 534 | 535 | _ = tree.insert(&ns[9].node); |
| 535 | 536 | tree.remove(&ns[3].node); |
| 536 | assert(tree.insert(&dup.node) == &ns[7].node); | |
| 537 | testing.expect(tree.insert(&dup.node) == &ns[7].node); | |
| 537 | 538 | try tree.replace(&ns[7].node, &dup.node); |
| 538 | 539 | |
| 539 | 540 | var num: *testNumber = undefined; |
| 540 | 541 | num = testGetNumber(tree.first().?); |
| 541 | 542 | while (num.node.next() != null) { |
| 542 | assert(testGetNumber(num.node.next().?).value > num.value); | |
| 543 | testing.expect(testGetNumber(num.node.next().?).value > num.value); | |
| 543 | 544 | num = testGetNumber(num.node.next().?); |
| 544 | 545 | } |
| 545 | 546 | } |
std/segmented_list.zig+16-15| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const Allocator = std.mem.Allocator; |
| 4 | 5 | |
| 5 | 6 | // Imagine that `fn at(self: *Self, index: usize) &T` is a customer asking for a box |
| ... | ... | @@ -352,14 +353,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void { |
| 352 | 353 | var i: usize = 0; |
| 353 | 354 | while (i < 100) : (i += 1) { |
| 354 | 355 | try list.push(@intCast(i32, i + 1)); |
| 355 | assert(list.len == i + 1); | |
| 356 | testing.expect(list.len == i + 1); | |
| 356 | 357 | } |
| 357 | 358 | } |
| 358 | 359 | |
| 359 | 360 | { |
| 360 | 361 | var i: usize = 0; |
| 361 | 362 | while (i < 100) : (i += 1) { |
| 362 | assert(list.at(i).* == @intCast(i32, i + 1)); | |
| 363 | testing.expect(list.at(i).* == @intCast(i32, i + 1)); | |
| 363 | 364 | } |
| 364 | 365 | } |
| 365 | 366 | |
| ... | ... | @@ -368,35 +369,35 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void { |
| 368 | 369 | var x: i32 = 0; |
| 369 | 370 | while (it.next()) |item| { |
| 370 | 371 | x += 1; |
| 371 | assert(item.* == x); | |
| 372 | testing.expect(item.* == x); | |
| 372 | 373 | } |
| 373 | assert(x == 100); | |
| 374 | testing.expect(x == 100); | |
| 374 | 375 | while (it.prev()) |item| : (x -= 1) { |
| 375 | assert(item.* == x); | |
| 376 | testing.expect(item.* == x); | |
| 376 | 377 | } |
| 377 | assert(x == 0); | |
| 378 | testing.expect(x == 0); | |
| 378 | 379 | } |
| 379 | 380 | |
| 380 | assert(list.pop().? == 100); | |
| 381 | assert(list.len == 99); | |
| 381 | testing.expect(list.pop().? == 100); | |
| 382 | testing.expect(list.len == 99); | |
| 382 | 383 | |
| 383 | 384 | try list.pushMany([]i32{ |
| 384 | 385 | 1, |
| 385 | 386 | 2, |
| 386 | 387 | 3, |
| 387 | 388 | }); |
| 388 | assert(list.len == 102); | |
| 389 | assert(list.pop().? == 3); | |
| 390 | assert(list.pop().? == 2); | |
| 391 | assert(list.pop().? == 1); | |
| 392 | assert(list.len == 99); | |
| 389 | testing.expect(list.len == 102); | |
| 390 | testing.expect(list.pop().? == 3); | |
| 391 | testing.expect(list.pop().? == 2); | |
| 392 | testing.expect(list.pop().? == 1); | |
| 393 | testing.expect(list.len == 99); | |
| 393 | 394 | |
| 394 | 395 | try list.pushMany([]const i32{}); |
| 395 | assert(list.len == 99); | |
| 396 | testing.expect(list.len == 99); | |
| 396 | 397 | |
| 397 | 398 | var i: i32 = 99; |
| 398 | 399 | while (list.pop()) |item| : (i -= 1) { |
| 399 | assert(item == i); | |
| 400 | testing.expect(item == i); | |
| 400 | 401 | list.shrinkCapacity(list.len); |
| 401 | 402 | } |
| 402 | 403 | } |
std/sort.zig+9-8| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | const math = std.math; |
| 5 | 6 | const builtin = @import("builtin"); |
| ... | ... | @@ -1031,8 +1032,8 @@ fn testStableSort() void { |
| 1031 | 1032 | for (cases) |*case| { |
| 1032 | 1033 | insertionSort(IdAndValue, (case.*)[0..], cmpByValue); |
| 1033 | 1034 | for (case.*) |item, i| { |
| 1034 | assert(item.id == expected[i].id); | |
| 1035 | assert(item.value == expected[i].value); | |
| 1035 | testing.expect(item.id == expected[i].id); | |
| 1036 | testing.expect(item.value == expected[i].value); | |
| 1036 | 1037 | } |
| 1037 | 1038 | } |
| 1038 | 1039 | } |
| ... | ... | @@ -1077,7 +1078,7 @@ test "std.sort" { |
| 1077 | 1078 | const slice = buf[0..case[0].len]; |
| 1078 | 1079 | mem.copy(u8, slice, case[0]); |
| 1079 | 1080 | sort(u8, slice, asc(u8)); |
| 1080 | assert(mem.eql(u8, slice, case[1])); | |
| 1081 | testing.expect(mem.eql(u8, slice, case[1])); | |
| 1081 | 1082 | } |
| 1082 | 1083 | |
| 1083 | 1084 | const i32cases = [][]const []const i32{ |
| ... | ... | @@ -1112,7 +1113,7 @@ test "std.sort" { |
| 1112 | 1113 | const slice = buf[0..case[0].len]; |
| 1113 | 1114 | mem.copy(i32, slice, case[0]); |
| 1114 | 1115 | sort(i32, slice, asc(i32)); |
| 1115 | assert(mem.eql(i32, slice, case[1])); | |
| 1116 | testing.expect(mem.eql(i32, slice, case[1])); | |
| 1116 | 1117 | } |
| 1117 | 1118 | } |
| 1118 | 1119 | |
| ... | ... | @@ -1149,7 +1150,7 @@ test "std.sort descending" { |
| 1149 | 1150 | const slice = buf[0..case[0].len]; |
| 1150 | 1151 | mem.copy(i32, slice, case[0]); |
| 1151 | 1152 | sort(i32, slice, desc(i32)); |
| 1152 | assert(mem.eql(i32, slice, case[1])); | |
| 1153 | testing.expect(mem.eql(i32, slice, case[1])); | |
| 1153 | 1154 | } |
| 1154 | 1155 | } |
| 1155 | 1156 | |
| ... | ... | @@ -1157,7 +1158,7 @@ test "another sort case" { |
| 1157 | 1158 | var arr = []i32{ 5, 3, 1, 2, 4 }; |
| 1158 | 1159 | sort(i32, arr[0..], asc(i32)); |
| 1159 | 1160 | |
| 1160 | assert(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 })); | |
| 1161 | testing.expect(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 })); | |
| 1161 | 1162 | } |
| 1162 | 1163 | |
| 1163 | 1164 | test "sort fuzz testing" { |
| ... | ... | @@ -1185,9 +1186,9 @@ fn fuzzTest(rng: *std.rand.Random) void { |
| 1185 | 1186 | var index: usize = 1; |
| 1186 | 1187 | while (index < array.len) : (index += 1) { |
| 1187 | 1188 | if (array[index].value == array[index - 1].value) { |
| 1188 | assert(array[index].id > array[index - 1].id); | |
| 1189 | testing.expect(array[index].id > array[index - 1].id); | |
| 1189 | 1190 | } else { |
| 1190 | assert(array[index].value > array[index - 1].value); | |
| 1191 | testing.expect(array[index].value > array[index - 1].value); | |
| 1191 | 1192 | } |
| 1192 | 1193 | } |
| 1193 | 1194 | } |
std/special/compiler_rt/divti3_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __divti3 = @import("divti3.zig").__divti3; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__divti3(a: i128, b: i128, expected: i128) void { |
| 5 | 5 | const x = __divti3(a, b); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "divti3" { |
std/special/compiler_rt/extendXfYf2_test.zig-1| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2; |
| 2 | 2 | const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2; |
| 3 | 3 | const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2; |
| 4 | const assert = @import("std").debug.assert; | |
| 5 | 4 | |
| 6 | 5 | fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void { |
| 7 | 6 | const x = __extenddftf2(a); |
std/special/compiler_rt/fixdfdi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixdfdi = @import("fixdfdi.zig").__fixdfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfdi(a: f64, expected: i64) void { |
| 8 | 8 | const x = __fixdfdi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixdfdi" { |
std/special/compiler_rt/fixdfsi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixdfsi = @import("fixdfsi.zig").__fixdfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfsi(a: f64, expected: i32) void { |
| 8 | 8 | const x = __fixdfsi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixdfsi" { |
std/special/compiler_rt/fixdfti_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixdfti = @import("fixdfti.zig").__fixdfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixdfti(a: f64, expected: i128) void { |
| 8 | 8 | const x = __fixdfti(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixdfti" { |
std/special/compiler_rt/fixint_test.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const is_test = @import("builtin").is_test; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | const fixint = @import("fixint.zig").fixint; |
| ... | ... | @@ -9,7 +9,7 @@ const fixint = @import("fixint.zig").fixint; |
| 9 | 9 | fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void { |
| 10 | 10 | const x = fixint(fp_t, fixint_t, a); |
| 11 | 11 | //warn("a={} x={}:{x} expected={}:{x})\n", a, x, x, expected, expected); |
| 12 | assert(x == expected); | |
| 12 | testing.expect(x == expected); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | test "fixint.i1" { |
std/special/compiler_rt/fixsfdi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixsfdi = @import("fixsfdi.zig").__fixsfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfdi(a: f32, expected: i64) void { |
| 8 | 8 | const x = __fixsfdi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixsfdi" { |
std/special/compiler_rt/fixsfsi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixsfsi = @import("fixsfsi.zig").__fixsfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfsi(a: f32, expected: i32) void { |
| 8 | 8 | const x = __fixsfsi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixsfsi" { |
std/special/compiler_rt/fixsfti_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixsfti = @import("fixsfti.zig").__fixsfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixsfti(a: f32, expected: i128) void { |
| 8 | 8 | const x = __fixsfti(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixsfti" { |
std/special/compiler_rt/fixtfdi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixtfdi = @import("fixtfdi.zig").__fixtfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfdi(a: f128, expected: i64) void { |
| 8 | 8 | const x = __fixtfdi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixtfdi" { |
std/special/compiler_rt/fixtfsi_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixtfsi = @import("fixtfsi.zig").__fixtfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfsi(a: f128, expected: i32) void { |
| 8 | 8 | const x = __fixtfsi(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixtfsi" { |
std/special/compiler_rt/fixtfti_test.zig+2-2| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const __fixtfti = @import("fixtfti.zig").__fixtfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | const assert = std.debug.assert; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | const warn = std.debug.warn; |
| 6 | 6 | |
| 7 | 7 | fn test__fixtfti(a: f128, expected: i128) void { |
| 8 | 8 | const x = __fixtfti(a); |
| 9 | 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); |
| 10 | assert(x == expected); | |
| 10 | testing.expect(x == expected); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "fixtfti" { |
std/special/compiler_rt/fixunsdfdi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunsdfdi(a: f64, expected: u64) void { |
| 5 | 5 | const x = __fixunsdfdi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunsdfdi" { |
std/special/compiler_rt/fixunsdfsi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunsdfsi(a: f64, expected: u32) void { |
| 5 | 5 | const x = __fixunsdfsi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunsdfsi" { |
std/special/compiler_rt/fixunsdfti_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunsdfti(a: f64, expected: u128) void { |
| 5 | 5 | const x = __fixunsdfti(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunsdfti" { |
std/special/compiler_rt/fixunssfdi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunssfdi(a: f32, expected: u64) void { |
| 5 | 5 | const x = __fixunssfdi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunssfdi" { |
std/special/compiler_rt/fixunssfsi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunssfsi(a: f32, expected: u32) void { |
| 5 | 5 | const x = __fixunssfsi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunssfsi" { |
std/special/compiler_rt/fixunssfti_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunssfti = @import("fixunssfti.zig").__fixunssfti; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunssfti(a: f32, expected: u128) void { |
| 5 | 5 | const x = __fixunssfti(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunssfti" { |
std/special/compiler_rt/fixunstfdi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunstfdi(a: f128, expected: u64) void { |
| 5 | 5 | const x = __fixunstfdi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixunstfdi" { |
std/special/compiler_rt/fixunstfsi_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunstfsi(a: f128, expected: u32) void { |
| 5 | 5 | const x = __fixunstfsi(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); |
std/special/compiler_rt/fixunstfti_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __fixunstfti = @import("fixunstfti.zig").__fixunstfti; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__fixunstfti(a: f128, expected: u128) void { |
| 5 | 5 | const x = __fixunstfti(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000)); |
std/special/compiler_rt/floattidf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floattidf = @import("floattidf.zig").__floattidf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floattidf(a: i128, expected: f64) void { |
| 5 | 5 | const x = __floattidf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floattidf" { |
std/special/compiler_rt/floattisf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floattisf = @import("floattisf.zig").__floattisf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floattisf(a: i128, expected: f32) void { |
| 5 | 5 | const x = __floattisf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floattisf" { |
std/special/compiler_rt/floattitf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floattitf = @import("floattitf.zig").__floattitf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floattitf(a: i128, expected: f128) void { |
| 5 | 5 | const x = __floattitf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floattitf" { |
std/special/compiler_rt/floatunditf_test.zig-1| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const __floatunditf = @import("floatunditf.zig").__floatunditf; |
| 2 | const assert = @import("std").debug.assert; | |
| 3 | 2 | |
| 4 | 3 | fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void { |
| 5 | 4 | const x = __floatunditf(a); |
std/special/compiler_rt/floatunsitf_test.zig-1| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const __floatunsitf = @import("floatunsitf.zig").__floatunsitf; |
| 2 | const assert = @import("std").debug.assert; | |
| 3 | 2 | |
| 4 | 3 | fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void { |
| 5 | 4 | const x = __floatunsitf(a); |
std/special/compiler_rt/floatuntidf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floatuntidf = @import("floatuntidf.zig").__floatuntidf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floatuntidf(a: u128, expected: f64) void { |
| 5 | 5 | const x = __floatuntidf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floatuntidf" { |
std/special/compiler_rt/floatuntisf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floatuntisf = @import("floatuntisf.zig").__floatuntisf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floatuntisf(a: u128, expected: f32) void { |
| 5 | 5 | const x = __floatuntisf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floatuntisf" { |
std/special/compiler_rt/floatuntitf_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __floatuntitf = @import("floatuntitf.zig").__floatuntitf; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__floatuntitf(a: u128, expected: f128) void { |
| 5 | 5 | const x = __floatuntitf(a); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "floatuntitf" { |
std/special/compiler_rt/index.zig+3-2| ... | ... | @@ -110,6 +110,7 @@ comptime { |
| 110 | 110 | |
| 111 | 111 | const std = @import("std"); |
| 112 | 112 | const assert = std.debug.assert; |
| 113 | const testing = std.testing; | |
| 113 | 114 | |
| 114 | 115 | const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; |
| 115 | 116 | |
| ... | ... | @@ -417,7 +418,7 @@ test "test_umoddi3" { |
| 417 | 418 | |
| 418 | 419 | fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void { |
| 419 | 420 | const r = __umoddi3(a, b); |
| 420 | assert(r == expected_r); | |
| 421 | testing.expect(r == expected_r); | |
| 421 | 422 | } |
| 422 | 423 | |
| 423 | 424 | test "test_udivsi3" { |
| ... | ... | @@ -1091,5 +1092,5 @@ test "test_udivsi3" { |
| 1091 | 1092 | |
| 1092 | 1093 | fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void { |
| 1093 | 1094 | const q: u32 = __udivsi3(a, b); |
| 1094 | assert(q == expected_q); | |
| 1095 | testing.expect(q == expected_q); | |
| 1095 | 1096 | } |
std/special/compiler_rt/muloti4_test.zig+2-2| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | 1 | const __muloti4 = @import("muloti4.zig").__muloti4; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void { |
| 5 | 5 | var overflow: c_int = undefined; |
| 6 | 6 | const x = __muloti4(a, b, &overflow); |
| 7 | assert(overflow == expected_overflow and (expected_overflow != 0 or x == expected)); | |
| 7 | testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected)); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | test "muloti4" { |
std/special/compiler_rt/multi3_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const __multi3 = @import("multi3.zig").__multi3; |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | const testing = @import("std").testing; | |
| 3 | 3 | |
| 4 | 4 | fn test__multi3(a: i128, b: i128, expected: i128) void { |
| 5 | 5 | const x = __multi3(a, b); |
| 6 | assert(x == expected); | |
| 6 | testing.expect(x == expected); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "multi3" { |
std/special/compiler_rt/udivmoddi4_test.zig+3-3| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | // Disable formatting to avoid unnecessary source repository bloat. |
| 2 | 2 | // zig fmt: off |
| 3 | 3 | const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; |
| 4 | const assert = @import("std").debug.assert; | |
| 4 | const testing = @import("std").testing; | |
| 5 | 5 | |
| 6 | 6 | fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void { |
| 7 | 7 | var r: u64 = undefined; |
| 8 | 8 | const q = __udivmoddi4(a, b, &r); |
| 9 | assert(q == expected_q); | |
| 10 | assert(r == expected_r); | |
| 9 | testing.expect(q == expected_q); | |
| 10 | testing.expect(r == expected_r); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "udivmoddi4" { |
std/special/compiler_rt/udivmodti4_test.zig+3-3| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | // Disable formatting to avoid unnecessary source repository bloat. |
| 2 | 2 | // zig fmt: off |
| 3 | 3 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; |
| 4 | const assert = @import("std").debug.assert; | |
| 4 | const testing = @import("std").testing; | |
| 5 | 5 | |
| 6 | 6 | fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void { |
| 7 | 7 | var r: u128 = undefined; |
| 8 | 8 | const q = __udivmodti4(a, b, &r); |
| 9 | assert(q == expected_q); | |
| 10 | assert(r == expected_r); | |
| 9 | testing.expect(q == expected_q); | |
| 10 | testing.expect(r == expected_r); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "udivmodti4" { |
std/special/init-lib/src/main.zig+2-2| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const testing = std.testing; | |
| 3 | 3 | |
| 4 | 4 | export fn add(a: i32, b: i32) i32 { |
| 5 | 5 | return a + b; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "basic add functionality" { |
| 9 | assertOrPanic(add(3, 7) == 10); | |
| 9 | testing.expect(add(3, 7) == 10); | |
| 10 | 10 | } |
std/statically_initialized_mutex.zig+3-2| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const AtomicOrder = builtin.AtomicOrder; |
| 4 | 4 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 5 | const assert = std.debug.assert; |
| 6 | const expect = std.testing.expect; | |
| 6 | 7 | const windows = std.os.windows; |
| 7 | 8 | |
| 8 | 9 | /// Lock may be held only once. If the same thread |
| ... | ... | @@ -95,7 +96,7 @@ test "std.StaticallyInitializedMutex" { |
| 95 | 96 | |
| 96 | 97 | if (builtin.single_threaded) { |
| 97 | 98 | TestContext.worker(&context); |
| 98 | std.debug.assertOrPanic(context.data == TestContext.incr_count); | |
| 99 | expect(context.data == TestContext.incr_count); | |
| 99 | 100 | } else { |
| 100 | 101 | const thread_count = 10; |
| 101 | 102 | var threads: [thread_count]*std.os.Thread = undefined; |
| ... | ... | @@ -105,6 +106,6 @@ test "std.StaticallyInitializedMutex" { |
| 105 | 106 | for (threads) |t| |
| 106 | 107 | t.wait(); |
| 107 | 108 | |
| 108 | std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count); | |
| 109 | expect(context.data == thread_count * TestContext.incr_count); | |
| 109 | 110 | } |
| 110 | 111 | } |
std/testing.zig created+152| ... | ... | @@ -0,0 +1,152 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const TypeId = builtin.TypeId; | |
| 3 | const std = @import("index.zig"); | |
| 4 | ||
| 5 | /// This function is intended to be used only in tests. It prints diagnostics to stderr | |
| 6 | /// and then aborts when actual_error_union is not expected_error. | |
| 7 | pub fn expectError(expected_error: anyerror, actual_error_union: var) void { | |
| 8 | // TODO remove the workaround here for https://github.com/ziglang/zig/issues/1936 | |
| 9 | if (actual_error_union) |actual_payload| { | |
| 10 | // TODO remove workaround here for https://github.com/ziglang/zig/issues/557 | |
| 11 | if (@sizeOf(@typeOf(actual_payload)) == 0) { | |
| 12 | std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload))); | |
| 13 | } else { | |
| 14 | std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload); | |
| 15 | } | |
| 16 | } else |actual_error| { | |
| 17 | if (expected_error != actual_error) { | |
| 18 | std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error)); | |
| 19 | } | |
| 20 | } | |
| 21 | } | |
| 22 | ||
| 23 | /// This function is intended to be used only in tests. When the two values are not | |
| 24 | /// equal, prints diagnostics to stderr to show exactly how they are not equal, | |
| 25 | /// then aborts. | |
| 26 | /// The types must match exactly. | |
| 27 | pub fn expectEqual(expected: var, actual: var) void { | |
| 28 | if (@typeOf(actual) != @typeOf(expected)) { | |
| 29 | @compileError("type mismatch. expected " ++ @typeName(@typeOf(expected)) ++ ", found " ++ @typeName(@typeOf(actual))); | |
| 30 | } | |
| 31 | ||
| 32 | switch (@typeInfo(@typeOf(actual))) { | |
| 33 | TypeId.NoReturn, | |
| 34 | TypeId.BoundFn, | |
| 35 | TypeId.ArgTuple, | |
| 36 | TypeId.Opaque, | |
| 37 | => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"), | |
| 38 | ||
| 39 | TypeId.Undefined, | |
| 40 | TypeId.Null, | |
| 41 | TypeId.Void, | |
| 42 | => return, | |
| 43 | ||
| 44 | TypeId.Type, | |
| 45 | TypeId.Bool, | |
| 46 | TypeId.Int, | |
| 47 | TypeId.Float, | |
| 48 | TypeId.ComptimeFloat, | |
| 49 | TypeId.ComptimeInt, | |
| 50 | TypeId.Enum, | |
| 51 | TypeId.Namespace, | |
| 52 | TypeId.Fn, | |
| 53 | TypeId.Promise, | |
| 54 | TypeId.Vector, | |
| 55 | TypeId.ErrorSet, | |
| 56 | => { | |
| 57 | if (actual != expected) { | |
| 58 | std.debug.panic("expected {}, found {}", expected, actual); | |
| 59 | } | |
| 60 | }, | |
| 61 | ||
| 62 | TypeId.Pointer => |pointer| { | |
| 63 | switch (pointer.size) { | |
| 64 | builtin.TypeInfo.Pointer.Size.One, | |
| 65 | builtin.TypeInfo.Pointer.Size.Many, | |
| 66 | => { | |
| 67 | if (actual != expected) { | |
| 68 | std.debug.panic("expected {}, found {}", expected, actual); | |
| 69 | } | |
| 70 | }, | |
| 71 | ||
| 72 | builtin.TypeInfo.Pointer.Size.Slice => { | |
| 73 | if (actual.ptr != expected.ptr) { | |
| 74 | std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr); | |
| 75 | } | |
| 76 | if (actual.len != expected.len) { | |
| 77 | std.debug.panic("expected slice len {}, found {}", expected.len, actual.len); | |
| 78 | } | |
| 79 | }, | |
| 80 | } | |
| 81 | }, | |
| 82 | ||
| 83 | TypeId.Array => |array| expectEqualSlices(array.child, &expected, &actual), | |
| 84 | ||
| 85 | TypeId.Struct => { | |
| 86 | @compileError("TODO implement testing.expectEqual for structs"); | |
| 87 | }, | |
| 88 | ||
| 89 | TypeId.Union => |union_info| { | |
| 90 | if (union_info.tag_type == null) { | |
| 91 | @compileError("Unable to compare untagged union values"); | |
| 92 | } | |
| 93 | @compileError("TODO implement testing.expectEqual for tagged unions"); | |
| 94 | }, | |
| 95 | ||
| 96 | TypeId.Optional => { | |
| 97 | if (expected) |expected_payload| { | |
| 98 | if (actual) |actual_payload| { | |
| 99 | expectEqual(expected_payload, actual_payload); | |
| 100 | } else { | |
| 101 | std.debug.panic("expected {}, found null", expected_payload); | |
| 102 | } | |
| 103 | } else { | |
| 104 | if (actual) |actual_payload| { | |
| 105 | std.debug.panic("expected null, found {}", actual_payload); | |
| 106 | } | |
| 107 | } | |
| 108 | }, | |
| 109 | ||
| 110 | TypeId.ErrorUnion => { | |
| 111 | if (expected) |expected_payload| { | |
| 112 | if (actual) |actual_payload| { | |
| 113 | expectEqual(expected_payload, actual_payload); | |
| 114 | } else |actual_err| { | |
| 115 | std.debug.panic("expected {}, found {}", expected_payload, actual_err); | |
| 116 | } | |
| 117 | } else |expected_err| { | |
| 118 | if (actual) |actual_payload| { | |
| 119 | std.debug.panic("expected {}, found {}", expected_err, actual_payload); | |
| 120 | } else |actual_err| { | |
| 121 | expectEqual(expected_err, actual_err); | |
| 122 | } | |
| 123 | } | |
| 124 | }, | |
| 125 | ||
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | /// This function is intended to be used only in tests. When the two slices are not | |
| 130 | /// equal, prints diagnostics to stderr to show exactly how they are not equal, | |
| 131 | /// then aborts. | |
| 132 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) void { | |
| 133 | // TODO better printing of the difference | |
| 134 | // If the arrays are small enough we could print the whole thing | |
| 135 | // If the child type is u8 and no weird bytes, we could print it as strings | |
| 136 | // Even for the length difference, it would be useful to see the values of the slices probably. | |
| 137 | if (expected.len != actual.len) { | |
| 138 | std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len); | |
| 139 | } | |
| 140 | var i: usize = 0; | |
| 141 | while (i < expected.len) : (i += 1) { | |
| 142 | if (expected[i] != actual[i]) { | |
| 143 | std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]); | |
| 144 | } | |
| 145 | } | |
| 146 | } | |
| 147 | ||
| 148 | /// This function is intended to be used only in tests. When `ok` is false, the test fails. | |
| 149 | /// A message is printed to stderr and then abort is called. | |
| 150 | pub fn expect(ok: bool) void { | |
| 151 | if (!ok) @panic("test failure"); | |
| 152 | } |
std/unicode.zig+53-66| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const std = @import("./index.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const debug = std.debug; | |
| 4 | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | |
| 7 | 7 | /// Returns how many bytes the UTF-8 representation would require |
| ... | ... | @@ -32,7 +32,7 @@ pub fn utf8ByteSequenceLength(first_byte: u8) !u3 { |
| 32 | 32 | /// Returns: the number of bytes written to out. |
| 33 | 33 | pub fn utf8Encode(c: u32, out: []u8) !u3 { |
| 34 | 34 | const length = try utf8CodepointSequenceLength(c); |
| 35 | debug.assert(out.len >= length); | |
| 35 | assert(out.len >= length); | |
| 36 | 36 | switch (length) { |
| 37 | 37 | // The pattern for each is the same |
| 38 | 38 | // - Increasing the initial shift by 6 each time |
| ... | ... | @@ -81,8 +81,8 @@ const Utf8Decode2Error = error{ |
| 81 | 81 | Utf8OverlongEncoding, |
| 82 | 82 | }; |
| 83 | 83 | pub fn utf8Decode2(bytes: []const u8) Utf8Decode2Error!u32 { |
| 84 | debug.assert(bytes.len == 2); | |
| 85 | debug.assert(bytes[0] & 0b11100000 == 0b11000000); | |
| 84 | assert(bytes.len == 2); | |
| 85 | assert(bytes[0] & 0b11100000 == 0b11000000); | |
| 86 | 86 | var value: u32 = bytes[0] & 0b00011111; |
| 87 | 87 | |
| 88 | 88 | if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation; |
| ... | ... | @@ -100,8 +100,8 @@ const Utf8Decode3Error = error{ |
| 100 | 100 | Utf8EncodesSurrogateHalf, |
| 101 | 101 | }; |
| 102 | 102 | pub fn utf8Decode3(bytes: []const u8) Utf8Decode3Error!u32 { |
| 103 | debug.assert(bytes.len == 3); | |
| 104 | debug.assert(bytes[0] & 0b11110000 == 0b11100000); | |
| 103 | assert(bytes.len == 3); | |
| 104 | assert(bytes[0] & 0b11110000 == 0b11100000); | |
| 105 | 105 | var value: u32 = bytes[0] & 0b00001111; |
| 106 | 106 | |
| 107 | 107 | if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation; |
| ... | ... | @@ -124,8 +124,8 @@ const Utf8Decode4Error = error{ |
| 124 | 124 | Utf8CodepointTooLarge, |
| 125 | 125 | }; |
| 126 | 126 | pub fn utf8Decode4(bytes: []const u8) Utf8Decode4Error!u32 { |
| 127 | debug.assert(bytes.len == 4); | |
| 128 | debug.assert(bytes[0] & 0b11111000 == 0b11110000); | |
| 127 | assert(bytes.len == 4); | |
| 128 | assert(bytes[0] & 0b11111000 == 0b11110000); | |
| 129 | 129 | var value: u32 = bytes[0] & 0b00000111; |
| 130 | 130 | |
| 131 | 131 | if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation; |
| ... | ... | @@ -274,23 +274,23 @@ test "utf8 encode" { |
| 274 | 274 | fn testUtf8Encode() !void { |
| 275 | 275 | // A few taken from wikipedia a few taken elsewhere |
| 276 | 276 | var array: [4]u8 = undefined; |
| 277 | debug.assert((try utf8Encode(try utf8Decode("€"), array[0..])) == 3); | |
| 278 | debug.assert(array[0] == 0b11100010); | |
| 279 | debug.assert(array[1] == 0b10000010); | |
| 280 | debug.assert(array[2] == 0b10101100); | |
| 277 | testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3); | |
| 278 | testing.expect(array[0] == 0b11100010); | |
| 279 | testing.expect(array[1] == 0b10000010); | |
| 280 | testing.expect(array[2] == 0b10101100); | |
| 281 | 281 | |
| 282 | debug.assert((try utf8Encode(try utf8Decode("$"), array[0..])) == 1); | |
| 283 | debug.assert(array[0] == 0b00100100); | |
| 282 | testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1); | |
| 283 | testing.expect(array[0] == 0b00100100); | |
| 284 | 284 | |
| 285 | debug.assert((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2); | |
| 286 | debug.assert(array[0] == 0b11000010); | |
| 287 | debug.assert(array[1] == 0b10100010); | |
| 285 | testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2); | |
| 286 | testing.expect(array[0] == 0b11000010); | |
| 287 | testing.expect(array[1] == 0b10100010); | |
| 288 | 288 | |
| 289 | debug.assert((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4); | |
| 290 | debug.assert(array[0] == 0b11110000); | |
| 291 | debug.assert(array[1] == 0b10010000); | |
| 292 | debug.assert(array[2] == 0b10001101); | |
| 293 | debug.assert(array[3] == 0b10001000); | |
| 289 | testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4); | |
| 290 | testing.expect(array[0] == 0b11110000); | |
| 291 | testing.expect(array[1] == 0b10010000); | |
| 292 | testing.expect(array[2] == 0b10001101); | |
| 293 | testing.expect(array[3] == 0b10001000); | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | test "utf8 encode error" { |
| ... | ... | @@ -306,11 +306,7 @@ fn testUtf8EncodeError() void { |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: anyerror) void { |
| 309 | if (utf8Encode(codePoint, array)) |_| { | |
| 310 | unreachable; | |
| 311 | } else |err| { | |
| 312 | debug.assert(err == expectedErr); | |
| 313 | } | |
| 309 | testing.expectError(expectedErr, utf8Encode(codePoint, array)); | |
| 314 | 310 | } |
| 315 | 311 | |
| 316 | 312 | test "utf8 iterator on ascii" { |
| ... | ... | @@ -321,16 +317,16 @@ fn testUtf8IteratorOnAscii() void { |
| 321 | 317 | const s = Utf8View.initComptime("abc"); |
| 322 | 318 | |
| 323 | 319 | var it1 = s.iterator(); |
| 324 | debug.assert(std.mem.eql(u8, "a", it1.nextCodepointSlice().?)); | |
| 325 | debug.assert(std.mem.eql(u8, "b", it1.nextCodepointSlice().?)); | |
| 326 | debug.assert(std.mem.eql(u8, "c", it1.nextCodepointSlice().?)); | |
| 327 | debug.assert(it1.nextCodepointSlice() == null); | |
| 320 | testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?)); | |
| 321 | testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?)); | |
| 322 | testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?)); | |
| 323 | testing.expect(it1.nextCodepointSlice() == null); | |
| 328 | 324 | |
| 329 | 325 | var it2 = s.iterator(); |
| 330 | debug.assert(it2.nextCodepoint().? == 'a'); | |
| 331 | debug.assert(it2.nextCodepoint().? == 'b'); | |
| 332 | debug.assert(it2.nextCodepoint().? == 'c'); | |
| 333 | debug.assert(it2.nextCodepoint() == null); | |
| 326 | testing.expect(it2.nextCodepoint().? == 'a'); | |
| 327 | testing.expect(it2.nextCodepoint().? == 'b'); | |
| 328 | testing.expect(it2.nextCodepoint().? == 'c'); | |
| 329 | testing.expect(it2.nextCodepoint() == null); | |
| 334 | 330 | } |
| 335 | 331 | |
| 336 | 332 | test "utf8 view bad" { |
| ... | ... | @@ -340,12 +336,7 @@ test "utf8 view bad" { |
| 340 | 336 | fn testUtf8ViewBad() void { |
| 341 | 337 | // Compile-time error. |
| 342 | 338 | // const s3 = Utf8View.initComptime("\xfe\xf2"); |
| 343 | const s = Utf8View.init("hel\xadlo"); | |
| 344 | if (s) |_| { | |
| 345 | unreachable; | |
| 346 | } else |err| { | |
| 347 | debug.assert(err == error.InvalidUtf8); | |
| 348 | } | |
| 339 | testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo")); | |
| 349 | 340 | } |
| 350 | 341 | |
| 351 | 342 | test "utf8 view ok" { |
| ... | ... | @@ -356,16 +347,16 @@ fn testUtf8ViewOk() void { |
| 356 | 347 | const s = Utf8View.initComptime("東京市"); |
| 357 | 348 | |
| 358 | 349 | var it1 = s.iterator(); |
| 359 | debug.assert(std.mem.eql(u8, "東", it1.nextCodepointSlice().?)); | |
| 360 | debug.assert(std.mem.eql(u8, "京", it1.nextCodepointSlice().?)); | |
| 361 | debug.assert(std.mem.eql(u8, "市", it1.nextCodepointSlice().?)); | |
| 362 | debug.assert(it1.nextCodepointSlice() == null); | |
| 350 | testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?)); | |
| 351 | testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?)); | |
| 352 | testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?)); | |
| 353 | testing.expect(it1.nextCodepointSlice() == null); | |
| 363 | 354 | |
| 364 | 355 | var it2 = s.iterator(); |
| 365 | debug.assert(it2.nextCodepoint().? == 0x6771); | |
| 366 | debug.assert(it2.nextCodepoint().? == 0x4eac); | |
| 367 | debug.assert(it2.nextCodepoint().? == 0x5e02); | |
| 368 | debug.assert(it2.nextCodepoint() == null); | |
| 356 | testing.expect(it2.nextCodepoint().? == 0x6771); | |
| 357 | testing.expect(it2.nextCodepoint().? == 0x4eac); | |
| 358 | testing.expect(it2.nextCodepoint().? == 0x5e02); | |
| 359 | testing.expect(it2.nextCodepoint() == null); | |
| 369 | 360 | } |
| 370 | 361 | |
| 371 | 362 | test "bad utf8 slice" { |
| ... | ... | @@ -373,10 +364,10 @@ test "bad utf8 slice" { |
| 373 | 364 | testBadUtf8Slice(); |
| 374 | 365 | } |
| 375 | 366 | fn testBadUtf8Slice() void { |
| 376 | debug.assert(utf8ValidateSlice("abc")); | |
| 377 | debug.assert(!utf8ValidateSlice("abc\xc0")); | |
| 378 | debug.assert(!utf8ValidateSlice("abc\xc0abc")); | |
| 379 | debug.assert(utf8ValidateSlice("abc\xdf\xbf")); | |
| 367 | testing.expect(utf8ValidateSlice("abc")); | |
| 368 | testing.expect(!utf8ValidateSlice("abc\xc0")); | |
| 369 | testing.expect(!utf8ValidateSlice("abc\xc0abc")); | |
| 370 | testing.expect(utf8ValidateSlice("abc\xdf\xbf")); | |
| 380 | 371 | } |
| 381 | 372 | |
| 382 | 373 | test "valid utf8" { |
| ... | ... | @@ -459,21 +450,17 @@ fn testMiscInvalidUtf8() void { |
| 459 | 450 | } |
| 460 | 451 | |
| 461 | 452 | fn testError(bytes: []const u8, expected_err: anyerror) void { |
| 462 | if (testDecode(bytes)) |_| { | |
| 463 | unreachable; | |
| 464 | } else |err| { | |
| 465 | debug.assert(err == expected_err); | |
| 466 | } | |
| 453 | testing.expectError(expected_err, testDecode(bytes)); | |
| 467 | 454 | } |
| 468 | 455 | |
| 469 | 456 | fn testValid(bytes: []const u8, expected_codepoint: u32) void { |
| 470 | debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint); | |
| 457 | testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint); | |
| 471 | 458 | } |
| 472 | 459 | |
| 473 | 460 | fn testDecode(bytes: []const u8) !u32 { |
| 474 | 461 | const length = try utf8ByteSequenceLength(bytes[0]); |
| 475 | 462 | if (bytes.len < length) return error.UnexpectedEof; |
| 476 | debug.assert(bytes.len == length); | |
| 463 | testing.expect(bytes.len == length); | |
| 477 | 464 | return utf8Decode(bytes); |
| 478 | 465 | } |
| 479 | 466 | |
| ... | ... | @@ -513,14 +500,14 @@ test "utf16leToUtf8" { |
| 513 | 500 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A'); |
| 514 | 501 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a'); |
| 515 | 502 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 516 | assert(mem.eql(u8, utf8, "Aa")); | |
| 503 | testing.expect(mem.eql(u8, utf8, "Aa")); | |
| 517 | 504 | } |
| 518 | 505 | |
| 519 | 506 | { |
| 520 | 507 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80); |
| 521 | 508 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff); |
| 522 | 509 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 523 | assert(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); | |
| 510 | testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); | |
| 524 | 511 | } |
| 525 | 512 | |
| 526 | 513 | { |
| ... | ... | @@ -528,7 +515,7 @@ test "utf16leToUtf8" { |
| 528 | 515 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff); |
| 529 | 516 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000); |
| 530 | 517 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 531 | assert(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); | |
| 518 | testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); | |
| 532 | 519 | } |
| 533 | 520 | |
| 534 | 521 | { |
| ... | ... | @@ -536,7 +523,7 @@ test "utf16leToUtf8" { |
| 536 | 523 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800); |
| 537 | 524 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); |
| 538 | 525 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 539 | assert(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); | |
| 526 | testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); | |
| 540 | 527 | } |
| 541 | 528 | |
| 542 | 529 | { |
| ... | ... | @@ -544,14 +531,14 @@ test "utf16leToUtf8" { |
| 544 | 531 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff); |
| 545 | 532 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff); |
| 546 | 533 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 547 | assert(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); | |
| 534 | testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); | |
| 548 | 535 | } |
| 549 | 536 | |
| 550 | 537 | { |
| 551 | 538 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff); |
| 552 | 539 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); |
| 553 | 540 | const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le); |
| 554 | assert(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); | |
| 541 | testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); | |
| 555 | 542 | } |
| 556 | 543 | } |
| 557 | 544 |
std/zig/ast.zig+2-1| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("../index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const testing = std.testing; | |
| 3 | 4 | const SegmentedList = std.SegmentedList; |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | const Token = std.zig.Token; |
| ... | ... | @@ -2224,5 +2225,5 @@ test "iterate" { |
| 2224 | 2225 | .shebang = null, |
| 2225 | 2226 | }; |
| 2226 | 2227 | var base = &root.base; |
| 2227 | assert(base.iterate(0) == null); | |
| 2228 | testing.expect(base.iterate(0) == null); | |
| 2228 | 2229 | } |
std/zig/parser_test.zig+1-1| ... | ... | @@ -1940,7 +1940,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 1940 | 1940 | warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected); |
| 1941 | 1941 | return error.TestFailed; |
| 1942 | 1942 | } |
| 1943 | std.debug.assert(anything_changed == changes_expected); | |
| 1943 | std.testing.expect(anything_changed == changes_expected); | |
| 1944 | 1944 | failing_allocator.allocator.free(result_source); |
| 1945 | 1945 | break :x failing_allocator.index; |
| 1946 | 1946 | }; |
std/zig/tokenizer.zig+1-1| ... | ... | @@ -1345,5 +1345,5 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { |
| 1345 | 1345 | } |
| 1346 | 1346 | } |
| 1347 | 1347 | const last_token = tokenizer.next(); |
| 1348 | std.debug.assert(last_token.id == Token.Id.Eof); | |
| 1348 | std.testing.expect(last_token.id == Token.Id.Eof); | |
| 1349 | 1349 | } |
test/cli.zig+5-5| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const os = std.os; |
| 4 | const assertOrPanic = std.debug.assertOrPanic; | |
| 4 | const testing = std.testing; | |
| 5 | 5 | |
| 6 | 6 | var a: *std.mem.Allocator = undefined; |
| 7 | 7 | |
| ... | ... | @@ -87,13 +87,13 @@ fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult { |
| 87 | 87 | fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void { |
| 88 | 88 | _ = try exec(dir_path, [][]const u8{ zig_exe, "init-lib" }); |
| 89 | 89 | const test_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "test" }); |
| 90 | assertOrPanic(std.mem.endsWith(u8, test_result.stderr, "All tests passed.\n")); | |
| 90 | testing.expect(std.mem.endsWith(u8, test_result.stderr, "All tests passed.\n")); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void { |
| 94 | 94 | _ = try exec(dir_path, [][]const u8{ zig_exe, "init-exe" }); |
| 95 | 95 | const run_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "run" }); |
| 96 | assertOrPanic(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n")); | |
| 96 | testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n")); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| ... | ... | @@ -126,6 +126,6 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 126 | 126 | _ = try exec(dir_path, args); |
| 127 | 127 | |
| 128 | 128 | const out_asm = try std.io.readFileAlloc(a, example_s_path); |
| 129 | assertOrPanic(std.mem.indexOf(u8, out_asm, "square:") != null); | |
| 130 | assertOrPanic(std.mem.indexOf(u8, out_asm, "imul\tedi, edi") != null); | |
| 129 | testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null); | |
| 130 | testing.expect(std.mem.indexOf(u8, out_asm, "imul\tedi, edi") != null); | |
| 131 | 131 | } |
test/stage1/behavior/align.zig+36-36| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | var foo: u8 align(4) = 100; |
| 5 | 5 | |
| 6 | 6 | test "global variable alignment" { |
| 7 | assertOrPanic(@typeOf(&foo).alignment == 4); | |
| 8 | assertOrPanic(@typeOf(&foo) == *align(4) u8); | |
| 7 | expect(@typeOf(&foo).alignment == 4); | |
| 8 | expect(@typeOf(&foo) == *align(4) u8); | |
| 9 | 9 | const slice = (*[1]u8)(&foo)[0..]; |
| 10 | assertOrPanic(@typeOf(slice) == []align(4) u8); | |
| 10 | expect(@typeOf(slice) == []align(4) u8); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | fn derp() align(@sizeOf(usize) * 2) i32 { |
| ... | ... | @@ -17,9 +17,9 @@ fn noop1() align(1) void {} |
| 17 | 17 | fn noop4() align(4) void {} |
| 18 | 18 | |
| 19 | 19 | test "function alignment" { |
| 20 | assertOrPanic(derp() == 1234); | |
| 21 | assertOrPanic(@typeOf(noop1) == fn () align(1) void); | |
| 22 | assertOrPanic(@typeOf(noop4) == fn () align(4) void); | |
| 20 | expect(derp() == 1234); | |
| 21 | expect(@typeOf(noop1) == fn () align(1) void); | |
| 22 | expect(@typeOf(noop4) == fn () align(4) void); | |
| 23 | 23 | noop1(); |
| 24 | 24 | noop4(); |
| 25 | 25 | } |
| ... | ... | @@ -30,7 +30,7 @@ var baz: packed struct { |
| 30 | 30 | } = undefined; |
| 31 | 31 | |
| 32 | 32 | test "packed struct alignment" { |
| 33 | assertOrPanic(@typeOf(&baz.b) == *align(1) u32); | |
| 33 | expect(@typeOf(&baz.b) == *align(1) u32); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | const blah: packed struct { |
| ... | ... | @@ -40,17 +40,17 @@ const blah: packed struct { |
| 40 | 40 | } = undefined; |
| 41 | 41 | |
| 42 | 42 | test "bit field alignment" { |
| 43 | assertOrPanic(@typeOf(&blah.b) == *align(1:3:1) const u3); | |
| 43 | expect(@typeOf(&blah.b) == *align(1:3:1) const u3); | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | test "default alignment allows unspecified in type syntax" { |
| 47 | assertOrPanic(*u32 == *align(@alignOf(u32)) u32); | |
| 47 | expect(*u32 == *align(@alignOf(u32)) u32); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "implicitly decreasing pointer alignment" { |
| 51 | 51 | const a: u32 align(4) = 3; |
| 52 | 52 | const b: u32 align(8) = 4; |
| 53 | assertOrPanic(addUnaligned(&a, &b) == 7); | |
| 53 | expect(addUnaligned(&a, &b) == 7); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| ... | ... | @@ -60,7 +60,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| 60 | 60 | test "implicitly decreasing slice alignment" { |
| 61 | 61 | const a: u32 align(4) = 3; |
| 62 | 62 | const b: u32 align(8) = 4; |
| 63 | assertOrPanic(addUnalignedSlice((*[1]u32)(&a)[0..], (*[1]u32)(&b)[0..]) == 7); | |
| 63 | expect(addUnalignedSlice((*[1]u32)(&a)[0..], (*[1]u32)(&b)[0..]) == 7); | |
| 64 | 64 | } |
| 65 | 65 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { |
| 66 | 66 | return a[0] + b[0]; |
| ... | ... | @@ -77,7 +77,7 @@ fn testBytesAlign(b: u8) void { |
| 77 | 77 | b, |
| 78 | 78 | }; |
| 79 | 79 | const ptr = @ptrCast(*u32, &bytes[0]); |
| 80 | assertOrPanic(ptr.* == 0x33333333); | |
| 80 | expect(ptr.* == 0x33333333); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "specifying alignment allows slice cast" { |
| ... | ... | @@ -91,13 +91,13 @@ fn testBytesAlignSlice(b: u8) void { |
| 91 | 91 | b, |
| 92 | 92 | }; |
| 93 | 93 | const slice: []u32 = @bytesToSlice(u32, bytes[0..]); |
| 94 | assertOrPanic(slice[0] == 0x33333333); | |
| 94 | expect(slice[0] == 0x33333333); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | test "@alignCast pointers" { |
| 98 | 98 | var x: u32 align(4) = 1; |
| 99 | 99 | expectsOnly1(&x); |
| 100 | assertOrPanic(x == 2); | |
| 100 | expect(x == 2); | |
| 101 | 101 | } |
| 102 | 102 | fn expectsOnly1(x: *align(1) u32) void { |
| 103 | 103 | expects4(@alignCast(4, x)); |
| ... | ... | @@ -113,7 +113,7 @@ test "@alignCast slices" { |
| 113 | 113 | }; |
| 114 | 114 | const slice = array[0..]; |
| 115 | 115 | sliceExpectsOnly1(slice); |
| 116 | assertOrPanic(slice[0] == 2); | |
| 116 | expect(slice[0] == 2); | |
| 117 | 117 | } |
| 118 | 118 | fn sliceExpectsOnly1(slice: []align(1) u32) void { |
| 119 | 119 | sliceExpects4(@alignCast(4, slice)); |
| ... | ... | @@ -128,7 +128,7 @@ test "implicitly decreasing fn alignment" { |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void { |
| 131 | assertOrPanic(ptr() == answer); | |
| 131 | expect(ptr() == answer); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | fn alignedSmall() align(8) i32 { |
| ... | ... | @@ -139,7 +139,7 @@ fn alignedBig() align(16) i32 { |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "@alignCast functions" { |
| 142 | assertOrPanic(fnExpectsOnly1(simple4) == 0x19); | |
| 142 | expect(fnExpectsOnly1(simple4) == 0x19); | |
| 143 | 143 | } |
| 144 | 144 | fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 { |
| 145 | 145 | return fnExpects4(@alignCast(4, ptr)); |
| ... | ... | @@ -152,9 +152,9 @@ fn simple4() align(4) i32 { |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "generic function with align param" { |
| 155 | assertOrPanic(whyWouldYouEverDoThis(1) == 0x1); | |
| 156 | assertOrPanic(whyWouldYouEverDoThis(4) == 0x1); | |
| 157 | assertOrPanic(whyWouldYouEverDoThis(8) == 0x1); | |
| 155 | expect(whyWouldYouEverDoThis(1) == 0x1); | |
| 156 | expect(whyWouldYouEverDoThis(4) == 0x1); | |
| 157 | expect(whyWouldYouEverDoThis(8) == 0x1); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { |
| ... | ... | @@ -164,28 +164,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { |
| 164 | 164 | test "@ptrCast preserves alignment of bigger source" { |
| 165 | 165 | var x: u32 align(16) = 1234; |
| 166 | 166 | const ptr = @ptrCast(*u8, &x); |
| 167 | assertOrPanic(@typeOf(ptr) == *align(16) u8); | |
| 167 | expect(@typeOf(ptr) == *align(16) u8); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | test "runtime known array index has best alignment possible" { |
| 171 | 171 | // take full advantage of over-alignment |
| 172 | 172 | var array align(4) = []u8{ 1, 2, 3, 4 }; |
| 173 | assertOrPanic(@typeOf(&array[0]) == *align(4) u8); | |
| 174 | assertOrPanic(@typeOf(&array[1]) == *u8); | |
| 175 | assertOrPanic(@typeOf(&array[2]) == *align(2) u8); | |
| 176 | assertOrPanic(@typeOf(&array[3]) == *u8); | |
| 173 | expect(@typeOf(&array[0]) == *align(4) u8); | |
| 174 | expect(@typeOf(&array[1]) == *u8); | |
| 175 | expect(@typeOf(&array[2]) == *align(2) u8); | |
| 176 | expect(@typeOf(&array[3]) == *u8); | |
| 177 | 177 | |
| 178 | 178 | // because align is too small but we still figure out to use 2 |
| 179 | 179 | var bigger align(2) = []u64{ 1, 2, 3, 4 }; |
| 180 | assertOrPanic(@typeOf(&bigger[0]) == *align(2) u64); | |
| 181 | assertOrPanic(@typeOf(&bigger[1]) == *align(2) u64); | |
| 182 | assertOrPanic(@typeOf(&bigger[2]) == *align(2) u64); | |
| 183 | assertOrPanic(@typeOf(&bigger[3]) == *align(2) u64); | |
| 180 | expect(@typeOf(&bigger[0]) == *align(2) u64); | |
| 181 | expect(@typeOf(&bigger[1]) == *align(2) u64); | |
| 182 | expect(@typeOf(&bigger[2]) == *align(2) u64); | |
| 183 | expect(@typeOf(&bigger[3]) == *align(2) u64); | |
| 184 | 184 | |
| 185 | 185 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 |
| 186 | 186 | var smaller align(2) = []u32{ 1, 2, 3, 4 }; |
| 187 | comptime assertOrPanic(@typeOf(smaller[0..]) == []align(2) u32); | |
| 188 | comptime assertOrPanic(@typeOf(smaller[0..].ptr) == [*]align(2) u32); | |
| 187 | comptime expect(@typeOf(smaller[0..]) == []align(2) u32); | |
| 188 | comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32); | |
| 189 | 189 | testIndex(smaller[0..].ptr, 0, *align(2) u32); |
| 190 | 190 | testIndex(smaller[0..].ptr, 1, *align(2) u32); |
| 191 | 191 | testIndex(smaller[0..].ptr, 2, *align(2) u32); |
| ... | ... | @@ -198,14 +198,14 @@ test "runtime known array index has best alignment possible" { |
| 198 | 198 | testIndex2(array[0..].ptr, 3, *u8); |
| 199 | 199 | } |
| 200 | 200 | fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void { |
| 201 | comptime assertOrPanic(@typeOf(&smaller[index]) == T); | |
| 201 | comptime expect(@typeOf(&smaller[index]) == T); | |
| 202 | 202 | } |
| 203 | 203 | fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void { |
| 204 | comptime assertOrPanic(@typeOf(&ptr[index]) == T); | |
| 204 | comptime expect(@typeOf(&ptr[index]) == T); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | test "alignstack" { |
| 208 | assertOrPanic(fnWithAlignedStack() == 1234); | |
| 208 | expect(fnWithAlignedStack() == 1234); | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | fn fnWithAlignedStack() i32 { |
| ... | ... | @@ -214,7 +214,7 @@ fn fnWithAlignedStack() i32 { |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | test "alignment of structs" { |
| 217 | assertOrPanic(@alignOf(struct { | |
| 217 | expect(@alignOf(struct { | |
| 218 | 218 | a: i32, |
| 219 | 219 | b: *i32, |
| 220 | 220 | }) == @alignOf(usize)); |
test/stage1/behavior/alignof.zig+3-3| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| ... | ... | @@ -10,9 +10,9 @@ const Foo = struct { |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | test "@alignOf(T) before referencing T" { |
| 13 | comptime assertOrPanic(@alignOf(Foo) != maxInt(usize)); | |
| 13 | comptime expect(@alignOf(Foo) != maxInt(usize)); | |
| 14 | 14 | if (builtin.arch == builtin.Arch.x86_64) { |
| 15 | comptime assertOrPanic(@alignOf(Foo) == 4); | |
| 15 | comptime expect(@alignOf(Foo) == 4); | |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 |
test/stage1/behavior/array.zig+55-55| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | test "arrays" { |
| ... | ... | @@ -18,8 +18,8 @@ test "arrays" { |
| 18 | 18 | i += 1; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | assertOrPanic(accumulator == 15); | |
| 22 | assertOrPanic(getArrayLen(array) == 5); | |
| 21 | expect(accumulator == 15); | |
| 22 | expect(getArrayLen(array) == 5); | |
| 23 | 23 | } |
| 24 | 24 | fn getArrayLen(a: []const u32) usize { |
| 25 | 25 | return a.len; |
| ... | ... | @@ -29,8 +29,8 @@ test "void arrays" { |
| 29 | 29 | var array: [4]void = undefined; |
| 30 | 30 | array[0] = void{}; |
| 31 | 31 | array[1] = array[2]; |
| 32 | assertOrPanic(@sizeOf(@typeOf(array)) == 0); | |
| 33 | assertOrPanic(array.len == 4); | |
| 32 | expect(@sizeOf(@typeOf(array)) == 0); | |
| 33 | expect(array.len == 4); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | test "array literal" { |
| ... | ... | @@ -41,12 +41,12 @@ test "array literal" { |
| 41 | 41 | 1, |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | assertOrPanic(hex_mult.len == 4); | |
| 45 | assertOrPanic(hex_mult[1] == 256); | |
| 44 | expect(hex_mult.len == 4); | |
| 45 | expect(hex_mult[1] == 256); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | test "array dot len const expr" { |
| 49 | assertOrPanic(comptime x: { | |
| 49 | expect(comptime x: { | |
| 50 | 50 | break :x some_array.len == 4; |
| 51 | 51 | }); |
| 52 | 52 | } |
| ... | ... | @@ -70,11 +70,11 @@ test "nested arrays" { |
| 70 | 70 | "thing", |
| 71 | 71 | }; |
| 72 | 72 | for (array_of_strings) |s, i| { |
| 73 | if (i == 0) assertOrPanic(mem.eql(u8, s, "hello")); | |
| 74 | if (i == 1) assertOrPanic(mem.eql(u8, s, "this")); | |
| 75 | if (i == 2) assertOrPanic(mem.eql(u8, s, "is")); | |
| 76 | if (i == 3) assertOrPanic(mem.eql(u8, s, "my")); | |
| 77 | if (i == 4) assertOrPanic(mem.eql(u8, s, "thing")); | |
| 73 | if (i == 0) expect(mem.eql(u8, s, "hello")); | |
| 74 | if (i == 1) expect(mem.eql(u8, s, "this")); | |
| 75 | if (i == 2) expect(mem.eql(u8, s, "is")); | |
| 76 | if (i == 3) expect(mem.eql(u8, s, "my")); | |
| 77 | if (i == 4) expect(mem.eql(u8, s, "thing")); | |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| ... | ... | @@ -92,9 +92,9 @@ test "set global var array via slice embedded in struct" { |
| 92 | 92 | s.a[1].b = 2; |
| 93 | 93 | s.a[2].b = 3; |
| 94 | 94 | |
| 95 | assertOrPanic(s_array[0].b == 1); | |
| 96 | assertOrPanic(s_array[1].b == 2); | |
| 97 | assertOrPanic(s_array[2].b == 3); | |
| 95 | expect(s_array[0].b == 1); | |
| 96 | expect(s_array[1].b == 2); | |
| 97 | expect(s_array[2].b == 3); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "array literal with specified size" { |
| ... | ... | @@ -102,27 +102,27 @@ test "array literal with specified size" { |
| 102 | 102 | 1, |
| 103 | 103 | 2, |
| 104 | 104 | }; |
| 105 | assertOrPanic(array[0] == 1); | |
| 106 | assertOrPanic(array[1] == 2); | |
| 105 | expect(array[0] == 1); | |
| 106 | expect(array[1] == 2); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "array child property" { |
| 110 | 110 | var x: [5]i32 = undefined; |
| 111 | assertOrPanic(@typeOf(x).Child == i32); | |
| 111 | expect(@typeOf(x).Child == i32); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "array len property" { |
| 115 | 115 | var x: [5]i32 = undefined; |
| 116 | assertOrPanic(@typeOf(x).len == 5); | |
| 116 | expect(@typeOf(x).len == 5); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "array len field" { |
| 120 | 120 | var arr = [4]u8{ 0, 0, 0, 0 }; |
| 121 | 121 | var ptr = &arr; |
| 122 | assertOrPanic(arr.len == 4); | |
| 123 | comptime assertOrPanic(arr.len == 4); | |
| 124 | assertOrPanic(ptr.len == 4); | |
| 125 | comptime assertOrPanic(ptr.len == 4); | |
| 122 | expect(arr.len == 4); | |
| 123 | comptime expect(arr.len == 4); | |
| 124 | expect(ptr.len == 4); | |
| 125 | comptime expect(ptr.len == 4); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | test "single-item pointer to array indexing and slicing" { |
| ... | ... | @@ -133,7 +133,7 @@ test "single-item pointer to array indexing and slicing" { |
| 133 | 133 | fn testSingleItemPtrArrayIndexSlice() void { |
| 134 | 134 | var array = "aaaa"; |
| 135 | 135 | doSomeMangling(&array); |
| 136 | assertOrPanic(mem.eql(u8, "azya", array)); | |
| 136 | expect(mem.eql(u8, "azya", array)); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | fn doSomeMangling(array: *[4]u8) void { |
| ... | ... | @@ -150,7 +150,7 @@ fn testImplicitCastSingleItemPtr() void { |
| 150 | 150 | var byte: u8 = 100; |
| 151 | 151 | const slice = (*[1]u8)(&byte)[0..]; |
| 152 | 152 | slice[0] += 1; |
| 153 | assertOrPanic(byte == 101); | |
| 153 | expect(byte == 101); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | fn testArrayByValAtComptime(b: [2]u8) u8 { |
| ... | ... | @@ -165,7 +165,7 @@ test "comptime evalutating function that takes array by value" { |
| 165 | 165 | |
| 166 | 166 | test "implicit comptime in array type size" { |
| 167 | 167 | var arr: [plusOne(10)]bool = undefined; |
| 168 | assertOrPanic(arr.len == 11); | |
| 168 | expect(arr.len == 11); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | fn plusOne(x: u32) u32 { |
| ... | ... | @@ -197,15 +197,15 @@ test "array literal as argument to function" { |
| 197 | 197 | }); |
| 198 | 198 | } |
| 199 | 199 | fn foo(x: []const i32) void { |
| 200 | assertOrPanic(x[0] == 1); | |
| 201 | assertOrPanic(x[1] == 2); | |
| 202 | assertOrPanic(x[2] == 3); | |
| 200 | expect(x[0] == 1); | |
| 201 | expect(x[1] == 2); | |
| 202 | expect(x[2] == 3); | |
| 203 | 203 | } |
| 204 | 204 | fn foo2(trash: bool, x: []const i32) void { |
| 205 | assertOrPanic(trash); | |
| 206 | assertOrPanic(x[0] == 1); | |
| 207 | assertOrPanic(x[1] == 2); | |
| 208 | assertOrPanic(x[2] == 3); | |
| 205 | expect(trash); | |
| 206 | expect(x[0] == 1); | |
| 207 | expect(x[1] == 2); | |
| 208 | expect(x[2] == 3); | |
| 209 | 209 | } |
| 210 | 210 | }; |
| 211 | 211 | S.entry(2); |
| ... | ... | @@ -229,12 +229,12 @@ test "double nested array to const slice cast in array literal" { |
| 229 | 229 | []i32{1}, |
| 230 | 230 | []i32{ two, 3 }, |
| 231 | 231 | }; |
| 232 | assertOrPanic(cases2.len == 2); | |
| 233 | assertOrPanic(cases2[0].len == 1); | |
| 234 | assertOrPanic(cases2[0][0] == 1); | |
| 235 | assertOrPanic(cases2[1].len == 2); | |
| 236 | assertOrPanic(cases2[1][0] == 2); | |
| 237 | assertOrPanic(cases2[1][1] == 3); | |
| 232 | expect(cases2.len == 2); | |
| 233 | expect(cases2[0].len == 1); | |
| 234 | expect(cases2[0][0] == 1); | |
| 235 | expect(cases2[1].len == 2); | |
| 236 | expect(cases2[1][0] == 2); | |
| 237 | expect(cases2[1][1] == 3); | |
| 238 | 238 | |
| 239 | 239 | const cases3 = [][]const []const i32{ |
| 240 | 240 | [][]const i32{[]i32{1}}, |
| ... | ... | @@ -248,21 +248,21 @@ test "double nested array to const slice cast in array literal" { |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | fn check(cases: []const []const []const i32) void { |
| 251 | assertOrPanic(cases.len == 3); | |
| 252 | assertOrPanic(cases[0].len == 1); | |
| 253 | assertOrPanic(cases[0][0].len == 1); | |
| 254 | assertOrPanic(cases[0][0][0] == 1); | |
| 255 | assertOrPanic(cases[1].len == 1); | |
| 256 | assertOrPanic(cases[1][0].len == 2); | |
| 257 | assertOrPanic(cases[1][0][0] == 2); | |
| 258 | assertOrPanic(cases[1][0][1] == 3); | |
| 259 | assertOrPanic(cases[2].len == 2); | |
| 260 | assertOrPanic(cases[2][0].len == 1); | |
| 261 | assertOrPanic(cases[2][0][0] == 4); | |
| 262 | assertOrPanic(cases[2][1].len == 3); | |
| 263 | assertOrPanic(cases[2][1][0] == 5); | |
| 264 | assertOrPanic(cases[2][1][1] == 6); | |
| 265 | assertOrPanic(cases[2][1][2] == 7); | |
| 251 | expect(cases.len == 3); | |
| 252 | expect(cases[0].len == 1); | |
| 253 | expect(cases[0][0].len == 1); | |
| 254 | expect(cases[0][0][0] == 1); | |
| 255 | expect(cases[1].len == 1); | |
| 256 | expect(cases[1][0].len == 2); | |
| 257 | expect(cases[1][0][0] == 2); | |
| 258 | expect(cases[1][0][1] == 3); | |
| 259 | expect(cases[2].len == 2); | |
| 260 | expect(cases[2][0].len == 1); | |
| 261 | expect(cases[2][0][0] == 4); | |
| 262 | expect(cases[2][1].len == 3); | |
| 263 | expect(cases[2][1][0] == 5); | |
| 264 | expect(cases[2][1][1] == 6); | |
| 265 | expect(cases[2][1][2] == 7); | |
| 266 | 266 | } |
| 267 | 267 | }; |
| 268 | 268 | S.entry(2); |
test/stage1/behavior/asm.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const config = @import("builtin"); |
| 2 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 2 | const expect = @import("std").testing.expect; | |
| 3 | 3 | |
| 4 | 4 | comptime { |
| 5 | 5 | if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) { |
| ... | ... | @@ -13,7 +13,7 @@ comptime { |
| 13 | 13 | |
| 14 | 14 | test "module level assembly" { |
| 15 | 15 | if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) { |
| 16 | assertOrPanic(aoeu() == 1234); | |
| 16 | expect(aoeu() == 1234); | |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 |
test/stage1/behavior/atomics.zig+16-16| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | const AtomicRmwOp = builtin.AtomicRmwOp; |
| 5 | 5 | const AtomicOrder = builtin.AtomicOrder; |
| ... | ... | @@ -7,18 +7,18 @@ const AtomicOrder = builtin.AtomicOrder; |
| 7 | 7 | test "cmpxchg" { |
| 8 | 8 | var x: i32 = 1234; |
| 9 | 9 | if (@cmpxchgWeak(i32, &x, 99, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| { |
| 10 | assertOrPanic(x1 == 1234); | |
| 10 | expect(x1 == 1234); | |
| 11 | 11 | } else { |
| 12 | 12 | @panic("cmpxchg should have failed"); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | while (@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| { |
| 16 | assertOrPanic(x1 == 1234); | |
| 16 | expect(x1 == 1234); | |
| 17 | 17 | } |
| 18 | assertOrPanic(x == 5678); | |
| 18 | expect(x == 5678); | |
| 19 | 19 | |
| 20 | assertOrPanic(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null); | |
| 21 | assertOrPanic(x == 42); | |
| 20 | expect(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null); | |
| 21 | expect(x == 42); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | test "fence" { |
| ... | ... | @@ -30,24 +30,24 @@ test "fence" { |
| 30 | 30 | test "atomicrmw and atomicload" { |
| 31 | 31 | var data: u8 = 200; |
| 32 | 32 | testAtomicRmw(&data); |
| 33 | assertOrPanic(data == 42); | |
| 33 | expect(data == 42); | |
| 34 | 34 | testAtomicLoad(&data); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | fn testAtomicRmw(ptr: *u8) void { |
| 38 | 38 | const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst); |
| 39 | assertOrPanic(prev_value == 200); | |
| 39 | expect(prev_value == 200); | |
| 40 | 40 | comptime { |
| 41 | 41 | var x: i32 = 1234; |
| 42 | 42 | const y: i32 = 12345; |
| 43 | assertOrPanic(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234); | |
| 44 | assertOrPanic(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345); | |
| 43 | expect(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234); | |
| 44 | expect(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345); | |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | fn testAtomicLoad(ptr: *u8) void { |
| 49 | 49 | const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst); |
| 50 | assertOrPanic(x == 42); | |
| 50 | expect(x == 42); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | test "cmpxchg with ptr" { |
| ... | ... | @@ -56,16 +56,16 @@ test "cmpxchg with ptr" { |
| 56 | 56 | var data3: i32 = 9101; |
| 57 | 57 | var x: *i32 = &data1; |
| 58 | 58 | if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| { |
| 59 | assertOrPanic(x1 == &data1); | |
| 59 | expect(x1 == &data1); | |
| 60 | 60 | } else { |
| 61 | 61 | @panic("cmpxchg should have failed"); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| { |
| 65 | assertOrPanic(x1 == &data1); | |
| 65 | expect(x1 == &data1); | |
| 66 | 66 | } |
| 67 | assertOrPanic(x == &data3); | |
| 67 | expect(x == &data3); | |
| 68 | 68 | |
| 69 | assertOrPanic(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null); | |
| 70 | assertOrPanic(x == &data2); | |
| 69 | expect(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null); | |
| 70 | expect(x == &data2); | |
| 71 | 71 | } |
test/stage1/behavior/bit_shifting.zig+5-5| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type { |
| 5 | assertOrPanic(Key == @IntType(false, Key.bit_count)); | |
| 6 | assertOrPanic(Key.bit_count >= mask_bit_count); | |
| 5 | expect(Key == @IntType(false, Key.bit_count)); | |
| 6 | expect(Key.bit_count >= mask_bit_count); | |
| 7 | 7 | const ShardKey = @IntType(false, mask_bit_count); |
| 8 | 8 | const shift_amount = Key.bit_count - ShardKey.bit_count; |
| 9 | 9 | return struct { |
| ... | ... | @@ -77,12 +77,12 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c |
| 77 | 77 | var node_buffer: [node_count]Table.Node = undefined; |
| 78 | 78 | for (node_buffer) |*node, i| { |
| 79 | 79 | const key = @intCast(Key, i); |
| 80 | assertOrPanic(table.get(key) == null); | |
| 80 | expect(table.get(key) == null); | |
| 81 | 81 | node.init(key, {}); |
| 82 | 82 | table.put(node); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | for (node_buffer) |*node, i| { |
| 86 | assertOrPanic(table.get(@intCast(Key, i)) == node); | |
| 86 | expect(table.get(@intCast(Key, i)) == node); | |
| 87 | 87 | } |
| 88 | 88 | } |
test/stage1/behavior/bitcast.zig+4-4| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const maxInt = std.math.maxInt; |
| 4 | 4 | |
| 5 | 5 | test "@bitCast i32 -> u32" { |
| ... | ... | @@ -8,8 +8,8 @@ test "@bitCast i32 -> u32" { |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | fn testBitCast_i32_u32() void { |
| 11 | assertOrPanic(conv(-1) == maxInt(u32)); | |
| 12 | assertOrPanic(conv2(maxInt(u32)) == -1); | |
| 11 | expect(conv(-1) == maxInt(u32)); | |
| 12 | expect(conv2(maxInt(u32)) == -1); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn conv(x: i32) u32 { |
| ... | ... | @@ -27,7 +27,7 @@ test "@bitCast extern enum to its integer type" { |
| 27 | 27 | fn testBitCastExternEnum() void { |
| 28 | 28 | var SOCK_DGRAM = @This().B; |
| 29 | 29 | var sock_dgram = @bitCast(c_int, SOCK_DGRAM); |
| 30 | assertOrPanic(sock_dgram == 1); | |
| 30 | expect(sock_dgram == 1); | |
| 31 | 31 | } |
| 32 | 32 | }; |
| 33 | 33 |
test/stage1/behavior/bitreverse.zig+43-43| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const minInt = std.math.minInt; |
| 4 | 4 | |
| 5 | 5 | test "@bitreverse" { |
| ... | ... | @@ -9,73 +9,73 @@ test "@bitreverse" { |
| 9 | 9 | |
| 10 | 10 | fn testBitReverse() void { |
| 11 | 11 | // using comptime_ints, unsigned |
| 12 | assertOrPanic(@bitreverse(u0, 0) == 0); | |
| 13 | assertOrPanic(@bitreverse(u5, 0x12) == 0x9); | |
| 14 | assertOrPanic(@bitreverse(u8, 0x12) == 0x48); | |
| 15 | assertOrPanic(@bitreverse(u16, 0x1234) == 0x2c48); | |
| 16 | assertOrPanic(@bitreverse(u24, 0x123456) == 0x6a2c48); | |
| 17 | assertOrPanic(@bitreverse(u32, 0x12345678) == 0x1e6a2c48); | |
| 18 | assertOrPanic(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48); | |
| 19 | assertOrPanic(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48); | |
| 20 | assertOrPanic(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48); | |
| 21 | assertOrPanic(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48); | |
| 22 | assertOrPanic(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 12 | expect(@bitreverse(u0, 0) == 0); | |
| 13 | expect(@bitreverse(u5, 0x12) == 0x9); | |
| 14 | expect(@bitreverse(u8, 0x12) == 0x48); | |
| 15 | expect(@bitreverse(u16, 0x1234) == 0x2c48); | |
| 16 | expect(@bitreverse(u24, 0x123456) == 0x6a2c48); | |
| 17 | expect(@bitreverse(u32, 0x12345678) == 0x1e6a2c48); | |
| 18 | expect(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48); | |
| 19 | expect(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48); | |
| 20 | expect(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48); | |
| 21 | expect(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48); | |
| 22 | expect(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 23 | 23 | |
| 24 | 24 | // using runtime uints, unsigned |
| 25 | 25 | var num0: u0 = 0; |
| 26 | assertOrPanic(@bitreverse(u0, num0) == 0); | |
| 26 | expect(@bitreverse(u0, num0) == 0); | |
| 27 | 27 | var num5: u5 = 0x12; |
| 28 | assertOrPanic(@bitreverse(u5, num5) == 0x9); | |
| 28 | expect(@bitreverse(u5, num5) == 0x9); | |
| 29 | 29 | var num8: u8 = 0x12; |
| 30 | assertOrPanic(@bitreverse(u8, num8) == 0x48); | |
| 30 | expect(@bitreverse(u8, num8) == 0x48); | |
| 31 | 31 | var num16: u16 = 0x1234; |
| 32 | assertOrPanic(@bitreverse(u16, num16) == 0x2c48); | |
| 32 | expect(@bitreverse(u16, num16) == 0x2c48); | |
| 33 | 33 | var num24: u24 = 0x123456; |
| 34 | assertOrPanic(@bitreverse(u24, num24) == 0x6a2c48); | |
| 34 | expect(@bitreverse(u24, num24) == 0x6a2c48); | |
| 35 | 35 | var num32: u32 = 0x12345678; |
| 36 | assertOrPanic(@bitreverse(u32, num32) == 0x1e6a2c48); | |
| 36 | expect(@bitreverse(u32, num32) == 0x1e6a2c48); | |
| 37 | 37 | var num40: u40 = 0x123456789a; |
| 38 | assertOrPanic(@bitreverse(u40, num40) == 0x591e6a2c48); | |
| 38 | expect(@bitreverse(u40, num40) == 0x591e6a2c48); | |
| 39 | 39 | var num48: u48 = 0x123456789abc; |
| 40 | assertOrPanic(@bitreverse(u48, num48) == 0x3d591e6a2c48); | |
| 40 | expect(@bitreverse(u48, num48) == 0x3d591e6a2c48); | |
| 41 | 41 | var num56: u56 = 0x123456789abcde; |
| 42 | assertOrPanic(@bitreverse(u56, num56) == 0x7b3d591e6a2c48); | |
| 42 | expect(@bitreverse(u56, num56) == 0x7b3d591e6a2c48); | |
| 43 | 43 | var num64: u64 = 0x123456789abcdef1; |
| 44 | assertOrPanic(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48); | |
| 44 | expect(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48); | |
| 45 | 45 | var num128: u128 = 0x123456789abcdef11121314151617181; |
| 46 | assertOrPanic(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 46 | expect(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 47 | 47 | |
| 48 | 48 | // using comptime_ints, signed, positive |
| 49 | assertOrPanic(@bitreverse(i0, 0) == 0); | |
| 50 | assertOrPanic(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49))); | |
| 51 | assertOrPanic(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48))); | |
| 52 | assertOrPanic(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48))); | |
| 53 | assertOrPanic(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48))); | |
| 54 | assertOrPanic(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48))); | |
| 55 | assertOrPanic(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48))); | |
| 56 | assertOrPanic(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48))); | |
| 57 | assertOrPanic(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48))); | |
| 58 | assertOrPanic(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48))); | |
| 49 | expect(@bitreverse(i0, 0) == 0); | |
| 50 | expect(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49))); | |
| 51 | expect(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48))); | |
| 52 | expect(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48))); | |
| 53 | expect(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48))); | |
| 54 | expect(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48))); | |
| 55 | expect(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48))); | |
| 56 | expect(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48))); | |
| 57 | expect(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48))); | |
| 58 | expect(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48))); | |
| 59 | 59 | |
| 60 | 60 | // using comptime_ints, signed, negative. Compare to runtime ints returned from llvm. |
| 61 | 61 | var neg5: i5 = minInt(i5) + 1; |
| 62 | assertOrPanic(@bitreverse(i5, minInt(i5) + 1) == @bitreverse(i5, neg5)); | |
| 62 | expect(@bitreverse(i5, minInt(i5) + 1) == @bitreverse(i5, neg5)); | |
| 63 | 63 | var neg8: i8 = -18; |
| 64 | assertOrPanic(@bitreverse(i8, -18) == @bitreverse(i8, neg8)); | |
| 64 | expect(@bitreverse(i8, -18) == @bitreverse(i8, neg8)); | |
| 65 | 65 | var neg16: i16 = -32694; |
| 66 | assertOrPanic(@bitreverse(i16, -32694) == @bitreverse(i16, neg16)); | |
| 66 | expect(@bitreverse(i16, -32694) == @bitreverse(i16, neg16)); | |
| 67 | 67 | var neg24: i24 = -6773785; |
| 68 | assertOrPanic(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24)); | |
| 68 | expect(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24)); | |
| 69 | 69 | var neg32: i32 = -16773785; |
| 70 | assertOrPanic(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32)); | |
| 70 | expect(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32)); | |
| 71 | 71 | var neg40: i40 = minInt(i40) + 12345; |
| 72 | assertOrPanic(@bitreverse(i40, minInt(i40) + 12345) == @bitreverse(i40, neg40)); | |
| 72 | expect(@bitreverse(i40, minInt(i40) + 12345) == @bitreverse(i40, neg40)); | |
| 73 | 73 | var neg48: i48 = minInt(i48) + 12345; |
| 74 | assertOrPanic(@bitreverse(i48, minInt(i48) + 12345) == @bitreverse(i48, neg48)); | |
| 74 | expect(@bitreverse(i48, minInt(i48) + 12345) == @bitreverse(i48, neg48)); | |
| 75 | 75 | var neg56: i56 = minInt(i56) + 12345; |
| 76 | assertOrPanic(@bitreverse(i56, minInt(i56) + 12345) == @bitreverse(i56, neg56)); | |
| 76 | expect(@bitreverse(i56, minInt(i56) + 12345) == @bitreverse(i56, neg56)); | |
| 77 | 77 | var neg64: i64 = minInt(i64) + 12345; |
| 78 | assertOrPanic(@bitreverse(i64, minInt(i64) + 12345) == @bitreverse(i64, neg64)); | |
| 78 | expect(@bitreverse(i64, minInt(i64) + 12345) == @bitreverse(i64, neg64)); | |
| 79 | 79 | var neg128: i128 = minInt(i128) + 12345; |
| 80 | assertOrPanic(@bitreverse(i128, minInt(i128) + 12345) == @bitreverse(i128, neg128)); | |
| 80 | expect(@bitreverse(i128, minInt(i128) + 12345) == @bitreverse(i128, neg128)); | |
| 81 | 81 | } |
test/stage1/behavior/bool.zig+10-10| ... | ... | @@ -1,25 +1,25 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "bool literals" { |
| 4 | assertOrPanic(true); | |
| 5 | assertOrPanic(!false); | |
| 4 | expect(true); | |
| 5 | expect(!false); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "cast bool to int" { |
| 9 | 9 | const t = true; |
| 10 | 10 | const f = false; |
| 11 | assertOrPanic(@boolToInt(t) == u32(1)); | |
| 12 | assertOrPanic(@boolToInt(f) == u32(0)); | |
| 11 | expect(@boolToInt(t) == u32(1)); | |
| 12 | expect(@boolToInt(f) == u32(0)); | |
| 13 | 13 | nonConstCastBoolToInt(t, f); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn nonConstCastBoolToInt(t: bool, f: bool) void { |
| 17 | assertOrPanic(@boolToInt(t) == u32(1)); | |
| 18 | assertOrPanic(@boolToInt(f) == u32(0)); | |
| 17 | expect(@boolToInt(t) == u32(1)); | |
| 18 | expect(@boolToInt(f) == u32(0)); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "bool cmp" { |
| 22 | assertOrPanic(testBoolCmp(true, false) == false); | |
| 22 | expect(testBoolCmp(true, false) == false); | |
| 23 | 23 | } |
| 24 | 24 | fn testBoolCmp(a: bool, b: bool) bool { |
| 25 | 25 | return a == b; |
| ... | ... | @@ -30,6 +30,6 @@ const global_t = true; |
| 30 | 30 | const not_global_f = !global_f; |
| 31 | 31 | const not_global_t = !global_t; |
| 32 | 32 | test "compile time bool not" { |
| 33 | assertOrPanic(not_global_f); | |
| 34 | assertOrPanic(!not_global_t); | |
| 33 | expect(not_global_f); | |
| 34 | expect(!not_global_t); | |
| 35 | 35 | } |
test/stage1/behavior/bswap.zig+21-21| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "@bswap" { |
| 5 | 5 | comptime testByteSwap(); |
| ... | ... | @@ -7,26 +7,26 @@ test "@bswap" { |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | fn testByteSwap() void { |
| 10 | assertOrPanic(@bswap(u0, 0) == 0); | |
| 11 | assertOrPanic(@bswap(u8, 0x12) == 0x12); | |
| 12 | assertOrPanic(@bswap(u16, 0x1234) == 0x3412); | |
| 13 | assertOrPanic(@bswap(u24, 0x123456) == 0x563412); | |
| 14 | assertOrPanic(@bswap(u32, 0x12345678) == 0x78563412); | |
| 15 | assertOrPanic(@bswap(u40, 0x123456789a) == 0x9a78563412); | |
| 16 | assertOrPanic(@bswap(u48, 0x123456789abc) == 0xbc9a78563412); | |
| 17 | assertOrPanic(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412); | |
| 18 | assertOrPanic(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412); | |
| 19 | assertOrPanic(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412); | |
| 10 | expect(@bswap(u0, 0) == 0); | |
| 11 | expect(@bswap(u8, 0x12) == 0x12); | |
| 12 | expect(@bswap(u16, 0x1234) == 0x3412); | |
| 13 | expect(@bswap(u24, 0x123456) == 0x563412); | |
| 14 | expect(@bswap(u32, 0x12345678) == 0x78563412); | |
| 15 | expect(@bswap(u40, 0x123456789a) == 0x9a78563412); | |
| 16 | expect(@bswap(u48, 0x123456789abc) == 0xbc9a78563412); | |
| 17 | expect(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412); | |
| 18 | expect(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412); | |
| 19 | expect(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412); | |
| 20 | 20 | |
| 21 | assertOrPanic(@bswap(i0, 0) == 0); | |
| 22 | assertOrPanic(@bswap(i8, -50) == -50); | |
| 23 | assertOrPanic(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412))); | |
| 24 | assertOrPanic(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412))); | |
| 25 | assertOrPanic(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412))); | |
| 26 | assertOrPanic(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412))); | |
| 27 | assertOrPanic(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412))); | |
| 28 | assertOrPanic(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412))); | |
| 29 | assertOrPanic(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412))); | |
| 30 | assertOrPanic(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == | |
| 21 | expect(@bswap(i0, 0) == 0); | |
| 22 | expect(@bswap(i8, -50) == -50); | |
| 23 | expect(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412))); | |
| 24 | expect(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412))); | |
| 25 | expect(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412))); | |
| 26 | expect(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412))); | |
| 27 | expect(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412))); | |
| 28 | expect(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412))); | |
| 29 | expect(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412))); | |
| 30 | expect(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == | |
| 31 | 31 | @bitCast(i128, u128(0x8171615141312111f1debc9a78563412))); |
| 32 | 32 | } |
test/stage1/behavior/bugs/1076.zig+2-2| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | test "comptime code should not modify constant data" { |
| 6 | 6 | testCastPtrOfArrayToSliceAndPtr(); |
| ... | ... | @@ -11,6 +11,6 @@ fn testCastPtrOfArrayToSliceAndPtr() void { |
| 11 | 11 | var array = "aoeu"; |
| 12 | 12 | const x: [*]u8 = &array; |
| 13 | 13 | x[0] += 1; |
| 14 | assertOrPanic(mem.eql(u8, array[0..], "boeu")); | |
| 14 | expect(mem.eql(u8, array[0..], "boeu")); | |
| 15 | 15 | } |
| 16 | 16 |
test/stage1/behavior/bugs/1277.zig+1-1| ... | ... | @@ -11,5 +11,5 @@ fn f() i32 { |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "don't emit an LLVM global for a const function when it's in an optional in a struct" { |
| 14 | std.debug.assertOrPanic(s.f.?() == 1234); | |
| 14 | std.testing.expect(s.f.?() == 1234); | |
| 15 | 15 | } |
test/stage1/behavior/bugs/1322.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ const C = struct {}; |
| 13 | 13 | |
| 14 | 14 | test "tagged union with all void fields but a meaningful tag" { |
| 15 | 15 | var a: A = A{ .b = B{ .c = C{} } }; |
| 16 | std.debug.assertOrPanic(@TagType(B)(a.b) == @TagType(B).c); | |
| 16 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).c); | |
| 17 | 17 | a = A{ .b = B.None }; |
| 18 | std.debug.assertOrPanic(@TagType(B)(a.b) == @TagType(B).None); | |
| 18 | std.testing.expect(@TagType(B)(a.b) == @TagType(B).None); | |
| 19 | 19 | } |
test/stage1/behavior/bugs/1381.zig+1-1| ... | ... | @@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" { |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | const a = as[0].B; |
| 20 | std.debug.assertOrPanic(a.D == 1); | |
| 20 | std.testing.expect(a.D == 1); | |
| 21 | 21 | } |
test/stage1/behavior/bugs/1421.zig+2-2| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | const S = struct { |
| 6 | 6 | fn method() builtin.TypeInfo { |
| ... | ... | @@ -10,5 +10,5 @@ const S = struct { |
| 10 | 10 | |
| 11 | 11 | test "functions with return type required to be comptime are generic" { |
| 12 | 12 | const ti = S.method(); |
| 13 | assertOrPanic(builtin.TypeId(ti) == builtin.TypeId.Struct); | |
| 13 | expect(builtin.TypeId(ti) == builtin.TypeId.Struct); | |
| 14 | 14 | } |
test/stage1/behavior/bugs/1442.zig+1-1| ... | ... | @@ -7,5 +7,5 @@ const Union = union(enum) { |
| 7 | 7 | |
| 8 | 8 | test "const error union field alignment" { |
| 9 | 9 | var union_or_err: anyerror!Union = Union{ .Color = 1234 }; |
| 10 | std.debug.assertOrPanic((union_or_err catch unreachable).Color == 1234); | |
| 10 | std.testing.expect((union_or_err catch unreachable).Color == 1234); | |
| 11 | 11 | } |
test/stage1/behavior/bugs/1486.zig+3-3| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const ptr = &global; |
| 4 | 4 | var global: u64 = 123; |
| 5 | 5 | |
| 6 | 6 | test "constant pointer to global variable causes runtime load" { |
| 7 | 7 | global = 1234; |
| 8 | assertOrPanic(&global == ptr); | |
| 9 | assertOrPanic(ptr.* == 1234); | |
| 8 | expect(&global == ptr); | |
| 9 | expect(ptr.* == 1234); | |
| 10 | 10 | } |
| 11 | 11 |
test/stage1/behavior/bugs/394.zig+2-2| ... | ... | @@ -7,12 +7,12 @@ const S = struct { |
| 7 | 7 | y: E, |
| 8 | 8 | }; |
| 9 | 9 | |
| 10 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 10 | const expect = @import("std").testing.expect; | |
| 11 | 11 | |
| 12 | 12 | test "bug 394 fixed" { |
| 13 | 13 | const x = S{ |
| 14 | 14 | .x = 3, |
| 15 | 15 | .y = E{ .B = 1 }, |
| 16 | 16 | }; |
| 17 | assertOrPanic(x.x == 3); | |
| 17 | expect(x.x == 3); | |
| 18 | 18 | } |
test/stage1/behavior/bugs/655.zig+2-2| ... | ... | @@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig"); |
| 3 | 3 | |
| 4 | 4 | test "function with *const parameter with type dereferenced by namespace" { |
| 5 | 5 | const x: other_file.Integer = 1234; |
| 6 | comptime std.debug.assertOrPanic(@typeOf(&x) == *const other_file.Integer); | |
| 6 | comptime std.testing.expect(@typeOf(&x) == *const other_file.Integer); | |
| 7 | 7 | foo(&x); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | fn foo(x: *const other_file.Integer) void { |
| 11 | std.debug.assertOrPanic(x.* == 1234); | |
| 11 | std.testing.expect(x.* == 1234); | |
| 12 | 12 | } |
test/stage1/behavior/bugs/656.zig+2-2| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const PrefixOp = union(enum) { |
| 4 | 4 | Return, |
| ... | ... | @@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void { |
| 22 | 22 | PrefixOp.AddrOf => |addr_of_info| { |
| 23 | 23 | if (b) {} |
| 24 | 24 | if (addr_of_info.align_expr) |align_expr| { |
| 25 | assertOrPanic(align_expr == 1234); | |
| 25 | expect(align_expr == 1234); | |
| 26 | 26 | } |
| 27 | 27 | }, |
| 28 | 28 | PrefixOp.Return => {}, |
test/stage1/behavior/bugs/726.zig+3-3| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "@ptrCast from const to nullable" { |
| 4 | 4 | const c: u8 = 4; |
| 5 | 5 | var x: ?*const u8 = @ptrCast(?*const u8, &c); |
| 6 | assertOrPanic(x.?.* == 4); | |
| 6 | expect(x.?.* == 4); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "@ptrCast from var in empty struct to nullable" { |
| ... | ... | @@ -11,6 +11,6 @@ test "@ptrCast from var in empty struct to nullable" { |
| 11 | 11 | var c: u8 = 4; |
| 12 | 12 | }; |
| 13 | 13 | var x: ?*const u8 = @ptrCast(?*const u8, &container.c); |
| 14 | assertOrPanic(x.?.* == 4); | |
| 14 | expect(x.?.* == 4); | |
| 15 | 15 | } |
| 16 | 16 |
test/stage1/behavior/bugs/920.zig+1-1| ... | ... | @@ -60,6 +60,6 @@ test "bug 920 fixed" { |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | 62 | for (NormalDist1.f) |_, i| { |
| 63 | std.debug.assertOrPanic(NormalDist1.f[i] == NormalDist.f[i]); | |
| 63 | std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]); | |
| 64 | 64 | } |
| 65 | 65 | } |
test/stage1/behavior/byval_arg_var.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" { |
| 6 | 6 | start(); |
| 7 | 7 | blowUpStack(10); |
| 8 | 8 | |
| 9 | std.debug.assertOrPanic(std.mem.eql(u8, result, "string literal")); | |
| 9 | std.testing.expect(std.mem.eql(u8, result, "string literal")); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn start() void { |
test/stage1/behavior/cancel.zig+7-7| ... | ... | @@ -10,9 +10,9 @@ test "cancel forwards" { |
| 10 | 10 | |
| 11 | 11 | const p = async<&da.allocator> f1() catch unreachable; |
| 12 | 12 | cancel p; |
| 13 | std.debug.assertOrPanic(defer_f1); | |
| 14 | std.debug.assertOrPanic(defer_f2); | |
| 15 | std.debug.assertOrPanic(defer_f3); | |
| 13 | std.testing.expect(defer_f1); | |
| 14 | std.testing.expect(defer_f2); | |
| 15 | std.testing.expect(defer_f3); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | async fn f1() void { |
| ... | ... | @@ -47,10 +47,10 @@ test "cancel backwards" { |
| 47 | 47 | |
| 48 | 48 | const p = async<&da.allocator> b1() catch unreachable; |
| 49 | 49 | cancel p; |
| 50 | std.debug.assertOrPanic(defer_b1); | |
| 51 | std.debug.assertOrPanic(defer_b2); | |
| 52 | std.debug.assertOrPanic(defer_b3); | |
| 53 | std.debug.assertOrPanic(defer_b4); | |
| 50 | std.testing.expect(defer_b1); | |
| 51 | std.testing.expect(defer_b2); | |
| 52 | std.testing.expect(defer_b3); | |
| 53 | std.testing.expect(defer_b4); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | async fn b1() void { |
test/stage1/behavior/cast.zig+79-79| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| ... | ... | @@ -7,12 +7,12 @@ test "int to ptr cast" { |
| 7 | 7 | const x = usize(13); |
| 8 | 8 | const y = @intToPtr(*u8, x); |
| 9 | 9 | const z = @ptrToInt(y); |
| 10 | assertOrPanic(z == 13); | |
| 10 | expect(z == 13); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "integer literal to pointer cast" { |
| 14 | 14 | const vga_mem = @intToPtr(*u16, 0xB8000); |
| 15 | assertOrPanic(@ptrToInt(vga_mem) == 0xB8000); | |
| 15 | expect(@ptrToInt(vga_mem) == 0xB8000); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "pointer reinterpret const float to int" { |
| ... | ... | @@ -20,7 +20,7 @@ test "pointer reinterpret const float to int" { |
| 20 | 20 | const float_ptr = &float; |
| 21 | 21 | const int_ptr = @ptrCast(*const i32, float_ptr); |
| 22 | 22 | const int_val = int_ptr.*; |
| 23 | assertOrPanic(int_val == 858993411); | |
| 23 | expect(int_val == 858993411); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| ... | ... | @@ -44,10 +44,10 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| 44 | 44 | const p = &s; |
| 45 | 45 | const q = &p; |
| 46 | 46 | const r = &q; |
| 47 | assertOrPanic(42 == S.constConst(q)); | |
| 48 | assertOrPanic(42 == S.maybeConstConst(q)); | |
| 49 | assertOrPanic(42 == S.constConstConst(r)); | |
| 50 | assertOrPanic(42 == S.maybeConstConstConst(r)); | |
| 47 | expect(42 == S.constConst(q)); | |
| 48 | expect(42 == S.maybeConstConst(q)); | |
| 49 | expect(42 == S.constConstConst(r)); | |
| 50 | expect(42 == S.maybeConstConstConst(r)); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | test "explicit cast from integer to error type" { |
| ... | ... | @@ -57,14 +57,14 @@ test "explicit cast from integer to error type" { |
| 57 | 57 | fn testCastIntToErr(err: anyerror) void { |
| 58 | 58 | const x = @errorToInt(err); |
| 59 | 59 | const y = @intToError(x); |
| 60 | assertOrPanic(error.ItBroke == y); | |
| 60 | expect(error.ItBroke == y); | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "peer resolve arrays of different size to const slice" { |
| 64 | assertOrPanic(mem.eql(u8, boolToStr(true), "true")); | |
| 65 | assertOrPanic(mem.eql(u8, boolToStr(false), "false")); | |
| 66 | comptime assertOrPanic(mem.eql(u8, boolToStr(true), "true")); | |
| 67 | comptime assertOrPanic(mem.eql(u8, boolToStr(false), "false")); | |
| 64 | expect(mem.eql(u8, boolToStr(true), "true")); | |
| 65 | expect(mem.eql(u8, boolToStr(false), "false")); | |
| 66 | comptime expect(mem.eql(u8, boolToStr(true), "true")); | |
| 67 | comptime expect(mem.eql(u8, boolToStr(false), "false")); | |
| 68 | 68 | } |
| 69 | 69 | fn boolToStr(b: bool) []const u8 { |
| 70 | 70 | return if (b) "true" else "false"; |
| ... | ... | @@ -77,8 +77,8 @@ test "peer resolve array and const slice" { |
| 77 | 77 | fn testPeerResolveArrayConstSlice(b: bool) void { |
| 78 | 78 | const value1 = if (b) "aoeu" else ([]const u8)("zz"); |
| 79 | 79 | const value2 = if (b) ([]const u8)("zz") else "aoeu"; |
| 80 | assertOrPanic(mem.eql(u8, value1, "aoeu")); | |
| 81 | assertOrPanic(mem.eql(u8, value2, "zz")); | |
| 80 | expect(mem.eql(u8, value1, "aoeu")); | |
| 81 | expect(mem.eql(u8, value2, "zz")); | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | test "implicitly cast from T to anyerror!?T" { |
| ... | ... | @@ -92,14 +92,14 @@ const A = struct { |
| 92 | 92 | fn castToOptionalTypeError(z: i32) void { |
| 93 | 93 | const x = i32(1); |
| 94 | 94 | const y: anyerror!?i32 = x; |
| 95 | assertOrPanic((try y).? == 1); | |
| 95 | expect((try y).? == 1); | |
| 96 | 96 | |
| 97 | 97 | const f = z; |
| 98 | 98 | const g: anyerror!?i32 = f; |
| 99 | 99 | |
| 100 | 100 | const a = A{ .a = z }; |
| 101 | 101 | const b: anyerror!?A = a; |
| 102 | assertOrPanic((b catch unreachable).?.a == 1); | |
| 102 | expect((b catch unreachable).?.a == 1); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "implicitly cast from int to anyerror!?T" { |
| ... | ... | @@ -114,7 +114,7 @@ fn implicitIntLitToOptional() void { |
| 114 | 114 | test "return null from fn() anyerror!?&T" { |
| 115 | 115 | const a = returnNullFromOptionalTypeErrorRef(); |
| 116 | 116 | const b = returnNullLitFromOptionalTypeErrorRef(); |
| 117 | assertOrPanic((try a) == null and (try b) == null); | |
| 117 | expect((try a) == null and (try b) == null); | |
| 118 | 118 | } |
| 119 | 119 | fn returnNullFromOptionalTypeErrorRef() anyerror!?*A { |
| 120 | 120 | const a: ?*A = null; |
| ... | ... | @@ -125,11 +125,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A { |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | test "peer type resolution: ?T and T" { |
| 128 | assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0); | |
| 129 | assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3); | |
| 128 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 129 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 130 | 130 | comptime { |
| 131 | assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0); | |
| 132 | assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3); | |
| 131 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 132 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| ... | ... | @@ -141,11 +141,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "peer type resolution: [0]u8 and []const u8" { |
| 144 | assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 145 | assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 144 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 145 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 146 | 146 | comptime { |
| 147 | assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 148 | assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 147 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 148 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| ... | ... | @@ -157,8 +157,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "implicitly cast from [N]T to ?[]const T" { |
| 160 | assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 161 | comptime assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 160 | expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 161 | comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | fn castToOptionalSlice() ?[]const u8 { |
| ... | ... | @@ -171,7 +171,7 @@ test "implicitly cast from [0]T to anyerror![]T" { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | fn testCastZeroArrayToErrSliceMut() void { |
| 174 | assertOrPanic((gimmeErrOrSlice() catch unreachable).len == 0); | |
| 174 | expect((gimmeErrOrSlice() catch unreachable).len == 0); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | fn gimmeErrOrSlice() anyerror![]u8 { |
| ... | ... | @@ -182,14 +182,14 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { |
| 182 | 182 | { |
| 183 | 183 | var data = "hi"; |
| 184 | 184 | const slice = data[0..]; |
| 185 | assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 186 | assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 185 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 186 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 187 | 187 | } |
| 188 | 188 | comptime { |
| 189 | 189 | var data = "hi"; |
| 190 | 190 | const slice = data[0..]; |
| 191 | assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 192 | assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 191 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 192 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| ... | ... | @@ -207,7 +207,7 @@ test "resolve undefined with integer" { |
| 207 | 207 | fn testResolveUndefWithInt(b: bool, x: i32) void { |
| 208 | 208 | const value = if (b) x else undefined; |
| 209 | 209 | if (b) { |
| 210 | assertOrPanic(value == x); | |
| 210 | expect(value == x); | |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| ... | ... | @@ -219,17 +219,17 @@ test "implicit cast from &const [N]T to []const T" { |
| 219 | 219 | fn testCastConstArrayRefToConstSlice() void { |
| 220 | 220 | const blah = "aoeu"; |
| 221 | 221 | const const_array_ref = &blah; |
| 222 | assertOrPanic(@typeOf(const_array_ref) == *const [4]u8); | |
| 222 | expect(@typeOf(const_array_ref) == *const [4]u8); | |
| 223 | 223 | const slice: []const u8 = const_array_ref; |
| 224 | assertOrPanic(mem.eql(u8, slice, "aoeu")); | |
| 224 | expect(mem.eql(u8, slice, "aoeu")); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | test "peer type resolution: error and [N]T" { |
| 228 | 228 | // TODO: implicit error!T to error!U where T can implicitly cast to U |
| 229 | //assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 230 | //comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 231 | assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 232 | comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 229 | //expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 230 | //comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 231 | expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 232 | comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | //fn testPeerErrorAndArray(x: u8) error![]const u8 { |
| ... | ... | @@ -253,9 +253,9 @@ test "@floatToInt" { |
| 253 | 253 | |
| 254 | 254 | fn testFloatToInts() void { |
| 255 | 255 | const x = i32(1e4); |
| 256 | assertOrPanic(x == 10000); | |
| 256 | expect(x == 10000); | |
| 257 | 257 | const y = @floatToInt(i32, f32(1e4)); |
| 258 | assertOrPanic(y == 10000); | |
| 258 | expect(y == 10000); | |
| 259 | 259 | expectFloatToInt(f16, 255.1, u8, 255); |
| 260 | 260 | expectFloatToInt(f16, 127.2, i8, 127); |
| 261 | 261 | expectFloatToInt(f16, -128.2, i8, -128); |
| ... | ... | @@ -266,7 +266,7 @@ fn testFloatToInts() void { |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void { |
| 269 | assertOrPanic(@floatToInt(I, f) == i); | |
| 269 | expect(@floatToInt(I, f) == i); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | test "cast u128 to f128 and back" { |
| ... | ... | @@ -275,7 +275,7 @@ test "cast u128 to f128 and back" { |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | fn testCast128() void { |
| 278 | assertOrPanic(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); | |
| 278 | expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); | |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | fn cast128Int(x: f128) u128 { |
| ... | ... | @@ -295,9 +295,9 @@ test "const slice widen cast" { |
| 295 | 295 | }; |
| 296 | 296 | |
| 297 | 297 | const u32_value = @bytesToSlice(u32, bytes[0..])[0]; |
| 298 | assertOrPanic(u32_value == 0x12121212); | |
| 298 | expect(u32_value == 0x12121212); | |
| 299 | 299 | |
| 300 | assertOrPanic(@bitCast(u32, bytes) == 0x12121212); | |
| 300 | expect(@bitCast(u32, bytes) == 0x12121212); | |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | test "single-item pointer of array to slice and to unknown length pointer" { |
| ... | ... | @@ -309,76 +309,76 @@ fn testCastPtrOfArrayToSliceAndPtr() void { |
| 309 | 309 | var array = "aoeu"; |
| 310 | 310 | const x: [*]u8 = &array; |
| 311 | 311 | x[0] += 1; |
| 312 | assertOrPanic(mem.eql(u8, array[0..], "boeu")); | |
| 312 | expect(mem.eql(u8, array[0..], "boeu")); | |
| 313 | 313 | const y: []u8 = &array; |
| 314 | 314 | y[0] += 1; |
| 315 | assertOrPanic(mem.eql(u8, array[0..], "coeu")); | |
| 315 | expect(mem.eql(u8, array[0..], "coeu")); | |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 319 | 319 | const window_name = [1][*]const u8{c"window name"}; |
| 320 | 320 | const x: [*]const ?[*]const u8 = &window_name; |
| 321 | assertOrPanic(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name")); | |
| 321 | expect(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name")); | |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | test "@intCast comptime_int" { |
| 325 | 325 | const result = @intCast(i32, 1234); |
| 326 | assertOrPanic(@typeOf(result) == i32); | |
| 327 | assertOrPanic(result == 1234); | |
| 326 | expect(@typeOf(result) == i32); | |
| 327 | expect(result == 1234); | |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | test "@floatCast comptime_int and comptime_float" { |
| 331 | 331 | { |
| 332 | 332 | const result = @floatCast(f16, 1234); |
| 333 | assertOrPanic(@typeOf(result) == f16); | |
| 334 | assertOrPanic(result == 1234.0); | |
| 333 | expect(@typeOf(result) == f16); | |
| 334 | expect(result == 1234.0); | |
| 335 | 335 | } |
| 336 | 336 | { |
| 337 | 337 | const result = @floatCast(f16, 1234.0); |
| 338 | assertOrPanic(@typeOf(result) == f16); | |
| 339 | assertOrPanic(result == 1234.0); | |
| 338 | expect(@typeOf(result) == f16); | |
| 339 | expect(result == 1234.0); | |
| 340 | 340 | } |
| 341 | 341 | { |
| 342 | 342 | const result = @floatCast(f32, 1234); |
| 343 | assertOrPanic(@typeOf(result) == f32); | |
| 344 | assertOrPanic(result == 1234.0); | |
| 343 | expect(@typeOf(result) == f32); | |
| 344 | expect(result == 1234.0); | |
| 345 | 345 | } |
| 346 | 346 | { |
| 347 | 347 | const result = @floatCast(f32, 1234.0); |
| 348 | assertOrPanic(@typeOf(result) == f32); | |
| 349 | assertOrPanic(result == 1234.0); | |
| 348 | expect(@typeOf(result) == f32); | |
| 349 | expect(result == 1234.0); | |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | test "comptime_int @intToFloat" { |
| 354 | 354 | { |
| 355 | 355 | const result = @intToFloat(f16, 1234); |
| 356 | assertOrPanic(@typeOf(result) == f16); | |
| 357 | assertOrPanic(result == 1234.0); | |
| 356 | expect(@typeOf(result) == f16); | |
| 357 | expect(result == 1234.0); | |
| 358 | 358 | } |
| 359 | 359 | { |
| 360 | 360 | const result = @intToFloat(f32, 1234); |
| 361 | assertOrPanic(@typeOf(result) == f32); | |
| 362 | assertOrPanic(result == 1234.0); | |
| 361 | expect(@typeOf(result) == f32); | |
| 362 | expect(result == 1234.0); | |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | test "@bytesToSlice keeps pointer alignment" { |
| 367 | 367 | var bytes = []u8{ 0x01, 0x02, 0x03, 0x04 }; |
| 368 | 368 | const numbers = @bytesToSlice(u32, bytes[0..]); |
| 369 | comptime assertOrPanic(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32); | |
| 369 | comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32); | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | test "@intCast i32 to u7" { |
| 373 | 373 | var x: u128 = maxInt(u128); |
| 374 | 374 | var y: i32 = 120; |
| 375 | 375 | var z = x >> @intCast(u7, y); |
| 376 | assertOrPanic(z == 0xff); | |
| 376 | expect(z == 0xff); | |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | test "implicit cast undefined to optional" { |
| 380 | assertOrPanic(MakeType(void).getNull() == null); | |
| 381 | assertOrPanic(MakeType(void).getNonNull() != null); | |
| 380 | expect(MakeType(void).getNull() == null); | |
| 381 | expect(MakeType(void).getNonNull() != null); | |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | fn MakeType(comptime T: type) type { |
| ... | ... | @@ -398,16 +398,16 @@ test "implicit cast from *[N]T to ?[*]T" { |
| 398 | 398 | var y: [4]u16 = [4]u16{ 0, 1, 2, 3 }; |
| 399 | 399 | |
| 400 | 400 | x = &y; |
| 401 | assertOrPanic(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 401 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 402 | 402 | x.?[0] = 8; |
| 403 | 403 | y[3] = 6; |
| 404 | assertOrPanic(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 404 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | test "implicit cast from *T to ?*c_void" { |
| 408 | 408 | var a: u8 = 1; |
| 409 | 409 | incrementVoidPtrValue(&a); |
| 410 | std.debug.assertOrPanic(a == 2); | |
| 410 | std.testing.expect(a == 2); | |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | fn incrementVoidPtrValue(value: ?*c_void) void { |
| ... | ... | @@ -417,7 +417,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void { |
| 417 | 417 | test "implicit cast from [*]T to ?*c_void" { |
| 418 | 418 | var a = []u8{ 3, 2, 1 }; |
| 419 | 419 | incrementVoidPtrArray(a[0..].ptr, 3); |
| 420 | assertOrPanic(std.mem.eql(u8, a, []u8{ 4, 3, 2 })); | |
| 420 | expect(std.mem.eql(u8, a, []u8{ 4, 3, 2 })); | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { |
| ... | ... | @@ -441,27 +441,27 @@ pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize)); |
| 441 | 441 | pub const PFN_void = extern fn (*c_void) void; |
| 442 | 442 | |
| 443 | 443 | fn foobar(func: PFN_void) void { |
| 444 | std.debug.assertOrPanic(@ptrToInt(func) == maxInt(usize)); | |
| 444 | std.testing.expect(@ptrToInt(func) == maxInt(usize)); | |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | test "implicit ptr to *c_void" { |
| 448 | 448 | var a: u32 = 1; |
| 449 | 449 | var ptr: *c_void = &a; |
| 450 | 450 | var b: *u32 = @ptrCast(*u32, ptr); |
| 451 | assertOrPanic(b.* == 1); | |
| 451 | expect(b.* == 1); | |
| 452 | 452 | var ptr2: ?*c_void = &a; |
| 453 | 453 | var c: *u32 = @ptrCast(*u32, ptr2.?); |
| 454 | assertOrPanic(c.* == 1); | |
| 454 | expect(c.* == 1); | |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | test "@intCast to comptime_int" { |
| 458 | assertOrPanic(@intCast(comptime_int, 0) == 0); | |
| 458 | expect(@intCast(comptime_int, 0) == 0); | |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | test "implicit cast comptime numbers to any type when the value fits" { |
| 462 | 462 | const a: u64 = 255; |
| 463 | 463 | var b: u8 = a; |
| 464 | assertOrPanic(b == 255); | |
| 464 | expect(b == 255); | |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | test "@intToEnum passed a comptime_int to an enum with one item" { |
| ... | ... | @@ -469,14 +469,14 @@ test "@intToEnum passed a comptime_int to an enum with one item" { |
| 469 | 469 | A, |
| 470 | 470 | }; |
| 471 | 471 | const x = @intToEnum(E, 0); |
| 472 | assertOrPanic(x == E.A); | |
| 472 | expect(x == E.A); | |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | test "@intCast to u0 and use the result" { |
| 476 | 476 | const S = struct { |
| 477 | 477 | fn doTheTest(zero: u1, one: u1, bigzero: i32) void { |
| 478 | assertOrPanic((one << @intCast(u0, bigzero)) == 1); | |
| 479 | assertOrPanic((zero << @intCast(u0, bigzero)) == 0); | |
| 478 | expect((one << @intCast(u0, bigzero)) == 1); | |
| 479 | expect((zero << @intCast(u0, bigzero)) == 0); | |
| 480 | 480 | } |
| 481 | 481 | }; |
| 482 | 482 | S.doTheTest(0, 1, 0); |
test/stage1/behavior/const_slice_child.zig+7-6| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | const debug = @import("std").debug; | |
| 2 | const assertOrPanic = debug.assertOrPanic; | |
| 1 | const std = @import("std"); | |
| 2 | const debug = std.debug; | |
| 3 | const expect = std.testing.expect; | |
| 3 | 4 | |
| 4 | 5 | var argv: [*]const [*]const u8 = undefined; |
| 5 | 6 | |
| ... | ... | @@ -15,10 +16,10 @@ test "const slice child" { |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | fn foo(args: [][]const u8) void { |
| 18 | assertOrPanic(args.len == 3); | |
| 19 | assertOrPanic(streql(args[0], "one")); | |
| 20 | assertOrPanic(streql(args[1], "two")); | |
| 21 | assertOrPanic(streql(args[2], "three")); | |
| 19 | expect(args.len == 3); | |
| 20 | expect(streql(args[0], "one")); | |
| 21 | expect(streql(args[1], "two")); | |
| 22 | expect(streql(args[2], "three")); | |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | fn bar(argc: usize) void { |
test/stage1/behavior/coroutine_await_struct.zig+3-3| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | const Foo = struct { |
| 6 | 6 | x: i32, |
| ... | ... | @@ -18,8 +18,8 @@ test "coroutine await struct" { |
| 18 | 18 | await_seq('f'); |
| 19 | 19 | resume await_a_promise; |
| 20 | 20 | await_seq('i'); |
| 21 | assertOrPanic(await_final_result.x == 1234); | |
| 22 | assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi")); | |
| 21 | expect(await_final_result.x == 1234); | |
| 22 | expect(std.mem.eql(u8, await_points, "abcdefghi")); | |
| 23 | 23 | } |
| 24 | 24 | async fn await_amain() void { |
| 25 | 25 | await_seq('b'); |
test/stage1/behavior/coroutines.zig+18-18| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | var x: i32 = 1; |
| 6 | 6 | |
| ... | ... | @@ -9,9 +9,9 @@ test "create a coroutine and cancel it" { |
| 9 | 9 | defer da.deinit(); |
| 10 | 10 | |
| 11 | 11 | const p = try async<&da.allocator> simpleAsyncFn(); |
| 12 | comptime assertOrPanic(@typeOf(p) == promise->void); | |
| 12 | comptime expect(@typeOf(p) == promise->void); | |
| 13 | 13 | cancel p; |
| 14 | assertOrPanic(x == 2); | |
| 14 | expect(x == 2); | |
| 15 | 15 | } |
| 16 | 16 | async fn simpleAsyncFn() void { |
| 17 | 17 | x += 1; |
| ... | ... | @@ -31,7 +31,7 @@ test "coroutine suspend, resume, cancel" { |
| 31 | 31 | cancel p; |
| 32 | 32 | seq('g'); |
| 33 | 33 | |
| 34 | assertOrPanic(std.mem.eql(u8, points, "abcdefg")); | |
| 34 | expect(std.mem.eql(u8, points, "abcdefg")); | |
| 35 | 35 | } |
| 36 | 36 | async fn testAsyncSeq() void { |
| 37 | 37 | defer seq('e'); |
| ... | ... | @@ -53,9 +53,9 @@ test "coroutine suspend with block" { |
| 53 | 53 | defer da.deinit(); |
| 54 | 54 | |
| 55 | 55 | const p = try async<&da.allocator> testSuspendBlock(); |
| 56 | std.debug.assertOrPanic(!result); | |
| 56 | std.testing.expect(!result); | |
| 57 | 57 | resume a_promise; |
| 58 | std.debug.assertOrPanic(result); | |
| 58 | std.testing.expect(result); | |
| 59 | 59 | cancel p; |
| 60 | 60 | } |
| 61 | 61 | |
| ... | ... | @@ -63,13 +63,13 @@ var a_promise: promise = undefined; |
| 63 | 63 | var result = false; |
| 64 | 64 | async fn testSuspendBlock() void { |
| 65 | 65 | suspend { |
| 66 | comptime assertOrPanic(@typeOf(@handle()) == promise->void); | |
| 66 | comptime expect(@typeOf(@handle()) == promise->void); | |
| 67 | 67 | a_promise = @handle(); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | //Test to make sure that @handle() works as advertised (issue #1296) |
| 71 | 71 | //var our_handle: promise = @handle(); |
| 72 | assertOrPanic(a_promise == @handle()); | |
| 72 | expect(a_promise == @handle()); | |
| 73 | 73 | |
| 74 | 74 | result = true; |
| 75 | 75 | } |
| ... | ... | @@ -86,8 +86,8 @@ test "coroutine await" { |
| 86 | 86 | await_seq('f'); |
| 87 | 87 | resume await_a_promise; |
| 88 | 88 | await_seq('i'); |
| 89 | assertOrPanic(await_final_result == 1234); | |
| 90 | assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi")); | |
| 89 | expect(await_final_result == 1234); | |
| 90 | expect(std.mem.eql(u8, await_points, "abcdefghi")); | |
| 91 | 91 | } |
| 92 | 92 | async fn await_amain() void { |
| 93 | 93 | await_seq('b'); |
| ... | ... | @@ -123,8 +123,8 @@ test "coroutine await early return" { |
| 123 | 123 | early_seq('a'); |
| 124 | 124 | const p = async<&da.allocator> early_amain() catch @panic("out of memory"); |
| 125 | 125 | early_seq('f'); |
| 126 | assertOrPanic(early_final_result == 1234); | |
| 127 | assertOrPanic(std.mem.eql(u8, early_points, "abcdef")); | |
| 126 | expect(early_final_result == 1234); | |
| 127 | expect(std.mem.eql(u8, early_points, "abcdef")); | |
| 128 | 128 | } |
| 129 | 129 | async fn early_amain() void { |
| 130 | 130 | early_seq('b'); |
| ... | ... | @@ -170,7 +170,7 @@ test "async function with dot syntax" { |
| 170 | 170 | defer da.deinit(); |
| 171 | 171 | const p = try async<&da.allocator> S.foo(); |
| 172 | 172 | cancel p; |
| 173 | assertOrPanic(S.y == 2); | |
| 173 | expect(S.y == 2); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "async fn pointer in a struct field" { |
| ... | ... | @@ -182,9 +182,9 @@ test "async fn pointer in a struct field" { |
| 182 | 182 | var da = std.heap.DirectAllocator.init(); |
| 183 | 183 | defer da.deinit(); |
| 184 | 184 | const p = (async<&da.allocator> foo.bar(&data)) catch unreachable; |
| 185 | assertOrPanic(data == 2); | |
| 185 | expect(data == 2); | |
| 186 | 186 | cancel p; |
| 187 | assertOrPanic(data == 4); | |
| 187 | expect(data == 4); | |
| 188 | 188 | } |
| 189 | 189 | async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void { |
| 190 | 190 | defer y.* += 2; |
| ... | ... | @@ -230,9 +230,9 @@ async fn suspendThenFail() anyerror!void { |
| 230 | 230 | } |
| 231 | 231 | async fn printTrace(p: promise->(anyerror!void)) void { |
| 232 | 232 | (await p) catch |e| { |
| 233 | std.debug.assertOrPanic(e == error.Fail); | |
| 233 | std.testing.expect(e == error.Fail); | |
| 234 | 234 | if (@errorReturnTrace()) |trace| { |
| 235 | assertOrPanic(trace.index == 1); | |
| 235 | expect(trace.index == 1); | |
| 236 | 236 | } else switch (builtin.mode) { |
| 237 | 237 | builtin.Mode.Debug, builtin.Mode.ReleaseSafe => @panic("expected return trace"), |
| 238 | 238 | builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {}, |
| ... | ... | @@ -246,7 +246,7 @@ test "break from suspend" { |
| 246 | 246 | var my_result: i32 = 1; |
| 247 | 247 | const p = try async<a> testBreakFromSuspend(&my_result); |
| 248 | 248 | cancel p; |
| 249 | std.debug.assertOrPanic(my_result == 2); | |
| 249 | std.testing.expect(my_result == 2); | |
| 250 | 250 | } |
| 251 | 251 | async fn testBreakFromSuspend(my_result: *i32) void { |
| 252 | 252 | suspend { |
test/stage1/behavior/defer.zig+12-12| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | var result: [3]u8 = undefined; |
| 4 | 4 | var index: usize = undefined; |
| ... | ... | @@ -21,18 +21,18 @@ fn runSomeErrorDefers(x: bool) !bool { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "mixing normal and error defers" { |
| 24 | assertOrPanic(runSomeErrorDefers(true) catch unreachable); | |
| 25 | assertOrPanic(result[0] == 'c'); | |
| 26 | assertOrPanic(result[1] == 'a'); | |
| 24 | expect(runSomeErrorDefers(true) catch unreachable); | |
| 25 | expect(result[0] == 'c'); | |
| 26 | expect(result[1] == 'a'); | |
| 27 | 27 | |
| 28 | 28 | const ok = runSomeErrorDefers(false) catch |err| x: { |
| 29 | assertOrPanic(err == error.FalseNotAllowed); | |
| 29 | expect(err == error.FalseNotAllowed); | |
| 30 | 30 | break :x true; |
| 31 | 31 | }; |
| 32 | assertOrPanic(ok); | |
| 33 | assertOrPanic(result[0] == 'c'); | |
| 34 | assertOrPanic(result[1] == 'b'); | |
| 35 | assertOrPanic(result[2] == 'a'); | |
| 32 | expect(ok); | |
| 33 | expect(result[0] == 'c'); | |
| 34 | expect(result[1] == 'b'); | |
| 35 | expect(result[2] == 'a'); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "break and continue inside loop inside defer expression" { |
| ... | ... | @@ -47,7 +47,7 @@ fn testBreakContInDefer(x: usize) void { |
| 47 | 47 | if (i < 5) continue; |
| 48 | 48 | if (i == 5) break; |
| 49 | 49 | } |
| 50 | assertOrPanic(i == 5); | |
| 50 | expect(i == 5); | |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| ... | ... | @@ -59,11 +59,11 @@ test "defer and labeled break" { |
| 59 | 59 | break :blk; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | assertOrPanic(i == 1); | |
| 62 | expect(i == 1); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | test "errdefer does not apply to fn inside fn" { |
| 66 | if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| assertOrPanic(e == error.Bad); | |
| 66 | if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| expect(e == error.Bad); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | fn testNestedFnErrDefer() anyerror!void { |
test/stage1/behavior/enum.zig+37-37| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | test "enum type" { |
| ... | ... | @@ -11,16 +11,16 @@ test "enum type" { |
| 11 | 11 | }; |
| 12 | 12 | const bar = Bar.B; |
| 13 | 13 | |
| 14 | assertOrPanic(bar == Bar.B); | |
| 15 | assertOrPanic(@memberCount(Foo) == 3); | |
| 16 | assertOrPanic(@memberCount(Bar) == 4); | |
| 17 | assertOrPanic(@sizeOf(Foo) == @sizeOf(FooNoVoid)); | |
| 18 | assertOrPanic(@sizeOf(Bar) == 1); | |
| 14 | expect(bar == Bar.B); | |
| 15 | expect(@memberCount(Foo) == 3); | |
| 16 | expect(@memberCount(Bar) == 4); | |
| 17 | expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); | |
| 18 | expect(@sizeOf(Bar) == 1); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "enum as return value" { |
| 22 | 22 | switch (returnAnInt(13)) { |
| 23 | Foo.One => |value| assertOrPanic(value == 13), | |
| 23 | Foo.One => |value| expect(value == 13), | |
| 24 | 24 | else => unreachable, |
| 25 | 25 | } |
| 26 | 26 | } |
| ... | ... | @@ -92,14 +92,14 @@ test "enum to int" { |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | fn shouldEqual(n: Number, expected: u3) void { |
| 95 | assertOrPanic(@enumToInt(n) == expected); | |
| 95 | expect(@enumToInt(n) == expected); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "int to enum" { |
| 99 | 99 | testIntToEnumEval(3); |
| 100 | 100 | } |
| 101 | 101 | fn testIntToEnumEval(x: i32) void { |
| 102 | assertOrPanic(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three); | |
| 102 | expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three); | |
| 103 | 103 | } |
| 104 | 104 | const IntToEnumNumber = enum { |
| 105 | 105 | Zero, |
| ... | ... | @@ -110,8 +110,8 @@ const IntToEnumNumber = enum { |
| 110 | 110 | }; |
| 111 | 111 | |
| 112 | 112 | test "@tagName" { |
| 113 | assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 114 | comptime assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 113 | expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 114 | comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | fn testEnumTagNameBare(n: BareNumber) []const u8 { |
| ... | ... | @@ -126,8 +126,8 @@ const BareNumber = enum { |
| 126 | 126 | |
| 127 | 127 | test "enum alignment" { |
| 128 | 128 | comptime { |
| 129 | assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf([9]u8)); | |
| 130 | assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf(u64)); | |
| 129 | expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8)); | |
| 130 | expect(@alignOf(AlignTestEnum) >= @alignOf(u64)); | |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| ... | ... | @@ -663,10 +663,10 @@ const ValueCount257 = enum { |
| 663 | 663 | |
| 664 | 664 | test "enum sizes" { |
| 665 | 665 | comptime { |
| 666 | assertOrPanic(@sizeOf(ValueCount1) == 0); | |
| 667 | assertOrPanic(@sizeOf(ValueCount2) == 1); | |
| 668 | assertOrPanic(@sizeOf(ValueCount256) == 1); | |
| 669 | assertOrPanic(@sizeOf(ValueCount257) == 2); | |
| 666 | expect(@sizeOf(ValueCount1) == 0); | |
| 667 | expect(@sizeOf(ValueCount2) == 1); | |
| 668 | expect(@sizeOf(ValueCount256) == 1); | |
| 669 | expect(@sizeOf(ValueCount257) == 2); | |
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
| ... | ... | @@ -685,12 +685,12 @@ test "set enum tag type" { |
| 685 | 685 | { |
| 686 | 686 | var x = Small.One; |
| 687 | 687 | x = Small.Two; |
| 688 | comptime assertOrPanic(@TagType(Small) == u2); | |
| 688 | comptime expect(@TagType(Small) == u2); | |
| 689 | 689 | } |
| 690 | 690 | { |
| 691 | 691 | var x = Small2.One; |
| 692 | 692 | x = Small2.Two; |
| 693 | comptime assertOrPanic(@TagType(Small2) == u2); | |
| 693 | comptime expect(@TagType(Small2) == u2); | |
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | 696 | |
| ... | ... | @@ -737,17 +737,17 @@ const bit_field_1 = BitFieldOfEnums{ |
| 737 | 737 | |
| 738 | 738 | test "bit field access with enum fields" { |
| 739 | 739 | var data = bit_field_1; |
| 740 | assertOrPanic(getA(&data) == A.Two); | |
| 741 | assertOrPanic(getB(&data) == B.Three3); | |
| 742 | assertOrPanic(getC(&data) == C.Four4); | |
| 743 | comptime assertOrPanic(@sizeOf(BitFieldOfEnums) == 1); | |
| 740 | expect(getA(&data) == A.Two); | |
| 741 | expect(getB(&data) == B.Three3); | |
| 742 | expect(getC(&data) == C.Four4); | |
| 743 | comptime expect(@sizeOf(BitFieldOfEnums) == 1); | |
| 744 | 744 | |
| 745 | 745 | data.b = B.Four3; |
| 746 | assertOrPanic(data.b == B.Four3); | |
| 746 | expect(data.b == B.Four3); | |
| 747 | 747 | |
| 748 | 748 | data.a = A.Three; |
| 749 | assertOrPanic(data.a == A.Three); | |
| 750 | assertOrPanic(data.b == B.Four3); | |
| 749 | expect(data.a == A.Three); | |
| 750 | expect(data.b == B.Four3); | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | fn getA(data: *const BitFieldOfEnums) A { |
| ... | ... | @@ -768,7 +768,7 @@ test "casting enum to its tag type" { |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | fn testCastEnumToTagType(value: Small2) void { |
| 771 | assertOrPanic(@enumToInt(value) == 1); | |
| 771 | expect(@enumToInt(value) == 1); | |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | const MultipleChoice = enum(u32) { |
| ... | ... | @@ -784,8 +784,8 @@ test "enum with specified tag values" { |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { |
| 787 | assertOrPanic(@enumToInt(x) == 60); | |
| 788 | assertOrPanic(1234 == switch (x) { | |
| 787 | expect(@enumToInt(x) == 60); | |
| 788 | expect(1234 == switch (x) { | |
| 789 | 789 | MultipleChoice.A => 1, |
| 790 | 790 | MultipleChoice.B => 2, |
| 791 | 791 | MultipleChoice.C => u32(1234), |
| ... | ... | @@ -811,8 +811,8 @@ test "enum with specified and unspecified tag values" { |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 814 | assertOrPanic(@enumToInt(x) == 1000); | |
| 815 | assertOrPanic(1234 == switch (x) { | |
| 814 | expect(@enumToInt(x) == 1000); | |
| 815 | expect(1234 == switch (x) { | |
| 816 | 816 | MultipleChoice2.A => 1, |
| 817 | 817 | MultipleChoice2.B => 2, |
| 818 | 818 | MultipleChoice2.C => 3, |
| ... | ... | @@ -826,8 +826,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | test "cast integer literal to enum" { |
| 829 | assertOrPanic(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1); | |
| 830 | assertOrPanic(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B); | |
| 829 | expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1); | |
| 830 | expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B); | |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | const EnumWithOneMember = enum { |
| ... | ... | @@ -865,14 +865,14 @@ const EnumWithTagValues = enum(u4) { |
| 865 | 865 | D = 1 << 3, |
| 866 | 866 | }; |
| 867 | 867 | test "enum with tag values don't require parens" { |
| 868 | assertOrPanic(@enumToInt(EnumWithTagValues.C) == 0b0100); | |
| 868 | expect(@enumToInt(EnumWithTagValues.C) == 0b0100); | |
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | test "enum with 1 field but explicit tag type should still have the tag type" { |
| 872 | 872 | const Enum = enum(u8) { |
| 873 | 873 | B = 2, |
| 874 | 874 | }; |
| 875 | comptime @import("std").debug.assertOrPanic(@sizeOf(Enum) == @sizeOf(u8)); | |
| 875 | comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8)); | |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | test "empty extern enum with members" { |
| ... | ... | @@ -881,7 +881,7 @@ test "empty extern enum with members" { |
| 881 | 881 | B, |
| 882 | 882 | C, |
| 883 | 883 | }; |
| 884 | assertOrPanic(@sizeOf(E) == @sizeOf(c_int)); | |
| 884 | expect(@sizeOf(E) == @sizeOf(c_int)); | |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | test "tag name with assigned enum values" { |
| ... | ... | @@ -890,5 +890,5 @@ test "tag name with assigned enum values" { |
| 890 | 890 | B = 0, |
| 891 | 891 | }; |
| 892 | 892 | var b = LocalFoo.B; |
| 893 | assertOrPanic(mem.eql(u8, @tagName(b), "B")); | |
| 893 | expect(mem.eql(u8, @tagName(b), "B")); | |
| 894 | 894 | } |
test/stage1/behavior/enum_with_members.zig+5-5| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | const fmt = @import("std").fmt; |
| 4 | 4 | |
| ... | ... | @@ -19,9 +19,9 @@ test "enum with members" { |
| 19 | 19 | const b = ET{ .UINT = 42 }; |
| 20 | 20 | var buf: [20]u8 = undefined; |
| 21 | 21 | |
| 22 | assertOrPanic((a.print(buf[0..]) catch unreachable) == 3); | |
| 23 | assertOrPanic(mem.eql(u8, buf[0..3], "-42")); | |
| 22 | expect((a.print(buf[0..]) catch unreachable) == 3); | |
| 23 | expect(mem.eql(u8, buf[0..3], "-42")); | |
| 24 | 24 | |
| 25 | assertOrPanic((b.print(buf[0..]) catch unreachable) == 2); | |
| 26 | assertOrPanic(mem.eql(u8, buf[0..2], "42")); | |
| 25 | expect((b.print(buf[0..]) catch unreachable) == 2); | |
| 26 | expect(mem.eql(u8, buf[0..2], "42")); | |
| 27 | 27 | } |
test/stage1/behavior/error.zig+31-31| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const assertError = std.debug.assertError; | |
| 2 | const expect = std.testing.expect; | |
| 3 | const expectError = std.testing.expectError; | |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | |
| ... | ... | @@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "error wrapping" { |
| 22 | assertOrPanic((baz() catch unreachable) == 15); | |
| 22 | expect((baz() catch unreachable) == 15); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | fn gimmeItBroke() []const u8 { |
| ... | ... | @@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 { |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | test "@errorName" { |
| 30 | assertOrPanic(mem.eql(u8, @errorName(error.AnError), "AnError")); | |
| 31 | assertOrPanic(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 30 | expect(mem.eql(u8, @errorName(error.AnError), "AnError")); | |
| 31 | expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "error values" { |
| 35 | 35 | const a = @errorToInt(error.err1); |
| 36 | 36 | const b = @errorToInt(error.err2); |
| 37 | assertOrPanic(a != b); | |
| 37 | expect(a != b); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "redefinition of error values allowed" { |
| ... | ... | @@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void { |
| 47 | 47 | test "error binary operator" { |
| 48 | 48 | const a = errBinaryOperatorG(true) catch 3; |
| 49 | 49 | const b = errBinaryOperatorG(false) catch 3; |
| 50 | assertOrPanic(a == 3); | |
| 51 | assertOrPanic(b == 10); | |
| 50 | expect(a == 3); | |
| 51 | expect(b == 10); | |
| 52 | 52 | } |
| 53 | 53 | fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 54 | 54 | return if (x) error.ItBroke else isize(10); |
| ... | ... | @@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 56 | 56 | |
| 57 | 57 | test "unwrap simple value from error" { |
| 58 | 58 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; |
| 59 | assertOrPanic(i == 13); | |
| 59 | expect(i == 13); | |
| 60 | 60 | } |
| 61 | 61 | fn unwrapSimpleValueFromErrorDo() anyerror!isize { |
| 62 | 62 | return 13; |
| ... | ... | @@ -82,10 +82,10 @@ test "error union type " { |
| 82 | 82 | |
| 83 | 83 | fn testErrorUnionType() void { |
| 84 | 84 | const x: anyerror!i32 = 1234; |
| 85 | if (x) |value| assertOrPanic(value == 1234) else |_| unreachable; | |
| 86 | assertOrPanic(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion); | |
| 87 | assertOrPanic(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); | |
| 88 | assertOrPanic(@typeOf(x).ErrorSet == anyerror); | |
| 85 | if (x) |value| expect(value == 1234) else |_| unreachable; | |
| 86 | expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion); | |
| 87 | expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); | |
| 88 | expect(@typeOf(x).ErrorSet == anyerror); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "error set type" { |
| ... | ... | @@ -99,12 +99,12 @@ const MyErrSet = error{ |
| 99 | 99 | }; |
| 100 | 100 | |
| 101 | 101 | fn testErrorSetType() void { |
| 102 | assertOrPanic(@memberCount(MyErrSet) == 2); | |
| 102 | expect(@memberCount(MyErrSet) == 2); | |
| 103 | 103 | |
| 104 | 104 | const a: MyErrSet!i32 = 5678; |
| 105 | 105 | const b: MyErrSet!i32 = MyErrSet.OutOfMemory; |
| 106 | 106 | |
| 107 | if (a) |value| assertOrPanic(value == 5678) else |err| switch (err) { | |
| 107 | if (a) |value| expect(value == 5678) else |err| switch (err) { | |
| 108 | 108 | error.OutOfMemory => unreachable, |
| 109 | 109 | error.FileNotFound => unreachable, |
| 110 | 110 | } |
| ... | ... | @@ -127,7 +127,7 @@ const Set2 = error{ |
| 127 | 127 | fn testExplicitErrorSetCast(set1: Set1) void { |
| 128 | 128 | var x = @errSetCast(Set2, set1); |
| 129 | 129 | var y = @errSetCast(Set1, x); |
| 130 | assertOrPanic(y == error.A); | |
| 130 | expect(y == error.A); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "comptime test error for empty error set" { |
| ... | ... | @@ -138,12 +138,12 @@ test "comptime test error for empty error set" { |
| 138 | 138 | const EmptyErrorSet = error{}; |
| 139 | 139 | |
| 140 | 140 | fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void { |
| 141 | if (x) |v| assertOrPanic(v == 1234) else |err| @compileError("bad"); | |
| 141 | if (x) |v| expect(v == 1234) else |err| @compileError("bad"); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "syntax: optional operator in front of error union operator" { |
| 145 | 145 | comptime { |
| 146 | assertOrPanic(?(anyerror!i32) == ?(anyerror!i32)); | |
| 146 | expect(?(anyerror!i32) == ?(anyerror!i32)); | |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| ... | ... | @@ -173,7 +173,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void { |
| 173 | 173 | if (y) |_| { |
| 174 | 174 | @panic("expected error"); |
| 175 | 175 | } else |e| { |
| 176 | assertOrPanic(e == error.A); | |
| 176 | expect(e == error.A); | |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| ... | ... | @@ -282,13 +282,13 @@ test "nested error union function call in optional unwrap" { |
| 282 | 282 | return null; |
| 283 | 283 | } |
| 284 | 284 | }; |
| 285 | assertOrPanic((try S.errorable()) == 1234); | |
| 286 | assertError(S.errorable2(), error.Failure); | |
| 287 | assertError(S.errorable3(), error.Other); | |
| 285 | expect((try S.errorable()) == 1234); | |
| 286 | expectError(error.Failure, S.errorable2()); | |
| 287 | expectError(error.Other, S.errorable3()); | |
| 288 | 288 | comptime { |
| 289 | assertOrPanic((try S.errorable()) == 1234); | |
| 290 | assertError(S.errorable2(), error.Failure); | |
| 291 | assertError(S.errorable3(), error.Other); | |
| 289 | expect((try S.errorable()) == 1234); | |
| 290 | expectError(error.Failure, S.errorable2()); | |
| 291 | expectError(error.Other, S.errorable3()); | |
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
| ... | ... | @@ -303,7 +303,7 @@ test "widen cast integer payload of error union function call" { |
| 303 | 303 | return 1234; |
| 304 | 304 | } |
| 305 | 305 | }; |
| 306 | assertOrPanic((try S.errorable()) == 1234); | |
| 306 | expect((try S.errorable()) == 1234); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | test "return function call to error set from error union function" { |
| ... | ... | @@ -316,17 +316,17 @@ test "return function call to error set from error union function" { |
| 316 | 316 | return error.Failure; |
| 317 | 317 | } |
| 318 | 318 | }; |
| 319 | assertError(S.errorable(), error.Failure); | |
| 320 | comptime assertError(S.errorable(), error.Failure); | |
| 319 | expectError(error.Failure, S.errorable()); | |
| 320 | comptime expectError(error.Failure, S.errorable()); | |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | test "optional error set is the same size as error set" { |
| 324 | comptime assertOrPanic(@sizeOf(?anyerror) == @sizeOf(anyerror)); | |
| 324 | comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror)); | |
| 325 | 325 | const S = struct { |
| 326 | 326 | fn returnsOptErrSet() ?anyerror { |
| 327 | 327 | return null; |
| 328 | 328 | } |
| 329 | 329 | }; |
| 330 | assertOrPanic(S.returnsOptErrSet() == null); | |
| 331 | comptime assertOrPanic(S.returnsOptErrSet() == null); | |
| 330 | expect(S.returnsOptErrSet() == null); | |
| 331 | comptime expect(S.returnsOptErrSet() == null); | |
| 332 | 332 | } |
test/stage1/behavior/eval.zig+116-116| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | |
| 5 | 5 | test "compile time recursion" { |
| 6 | assertOrPanic(some_data.len == 21); | |
| 6 | expect(some_data.len == 21); | |
| 7 | 7 | } |
| 8 | 8 | var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined; |
| 9 | 9 | fn fibonacci(x: i32) i32 { |
| ... | ... | @@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 { |
| 16 | 16 | } |
| 17 | 17 | const should_be_1235 = unwrapAndAddOne(1234); |
| 18 | 18 | test "static add one" { |
| 19 | assertOrPanic(should_be_1235 == 1235); | |
| 19 | expect(should_be_1235 == 1235); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "inlined loop" { |
| ... | ... | @@ -24,7 +24,7 @@ test "inlined loop" { |
| 24 | 24 | comptime var sum = 0; |
| 25 | 25 | inline while (i <= 5) : (i += 1) |
| 26 | 26 | sum += i; |
| 27 | assertOrPanic(sum == 15); | |
| 27 | expect(sum == 15); | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | fn gimme1or2(comptime a: bool) i32 { |
| ... | ... | @@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 { |
| 34 | 34 | return z; |
| 35 | 35 | } |
| 36 | 36 | test "inline variable gets result of const if" { |
| 37 | assertOrPanic(gimme1or2(true) == 1); | |
| 38 | assertOrPanic(gimme1or2(false) == 2); | |
| 37 | expect(gimme1or2(true) == 1); | |
| 38 | expect(gimme1or2(false) == 2); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | test "static function evaluation" { |
| 42 | assertOrPanic(statically_added_number == 3); | |
| 42 | expect(statically_added_number == 3); | |
| 43 | 43 | } |
| 44 | 44 | const statically_added_number = staticAdd(1, 2); |
| 45 | 45 | fn staticAdd(a: i32, b: i32) i32 { |
| ... | ... | @@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 { |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "const expr eval on single expr blocks" { |
| 50 | assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 51 | comptime assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 50 | expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 51 | comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| ... | ... | @@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | test "statically initialized list" { |
| 67 | assertOrPanic(static_point_list[0].x == 1); | |
| 68 | assertOrPanic(static_point_list[0].y == 2); | |
| 69 | assertOrPanic(static_point_list[1].x == 3); | |
| 70 | assertOrPanic(static_point_list[1].y == 4); | |
| 67 | expect(static_point_list[0].x == 1); | |
| 68 | expect(static_point_list[0].y == 2); | |
| 69 | expect(static_point_list[1].x == 3); | |
| 70 | expect(static_point_list[1].y == 4); | |
| 71 | 71 | } |
| 72 | 72 | const Point = struct { |
| 73 | 73 | x: i32, |
| ... | ... | @@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point { |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | test "static eval list init" { |
| 88 | assertOrPanic(static_vec3.data[2] == 1.0); | |
| 89 | assertOrPanic(vec3(0.0, 0.0, 3.0).data[2] == 3.0); | |
| 88 | expect(static_vec3.data[2] == 1.0); | |
| 89 | expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0); | |
| 90 | 90 | } |
| 91 | 91 | const static_vec3 = vec3(0.0, 0.0, 1.0); |
| 92 | 92 | pub const Vec3 = struct { |
| ... | ... | @@ -102,12 +102,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 { |
| 102 | 102 | |
| 103 | 103 | test "constant expressions" { |
| 104 | 104 | var array: [array_size]u8 = undefined; |
| 105 | assertOrPanic(@sizeOf(@typeOf(array)) == 20); | |
| 105 | expect(@sizeOf(@typeOf(array)) == 20); | |
| 106 | 106 | } |
| 107 | 107 | const array_size: u8 = 20; |
| 108 | 108 | |
| 109 | 109 | test "constant struct with negation" { |
| 110 | assertOrPanic(vertices[0].x == -0.6); | |
| 110 | expect(vertices[0].x == -0.6); | |
| 111 | 111 | } |
| 112 | 112 | const Vertex = struct { |
| 113 | 113 | x: f32, |
| ... | ... | @@ -142,7 +142,7 @@ const vertices = []Vertex{ |
| 142 | 142 | |
| 143 | 143 | test "statically initialized struct" { |
| 144 | 144 | st_init_str_foo.x += 1; |
| 145 | assertOrPanic(st_init_str_foo.x == 14); | |
| 145 | expect(st_init_str_foo.x == 14); | |
| 146 | 146 | } |
| 147 | 147 | const StInitStrFoo = struct { |
| 148 | 148 | x: i32, |
| ... | ... | @@ -155,7 +155,7 @@ var st_init_str_foo = StInitStrFoo{ |
| 155 | 155 | |
| 156 | 156 | test "statically initalized array literal" { |
| 157 | 157 | const y: [4]u8 = st_init_arr_lit_x; |
| 158 | assertOrPanic(y[3] == 4); | |
| 158 | expect(y[3] == 4); | |
| 159 | 159 | } |
| 160 | 160 | const st_init_arr_lit_x = []u8{ |
| 161 | 161 | 1, |
| ... | ... | @@ -167,15 +167,15 @@ const st_init_arr_lit_x = []u8{ |
| 167 | 167 | test "const slice" { |
| 168 | 168 | comptime { |
| 169 | 169 | const a = "1234567890"; |
| 170 | assertOrPanic(a.len == 10); | |
| 170 | expect(a.len == 10); | |
| 171 | 171 | const b = a[1..2]; |
| 172 | assertOrPanic(b.len == 1); | |
| 173 | assertOrPanic(b[0] == '2'); | |
| 172 | expect(b.len == 1); | |
| 173 | expect(b[0] == '2'); | |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "try to trick eval with runtime if" { |
| 178 | assertOrPanic(testTryToTrickEvalWithRuntimeIf(true) == 10); | |
| 178 | expect(testTryToTrickEvalWithRuntimeIf(true) == 10); | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | fn testTryToTrickEvalWithRuntimeIf(b: bool) usize { |
| ... | ... | @@ -201,16 +201,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool { |
| 201 | 201 | return max(bool, a, b); |
| 202 | 202 | } |
| 203 | 203 | test "inlined block and runtime block phi" { |
| 204 | assertOrPanic(letsTryToCompareBools(true, true)); | |
| 205 | assertOrPanic(letsTryToCompareBools(true, false)); | |
| 206 | assertOrPanic(letsTryToCompareBools(false, true)); | |
| 207 | assertOrPanic(!letsTryToCompareBools(false, false)); | |
| 204 | expect(letsTryToCompareBools(true, true)); | |
| 205 | expect(letsTryToCompareBools(true, false)); | |
| 206 | expect(letsTryToCompareBools(false, true)); | |
| 207 | expect(!letsTryToCompareBools(false, false)); | |
| 208 | 208 | |
| 209 | 209 | comptime { |
| 210 | assertOrPanic(letsTryToCompareBools(true, true)); | |
| 211 | assertOrPanic(letsTryToCompareBools(true, false)); | |
| 212 | assertOrPanic(letsTryToCompareBools(false, true)); | |
| 213 | assertOrPanic(!letsTryToCompareBools(false, false)); | |
| 210 | expect(letsTryToCompareBools(true, true)); | |
| 211 | expect(letsTryToCompareBools(true, false)); | |
| 212 | expect(letsTryToCompareBools(false, true)); | |
| 213 | expect(!letsTryToCompareBools(false, false)); | |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| ... | ... | @@ -255,14 +255,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | test "comptime iterate over fn ptr list" { |
| 258 | assertOrPanic(performFn('t', 1) == 6); | |
| 259 | assertOrPanic(performFn('o', 0) == 1); | |
| 260 | assertOrPanic(performFn('w', 99) == 99); | |
| 258 | expect(performFn('t', 1) == 6); | |
| 259 | expect(performFn('o', 0) == 1); | |
| 260 | expect(performFn('w', 99) == 99); | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | test "eval @setRuntimeSafety at compile-time" { |
| 264 | 264 | const result = comptime fnWithSetRuntimeSafety(); |
| 265 | assertOrPanic(result == 1234); | |
| 265 | expect(result == 1234); | |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | fn fnWithSetRuntimeSafety() i32 { |
| ... | ... | @@ -272,7 +272,7 @@ fn fnWithSetRuntimeSafety() i32 { |
| 272 | 272 | |
| 273 | 273 | test "eval @setFloatMode at compile-time" { |
| 274 | 274 | const result = comptime fnWithFloatMode(); |
| 275 | assertOrPanic(result == 1234.0); | |
| 275 | expect(result == 1234.0); | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | fn fnWithFloatMode() f32 { |
| ... | ... | @@ -293,15 +293,15 @@ var simple_struct = SimpleStruct{ .field = 1234 }; |
| 293 | 293 | const bound_fn = simple_struct.method; |
| 294 | 294 | |
| 295 | 295 | test "call method on bound fn referring to var instance" { |
| 296 | assertOrPanic(bound_fn() == 1237); | |
| 296 | expect(bound_fn() == 1237); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | test "ptr to local array argument at comptime" { |
| 300 | 300 | comptime { |
| 301 | 301 | var bytes: [10]u8 = undefined; |
| 302 | 302 | modifySomeBytes(bytes[0..]); |
| 303 | assertOrPanic(bytes[0] == 'a'); | |
| 304 | assertOrPanic(bytes[9] == 'b'); | |
| 303 | expect(bytes[0] == 'a'); | |
| 304 | expect(bytes[9] == 'b'); | |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| ... | ... | @@ -329,9 +329,9 @@ fn testCompTimeUIntComparisons(x: u32) void { |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | test "const ptr to variable data changes at runtime" { |
| 332 | assertOrPanic(foo_ref.name[0] == 'a'); | |
| 332 | expect(foo_ref.name[0] == 'a'); | |
| 333 | 333 | foo_ref.name = "b"; |
| 334 | assertOrPanic(foo_ref.name[0] == 'b'); | |
| 334 | expect(foo_ref.name[0] == 'b'); | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | const Foo = struct { |
| ... | ... | @@ -342,8 +342,8 @@ var foo_contents = Foo{ .name = "a" }; |
| 342 | 342 | const foo_ref = &foo_contents; |
| 343 | 343 | |
| 344 | 344 | test "create global array with for loop" { |
| 345 | assertOrPanic(global_array[5] == 5 * 5); | |
| 346 | assertOrPanic(global_array[9] == 9 * 9); | |
| 345 | expect(global_array[5] == 5 * 5); | |
| 346 | expect(global_array[9] == 9 * 9); | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | const global_array = x: { |
| ... | ... | @@ -358,7 +358,7 @@ test "compile-time downcast when the bits fit" { |
| 358 | 358 | comptime { |
| 359 | 359 | const spartan_count: u16 = 255; |
| 360 | 360 | const byte = @intCast(u8, spartan_count); |
| 361 | assertOrPanic(byte == 255); | |
| 361 | expect(byte == 255); | |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| ... | ... | @@ -366,44 +366,44 @@ const hi1 = "hi"; |
| 366 | 366 | const hi2 = hi1; |
| 367 | 367 | test "const global shares pointer with other same one" { |
| 368 | 368 | assertEqualPtrs(&hi1[0], &hi2[0]); |
| 369 | comptime assertOrPanic(&hi1[0] == &hi2[0]); | |
| 369 | comptime expect(&hi1[0] == &hi2[0]); | |
| 370 | 370 | } |
| 371 | 371 | fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void { |
| 372 | assertOrPanic(ptr1 == ptr2); | |
| 372 | expect(ptr1 == ptr2); | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | test "@setEvalBranchQuota" { |
| 376 | 376 | comptime { |
| 377 | // 1001 for the loop and then 1 more for the assertOrPanic fn call | |
| 377 | // 1001 for the loop and then 1 more for the expect fn call | |
| 378 | 378 | @setEvalBranchQuota(1002); |
| 379 | 379 | var i = 0; |
| 380 | 380 | var sum = 0; |
| 381 | 381 | while (i < 1001) : (i += 1) { |
| 382 | 382 | sum += i; |
| 383 | 383 | } |
| 384 | assertOrPanic(sum == 500500); | |
| 384 | expect(sum == 500500); | |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // TODO test "float literal at compile time not lossy" { |
| 389 | // TODO assertOrPanic(16777216.0 + 1.0 == 16777217.0); | |
| 390 | // TODO assertOrPanic(9007199254740992.0 + 1.0 == 9007199254740993.0); | |
| 389 | // TODO expect(16777216.0 + 1.0 == 16777217.0); | |
| 390 | // TODO expect(9007199254740992.0 + 1.0 == 9007199254740993.0); | |
| 391 | 391 | // TODO } |
| 392 | 392 | |
| 393 | 393 | test "f32 at compile time is lossy" { |
| 394 | assertOrPanic(f32(1 << 24) + 1 == 1 << 24); | |
| 394 | expect(f32(1 << 24) + 1 == 1 << 24); | |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | test "f64 at compile time is lossy" { |
| 398 | assertOrPanic(f64(1 << 53) + 1 == 1 << 53); | |
| 398 | expect(f64(1 << 53) + 1 == 1 << 53); | |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | test "f128 at compile time is lossy" { |
| 402 | assertOrPanic(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 402 | expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | comptime { |
| 406 | assertOrPanic(f128(1 << 113) == 10384593717069655257060992658440192); | |
| 406 | expect(f128(1 << 113) == 10384593717069655257060992658440192); | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| ... | ... | @@ -415,15 +415,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| 415 | 415 | test "string literal used as comptime slice is memoized" { |
| 416 | 416 | const a = "link"; |
| 417 | 417 | const b = "link"; |
| 418 | comptime assertOrPanic(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 419 | comptime assertOrPanic(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 418 | comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 419 | comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | test "comptime slice of undefined pointer of length 0" { |
| 423 | 423 | const slice1 = ([*]i32)(undefined)[0..0]; |
| 424 | assertOrPanic(slice1.len == 0); | |
| 424 | expect(slice1.len == 0); | |
| 425 | 425 | const slice2 = ([*]i32)(undefined)[100..100]; |
| 426 | assertOrPanic(slice2.len == 0); | |
| 426 | expect(slice2.len == 0); | |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | fn copyWithPartialInline(s: []u32, b: []u8) void { |
| ... | ... | @@ -445,16 +445,16 @@ test "binary math operator in partially inlined function" { |
| 445 | 445 | r.* = @intCast(u8, i + 1); |
| 446 | 446 | |
| 447 | 447 | copyWithPartialInline(s[0..], b[0..]); |
| 448 | assertOrPanic(s[0] == 0x1020304); | |
| 449 | assertOrPanic(s[1] == 0x5060708); | |
| 450 | assertOrPanic(s[2] == 0x90a0b0c); | |
| 451 | assertOrPanic(s[3] == 0xd0e0f10); | |
| 448 | expect(s[0] == 0x1020304); | |
| 449 | expect(s[1] == 0x5060708); | |
| 450 | expect(s[2] == 0x90a0b0c); | |
| 451 | expect(s[3] == 0xd0e0f10); | |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | test "comptime function with the same args is memoized" { |
| 455 | 455 | comptime { |
| 456 | assertOrPanic(MakeType(i32) == MakeType(i32)); | |
| 457 | assertOrPanic(MakeType(i32) != MakeType(f64)); | |
| 456 | expect(MakeType(i32) == MakeType(i32)); | |
| 457 | expect(MakeType(i32) != MakeType(f64)); | |
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | |
| ... | ... | @@ -470,7 +470,7 @@ test "comptime function with mutable pointer is not memoized" { |
| 470 | 470 | const ptr = &x; |
| 471 | 471 | increment(ptr); |
| 472 | 472 | increment(ptr); |
| 473 | assertOrPanic(x == 3); | |
| 473 | expect(x == 3); | |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| ... | ... | @@ -496,14 +496,14 @@ fn doesAlotT(comptime T: type, value: usize) T { |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | test "@setEvalBranchQuota at same scope as generic function call" { |
| 499 | assertOrPanic(doesAlotT(u32, 2) == 2); | |
| 499 | expect(doesAlotT(u32, 2) == 2); | |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | test "comptime slice of slice preserves comptime var" { |
| 503 | 503 | comptime { |
| 504 | 504 | var buff: [10]u8 = undefined; |
| 505 | 505 | buff[0..][0..][0] = 1; |
| 506 | assertOrPanic(buff[0..][0..][0] == 1); | |
| 506 | expect(buff[0..][0..][0] == 1); | |
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | |
| ... | ... | @@ -512,7 +512,7 @@ test "comptime slice of pointer preserves comptime var" { |
| 512 | 512 | var buff: [10]u8 = undefined; |
| 513 | 513 | var a = buff[0..].ptr; |
| 514 | 514 | a[0..1][0] = 1; |
| 515 | assertOrPanic(buff[0..][0..][0] == 1); | |
| 515 | expect(buff[0..][0..][0] == 1); | |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | |
| ... | ... | @@ -526,9 +526,9 @@ const SingleFieldStruct = struct { |
| 526 | 526 | test "const ptr to comptime mutable data is not memoized" { |
| 527 | 527 | comptime { |
| 528 | 528 | var foo = SingleFieldStruct{ .x = 1 }; |
| 529 | assertOrPanic(foo.read_x() == 1); | |
| 529 | expect(foo.read_x() == 1); | |
| 530 | 530 | foo.x = 2; |
| 531 | assertOrPanic(foo.read_x() == 2); | |
| 531 | expect(foo.read_x() == 2); | |
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
| ... | ... | @@ -537,7 +537,7 @@ test "array concat of slices gives slice" { |
| 537 | 537 | var a: []const u8 = "aoeu"; |
| 538 | 538 | var b: []const u8 = "asdf"; |
| 539 | 539 | const c = a ++ b; |
| 540 | assertOrPanic(std.mem.eql(u8, c, "aoeuasdf")); | |
| 540 | expect(std.mem.eql(u8, c, "aoeuasdf")); | |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| ... | ... | @@ -554,14 +554,14 @@ test "comptime shlWithOverflow" { |
| 554 | 554 | break :amt amt; |
| 555 | 555 | }; |
| 556 | 556 | |
| 557 | assertOrPanic(ct_shifted == rt_shifted); | |
| 557 | expect(ct_shifted == rt_shifted); | |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | test "runtime 128 bit integer division" { |
| 561 | 561 | var a: u128 = 152313999999999991610955792383; |
| 562 | 562 | var b: u128 = 10000000000000000000; |
| 563 | 563 | var c = a / b; |
| 564 | assertOrPanic(c == 15231399999); | |
| 564 | expect(c == 15231399999); | |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | pub const Info = struct { |
| ... | ... | @@ -574,20 +574,20 @@ test "comptime modification of const struct field" { |
| 574 | 574 | comptime { |
| 575 | 575 | var res = diamond_info; |
| 576 | 576 | res.version = 1; |
| 577 | assertOrPanic(diamond_info.version == 0); | |
| 578 | assertOrPanic(res.version == 1); | |
| 577 | expect(diamond_info.version == 0); | |
| 578 | expect(res.version == 1); | |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | test "pointer to type" { |
| 583 | 583 | comptime { |
| 584 | 584 | var T: type = i32; |
| 585 | assertOrPanic(T == i32); | |
| 585 | expect(T == i32); | |
| 586 | 586 | var ptr = &T; |
| 587 | assertOrPanic(@typeOf(ptr) == *type); | |
| 587 | expect(@typeOf(ptr) == *type); | |
| 588 | 588 | ptr.* = f32; |
| 589 | assertOrPanic(T == f32); | |
| 590 | assertOrPanic(*T == *f32); | |
| 589 | expect(T == f32); | |
| 590 | expect(*T == *f32); | |
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | |
| ... | ... | @@ -596,17 +596,17 @@ test "slice of type" { |
| 596 | 596 | var types_array = []type{ i32, f64, type }; |
| 597 | 597 | for (types_array) |T, i| { |
| 598 | 598 | switch (i) { |
| 599 | 0 => assertOrPanic(T == i32), | |
| 600 | 1 => assertOrPanic(T == f64), | |
| 601 | 2 => assertOrPanic(T == type), | |
| 599 | 0 => expect(T == i32), | |
| 600 | 1 => expect(T == f64), | |
| 601 | 2 => expect(T == type), | |
| 602 | 602 | else => unreachable, |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | for (types_array[0..]) |T, i| { |
| 606 | 606 | switch (i) { |
| 607 | 0 => assertOrPanic(T == i32), | |
| 608 | 1 => assertOrPanic(T == f64), | |
| 609 | 2 => assertOrPanic(T == type), | |
| 607 | 0 => expect(T == i32), | |
| 608 | 1 => expect(T == f64), | |
| 609 | 2 => expect(T == type), | |
| 610 | 610 | else => unreachable, |
| 611 | 611 | } |
| 612 | 612 | } |
| ... | ... | @@ -623,7 +623,7 @@ fn wrap(comptime T: type) Wrapper { |
| 623 | 623 | |
| 624 | 624 | test "function which returns struct with type field causes implicit comptime" { |
| 625 | 625 | const ty = wrap(i32).T; |
| 626 | assertOrPanic(ty == i32); | |
| 626 | expect(ty == i32); | |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | test "call method with comptime pass-by-non-copying-value self parameter" { |
| ... | ... | @@ -637,12 +637,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" { |
| 637 | 637 | |
| 638 | 638 | const s = S{ .a = 2 }; |
| 639 | 639 | var b = s.b(); |
| 640 | assertOrPanic(b == 2); | |
| 640 | expect(b == 2); | |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | test "@tagName of @typeId" { |
| 644 | 644 | const str = @tagName(@typeId(u8)); |
| 645 | assertOrPanic(std.mem.eql(u8, str, "Int")); | |
| 645 | expect(std.mem.eql(u8, str, "Int")); | |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | test "setting backward branch quota just before a generic fn call" { |
| ... | ... | @@ -663,8 +663,8 @@ fn testVarInsideInlineLoop(args: ...) void { |
| 663 | 663 | comptime var i = 0; |
| 664 | 664 | inline while (i < args.len) : (i += 1) { |
| 665 | 665 | const x = args[i]; |
| 666 | if (i == 0) assertOrPanic(x); | |
| 667 | if (i == 1) assertOrPanic(x == 42); | |
| 666 | if (i == 0) expect(x); | |
| 667 | if (i == 1) expect(x == 42); | |
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | 670 | |
| ... | ... | @@ -674,7 +674,7 @@ test "inline for with same type but different values" { |
| 674 | 674 | var a: T = undefined; |
| 675 | 675 | res += a.len; |
| 676 | 676 | } |
| 677 | assertOrPanic(res == 5); | |
| 677 | expect(res == 5); | |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | test "refer to the type of a generic function" { |
| ... | ... | @@ -688,13 +688,13 @@ fn doNothingWithType(comptime T: type) void {} |
| 688 | 688 | test "zero extend from u0 to u1" { |
| 689 | 689 | var zero_u0: u0 = 0; |
| 690 | 690 | var zero_u1: u1 = zero_u0; |
| 691 | assertOrPanic(zero_u1 == 0); | |
| 691 | expect(zero_u1 == 0); | |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | test "bit shift a u1" { |
| 695 | 695 | var x: u1 = 1; |
| 696 | 696 | var y = x << 0; |
| 697 | assertOrPanic(y == 1); | |
| 697 | expect(y == 1); | |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | test "@bytesToslice on a packed struct" { |
| ... | ... | @@ -704,7 +704,7 @@ test "@bytesToslice on a packed struct" { |
| 704 | 704 | |
| 705 | 705 | var b = [1]u8{9}; |
| 706 | 706 | var f = @bytesToSlice(F, b); |
| 707 | assertOrPanic(f[0].a == 9); | |
| 707 | expect(f[0].a == 9); | |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | test "comptime pointer cast array and then slice" { |
| ... | ... | @@ -716,8 +716,8 @@ test "comptime pointer cast array and then slice" { |
| 716 | 716 | const ptrB: [*]const u8 = &array; |
| 717 | 717 | const sliceB: []const u8 = ptrB[0..2]; |
| 718 | 718 | |
| 719 | assertOrPanic(sliceA[1] == 2); | |
| 720 | assertOrPanic(sliceB[1] == 2); | |
| 719 | expect(sliceA[1] == 2); | |
| 720 | expect(sliceB[1] == 2); | |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | test "slice bounds in comptime concatenation" { |
| ... | ... | @@ -726,47 +726,47 @@ test "slice bounds in comptime concatenation" { |
| 726 | 726 | break :blk b[8..9]; |
| 727 | 727 | }; |
| 728 | 728 | const str = "" ++ bs; |
| 729 | assertOrPanic(str.len == 1); | |
| 730 | assertOrPanic(std.mem.eql(u8, str, "1")); | |
| 729 | expect(str.len == 1); | |
| 730 | expect(std.mem.eql(u8, str, "1")); | |
| 731 | 731 | |
| 732 | 732 | const str2 = bs ++ ""; |
| 733 | assertOrPanic(str2.len == 1); | |
| 734 | assertOrPanic(std.mem.eql(u8, str2, "1")); | |
| 733 | expect(str2.len == 1); | |
| 734 | expect(std.mem.eql(u8, str2, "1")); | |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | test "comptime bitwise operators" { |
| 738 | 738 | comptime { |
| 739 | assertOrPanic(3 & 1 == 1); | |
| 740 | assertOrPanic(3 & -1 == 3); | |
| 741 | assertOrPanic(-3 & -1 == -3); | |
| 742 | assertOrPanic(3 | -1 == -1); | |
| 743 | assertOrPanic(-3 | -1 == -1); | |
| 744 | assertOrPanic(3 ^ -1 == -4); | |
| 745 | assertOrPanic(-3 ^ -1 == 2); | |
| 746 | assertOrPanic(~i8(-1) == 0); | |
| 747 | assertOrPanic(~i128(-1) == 0); | |
| 748 | assertOrPanic(18446744073709551615 & 18446744073709551611 == 18446744073709551611); | |
| 749 | assertOrPanic(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); | |
| 750 | assertOrPanic(~u128(0) == 0xffffffffffffffffffffffffffffffff); | |
| 739 | expect(3 & 1 == 1); | |
| 740 | expect(3 & -1 == 3); | |
| 741 | expect(-3 & -1 == -3); | |
| 742 | expect(3 | -1 == -1); | |
| 743 | expect(-3 | -1 == -1); | |
| 744 | expect(3 ^ -1 == -4); | |
| 745 | expect(-3 ^ -1 == 2); | |
| 746 | expect(~i8(-1) == 0); | |
| 747 | expect(~i128(-1) == 0); | |
| 748 | expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); | |
| 749 | expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); | |
| 750 | expect(~u128(0) == 0xffffffffffffffffffffffffffffffff); | |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | test "*align(1) u16 is the same as *align(1:0:2) u16" { |
| 755 | 755 | comptime { |
| 756 | assertOrPanic(*align(1:0:2) u16 == *align(1) u16); | |
| 756 | expect(*align(1:0:2) u16 == *align(1) u16); | |
| 757 | 757 | // TODO add parsing support for this syntax |
| 758 | //assertOrPanic(*align(:0:2) u16 == *u16); | |
| 758 | //expect(*align(:0:2) u16 == *u16); | |
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | test "array concatenation forces comptime" { |
| 763 | 763 | var a = oneItem(3) ++ oneItem(4); |
| 764 | assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 4 })); | |
| 764 | expect(std.mem.eql(i32, a, []i32{ 3, 4 })); | |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | test "array multiplication forces comptime" { |
| 768 | 768 | var a = oneItem(3) ** scalar(2); |
| 769 | assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 3 })); | |
| 769 | expect(std.mem.eql(i32, a, []i32{ 3, 3 })); | |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | fn oneItem(x: i32) [1]i32 { |
test/stage1/behavior/field_parent_ptr.zig+7-7| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "@fieldParentPtr non-first field" { |
| 4 | 4 | testParentFieldPtr(&foo.c); |
| ... | ... | @@ -25,17 +25,17 @@ const foo = Foo{ |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | fn testParentFieldPtr(c: *const i32) void { |
| 28 | assertOrPanic(c == &foo.c); | |
| 28 | expect(c == &foo.c); | |
| 29 | 29 | |
| 30 | 30 | const base = @fieldParentPtr(Foo, "c", c); |
| 31 | assertOrPanic(base == &foo); | |
| 32 | assertOrPanic(&base.c == c); | |
| 31 | expect(base == &foo); | |
| 32 | expect(&base.c == c); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | fn testParentFieldPtrFirst(a: *const bool) void { |
| 36 | assertOrPanic(a == &foo.a); | |
| 36 | expect(a == &foo.a); | |
| 37 | 37 | |
| 38 | 38 | const base = @fieldParentPtr(Foo, "a", a); |
| 39 | assertOrPanic(base == &foo); | |
| 40 | assertOrPanic(&base.a == a); | |
| 39 | expect(base == &foo); | |
| 40 | expect(&base.a == a); | |
| 41 | 41 | } |
test/stage1/behavior/fn.zig+19-19| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "params" { |
| 4 | assertOrPanic(testParamsAdd(22, 11) == 33); | |
| 4 | expect(testParamsAdd(22, 11) == 33); | |
| 5 | 5 | } |
| 6 | 6 | fn testParamsAdd(a: i32, b: i32) i32 { |
| 7 | 7 | return a + b; |
| ... | ... | @@ -21,32 +21,32 @@ test "void parameters" { |
| 21 | 21 | fn voidFun(a: i32, b: void, c: i32, d: void) void { |
| 22 | 22 | const v = b; |
| 23 | 23 | const vv: void = if (a == 1) v else {}; |
| 24 | assertOrPanic(a + c == 3); | |
| 24 | expect(a + c == 3); | |
| 25 | 25 | return vv; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "mutable local variables" { |
| 29 | 29 | var zero: i32 = 0; |
| 30 | assertOrPanic(zero == 0); | |
| 30 | expect(zero == 0); | |
| 31 | 31 | |
| 32 | 32 | var i = i32(0); |
| 33 | 33 | while (i != 3) { |
| 34 | 34 | i += 1; |
| 35 | 35 | } |
| 36 | assertOrPanic(i == 3); | |
| 36 | expect(i == 3); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "separate block scopes" { |
| 40 | 40 | { |
| 41 | 41 | const no_conflict: i32 = 5; |
| 42 | assertOrPanic(no_conflict == 5); | |
| 42 | expect(no_conflict == 5); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | const c = x: { |
| 46 | 46 | const no_conflict = i32(10); |
| 47 | 47 | break :x no_conflict; |
| 48 | 48 | }; |
| 49 | assertOrPanic(c == 10); | |
| 49 | expect(c == 10); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | test "call function with empty string" { |
| ... | ... | @@ -59,7 +59,7 @@ fn @"weird function name"() i32 { |
| 59 | 59 | return 1234; |
| 60 | 60 | } |
| 61 | 61 | test "weird function name" { |
| 62 | assertOrPanic(@"weird function name"() == 1234); | |
| 62 | expect(@"weird function name"() == 1234); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | test "implicit cast function unreachable return" { |
| ... | ... | @@ -80,7 +80,7 @@ test "function pointers" { |
| 80 | 80 | fn4, |
| 81 | 81 | }; |
| 82 | 82 | for (fns) |f, i| { |
| 83 | assertOrPanic(f() == @intCast(u32, i) + 5); | |
| 83 | expect(f() == @intCast(u32, i) + 5); | |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | fn fn1() u32 { |
| ... | ... | @@ -97,7 +97,7 @@ fn fn4() u32 { |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test "inline function call" { |
| 100 | assertOrPanic(@inlineCall(add, 3, 9) == 12); | |
| 100 | expect(@inlineCall(add, 3, 9) == 12); | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -110,7 +110,7 @@ test "number literal as an argument" { |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | fn numberLiteralArg(a: var) void { |
| 113 | assertOrPanic(a == 3); | |
| 113 | expect(a == 3); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | test "assign inline fn to const variable" { |
| ... | ... | @@ -121,7 +121,7 @@ test "assign inline fn to const variable" { |
| 121 | 121 | inline fn inlineFn() void {} |
| 122 | 122 | |
| 123 | 123 | test "pass by non-copying value" { |
| 124 | assertOrPanic(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); | |
| 124 | expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | const Point = struct { |
| ... | ... | @@ -134,17 +134,17 @@ fn addPointCoords(pt: Point) i32 { |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "pass by non-copying value through var arg" { |
| 137 | assertOrPanic(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3); | |
| 137 | expect(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | fn addPointCoordsVar(pt: var) i32 { |
| 141 | comptime assertOrPanic(@typeOf(pt) == Point); | |
| 141 | comptime expect(@typeOf(pt) == Point); | |
| 142 | 142 | return pt.x + pt.y; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "pass by non-copying value as method" { |
| 146 | 146 | var pt = Point2{ .x = 1, .y = 2 }; |
| 147 | assertOrPanic(pt.addPointCoords() == 3); | |
| 147 | expect(pt.addPointCoords() == 3); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | const Point2 = struct { |
| ... | ... | @@ -158,7 +158,7 @@ const Point2 = struct { |
| 158 | 158 | |
| 159 | 159 | test "pass by non-copying value as method, which is generic" { |
| 160 | 160 | var pt = Point3{ .x = 1, .y = 2 }; |
| 161 | assertOrPanic(pt.addPointCoords(i32) == 3); | |
| 161 | expect(pt.addPointCoords(i32) == 3); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | const Point3 = struct { |
| ... | ... | @@ -173,7 +173,7 @@ const Point3 = struct { |
| 173 | 173 | test "pass by non-copying value as method, at comptime" { |
| 174 | 174 | comptime { |
| 175 | 175 | var pt = Point2{ .x = 1, .y = 2 }; |
| 176 | assertOrPanic(pt.addPointCoords() == 3); | |
| 176 | expect(pt.addPointCoords() == 3); | |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| ... | ... | @@ -189,7 +189,7 @@ fn outer(y: u32) fn (u32) u32 { |
| 189 | 189 | |
| 190 | 190 | test "return inner function which references comptime variable of outer function" { |
| 191 | 191 | var func = outer(10); |
| 192 | assertOrPanic(func(3) == 7); | |
| 192 | expect(func(3) == 7); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | test "extern struct with stdcallcc fn pointer" { |
| ... | ... | @@ -203,6 +203,6 @@ test "extern struct with stdcallcc fn pointer" { |
| 203 | 203 | |
| 204 | 204 | var s: S = undefined; |
| 205 | 205 | s.ptr = S.foo; |
| 206 | assertOrPanic(s.ptr() == 1234); | |
| 206 | expect(s.ptr() == 1234); | |
| 207 | 207 | } |
| 208 | 208 |
test/stage1/behavior/fn_in_struct_in_comptime.zig+2-2| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | fn get_foo() fn (*u8) usize { |
| 4 | 4 | comptime { |
| ... | ... | @@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize { |
| 13 | 13 | |
| 14 | 14 | test "define a function in an anonymous struct in comptime" { |
| 15 | 15 | const foo = get_foo(); |
| 16 | assertOrPanic(foo(@intToPtr(*u8, 12345)) == 12345); | |
| 16 | expect(foo(@intToPtr(*u8, 12345)) == 12345); | |
| 17 | 17 | } |
test/stage1/behavior/for.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | |
| 5 | 5 | test "continue in for loop" { |
| ... | ... | @@ -26,7 +26,7 @@ test "for loop with pointer elem var" { |
| 26 | 26 | var target: [source.len]u8 = undefined; |
| 27 | 27 | mem.copy(u8, target[0..], source); |
| 28 | 28 | mangleString(target[0..]); |
| 29 | assertOrPanic(mem.eql(u8, target, "bcdefgh")); | |
| 29 | expect(mem.eql(u8, target, "bcdefgh")); | |
| 30 | 30 | } |
| 31 | 31 | fn mangleString(s: []u8) void { |
| 32 | 32 | for (s) |*c| { |
| ... | ... | @@ -68,7 +68,7 @@ test "basic for loop" { |
| 68 | 68 | buf_index += 1; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | assertOrPanic(mem.eql(u8, buffer[0..buf_index], expected_result)); | |
| 71 | expect(mem.eql(u8, buffer[0..buf_index], expected_result)); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "break from outer for loop" { |
| ... | ... | @@ -85,7 +85,7 @@ fn testBreakOuter() void { |
| 85 | 85 | break :outer; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | assertOrPanic(count == 1); | |
| 88 | expect(count == 1); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "continue outer for loop" { |
| ... | ... | @@ -102,5 +102,5 @@ fn testContinueOuter() void { |
| 102 | 102 | continue :outer; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | assertOrPanic(counter == array.len); | |
| 105 | expect(counter == array.len); | |
| 106 | 106 | } |
test/stage1/behavior/generics.zig+23-23| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "simple generic fn" { |
| 4 | assertOrPanic(max(i32, 3, -1) == 3); | |
| 5 | assertOrPanic(max(f32, 0.123, 0.456) == 0.456); | |
| 6 | assertOrPanic(add(2, 3) == 5); | |
| 4 | expect(max(i32, 3, -1) == 3); | |
| 5 | expect(max(f32, 0.123, 0.456) == 0.456); | |
| 6 | expect(add(2, 3) == 5); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | fn max(comptime T: type, a: T, b: T) T { |
| ... | ... | @@ -16,7 +16,7 @@ fn add(comptime a: i32, b: i32) i32 { |
| 16 | 16 | |
| 17 | 17 | const the_max = max(u32, 1234, 5678); |
| 18 | 18 | test "compile time generic eval" { |
| 19 | assertOrPanic(the_max == 5678); | |
| 19 | expect(the_max == 5678); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | fn gimmeTheBigOne(a: u32, b: u32) u32 { |
| ... | ... | @@ -32,19 +32,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 { |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "fn with comptime args" { |
| 35 | assertOrPanic(gimmeTheBigOne(1234, 5678) == 5678); | |
| 36 | assertOrPanic(shouldCallSameInstance(34, 12) == 34); | |
| 37 | assertOrPanic(sameButWithFloats(0.43, 0.49) == 0.49); | |
| 35 | expect(gimmeTheBigOne(1234, 5678) == 5678); | |
| 36 | expect(shouldCallSameInstance(34, 12) == 34); | |
| 37 | expect(sameButWithFloats(0.43, 0.49) == 0.49); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "var params" { |
| 41 | assertOrPanic(max_i32(12, 34) == 34); | |
| 42 | assertOrPanic(max_f64(1.2, 3.4) == 3.4); | |
| 41 | expect(max_i32(12, 34) == 34); | |
| 42 | expect(max_f64(1.2, 3.4) == 3.4); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | comptime { |
| 46 | assertOrPanic(max_i32(12, 34) == 34); | |
| 47 | assertOrPanic(max_f64(1.2, 3.4) == 3.4); | |
| 46 | expect(max_i32(12, 34) == 34); | |
| 47 | expect(max_f64(1.2, 3.4) == 3.4); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | fn max_var(a: var, b: var) @typeOf(a + b) { |
| ... | ... | @@ -76,8 +76,8 @@ test "function with return type type" { |
| 76 | 76 | var list2: List(i32) = undefined; |
| 77 | 77 | list.length = 10; |
| 78 | 78 | list2.length = 10; |
| 79 | assertOrPanic(list.prealloc_items.len == 8); | |
| 80 | assertOrPanic(list2.prealloc_items.len == 8); | |
| 79 | expect(list.prealloc_items.len == 8); | |
| 80 | expect(list2.prealloc_items.len == 8); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "generic struct" { |
| ... | ... | @@ -89,9 +89,9 @@ test "generic struct" { |
| 89 | 89 | .value = true, |
| 90 | 90 | .next = null, |
| 91 | 91 | }; |
| 92 | assertOrPanic(a1.value == 13); | |
| 93 | assertOrPanic(a1.value == a1.getVal()); | |
| 94 | assertOrPanic(b1.getVal()); | |
| 92 | expect(a1.value == 13); | |
| 93 | expect(a1.value == a1.getVal()); | |
| 94 | expect(b1.getVal()); | |
| 95 | 95 | } |
| 96 | 96 | fn GenNode(comptime T: type) type { |
| 97 | 97 | return struct { |
| ... | ... | @@ -104,7 +104,7 @@ fn GenNode(comptime T: type) type { |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | test "const decls in struct" { |
| 107 | assertOrPanic(GenericDataThing(3).count_plus_one == 4); | |
| 107 | expect(GenericDataThing(3).count_plus_one == 4); | |
| 108 | 108 | } |
| 109 | 109 | fn GenericDataThing(comptime count: isize) type { |
| 110 | 110 | return struct { |
| ... | ... | @@ -113,15 +113,15 @@ fn GenericDataThing(comptime count: isize) type { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "use generic param in generic param" { |
| 116 | assertOrPanic(aGenericFn(i32, 3, 4) == 7); | |
| 116 | expect(aGenericFn(i32, 3, 4) == 7); | |
| 117 | 117 | } |
| 118 | 118 | fn aGenericFn(comptime T: type, comptime a: T, b: T) T { |
| 119 | 119 | return a + b; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "generic fn with implicit cast" { |
| 123 | assertOrPanic(getFirstByte(u8, []u8{13}) == 13); | |
| 124 | assertOrPanic(getFirstByte(u16, []u16{ | |
| 123 | expect(getFirstByte(u8, []u8{13}) == 13); | |
| 124 | expect(getFirstByte(u16, []u16{ | |
| 125 | 125 | 0, |
| 126 | 126 | 13, |
| 127 | 127 | }) == 0); |
| ... | ... | @@ -146,6 +146,6 @@ fn foo2(arg: var) bool { |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "array of generic fns" { |
| 149 | assertOrPanic(foos[0](true)); | |
| 150 | assertOrPanic(!foos[1](true)); | |
| 149 | expect(foos[0](true)); | |
| 150 | expect(!foos[1](true)); | |
| 151 | 151 | } |
test/stage1/behavior/if.zig+2-2| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "if statements" { |
| 4 | 4 | shouldBeEqual(1, 1); |
| ... | ... | @@ -24,7 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | test "else if expression" { |
| 27 | assertOrPanic(elseIfExpressionF(1) == 1); | |
| 27 | expect(elseIfExpressionF(1) == 1); | |
| 28 | 28 | } |
| 29 | 29 | fn elseIfExpressionF(c: u8) u8 { |
| 30 | 30 | if (c == 0) { |
test/stage1/behavior/import.zig+3-3| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const a_namespace = @import("import/a_namespace.zig"); |
| 3 | 3 | |
| 4 | 4 | test "call fn via namespace lookup" { |
| 5 | assertOrPanic(a_namespace.foo() == 1234); | |
| 5 | expect(a_namespace.foo() == 1234); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "importing the same thing gives the same import" { |
| 9 | assertOrPanic(@import("std") == @import("std")); | |
| 9 | expect(@import("std") == @import("std")); | |
| 10 | 10 | } |
test/stage1/behavior/incomplete_struct_param_tld.zig+2-2| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const A = struct { |
| 4 | 4 | b: B, |
| ... | ... | @@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" { |
| 26 | 26 | .c = C{ .x = 13 }, |
| 27 | 27 | }, |
| 28 | 28 | }; |
| 29 | assertOrPanic(foo(a) == 13); | |
| 29 | expect(foo(a) == 13); | |
| 30 | 30 | } |
test/stage1/behavior/inttoptr.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | test "casting random address to function pointer" { |
| 6 | 6 | randomAddressToFunction(); |
test/stage1/behavior/ir_block_deps.zig+3-3| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | fn foo(id: u64) !i32 { |
| 4 | 4 | return switch (id) { |
| ... | ... | @@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 { |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "ir block deps" { |
| 19 | assertOrPanic((foo(1) catch unreachable) == 0); | |
| 20 | assertOrPanic((foo(2) catch unreachable) == 0); | |
| 19 | expect((foo(1) catch unreachable) == 0); | |
| 20 | expect((foo(2) catch unreachable) == 0); | |
| 21 | 21 | } |
test/stage1/behavior/math.zig+131-131| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const maxInt = std.math.maxInt; |
| 4 | 4 | const minInt = std.math.minInt; |
| 5 | 5 | |
| ... | ... | @@ -8,57 +8,57 @@ test "division" { |
| 8 | 8 | comptime testDivision(); |
| 9 | 9 | } |
| 10 | 10 | fn testDivision() void { |
| 11 | assertOrPanic(div(u32, 13, 3) == 4); | |
| 12 | assertOrPanic(div(f16, 1.0, 2.0) == 0.5); | |
| 13 | assertOrPanic(div(f32, 1.0, 2.0) == 0.5); | |
| 14 | ||
| 15 | assertOrPanic(divExact(u32, 55, 11) == 5); | |
| 16 | assertOrPanic(divExact(i32, -55, 11) == -5); | |
| 17 | assertOrPanic(divExact(f16, 55.0, 11.0) == 5.0); | |
| 18 | assertOrPanic(divExact(f16, -55.0, 11.0) == -5.0); | |
| 19 | assertOrPanic(divExact(f32, 55.0, 11.0) == 5.0); | |
| 20 | assertOrPanic(divExact(f32, -55.0, 11.0) == -5.0); | |
| 21 | ||
| 22 | assertOrPanic(divFloor(i32, 5, 3) == 1); | |
| 23 | assertOrPanic(divFloor(i32, -5, 3) == -2); | |
| 24 | assertOrPanic(divFloor(f16, 5.0, 3.0) == 1.0); | |
| 25 | assertOrPanic(divFloor(f16, -5.0, 3.0) == -2.0); | |
| 26 | assertOrPanic(divFloor(f32, 5.0, 3.0) == 1.0); | |
| 27 | assertOrPanic(divFloor(f32, -5.0, 3.0) == -2.0); | |
| 28 | assertOrPanic(divFloor(i32, -0x80000000, -2) == 0x40000000); | |
| 29 | assertOrPanic(divFloor(i32, 0, -0x80000000) == 0); | |
| 30 | assertOrPanic(divFloor(i32, -0x40000001, 0x40000000) == -2); | |
| 31 | assertOrPanic(divFloor(i32, -0x80000000, 1) == -0x80000000); | |
| 32 | ||
| 33 | assertOrPanic(divTrunc(i32, 5, 3) == 1); | |
| 34 | assertOrPanic(divTrunc(i32, -5, 3) == -1); | |
| 35 | assertOrPanic(divTrunc(f16, 5.0, 3.0) == 1.0); | |
| 36 | assertOrPanic(divTrunc(f16, -5.0, 3.0) == -1.0); | |
| 37 | assertOrPanic(divTrunc(f32, 5.0, 3.0) == 1.0); | |
| 38 | assertOrPanic(divTrunc(f32, -5.0, 3.0) == -1.0); | |
| 39 | assertOrPanic(divTrunc(f64, 5.0, 3.0) == 1.0); | |
| 40 | assertOrPanic(divTrunc(f64, -5.0, 3.0) == -1.0); | |
| 11 | expect(div(u32, 13, 3) == 4); | |
| 12 | expect(div(f16, 1.0, 2.0) == 0.5); | |
| 13 | expect(div(f32, 1.0, 2.0) == 0.5); | |
| 14 | ||
| 15 | expect(divExact(u32, 55, 11) == 5); | |
| 16 | expect(divExact(i32, -55, 11) == -5); | |
| 17 | expect(divExact(f16, 55.0, 11.0) == 5.0); | |
| 18 | expect(divExact(f16, -55.0, 11.0) == -5.0); | |
| 19 | expect(divExact(f32, 55.0, 11.0) == 5.0); | |
| 20 | expect(divExact(f32, -55.0, 11.0) == -5.0); | |
| 21 | ||
| 22 | expect(divFloor(i32, 5, 3) == 1); | |
| 23 | expect(divFloor(i32, -5, 3) == -2); | |
| 24 | expect(divFloor(f16, 5.0, 3.0) == 1.0); | |
| 25 | expect(divFloor(f16, -5.0, 3.0) == -2.0); | |
| 26 | expect(divFloor(f32, 5.0, 3.0) == 1.0); | |
| 27 | expect(divFloor(f32, -5.0, 3.0) == -2.0); | |
| 28 | expect(divFloor(i32, -0x80000000, -2) == 0x40000000); | |
| 29 | expect(divFloor(i32, 0, -0x80000000) == 0); | |
| 30 | expect(divFloor(i32, -0x40000001, 0x40000000) == -2); | |
| 31 | expect(divFloor(i32, -0x80000000, 1) == -0x80000000); | |
| 32 | ||
| 33 | expect(divTrunc(i32, 5, 3) == 1); | |
| 34 | expect(divTrunc(i32, -5, 3) == -1); | |
| 35 | expect(divTrunc(f16, 5.0, 3.0) == 1.0); | |
| 36 | expect(divTrunc(f16, -5.0, 3.0) == -1.0); | |
| 37 | expect(divTrunc(f32, 5.0, 3.0) == 1.0); | |
| 38 | expect(divTrunc(f32, -5.0, 3.0) == -1.0); | |
| 39 | expect(divTrunc(f64, 5.0, 3.0) == 1.0); | |
| 40 | expect(divTrunc(f64, -5.0, 3.0) == -1.0); | |
| 41 | 41 | |
| 42 | 42 | comptime { |
| 43 | assertOrPanic( | |
| 43 | expect( | |
| 44 | 44 | 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600, |
| 45 | 45 | ); |
| 46 | assertOrPanic( | |
| 46 | expect( | |
| 47 | 47 | @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600, |
| 48 | 48 | ); |
| 49 | assertOrPanic( | |
| 49 | expect( | |
| 50 | 50 | 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2, |
| 51 | 51 | ); |
| 52 | assertOrPanic( | |
| 52 | expect( | |
| 53 | 53 | @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2, |
| 54 | 54 | ); |
| 55 | assertOrPanic( | |
| 55 | expect( | |
| 56 | 56 | @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2, |
| 57 | 57 | ); |
| 58 | assertOrPanic( | |
| 58 | expect( | |
| 59 | 59 | @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2, |
| 60 | 60 | ); |
| 61 | assertOrPanic( | |
| 61 | expect( | |
| 62 | 62 | 4126227191251978491697987544882340798050766755606969681711 % 10 == 1, |
| 63 | 63 | ); |
| 64 | 64 | } |
| ... | ... | @@ -78,9 +78,9 @@ fn divTrunc(comptime T: type, a: T, b: T) T { |
| 78 | 78 | |
| 79 | 79 | test "@addWithOverflow" { |
| 80 | 80 | var result: u8 = undefined; |
| 81 | assertOrPanic(@addWithOverflow(u8, 250, 100, &result)); | |
| 82 | assertOrPanic(!@addWithOverflow(u8, 100, 150, &result)); | |
| 83 | assertOrPanic(result == 250); | |
| 81 | expect(@addWithOverflow(u8, 250, 100, &result)); | |
| 82 | expect(!@addWithOverflow(u8, 100, 150, &result)); | |
| 83 | expect(result == 250); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // TODO test mulWithOverflow |
| ... | ... | @@ -88,9 +88,9 @@ test "@addWithOverflow" { |
| 88 | 88 | |
| 89 | 89 | test "@shlWithOverflow" { |
| 90 | 90 | var result: u16 = undefined; |
| 91 | assertOrPanic(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); | |
| 92 | assertOrPanic(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); | |
| 93 | assertOrPanic(result == 0b1011111111111100); | |
| 91 | expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); | |
| 92 | expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); | |
| 93 | expect(result == 0b1011111111111100); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "@clz" { |
| ... | ... | @@ -99,11 +99,11 @@ test "@clz" { |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | fn testClz() void { |
| 102 | assertOrPanic(clz(u8(0b00001010)) == 4); | |
| 103 | assertOrPanic(clz(u8(0b10001010)) == 0); | |
| 104 | assertOrPanic(clz(u8(0b00000000)) == 8); | |
| 105 | assertOrPanic(clz(u128(0xffffffffffffffff)) == 64); | |
| 106 | assertOrPanic(clz(u128(0x10000000000000000)) == 63); | |
| 102 | expect(clz(u8(0b00001010)) == 4); | |
| 103 | expect(clz(u8(0b10001010)) == 0); | |
| 104 | expect(clz(u8(0b00000000)) == 8); | |
| 105 | expect(clz(u128(0xffffffffffffffff)) == 64); | |
| 106 | expect(clz(u128(0x10000000000000000)) == 63); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | fn clz(x: var) usize { |
| ... | ... | @@ -116,9 +116,9 @@ test "@ctz" { |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | fn testCtz() void { |
| 119 | assertOrPanic(ctz(u8(0b10100000)) == 5); | |
| 120 | assertOrPanic(ctz(u8(0b10001010)) == 1); | |
| 121 | assertOrPanic(ctz(u8(0b00000000)) == 8); | |
| 119 | expect(ctz(u8(0b10100000)) == 5); | |
| 120 | expect(ctz(u8(0b10001010)) == 1); | |
| 121 | expect(ctz(u8(0b00000000)) == 8); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | fn ctz(x: var) usize { |
| ... | ... | @@ -128,27 +128,27 @@ fn ctz(x: var) usize { |
| 128 | 128 | test "assignment operators" { |
| 129 | 129 | var i: u32 = 0; |
| 130 | 130 | i += 5; |
| 131 | assertOrPanic(i == 5); | |
| 131 | expect(i == 5); | |
| 132 | 132 | i -= 2; |
| 133 | assertOrPanic(i == 3); | |
| 133 | expect(i == 3); | |
| 134 | 134 | i *= 20; |
| 135 | assertOrPanic(i == 60); | |
| 135 | expect(i == 60); | |
| 136 | 136 | i /= 3; |
| 137 | assertOrPanic(i == 20); | |
| 137 | expect(i == 20); | |
| 138 | 138 | i %= 11; |
| 139 | assertOrPanic(i == 9); | |
| 139 | expect(i == 9); | |
| 140 | 140 | i <<= 1; |
| 141 | assertOrPanic(i == 18); | |
| 141 | expect(i == 18); | |
| 142 | 142 | i >>= 2; |
| 143 | assertOrPanic(i == 4); | |
| 143 | expect(i == 4); | |
| 144 | 144 | i = 6; |
| 145 | 145 | i &= 5; |
| 146 | assertOrPanic(i == 4); | |
| 146 | expect(i == 4); | |
| 147 | 147 | i ^= 6; |
| 148 | assertOrPanic(i == 2); | |
| 148 | expect(i == 2); | |
| 149 | 149 | i = 6; |
| 150 | 150 | i |= 3; |
| 151 | assertOrPanic(i == 7); | |
| 151 | expect(i == 7); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "three expr in a row" { |
| ... | ... | @@ -170,14 +170,14 @@ fn testThreeExprInARow(f: bool, t: bool) void { |
| 170 | 170 | assertFalse(i32(7) != --(i32(7))); |
| 171 | 171 | } |
| 172 | 172 | fn assertFalse(b: bool) void { |
| 173 | assertOrPanic(!b); | |
| 173 | expect(!b); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "const number literal" { |
| 177 | 177 | const one = 1; |
| 178 | 178 | const eleven = ten + one; |
| 179 | 179 | |
| 180 | assertOrPanic(eleven == 11); | |
| 180 | expect(eleven == 11); | |
| 181 | 181 | } |
| 182 | 182 | const ten = 10; |
| 183 | 183 | |
| ... | ... | @@ -187,9 +187,9 @@ test "unsigned wrapping" { |
| 187 | 187 | } |
| 188 | 188 | fn testUnsignedWrappingEval(x: u32) void { |
| 189 | 189 | const zero = x +% 1; |
| 190 | assertOrPanic(zero == 0); | |
| 190 | expect(zero == 0); | |
| 191 | 191 | const orig = zero -% 1; |
| 192 | assertOrPanic(orig == maxInt(u32)); | |
| 192 | expect(orig == maxInt(u32)); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | test "signed wrapping" { |
| ... | ... | @@ -198,9 +198,9 @@ test "signed wrapping" { |
| 198 | 198 | } |
| 199 | 199 | fn testSignedWrappingEval(x: i32) void { |
| 200 | 200 | const min_val = x +% 1; |
| 201 | assertOrPanic(min_val == minInt(i32)); | |
| 201 | expect(min_val == minInt(i32)); | |
| 202 | 202 | const max_val = min_val -% 1; |
| 203 | assertOrPanic(max_val == maxInt(i32)); | |
| 203 | expect(max_val == maxInt(i32)); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | test "negation wrapping" { |
| ... | ... | @@ -208,9 +208,9 @@ test "negation wrapping" { |
| 208 | 208 | comptime testNegationWrappingEval(minInt(i16)); |
| 209 | 209 | } |
| 210 | 210 | fn testNegationWrappingEval(x: i16) void { |
| 211 | assertOrPanic(x == -32768); | |
| 211 | expect(x == -32768); | |
| 212 | 212 | const neg = -%x; |
| 213 | assertOrPanic(neg == -32768); | |
| 213 | expect(neg == -32768); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | test "unsigned 64-bit division" { |
| ... | ... | @@ -219,8 +219,8 @@ test "unsigned 64-bit division" { |
| 219 | 219 | } |
| 220 | 220 | fn test_u64_div() void { |
| 221 | 221 | const result = divWithResult(1152921504606846976, 34359738365); |
| 222 | assertOrPanic(result.quotient == 33554432); | |
| 223 | assertOrPanic(result.remainder == 100663296); | |
| 222 | expect(result.quotient == 33554432); | |
| 223 | expect(result.remainder == 100663296); | |
| 224 | 224 | } |
| 225 | 225 | fn divWithResult(a: u64, b: u64) DivResult { |
| 226 | 226 | return DivResult{ |
| ... | ... | @@ -234,36 +234,36 @@ const DivResult = struct { |
| 234 | 234 | }; |
| 235 | 235 | |
| 236 | 236 | test "binary not" { |
| 237 | assertOrPanic(comptime x: { | |
| 237 | expect(comptime x: { | |
| 238 | 238 | break :x ~u16(0b1010101010101010) == 0b0101010101010101; |
| 239 | 239 | }); |
| 240 | assertOrPanic(comptime x: { | |
| 240 | expect(comptime x: { | |
| 241 | 241 | break :x ~u64(2147483647) == 18446744071562067968; |
| 242 | 242 | }); |
| 243 | 243 | testBinaryNot(0b1010101010101010); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | fn testBinaryNot(x: u16) void { |
| 247 | assertOrPanic(~x == 0b0101010101010101); | |
| 247 | expect(~x == 0b0101010101010101); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | test "small int addition" { |
| 251 | 251 | var x: @IntType(false, 2) = 0; |
| 252 | assertOrPanic(x == 0); | |
| 252 | expect(x == 0); | |
| 253 | 253 | |
| 254 | 254 | x += 1; |
| 255 | assertOrPanic(x == 1); | |
| 255 | expect(x == 1); | |
| 256 | 256 | |
| 257 | 257 | x += 1; |
| 258 | assertOrPanic(x == 2); | |
| 258 | expect(x == 2); | |
| 259 | 259 | |
| 260 | 260 | x += 1; |
| 261 | assertOrPanic(x == 3); | |
| 261 | expect(x == 3); | |
| 262 | 262 | |
| 263 | 263 | var result: @typeOf(x) = 3; |
| 264 | assertOrPanic(@addWithOverflow(@typeOf(x), x, 1, &result)); | |
| 264 | expect(@addWithOverflow(@typeOf(x), x, 1, &result)); | |
| 265 | 265 | |
| 266 | assertOrPanic(result == 0); | |
| 266 | expect(result == 0); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | test "float equality" { |
| ... | ... | @@ -276,20 +276,20 @@ test "float equality" { |
| 276 | 276 | |
| 277 | 277 | fn testFloatEqualityImpl(x: f64, y: f64) void { |
| 278 | 278 | const y2 = x + 1.0; |
| 279 | assertOrPanic(y == y2); | |
| 279 | expect(y == y2); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | test "allow signed integer division/remainder when values are comptime known and positive or exact" { |
| 283 | assertOrPanic(5 / 3 == 1); | |
| 284 | assertOrPanic(-5 / -3 == 1); | |
| 285 | assertOrPanic(-6 / 3 == -2); | |
| 283 | expect(5 / 3 == 1); | |
| 284 | expect(-5 / -3 == 1); | |
| 285 | expect(-6 / 3 == -2); | |
| 286 | 286 | |
| 287 | assertOrPanic(5 % 3 == 2); | |
| 288 | assertOrPanic(-6 % 3 == 0); | |
| 287 | expect(5 % 3 == 2); | |
| 288 | expect(-6 % 3 == 0); | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | test "hex float literal parsing" { |
| 292 | comptime assertOrPanic(0x1.0 == 1.0); | |
| 292 | comptime expect(0x1.0 == 1.0); | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | test "quad hex float literal parsing in range" { |
| ... | ... | @@ -304,7 +304,7 @@ test "quad hex float literal parsing accurate" { |
| 304 | 304 | |
| 305 | 305 | // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing. |
| 306 | 306 | const expected: u128 = 0x3fff1111222233334444555566667777; |
| 307 | assertOrPanic(@bitCast(u128, a) == expected); | |
| 307 | expect(@bitCast(u128, a) == expected); | |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | test "hex float literal within range" { |
| ... | ... | @@ -319,7 +319,7 @@ test "truncating shift left" { |
| 319 | 319 | } |
| 320 | 320 | fn testShlTrunc(x: u16) void { |
| 321 | 321 | const shifted = x << 1; |
| 322 | assertOrPanic(shifted == 65534); | |
| 322 | expect(shifted == 65534); | |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | test "truncating shift right" { |
| ... | ... | @@ -328,7 +328,7 @@ test "truncating shift right" { |
| 328 | 328 | } |
| 329 | 329 | fn testShrTrunc(x: u16) void { |
| 330 | 330 | const shifted = x >> 1; |
| 331 | assertOrPanic(shifted == 32767); | |
| 331 | expect(shifted == 32767); | |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | test "exact shift left" { |
| ... | ... | @@ -337,7 +337,7 @@ test "exact shift left" { |
| 337 | 337 | } |
| 338 | 338 | fn testShlExact(x: u8) void { |
| 339 | 339 | const shifted = @shlExact(x, 2); |
| 340 | assertOrPanic(shifted == 0b11010100); | |
| 340 | expect(shifted == 0b11010100); | |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | test "exact shift right" { |
| ... | ... | @@ -346,22 +346,22 @@ test "exact shift right" { |
| 346 | 346 | } |
| 347 | 347 | fn testShrExact(x: u8) void { |
| 348 | 348 | const shifted = @shrExact(x, 2); |
| 349 | assertOrPanic(shifted == 0b00101101); | |
| 349 | expect(shifted == 0b00101101); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | test "comptime_int addition" { |
| 353 | 353 | comptime { |
| 354 | assertOrPanic(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950); | |
| 355 | assertOrPanic(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380); | |
| 354 | expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950); | |
| 355 | expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380); | |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | test "comptime_int multiplication" { |
| 360 | 360 | comptime { |
| 361 | assertOrPanic( | |
| 361 | expect( | |
| 362 | 362 | 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567, |
| 363 | 363 | ); |
| 364 | assertOrPanic( | |
| 364 | expect( | |
| 365 | 365 | 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016, |
| 366 | 366 | ); |
| 367 | 367 | } |
| ... | ... | @@ -369,7 +369,7 @@ test "comptime_int multiplication" { |
| 369 | 369 | |
| 370 | 370 | test "comptime_int shifting" { |
| 371 | 371 | comptime { |
| 372 | assertOrPanic((u128(1) << 127) == 0x80000000000000000000000000000000); | |
| 372 | expect((u128(1) << 127) == 0x80000000000000000000000000000000); | |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| ... | ... | @@ -377,16 +377,16 @@ test "comptime_int multi-limb shift and mask" { |
| 377 | 377 | comptime { |
| 378 | 378 | var a = 0xefffffffa0000001eeeeeeefaaaaaaab; |
| 379 | 379 | |
| 380 | assertOrPanic(u32(a & 0xffffffff) == 0xaaaaaaab); | |
| 380 | expect(u32(a & 0xffffffff) == 0xaaaaaaab); | |
| 381 | 381 | a >>= 32; |
| 382 | assertOrPanic(u32(a & 0xffffffff) == 0xeeeeeeef); | |
| 382 | expect(u32(a & 0xffffffff) == 0xeeeeeeef); | |
| 383 | 383 | a >>= 32; |
| 384 | assertOrPanic(u32(a & 0xffffffff) == 0xa0000001); | |
| 384 | expect(u32(a & 0xffffffff) == 0xa0000001); | |
| 385 | 385 | a >>= 32; |
| 386 | assertOrPanic(u32(a & 0xffffffff) == 0xefffffff); | |
| 386 | expect(u32(a & 0xffffffff) == 0xefffffff); | |
| 387 | 387 | a >>= 32; |
| 388 | 388 | |
| 389 | assertOrPanic(a == 0); | |
| 389 | expect(a == 0); | |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
| ... | ... | @@ -394,7 +394,7 @@ test "comptime_int multi-limb partial shift right" { |
| 394 | 394 | comptime { |
| 395 | 395 | var a = 0x1ffffffffeeeeeeee; |
| 396 | 396 | a >>= 16; |
| 397 | assertOrPanic(a == 0x1ffffffffeeee); | |
| 397 | expect(a == 0x1ffffffffeeee); | |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
| ... | ... | @@ -404,23 +404,23 @@ test "xor" { |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | fn test_xor() void { |
| 407 | assertOrPanic(0xFF ^ 0x00 == 0xFF); | |
| 408 | assertOrPanic(0xF0 ^ 0x0F == 0xFF); | |
| 409 | assertOrPanic(0xFF ^ 0xF0 == 0x0F); | |
| 410 | assertOrPanic(0xFF ^ 0x0F == 0xF0); | |
| 411 | assertOrPanic(0xFF ^ 0xFF == 0x00); | |
| 407 | expect(0xFF ^ 0x00 == 0xFF); | |
| 408 | expect(0xF0 ^ 0x0F == 0xFF); | |
| 409 | expect(0xFF ^ 0xF0 == 0x0F); | |
| 410 | expect(0xFF ^ 0x0F == 0xF0); | |
| 411 | expect(0xFF ^ 0xFF == 0x00); | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | test "comptime_int xor" { |
| 415 | 415 | comptime { |
| 416 | assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 417 | assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 418 | assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF); | |
| 419 | assertOrPanic(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000); | |
| 420 | assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000); | |
| 421 | assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 422 | assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF); | |
| 423 | assertOrPanic(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000); | |
| 416 | expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 417 | expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 418 | expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF); | |
| 419 | expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000); | |
| 420 | expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000); | |
| 421 | expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 422 | expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF); | |
| 423 | expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000); | |
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | 426 | |
| ... | ... | @@ -434,23 +434,23 @@ fn make_f128(x: f128) f128 { |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | fn test_f128() void { |
| 437 | assertOrPanic(@sizeOf(f128) == 16); | |
| 438 | assertOrPanic(make_f128(1.0) == 1.0); | |
| 439 | assertOrPanic(make_f128(1.0) != 1.1); | |
| 440 | assertOrPanic(make_f128(1.0) > 0.9); | |
| 441 | assertOrPanic(make_f128(1.0) >= 0.9); | |
| 442 | assertOrPanic(make_f128(1.0) >= 1.0); | |
| 437 | expect(@sizeOf(f128) == 16); | |
| 438 | expect(make_f128(1.0) == 1.0); | |
| 439 | expect(make_f128(1.0) != 1.1); | |
| 440 | expect(make_f128(1.0) > 0.9); | |
| 441 | expect(make_f128(1.0) >= 0.9); | |
| 442 | expect(make_f128(1.0) >= 1.0); | |
| 443 | 443 | should_not_be_zero(1.0); |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | fn should_not_be_zero(x: f128) void { |
| 447 | assertOrPanic(x != 0.0); | |
| 447 | expect(x != 0.0); | |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | test "comptime float rem int" { |
| 451 | 451 | comptime { |
| 452 | 452 | var x = f32(1) % 2; |
| 453 | assertOrPanic(x == 1.0); | |
| 453 | expect(x == 1.0); | |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | |
| ... | ... | @@ -465,8 +465,8 @@ test "remainder division" { |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | fn remdiv(comptime T: type) void { |
| 468 | assertOrPanic(T(1) == T(1) % T(2)); | |
| 469 | assertOrPanic(T(1) == T(7) % T(3)); | |
| 468 | expect(T(1) == T(1) % T(2)); | |
| 469 | expect(T(1) == T(7) % T(3)); | |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | test "@sqrt" { |
| ... | ... | @@ -480,19 +480,19 @@ test "@sqrt" { |
| 480 | 480 | const x = 14.0; |
| 481 | 481 | const y = x * x; |
| 482 | 482 | const z = @sqrt(@typeOf(y), y); |
| 483 | comptime assertOrPanic(z == x); | |
| 483 | comptime expect(z == x); | |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | fn testSqrt(comptime T: type, x: T) void { |
| 487 | assertOrPanic(@sqrt(T, x * x) == x); | |
| 487 | expect(@sqrt(T, x * x) == x); | |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | test "comptime_int param and return" { |
| 491 | 491 | const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702); |
| 492 | assertOrPanic(a == 137114567242441932203689521744947848950); | |
| 492 | expect(a == 137114567242441932203689521744947848950); | |
| 493 | 493 | |
| 494 | 494 | const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768); |
| 495 | assertOrPanic(b == 985095453608931032642182098849559179469148836107390954364380); | |
| 495 | expect(b == 985095453608931032642182098849559179469148836107390954364380); | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int { |
test/stage1/behavior/misc.zig+138-138| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const cstr = std.cstr; |
| 5 | 5 | const builtin = @import("builtin"); |
| ... | ... | @@ -26,38 +26,38 @@ test "call disabled extern fn" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "@IntType builtin" { |
| 29 | assertOrPanic(@IntType(true, 8) == i8); | |
| 30 | assertOrPanic(@IntType(true, 16) == i16); | |
| 31 | assertOrPanic(@IntType(true, 32) == i32); | |
| 32 | assertOrPanic(@IntType(true, 64) == i64); | |
| 33 | ||
| 34 | assertOrPanic(@IntType(false, 8) == u8); | |
| 35 | assertOrPanic(@IntType(false, 16) == u16); | |
| 36 | assertOrPanic(@IntType(false, 32) == u32); | |
| 37 | assertOrPanic(@IntType(false, 64) == u64); | |
| 38 | ||
| 39 | assertOrPanic(i8.bit_count == 8); | |
| 40 | assertOrPanic(i16.bit_count == 16); | |
| 41 | assertOrPanic(i32.bit_count == 32); | |
| 42 | assertOrPanic(i64.bit_count == 64); | |
| 43 | ||
| 44 | assertOrPanic(i8.is_signed); | |
| 45 | assertOrPanic(i16.is_signed); | |
| 46 | assertOrPanic(i32.is_signed); | |
| 47 | assertOrPanic(i64.is_signed); | |
| 48 | assertOrPanic(isize.is_signed); | |
| 49 | ||
| 50 | assertOrPanic(!u8.is_signed); | |
| 51 | assertOrPanic(!u16.is_signed); | |
| 52 | assertOrPanic(!u32.is_signed); | |
| 53 | assertOrPanic(!u64.is_signed); | |
| 54 | assertOrPanic(!usize.is_signed); | |
| 29 | expect(@IntType(true, 8) == i8); | |
| 30 | expect(@IntType(true, 16) == i16); | |
| 31 | expect(@IntType(true, 32) == i32); | |
| 32 | expect(@IntType(true, 64) == i64); | |
| 33 | ||
| 34 | expect(@IntType(false, 8) == u8); | |
| 35 | expect(@IntType(false, 16) == u16); | |
| 36 | expect(@IntType(false, 32) == u32); | |
| 37 | expect(@IntType(false, 64) == u64); | |
| 38 | ||
| 39 | expect(i8.bit_count == 8); | |
| 40 | expect(i16.bit_count == 16); | |
| 41 | expect(i32.bit_count == 32); | |
| 42 | expect(i64.bit_count == 64); | |
| 43 | ||
| 44 | expect(i8.is_signed); | |
| 45 | expect(i16.is_signed); | |
| 46 | expect(i32.is_signed); | |
| 47 | expect(i64.is_signed); | |
| 48 | expect(isize.is_signed); | |
| 49 | ||
| 50 | expect(!u8.is_signed); | |
| 51 | expect(!u16.is_signed); | |
| 52 | expect(!u32.is_signed); | |
| 53 | expect(!u64.is_signed); | |
| 54 | expect(!usize.is_signed); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "floating point primitive bit counts" { |
| 58 | assertOrPanic(f16.bit_count == 16); | |
| 59 | assertOrPanic(f32.bit_count == 32); | |
| 60 | assertOrPanic(f64.bit_count == 64); | |
| 58 | expect(f16.bit_count == 16); | |
| 59 | expect(f32.bit_count == 32); | |
| 60 | expect(f64.bit_count == 64); | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "short circuit" { |
| ... | ... | @@ -72,7 +72,7 @@ fn testShortCircuit(f: bool, t: bool) void { |
| 72 | 72 | var hit_4 = f; |
| 73 | 73 | |
| 74 | 74 | if (t or x: { |
| 75 | assertOrPanic(f); | |
| 75 | expect(f); | |
| 76 | 76 | break :x f; |
| 77 | 77 | }) { |
| 78 | 78 | hit_1 = t; |
| ... | ... | @@ -81,31 +81,31 @@ fn testShortCircuit(f: bool, t: bool) void { |
| 81 | 81 | hit_2 = t; |
| 82 | 82 | break :x f; |
| 83 | 83 | }) { |
| 84 | assertOrPanic(f); | |
| 84 | expect(f); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | if (t and x: { |
| 88 | 88 | hit_3 = t; |
| 89 | 89 | break :x f; |
| 90 | 90 | }) { |
| 91 | assertOrPanic(f); | |
| 91 | expect(f); | |
| 92 | 92 | } |
| 93 | 93 | if (f and x: { |
| 94 | assertOrPanic(f); | |
| 94 | expect(f); | |
| 95 | 95 | break :x f; |
| 96 | 96 | }) { |
| 97 | assertOrPanic(f); | |
| 97 | expect(f); | |
| 98 | 98 | } else { |
| 99 | 99 | hit_4 = t; |
| 100 | 100 | } |
| 101 | assertOrPanic(hit_1); | |
| 102 | assertOrPanic(hit_2); | |
| 103 | assertOrPanic(hit_3); | |
| 104 | assertOrPanic(hit_4); | |
| 101 | expect(hit_1); | |
| 102 | expect(hit_2); | |
| 103 | expect(hit_3); | |
| 104 | expect(hit_4); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | test "truncate" { |
| 108 | assertOrPanic(testTruncate(0x10fd) == 0xfd); | |
| 108 | expect(testTruncate(0x10fd) == 0xfd); | |
| 109 | 109 | } |
| 110 | 110 | fn testTruncate(x: u32) u8 { |
| 111 | 111 | return @truncate(u8, x); |
| ... | ... | @@ -116,16 +116,16 @@ fn first4KeysOfHomeRow() []const u8 { |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | test "return string from function" { |
| 119 | assertOrPanic(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); | |
| 119 | expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | const g1: i32 = 1233 + 1; |
| 123 | 123 | var g2: i32 = 0; |
| 124 | 124 | |
| 125 | 125 | test "global variables" { |
| 126 | assertOrPanic(g2 == 0); | |
| 126 | expect(g2 == 0); | |
| 127 | 127 | g2 = g1; |
| 128 | assertOrPanic(g2 == 1234); | |
| 128 | expect(g2 == 1234); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "memcpy and memset intrinsics" { |
| ... | ... | @@ -142,7 +142,7 @@ test "builtin static eval" { |
| 142 | 142 | const x: i32 = comptime x: { |
| 143 | 143 | break :x 1 + 2 + 3; |
| 144 | 144 | }; |
| 145 | assertOrPanic(x == comptime 6); | |
| 145 | expect(x == comptime 6); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "slicing" { |
| ... | ... | @@ -163,7 +163,7 @@ test "slicing" { |
| 163 | 163 | |
| 164 | 164 | test "constant equal function pointers" { |
| 165 | 165 | const alias = emptyFn; |
| 166 | assertOrPanic(comptime x: { | |
| 166 | expect(comptime x: { | |
| 167 | 167 | break :x emptyFn == alias; |
| 168 | 168 | }); |
| 169 | 169 | } |
| ... | ... | @@ -171,25 +171,25 @@ test "constant equal function pointers" { |
| 171 | 171 | fn emptyFn() void {} |
| 172 | 172 | |
| 173 | 173 | test "hex escape" { |
| 174 | assertOrPanic(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello")); | |
| 174 | expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello")); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "string concatenation" { |
| 178 | assertOrPanic(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 178 | expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | test "array mult operator" { |
| 182 | assertOrPanic(mem.eql(u8, "ab" ** 5, "ababababab")); | |
| 182 | expect(mem.eql(u8, "ab" ** 5, "ababababab")); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "string escapes" { |
| 186 | assertOrPanic(mem.eql(u8, "\"", "\x22")); | |
| 187 | assertOrPanic(mem.eql(u8, "\'", "\x27")); | |
| 188 | assertOrPanic(mem.eql(u8, "\n", "\x0a")); | |
| 189 | assertOrPanic(mem.eql(u8, "\r", "\x0d")); | |
| 190 | assertOrPanic(mem.eql(u8, "\t", "\x09")); | |
| 191 | assertOrPanic(mem.eql(u8, "\\", "\x5c")); | |
| 192 | assertOrPanic(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 186 | expect(mem.eql(u8, "\"", "\x22")); | |
| 187 | expect(mem.eql(u8, "\'", "\x27")); | |
| 188 | expect(mem.eql(u8, "\n", "\x0a")); | |
| 189 | expect(mem.eql(u8, "\r", "\x0d")); | |
| 190 | expect(mem.eql(u8, "\t", "\x09")); | |
| 191 | expect(mem.eql(u8, "\\", "\x5c")); | |
| 192 | expect(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | test "multiline string" { |
| ... | ... | @@ -199,7 +199,7 @@ test "multiline string" { |
| 199 | 199 | \\three |
| 200 | 200 | ; |
| 201 | 201 | const s2 = "one\ntwo)\nthree"; |
| 202 | assertOrPanic(mem.eql(u8, s1, s2)); | |
| 202 | expect(mem.eql(u8, s1, s2)); | |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | test "multiline C string" { |
| ... | ... | @@ -209,11 +209,11 @@ test "multiline C string" { |
| 209 | 209 | c\\three |
| 210 | 210 | ; |
| 211 | 211 | const s2 = c"one\ntwo)\nthree"; |
| 212 | assertOrPanic(cstr.cmp(s1, s2) == 0); | |
| 212 | expect(cstr.cmp(s1, s2) == 0); | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | test "type equality" { |
| 216 | assertOrPanic(*const u8 != *u8); | |
| 216 | expect(*const u8 != *u8); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | const global_a: i32 = 1234; |
| ... | ... | @@ -221,7 +221,7 @@ const global_b: *const i32 = &global_a; |
| 221 | 221 | const global_c: *const f32 = @ptrCast(*const f32, global_b); |
| 222 | 222 | test "compile time global reinterpret" { |
| 223 | 223 | const d = @ptrCast(*const i32, global_c); |
| 224 | assertOrPanic(d.* == 1234); | |
| 224 | expect(d.* == 1234); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | test "explicit cast maybe pointers" { |
| ... | ... | @@ -247,8 +247,8 @@ test "cast undefined" { |
| 247 | 247 | fn testCastUndefined(x: []const u8) void {} |
| 248 | 248 | |
| 249 | 249 | test "cast small unsigned to larger signed" { |
| 250 | assertOrPanic(castSmallUnsignedToLargerSigned1(200) == i16(200)); | |
| 251 | assertOrPanic(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | |
| 250 | expect(castSmallUnsignedToLargerSigned1(200) == i16(200)); | |
| 251 | expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | |
| 252 | 252 | } |
| 253 | 253 | fn castSmallUnsignedToLargerSigned1(x: u8) i16 { |
| 254 | 254 | return x; |
| ... | ... | @@ -258,7 +258,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 { |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | test "implicit cast after unreachable" { |
| 261 | assertOrPanic(outer() == 1234); | |
| 261 | expect(outer() == 1234); | |
| 262 | 262 | } |
| 263 | 263 | fn inner() i32 { |
| 264 | 264 | return 1234; |
| ... | ... | @@ -273,13 +273,13 @@ test "pointer dereferencing" { |
| 273 | 273 | |
| 274 | 274 | y.* += 1; |
| 275 | 275 | |
| 276 | assertOrPanic(x == 4); | |
| 277 | assertOrPanic(y.* == 4); | |
| 276 | expect(x == 4); | |
| 277 | expect(y.* == 4); | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | test "call result of if else expression" { |
| 281 | assertOrPanic(mem.eql(u8, f2(true), "a")); | |
| 282 | assertOrPanic(mem.eql(u8, f2(false), "b")); | |
| 281 | expect(mem.eql(u8, f2(true), "a")); | |
| 282 | expect(mem.eql(u8, f2(false), "b")); | |
| 283 | 283 | } |
| 284 | 284 | fn f2(x: bool) []const u8 { |
| 285 | 285 | return (if (x) fA else fB)(); |
| ... | ... | @@ -321,8 +321,8 @@ const test3_bar = Test3Foo{ .Two = 13 }; |
| 321 | 321 | fn test3_1(f: Test3Foo) void { |
| 322 | 322 | switch (f) { |
| 323 | 323 | Test3Foo.Three => |pt| { |
| 324 | assertOrPanic(pt.x == 3); | |
| 325 | assertOrPanic(pt.y == 4); | |
| 324 | expect(pt.x == 3); | |
| 325 | expect(pt.y == 4); | |
| 326 | 326 | }, |
| 327 | 327 | else => unreachable, |
| 328 | 328 | } |
| ... | ... | @@ -330,14 +330,14 @@ fn test3_1(f: Test3Foo) void { |
| 330 | 330 | fn test3_2(f: Test3Foo) void { |
| 331 | 331 | switch (f) { |
| 332 | 332 | Test3Foo.Two => |x| { |
| 333 | assertOrPanic(x == 13); | |
| 333 | expect(x == 13); | |
| 334 | 334 | }, |
| 335 | 335 | else => unreachable, |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | test "character literals" { |
| 340 | assertOrPanic('\'' == single_quote); | |
| 340 | expect('\'' == single_quote); | |
| 341 | 341 | } |
| 342 | 342 | const single_quote = '\''; |
| 343 | 343 | |
| ... | ... | @@ -346,13 +346,13 @@ test "take address of parameter" { |
| 346 | 346 | } |
| 347 | 347 | fn testTakeAddressOfParameter(f: f32) void { |
| 348 | 348 | const f_ptr = &f; |
| 349 | assertOrPanic(f_ptr.* == 12.34); | |
| 349 | expect(f_ptr.* == 12.34); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | test "pointer comparison" { |
| 353 | 353 | const a = ([]const u8)("a"); |
| 354 | 354 | const b = &a; |
| 355 | assertOrPanic(ptrEql(b, b)); | |
| 355 | expect(ptrEql(b, b)); | |
| 356 | 356 | } |
| 357 | 357 | fn ptrEql(a: *const []const u8, b: *const []const u8) bool { |
| 358 | 358 | return a == b; |
| ... | ... | @@ -367,31 +367,31 @@ test "C string concatenation" { |
| 367 | 367 | { |
| 368 | 368 | var i: u32 = 0; |
| 369 | 369 | while (i < len_with_null) : (i += 1) { |
| 370 | assertOrPanic(a[i] == b[i]); | |
| 370 | expect(a[i] == b[i]); | |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | assertOrPanic(a[len] == 0); | |
| 374 | assertOrPanic(b[len] == 0); | |
| 373 | expect(a[len] == 0); | |
| 374 | expect(b[len] == 0); | |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | test "cast slice to u8 slice" { |
| 378 | assertOrPanic(@sizeOf(i32) == 4); | |
| 378 | expect(@sizeOf(i32) == 4); | |
| 379 | 379 | var big_thing_array = []i32{ 1, 2, 3, 4 }; |
| 380 | 380 | const big_thing_slice: []i32 = big_thing_array[0..]; |
| 381 | 381 | const bytes = @sliceToBytes(big_thing_slice); |
| 382 | assertOrPanic(bytes.len == 4 * 4); | |
| 382 | expect(bytes.len == 4 * 4); | |
| 383 | 383 | bytes[4] = 0; |
| 384 | 384 | bytes[5] = 0; |
| 385 | 385 | bytes[6] = 0; |
| 386 | 386 | bytes[7] = 0; |
| 387 | assertOrPanic(big_thing_slice[1] == 0); | |
| 387 | expect(big_thing_slice[1] == 0); | |
| 388 | 388 | const big_thing_again = @bytesToSlice(i32, bytes); |
| 389 | assertOrPanic(big_thing_again[2] == 3); | |
| 389 | expect(big_thing_again[2] == 3); | |
| 390 | 390 | big_thing_again[2] = -1; |
| 391 | assertOrPanic(bytes[8] == maxInt(u8)); | |
| 392 | assertOrPanic(bytes[9] == maxInt(u8)); | |
| 393 | assertOrPanic(bytes[10] == maxInt(u8)); | |
| 394 | assertOrPanic(bytes[11] == maxInt(u8)); | |
| 391 | expect(bytes[8] == maxInt(u8)); | |
| 392 | expect(bytes[9] == maxInt(u8)); | |
| 393 | expect(bytes[10] == maxInt(u8)); | |
| 394 | expect(bytes[11] == maxInt(u8)); | |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | test "pointer to void return type" { |
| ... | ... | @@ -408,7 +408,7 @@ fn testPointerToVoidReturnType2() *const void { |
| 408 | 408 | |
| 409 | 409 | test "non const ptr to aliased type" { |
| 410 | 410 | const int = i32; |
| 411 | assertOrPanic(?*int == ?*i32); | |
| 411 | expect(?*int == ?*i32); | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | test "array 2D const double ptr" { |
| ... | ... | @@ -421,8 +421,8 @@ test "array 2D const double ptr" { |
| 421 | 421 | |
| 422 | 422 | fn testArray2DConstDoublePtr(ptr: *const f32) void { |
| 423 | 423 | const ptr2 = @ptrCast([*]const f32, ptr); |
| 424 | assertOrPanic(ptr2[0] == 1.0); | |
| 425 | assertOrPanic(ptr2[1] == 2.0); | |
| 424 | expect(ptr2[0] == 1.0); | |
| 425 | expect(ptr2[1] == 2.0); | |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | const Tid = builtin.TypeId; |
| ... | ... | @@ -444,32 +444,32 @@ const AUnion = union { |
| 444 | 444 | |
| 445 | 445 | test "@typeId" { |
| 446 | 446 | comptime { |
| 447 | assertOrPanic(@typeId(type) == Tid.Type); | |
| 448 | assertOrPanic(@typeId(void) == Tid.Void); | |
| 449 | assertOrPanic(@typeId(bool) == Tid.Bool); | |
| 450 | assertOrPanic(@typeId(noreturn) == Tid.NoReturn); | |
| 451 | assertOrPanic(@typeId(i8) == Tid.Int); | |
| 452 | assertOrPanic(@typeId(u8) == Tid.Int); | |
| 453 | assertOrPanic(@typeId(i64) == Tid.Int); | |
| 454 | assertOrPanic(@typeId(u64) == Tid.Int); | |
| 455 | assertOrPanic(@typeId(f32) == Tid.Float); | |
| 456 | assertOrPanic(@typeId(f64) == Tid.Float); | |
| 457 | assertOrPanic(@typeId(*f32) == Tid.Pointer); | |
| 458 | assertOrPanic(@typeId([2]u8) == Tid.Array); | |
| 459 | assertOrPanic(@typeId(AStruct) == Tid.Struct); | |
| 460 | assertOrPanic(@typeId(@typeOf(1)) == Tid.ComptimeInt); | |
| 461 | assertOrPanic(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat); | |
| 462 | assertOrPanic(@typeId(@typeOf(undefined)) == Tid.Undefined); | |
| 463 | assertOrPanic(@typeId(@typeOf(null)) == Tid.Null); | |
| 464 | assertOrPanic(@typeId(?i32) == Tid.Optional); | |
| 465 | assertOrPanic(@typeId(anyerror!i32) == Tid.ErrorUnion); | |
| 466 | assertOrPanic(@typeId(anyerror) == Tid.ErrorSet); | |
| 467 | assertOrPanic(@typeId(AnEnum) == Tid.Enum); | |
| 468 | assertOrPanic(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); | |
| 469 | assertOrPanic(@typeId(AUnionEnum) == Tid.Union); | |
| 470 | assertOrPanic(@typeId(AUnion) == Tid.Union); | |
| 471 | assertOrPanic(@typeId(fn () void) == Tid.Fn); | |
| 472 | assertOrPanic(@typeId(@typeOf(builtin)) == Tid.Namespace); | |
| 447 | expect(@typeId(type) == Tid.Type); | |
| 448 | expect(@typeId(void) == Tid.Void); | |
| 449 | expect(@typeId(bool) == Tid.Bool); | |
| 450 | expect(@typeId(noreturn) == Tid.NoReturn); | |
| 451 | expect(@typeId(i8) == Tid.Int); | |
| 452 | expect(@typeId(u8) == Tid.Int); | |
| 453 | expect(@typeId(i64) == Tid.Int); | |
| 454 | expect(@typeId(u64) == Tid.Int); | |
| 455 | expect(@typeId(f32) == Tid.Float); | |
| 456 | expect(@typeId(f64) == Tid.Float); | |
| 457 | expect(@typeId(*f32) == Tid.Pointer); | |
| 458 | expect(@typeId([2]u8) == Tid.Array); | |
| 459 | expect(@typeId(AStruct) == Tid.Struct); | |
| 460 | expect(@typeId(@typeOf(1)) == Tid.ComptimeInt); | |
| 461 | expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat); | |
| 462 | expect(@typeId(@typeOf(undefined)) == Tid.Undefined); | |
| 463 | expect(@typeId(@typeOf(null)) == Tid.Null); | |
| 464 | expect(@typeId(?i32) == Tid.Optional); | |
| 465 | expect(@typeId(anyerror!i32) == Tid.ErrorUnion); | |
| 466 | expect(@typeId(anyerror) == Tid.ErrorSet); | |
| 467 | expect(@typeId(AnEnum) == Tid.Enum); | |
| 468 | expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); | |
| 469 | expect(@typeId(AUnionEnum) == Tid.Union); | |
| 470 | expect(@typeId(AUnion) == Tid.Union); | |
| 471 | expect(@typeId(fn () void) == Tid.Fn); | |
| 472 | expect(@typeId(@typeOf(builtin)) == Tid.Namespace); | |
| 473 | 473 | // TODO bound fn |
| 474 | 474 | // TODO arg tuple |
| 475 | 475 | // TODO opaque |
| ... | ... | @@ -485,13 +485,13 @@ test "@typeName" { |
| 485 | 485 | Unused, |
| 486 | 486 | }; |
| 487 | 487 | comptime { |
| 488 | assertOrPanic(mem.eql(u8, @typeName(i64), "i64")); | |
| 489 | assertOrPanic(mem.eql(u8, @typeName(*usize), "*usize")); | |
| 488 | expect(mem.eql(u8, @typeName(i64), "i64")); | |
| 489 | expect(mem.eql(u8, @typeName(*usize), "*usize")); | |
| 490 | 490 | // https://github.com/ziglang/zig/issues/675 |
| 491 | assertOrPanic(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)")); | |
| 492 | assertOrPanic(mem.eql(u8, @typeName(Struct), "Struct")); | |
| 493 | assertOrPanic(mem.eql(u8, @typeName(Union), "Union")); | |
| 494 | assertOrPanic(mem.eql(u8, @typeName(Enum), "Enum")); | |
| 491 | expect(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)")); | |
| 492 | expect(mem.eql(u8, @typeName(Struct), "Struct")); | |
| 493 | expect(mem.eql(u8, @typeName(Union), "Union")); | |
| 494 | expect(mem.eql(u8, @typeName(Enum), "Enum")); | |
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | |
| ... | ... | @@ -501,14 +501,14 @@ fn TypeFromFn(comptime T: type) type { |
| 501 | 501 | |
| 502 | 502 | test "double implicit cast in same expression" { |
| 503 | 503 | var x = i32(u16(nine())); |
| 504 | assertOrPanic(x == 9); | |
| 504 | expect(x == 9); | |
| 505 | 505 | } |
| 506 | 506 | fn nine() u8 { |
| 507 | 507 | return 9; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | test "global variable initialized to global variable array element" { |
| 511 | assertOrPanic(global_ptr == &gdt[0]); | |
| 511 | expect(global_ptr == &gdt[0]); | |
| 512 | 512 | } |
| 513 | 513 | const GDTEntry = struct { |
| 514 | 514 | field: i32, |
| ... | ... | @@ -529,9 +529,9 @@ export fn writeToVRam() void { |
| 529 | 529 | const OpaqueA = @OpaqueType(); |
| 530 | 530 | const OpaqueB = @OpaqueType(); |
| 531 | 531 | test "@OpaqueType" { |
| 532 | assertOrPanic(*OpaqueA != *OpaqueB); | |
| 533 | assertOrPanic(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); | |
| 534 | assertOrPanic(mem.eql(u8, @typeName(OpaqueB), "OpaqueB")); | |
| 532 | expect(*OpaqueA != *OpaqueB); | |
| 533 | expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); | |
| 534 | expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB")); | |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | test "variable is allowed to be a pointer to an opaque type" { |
| ... | ... | @@ -571,7 +571,7 @@ fn fnThatClosesOverLocalConst() type { |
| 571 | 571 | |
| 572 | 572 | test "function closes over local const" { |
| 573 | 573 | const x = fnThatClosesOverLocalConst().g(); |
| 574 | assertOrPanic(x == 1); | |
| 574 | expect(x == 1); | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | test "cold function" { |
| ... | ... | @@ -608,21 +608,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack |
| 608 | 608 | test "slicing zero length array" { |
| 609 | 609 | const s1 = ""[0..]; |
| 610 | 610 | const s2 = ([]u32{})[0..]; |
| 611 | assertOrPanic(s1.len == 0); | |
| 612 | assertOrPanic(s2.len == 0); | |
| 613 | assertOrPanic(mem.eql(u8, s1, "")); | |
| 614 | assertOrPanic(mem.eql(u32, s2, []u32{})); | |
| 611 | expect(s1.len == 0); | |
| 612 | expect(s2.len == 0); | |
| 613 | expect(mem.eql(u8, s1, "")); | |
| 614 | expect(mem.eql(u32, s2, []u32{})); | |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | const addr1 = @ptrCast(*const u8, emptyFn); |
| 618 | 618 | test "comptime cast fn to ptr" { |
| 619 | 619 | const addr2 = @ptrCast(*const u8, emptyFn); |
| 620 | comptime assertOrPanic(addr1 == addr2); | |
| 620 | comptime expect(addr1 == addr2); | |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | test "equality compare fn ptrs" { |
| 624 | 624 | var a = emptyFn; |
| 625 | assertOrPanic(a == a); | |
| 625 | expect(a == a); | |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | test "self reference through fn ptr field" { |
| ... | ... | @@ -637,26 +637,26 @@ test "self reference through fn ptr field" { |
| 637 | 637 | }; |
| 638 | 638 | var a: S.A = undefined; |
| 639 | 639 | a.f = S.foo; |
| 640 | assertOrPanic(a.f(a) == 12); | |
| 640 | expect(a.f(a) == 12); | |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | test "volatile load and store" { |
| 644 | 644 | var number: i32 = 1234; |
| 645 | 645 | const ptr = (*volatile i32)(&number); |
| 646 | 646 | ptr.* += 1; |
| 647 | assertOrPanic(ptr.* == 1235); | |
| 647 | expect(ptr.* == 1235); | |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | test "slice string literal has type []const u8" { |
| 651 | 651 | comptime { |
| 652 | assertOrPanic(@typeOf("aoeu"[0..]) == []const u8); | |
| 652 | expect(@typeOf("aoeu"[0..]) == []const u8); | |
| 653 | 653 | const array = []i32{ 1, 2, 3, 4 }; |
| 654 | assertOrPanic(@typeOf(array[0..]) == []const i32); | |
| 654 | expect(@typeOf(array[0..]) == []const i32); | |
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | test "pointer child field" { |
| 659 | assertOrPanic((*u32).Child == u32); | |
| 659 | expect((*u32).Child == u32); | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | test "struct inside function" { |
| ... | ... | @@ -675,11 +675,11 @@ fn testStructInFn() void { |
| 675 | 675 | |
| 676 | 676 | block.kind += 1; |
| 677 | 677 | |
| 678 | assertOrPanic(block.kind == 1235); | |
| 678 | expect(block.kind == 1235); | |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | test "fn call returning scalar optional in equality expression" { |
| 682 | assertOrPanic(getNull() == null); | |
| 682 | expect(getNull() == null); | |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | fn getNull() ?*i32 { |
| ... | ... | @@ -691,5 +691,5 @@ test "thread local variable" { |
| 691 | 691 | threadlocal var t: i32 = 1234; |
| 692 | 692 | }; |
| 693 | 693 | S.t += 1; |
| 694 | assertOrPanic(S.t == 1235); | |
| 694 | expect(S.t == 1235); | |
| 695 | 695 | } |
test/stage1/behavior/namespace_depends_on_compile_var/index.zig+3-3| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 2 | const expect = @import("std").testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "namespace depends on compile var" { |
| 5 | 5 | if (some_namespace.a_bool) { |
| 6 | assertOrPanic(some_namespace.a_bool); | |
| 6 | expect(some_namespace.a_bool); | |
| 7 | 7 | } else { |
| 8 | assertOrPanic(!some_namespace.a_bool); | |
| 8 | expect(!some_namespace.a_bool); | |
| 9 | 9 | } |
| 10 | 10 | } |
| 11 | 11 | const some_namespace = switch (builtin.os) { |
test/stage1/behavior/new_stack_call.zig+5-5| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | var new_stack_bytes: [1024]u8 = undefined; |
| 5 | 5 | |
| ... | ... | @@ -10,17 +10,17 @@ test "calling a function with a new stack" { |
| 10 | 10 | const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg); |
| 11 | 11 | _ = targetFunction(arg); |
| 12 | 12 | |
| 13 | assertOrPanic(arg == 1234); | |
| 14 | assertOrPanic(a < b); | |
| 13 | expect(arg == 1234); | |
| 14 | expect(a < b); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn targetFunction(x: i32) usize { |
| 18 | assertOrPanic(x == 1234); | |
| 18 | expect(x == 1234); | |
| 19 | 19 | |
| 20 | 20 | var local_variable: i32 = 42; |
| 21 | 21 | const ptr = &local_variable; |
| 22 | 22 | ptr.* += 1; |
| 23 | 23 | |
| 24 | assertOrPanic(local_variable == 43); | |
| 24 | expect(local_variable == 43); | |
| 25 | 25 | return @ptrToInt(ptr); |
| 26 | 26 | } |
test/stage1/behavior/null.zig+17-17| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "optional type" { |
| 4 | 4 | const x: ?bool = true; |
| ... | ... | @@ -17,13 +17,13 @@ test "optional type" { |
| 17 | 17 | |
| 18 | 18 | const z = next_x orelse 1234; |
| 19 | 19 | |
| 20 | assertOrPanic(z == 1234); | |
| 20 | expect(z == 1234); | |
| 21 | 21 | |
| 22 | 22 | const final_x: ?i32 = 13; |
| 23 | 23 | |
| 24 | 24 | const num = final_x orelse unreachable; |
| 25 | 25 | |
| 26 | assertOrPanic(num == 13); | |
| 26 | expect(num == 13); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | test "test maybe object and get a pointer to the inner value" { |
| ... | ... | @@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" { |
| 33 | 33 | b.* = false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | assertOrPanic(maybe_bool.? == false); | |
| 36 | expect(maybe_bool.? == false); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "rhs maybe unwrap return" { |
| ... | ... | @@ -47,9 +47,9 @@ test "maybe return" { |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | fn maybeReturnImpl() void { |
| 50 | assertOrPanic(foo(1235).?); | |
| 50 | expect(foo(1235).?); | |
| 51 | 51 | if (foo(null) != null) unreachable; |
| 52 | assertOrPanic(!foo(1234).?); | |
| 52 | expect(!foo(1234).?); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn foo(x: ?i32) ?bool { |
| ... | ... | @@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool { |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | test "if var maybe pointer" { |
| 61 | assertOrPanic(shouldBeAPlus1(Particle{ | |
| 61 | expect(shouldBeAPlus1(Particle{ | |
| 62 | 62 | .a = 14, |
| 63 | 63 | .b = 1, |
| 64 | 64 | .c = 1, |
| ... | ... | @@ -84,10 +84,10 @@ const Particle = struct { |
| 84 | 84 | |
| 85 | 85 | test "null literal outside function" { |
| 86 | 86 | const is_null = here_is_a_null_literal.context == null; |
| 87 | assertOrPanic(is_null); | |
| 87 | expect(is_null); | |
| 88 | 88 | |
| 89 | 89 | const is_non_null = here_is_a_null_literal.context != null; |
| 90 | assertOrPanic(!is_non_null); | |
| 90 | expect(!is_non_null); | |
| 91 | 91 | } |
| 92 | 92 | const SillyStruct = struct { |
| 93 | 93 | context: ?i32, |
| ... | ... | @@ -98,8 +98,8 @@ test "test null runtime" { |
| 98 | 98 | testTestNullRuntime(null); |
| 99 | 99 | } |
| 100 | 100 | fn testTestNullRuntime(x: ?i32) void { |
| 101 | assertOrPanic(x == null); | |
| 102 | assertOrPanic(!(x != null)); | |
| 101 | expect(x == null); | |
| 102 | expect(!(x != null)); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "optional void" { |
| ... | ... | @@ -108,8 +108,8 @@ test "optional void" { |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | fn optionalVoidImpl() void { |
| 111 | assertOrPanic(bar(null) == null); | |
| 112 | assertOrPanic(bar({}) != null); | |
| 111 | expect(bar(null) == null); | |
| 112 | expect(bar({}) != null); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | fn bar(x: ?void) ?void { |
| ... | ... | @@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" { |
| 133 | 133 | } |
| 134 | 134 | struct_with_optional.field = 1234; |
| 135 | 135 | if (struct_with_optional.field) |payload| { |
| 136 | assertOrPanic(payload == 1234); | |
| 136 | expect(payload == 1234); | |
| 137 | 137 | } else { |
| 138 | 138 | unreachable; |
| 139 | 139 | } |
| ... | ... | @@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" { |
| 141 | 141 | |
| 142 | 142 | test "null with default unwrap" { |
| 143 | 143 | const x: i32 = null orelse 1; |
| 144 | assertOrPanic(x == 1); | |
| 144 | expect(x == 1); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | test "optional types" { |
| 148 | 148 | comptime { |
| 149 | 149 | const opt_type_struct = StructWithOptionalType{ .t = u8 }; |
| 150 | assertOrPanic(opt_type_struct.t != null and opt_type_struct.t.? == u8); | |
| 150 | expect(opt_type_struct.t != null and opt_type_struct.t.? == u8); | |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| ... | ... | @@ -158,5 +158,5 @@ const StructWithOptionalType = struct { |
| 158 | 158 | test "optional pointer to 0 bit type null value at runtime" { |
| 159 | 159 | const EmptyStruct = struct {}; |
| 160 | 160 | var x: ?*EmptyStruct = null; |
| 161 | assertOrPanic(x == null); | |
| 161 | expect(x == null); | |
| 162 | 162 | } |
test/stage1/behavior/optional.zig+14-14| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | pub const EmptyStruct = struct {}; |
| 4 | 4 | |
| 5 | 5 | test "optional pointer to size zero struct" { |
| 6 | 6 | var e = EmptyStruct{}; |
| 7 | 7 | var o: ?*EmptyStruct = &e; |
| 8 | assertOrPanic(o != null); | |
| 8 | expect(o != null); | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | test "equality compare nullable pointers" { |
| ... | ... | @@ -18,15 +18,15 @@ fn testNullPtrsEql() void { |
| 18 | 18 | |
| 19 | 19 | var x: ?*i32 = null; |
| 20 | 20 | var y: ?*i32 = null; |
| 21 | assertOrPanic(x == y); | |
| 21 | expect(x == y); | |
| 22 | 22 | y = &number; |
| 23 | assertOrPanic(x != y); | |
| 24 | assertOrPanic(x != &number); | |
| 25 | assertOrPanic(&number != x); | |
| 23 | expect(x != y); | |
| 24 | expect(x != &number); | |
| 25 | expect(&number != x); | |
| 26 | 26 | x = &number; |
| 27 | assertOrPanic(x == y); | |
| 28 | assertOrPanic(x == &number); | |
| 29 | assertOrPanic(&number == x); | |
| 27 | expect(x == y); | |
| 28 | expect(x == &number); | |
| 29 | expect(&number == x); | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | test "address of unwrap optional" { |
| ... | ... | @@ -43,7 +43,7 @@ test "address of unwrap optional" { |
| 43 | 43 | }; |
| 44 | 44 | S.global = S.Foo{ .a = 1234 }; |
| 45 | 45 | const foo = S.getFoo() catch unreachable; |
| 46 | assertOrPanic(foo.a == 1234); | |
| 46 | expect(foo.a == 1234); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "passing an optional integer as a parameter" { |
| ... | ... | @@ -57,15 +57,15 @@ test "passing an optional integer as a parameter" { |
| 57 | 57 | return x.? == 1234; |
| 58 | 58 | } |
| 59 | 59 | }; |
| 60 | assertOrPanic(S.entry()); | |
| 61 | comptime assertOrPanic(S.entry()); | |
| 60 | expect(S.entry()); | |
| 61 | comptime expect(S.entry()); | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | test "unwrap function call with optional pointer return value" { |
| 65 | 65 | const S = struct { |
| 66 | 66 | fn entry() void { |
| 67 | assertOrPanic(foo().?.* == 1234); | |
| 68 | assertOrPanic(bar() == null); | |
| 67 | expect(foo().?.* == 1234); | |
| 68 | expect(bar() == null); | |
| 69 | 69 | } |
| 70 | 70 | const global: i32 = 1234; |
| 71 | 71 | fn foo() ?*const i32 { |
test/stage1/behavior/pointers.zig+12-12| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "dereference pointer" { |
| 5 | 5 | comptime testDerefPtr(); |
| ... | ... | @@ -10,33 +10,33 @@ fn testDerefPtr() void { |
| 10 | 10 | var x: i32 = 1234; |
| 11 | 11 | var y = &x; |
| 12 | 12 | y.* += 1; |
| 13 | assertOrPanic(x == 1235); | |
| 13 | expect(x == 1235); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | test "pointer arithmetic" { |
| 17 | 17 | var ptr = c"abcd"; |
| 18 | 18 | |
| 19 | assertOrPanic(ptr[0] == 'a'); | |
| 19 | expect(ptr[0] == 'a'); | |
| 20 | 20 | ptr += 1; |
| 21 | assertOrPanic(ptr[0] == 'b'); | |
| 21 | expect(ptr[0] == 'b'); | |
| 22 | 22 | ptr += 1; |
| 23 | assertOrPanic(ptr[0] == 'c'); | |
| 23 | expect(ptr[0] == 'c'); | |
| 24 | 24 | ptr += 1; |
| 25 | assertOrPanic(ptr[0] == 'd'); | |
| 25 | expect(ptr[0] == 'd'); | |
| 26 | 26 | ptr += 1; |
| 27 | assertOrPanic(ptr[0] == 0); | |
| 27 | expect(ptr[0] == 0); | |
| 28 | 28 | ptr -= 1; |
| 29 | assertOrPanic(ptr[0] == 'd'); | |
| 29 | expect(ptr[0] == 'd'); | |
| 30 | 30 | ptr -= 1; |
| 31 | assertOrPanic(ptr[0] == 'c'); | |
| 31 | expect(ptr[0] == 'c'); | |
| 32 | 32 | ptr -= 1; |
| 33 | assertOrPanic(ptr[0] == 'b'); | |
| 33 | expect(ptr[0] == 'b'); | |
| 34 | 34 | ptr -= 1; |
| 35 | assertOrPanic(ptr[0] == 'a'); | |
| 35 | expect(ptr[0] == 'a'); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "double pointer parsing" { |
| 39 | comptime assertOrPanic(PtrOf(PtrOf(i32)) == **i32); | |
| 39 | comptime expect(PtrOf(PtrOf(i32)) == **i32); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | fn PtrOf(comptime T: type) type { |
test/stage1/behavior/popcount.zig+5-5| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "@popCount" { |
| 4 | 4 | comptime testPopCount(); |
| ... | ... | @@ -8,18 +8,18 @@ test "@popCount" { |
| 8 | 8 | fn testPopCount() void { |
| 9 | 9 | { |
| 10 | 10 | var x: u32 = 0xaa; |
| 11 | assertOrPanic(@popCount(x) == 4); | |
| 11 | expect(@popCount(x) == 4); | |
| 12 | 12 | } |
| 13 | 13 | { |
| 14 | 14 | var x: u32 = 0xaaaaaaaa; |
| 15 | assertOrPanic(@popCount(x) == 16); | |
| 15 | expect(@popCount(x) == 16); | |
| 16 | 16 | } |
| 17 | 17 | { |
| 18 | 18 | var x: i16 = -1; |
| 19 | assertOrPanic(@popCount(x) == 16); | |
| 19 | expect(@popCount(x) == 16); | |
| 20 | 20 | } |
| 21 | 21 | comptime { |
| 22 | assertOrPanic(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24); | |
| 22 | expect(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24); | |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 |
test/stage1/behavior/ptrcast.zig+4-4| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | test "reinterpret bytes as integer with nonzero offset" { |
| 6 | 6 | testReinterpretBytesAsInteger(); |
| ... | ... | @@ -13,7 +13,7 @@ fn testReinterpretBytesAsInteger() void { |
| 13 | 13 | builtin.Endian.Little => 0xab785634, |
| 14 | 14 | builtin.Endian.Big => 0x345678ab, |
| 15 | 15 | }; |
| 16 | assertOrPanic(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected); | |
| 16 | expect(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "reinterpret bytes of an array into an extern struct" { |
| ... | ... | @@ -32,12 +32,12 @@ fn testReinterpretBytesAsExternStruct() void { |
| 32 | 32 | |
| 33 | 33 | var ptr = @ptrCast(*const S, &bytes); |
| 34 | 34 | var val = ptr.c; |
| 35 | assertOrPanic(val == 5); | |
| 35 | expect(val == 5); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "reinterpret struct field at comptime" { |
| 39 | 39 | const numLittle = comptime Bytes.init(0x12345678); |
| 40 | assertOrPanic(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes)); | |
| 40 | expect(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes)); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | const Bytes = struct { |
test/stage1/behavior/pub_enum/index.zig+3-3| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const other = @import("other.zig"); |
| 2 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 2 | const expect = @import("std").testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "pub enum" { |
| 5 | 5 | pubEnumTest(other.APubEnum.Two); |
| 6 | 6 | } |
| 7 | 7 | fn pubEnumTest(foo: other.APubEnum) void { |
| 8 | assertOrPanic(foo == other.APubEnum.Two); | |
| 8 | expect(foo == other.APubEnum.Two); | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | test "cast with imported symbol" { |
| 12 | assertOrPanic(other.size_t(42) == 42); | |
| 12 | expect(other.size_t(42) == 42); | |
| 13 | 13 | } |
test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+5-5| ... | ... | @@ -1,14 +1,14 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | var ok: bool = false; |
| 5 | 5 | test "reference a variable in an if after an if in the 2nd switch prong" { |
| 6 | 6 | foo(true, Num.Two, false, "aoeu"); |
| 7 | assertOrPanic(!ok); | |
| 7 | expect(!ok); | |
| 8 | 8 | foo(false, Num.One, false, "aoeu"); |
| 9 | assertOrPanic(!ok); | |
| 9 | expect(!ok); | |
| 10 | 10 | foo(true, Num.One, false, "aoeu"); |
| 11 | assertOrPanic(ok); | |
| 11 | expect(ok); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | const Num = enum { |
| ... | ... | @@ -32,6 +32,6 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void { |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | fn a(x: []const u8) void { |
| 35 | assertOrPanic(mem.eql(u8, x, "aoeu")); | |
| 35 | expect(mem.eql(u8, x, "aoeu")); | |
| 36 | 36 | ok = true; |
| 37 | 37 | } |
test/stage1/behavior/reflection.zig+39-39| ... | ... | @@ -1,25 +1,25 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | const reflection = @This(); |
| 4 | 4 | |
| 5 | 5 | test "reflection: array, pointer, optional, error union type child" { |
| 6 | 6 | comptime { |
| 7 | assertOrPanic(([10]u8).Child == u8); | |
| 8 | assertOrPanic((*u8).Child == u8); | |
| 9 | assertOrPanic((anyerror!u8).Payload == u8); | |
| 10 | assertOrPanic((?u8).Child == u8); | |
| 7 | expect(([10]u8).Child == u8); | |
| 8 | expect((*u8).Child == u8); | |
| 9 | expect((anyerror!u8).Payload == u8); | |
| 10 | expect((?u8).Child == u8); | |
| 11 | 11 | } |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "reflection: function return type, var args, and param types" { |
| 15 | 15 | comptime { |
| 16 | assertOrPanic(@typeOf(dummy).ReturnType == i32); | |
| 17 | assertOrPanic(!@typeOf(dummy).is_var_args); | |
| 18 | assertOrPanic(@typeOf(dummy_varargs).is_var_args); | |
| 19 | assertOrPanic(@typeOf(dummy).arg_count == 3); | |
| 20 | assertOrPanic(@ArgType(@typeOf(dummy), 0) == bool); | |
| 21 | assertOrPanic(@ArgType(@typeOf(dummy), 1) == i32); | |
| 22 | assertOrPanic(@ArgType(@typeOf(dummy), 2) == f32); | |
| 16 | expect(@typeOf(dummy).ReturnType == i32); | |
| 17 | expect(!@typeOf(dummy).is_var_args); | |
| 18 | expect(@typeOf(dummy_varargs).is_var_args); | |
| 19 | expect(@typeOf(dummy).arg_count == 3); | |
| 20 | expect(@ArgType(@typeOf(dummy), 0) == bool); | |
| 21 | expect(@ArgType(@typeOf(dummy), 1) == i32); | |
| 22 | expect(@ArgType(@typeOf(dummy), 2) == f32); | |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| ... | ... | @@ -30,31 +30,31 @@ fn dummy_varargs(args: ...) void {} |
| 30 | 30 | |
| 31 | 31 | test "reflection: struct member types and names" { |
| 32 | 32 | comptime { |
| 33 | assertOrPanic(@memberCount(Foo) == 3); | |
| 33 | expect(@memberCount(Foo) == 3); | |
| 34 | 34 | |
| 35 | assertOrPanic(@memberType(Foo, 0) == i32); | |
| 36 | assertOrPanic(@memberType(Foo, 1) == bool); | |
| 37 | assertOrPanic(@memberType(Foo, 2) == void); | |
| 35 | expect(@memberType(Foo, 0) == i32); | |
| 36 | expect(@memberType(Foo, 1) == bool); | |
| 37 | expect(@memberType(Foo, 2) == void); | |
| 38 | 38 | |
| 39 | assertOrPanic(mem.eql(u8, @memberName(Foo, 0), "one")); | |
| 40 | assertOrPanic(mem.eql(u8, @memberName(Foo, 1), "two")); | |
| 41 | assertOrPanic(mem.eql(u8, @memberName(Foo, 2), "three")); | |
| 39 | expect(mem.eql(u8, @memberName(Foo, 0), "one")); | |
| 40 | expect(mem.eql(u8, @memberName(Foo, 1), "two")); | |
| 41 | expect(mem.eql(u8, @memberName(Foo, 2), "three")); | |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | test "reflection: enum member types and names" { |
| 46 | 46 | comptime { |
| 47 | assertOrPanic(@memberCount(Bar) == 4); | |
| 47 | expect(@memberCount(Bar) == 4); | |
| 48 | 48 | |
| 49 | assertOrPanic(@memberType(Bar, 0) == void); | |
| 50 | assertOrPanic(@memberType(Bar, 1) == i32); | |
| 51 | assertOrPanic(@memberType(Bar, 2) == bool); | |
| 52 | assertOrPanic(@memberType(Bar, 3) == f64); | |
| 49 | expect(@memberType(Bar, 0) == void); | |
| 50 | expect(@memberType(Bar, 1) == i32); | |
| 51 | expect(@memberType(Bar, 2) == bool); | |
| 52 | expect(@memberType(Bar, 3) == f64); | |
| 53 | 53 | |
| 54 | assertOrPanic(mem.eql(u8, @memberName(Bar, 0), "One")); | |
| 55 | assertOrPanic(mem.eql(u8, @memberName(Bar, 1), "Two")); | |
| 56 | assertOrPanic(mem.eql(u8, @memberName(Bar, 2), "Three")); | |
| 57 | assertOrPanic(mem.eql(u8, @memberName(Bar, 3), "Four")); | |
| 54 | expect(mem.eql(u8, @memberName(Bar, 0), "One")); | |
| 55 | expect(mem.eql(u8, @memberName(Bar, 1), "Two")); | |
| 56 | expect(mem.eql(u8, @memberName(Bar, 2), "Three")); | |
| 57 | expect(mem.eql(u8, @memberName(Bar, 3), "Four")); | |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| ... | ... | @@ -65,18 +65,18 @@ test "reflection: @field" { |
| 65 | 65 | .three = void{}, |
| 66 | 66 | }; |
| 67 | 67 | |
| 68 | assertOrPanic(f.one == f.one); | |
| 69 | assertOrPanic(@field(f, "o" ++ "ne") == f.one); | |
| 70 | assertOrPanic(@field(f, "t" ++ "wo") == f.two); | |
| 71 | assertOrPanic(@field(f, "th" ++ "ree") == f.three); | |
| 72 | assertOrPanic(@field(Foo, "const" ++ "ant") == Foo.constant); | |
| 73 | assertOrPanic(@field(Bar, "O" ++ "ne") == Bar.One); | |
| 74 | assertOrPanic(@field(Bar, "T" ++ "wo") == Bar.Two); | |
| 75 | assertOrPanic(@field(Bar, "Th" ++ "ree") == Bar.Three); | |
| 76 | assertOrPanic(@field(Bar, "F" ++ "our") == Bar.Four); | |
| 77 | assertOrPanic(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2)); | |
| 68 | expect(f.one == f.one); | |
| 69 | expect(@field(f, "o" ++ "ne") == f.one); | |
| 70 | expect(@field(f, "t" ++ "wo") == f.two); | |
| 71 | expect(@field(f, "th" ++ "ree") == f.three); | |
| 72 | expect(@field(Foo, "const" ++ "ant") == Foo.constant); | |
| 73 | expect(@field(Bar, "O" ++ "ne") == Bar.One); | |
| 74 | expect(@field(Bar, "T" ++ "wo") == Bar.Two); | |
| 75 | expect(@field(Bar, "Th" ++ "ree") == Bar.Three); | |
| 76 | expect(@field(Bar, "F" ++ "our") == Bar.Four); | |
| 77 | expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2)); | |
| 78 | 78 | @field(f, "o" ++ "ne") = 4; |
| 79 | assertOrPanic(f.one == 4); | |
| 79 | expect(f.one == 4); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | const Foo = struct { |
test/stage1/behavior/sizeof_and_typeof.zig+30-30| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 2 | const expect = @import("std").testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "@sizeOf and @typeOf" { |
| 5 | 5 | const y: @typeOf(x) = 120; |
| 6 | assertOrPanic(@sizeOf(@typeOf(y)) == 2); | |
| 6 | expect(@sizeOf(@typeOf(y)) == 2); | |
| 7 | 7 | } |
| 8 | 8 | const x: u16 = 13; |
| 9 | 9 | const z: @typeOf(x) = 19; |
| ... | ... | @@ -30,40 +30,40 @@ const P = packed struct { |
| 30 | 30 | |
| 31 | 31 | test "@byteOffsetOf" { |
| 32 | 32 | // Packed structs have fixed memory layout |
| 33 | assertOrPanic(@byteOffsetOf(P, "a") == 0); | |
| 34 | assertOrPanic(@byteOffsetOf(P, "b") == 1); | |
| 35 | assertOrPanic(@byteOffsetOf(P, "c") == 5); | |
| 36 | assertOrPanic(@byteOffsetOf(P, "d") == 6); | |
| 37 | assertOrPanic(@byteOffsetOf(P, "e") == 6); | |
| 38 | assertOrPanic(@byteOffsetOf(P, "f") == 7); | |
| 39 | assertOrPanic(@byteOffsetOf(P, "g") == 9); | |
| 33 | expect(@byteOffsetOf(P, "a") == 0); | |
| 34 | expect(@byteOffsetOf(P, "b") == 1); | |
| 35 | expect(@byteOffsetOf(P, "c") == 5); | |
| 36 | expect(@byteOffsetOf(P, "d") == 6); | |
| 37 | expect(@byteOffsetOf(P, "e") == 6); | |
| 38 | expect(@byteOffsetOf(P, "f") == 7); | |
| 39 | expect(@byteOffsetOf(P, "g") == 9); | |
| 40 | 40 | |
| 41 | 41 | // Normal struct fields can be moved/padded |
| 42 | 42 | var a: A = undefined; |
| 43 | assertOrPanic(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a")); | |
| 44 | assertOrPanic(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b")); | |
| 45 | assertOrPanic(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c")); | |
| 46 | assertOrPanic(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d")); | |
| 47 | assertOrPanic(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e")); | |
| 48 | assertOrPanic(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f")); | |
| 49 | assertOrPanic(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g")); | |
| 43 | expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a")); | |
| 44 | expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b")); | |
| 45 | expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c")); | |
| 46 | expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d")); | |
| 47 | expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e")); | |
| 48 | expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f")); | |
| 49 | expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g")); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | test "@bitOffsetOf" { |
| 53 | 53 | // Packed structs have fixed memory layout |
| 54 | assertOrPanic(@bitOffsetOf(P, "a") == 0); | |
| 55 | assertOrPanic(@bitOffsetOf(P, "b") == 8); | |
| 56 | assertOrPanic(@bitOffsetOf(P, "c") == 40); | |
| 57 | assertOrPanic(@bitOffsetOf(P, "d") == 48); | |
| 58 | assertOrPanic(@bitOffsetOf(P, "e") == 51); | |
| 59 | assertOrPanic(@bitOffsetOf(P, "f") == 56); | |
| 60 | assertOrPanic(@bitOffsetOf(P, "g") == 72); | |
| 54 | expect(@bitOffsetOf(P, "a") == 0); | |
| 55 | expect(@bitOffsetOf(P, "b") == 8); | |
| 56 | expect(@bitOffsetOf(P, "c") == 40); | |
| 57 | expect(@bitOffsetOf(P, "d") == 48); | |
| 58 | expect(@bitOffsetOf(P, "e") == 51); | |
| 59 | expect(@bitOffsetOf(P, "f") == 56); | |
| 60 | expect(@bitOffsetOf(P, "g") == 72); | |
| 61 | 61 | |
| 62 | assertOrPanic(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a")); | |
| 63 | assertOrPanic(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b")); | |
| 64 | assertOrPanic(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c")); | |
| 65 | assertOrPanic(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d")); | |
| 66 | assertOrPanic(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e")); | |
| 67 | assertOrPanic(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f")); | |
| 68 | assertOrPanic(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g")); | |
| 62 | expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a")); | |
| 63 | expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b")); | |
| 64 | expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c")); | |
| 65 | expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d")); | |
| 66 | expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e")); | |
| 67 | expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f")); | |
| 68 | expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g")); | |
| 69 | 69 | } |
test/stage1/behavior/slice.zig+8-8| ... | ... | @@ -1,20 +1,20 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | const x = @intToPtr([*]i32, 0x1000)[0..0x500]; |
| 5 | 5 | const y = x[0x100..]; |
| 6 | 6 | test "compile time slice of pointer to hard coded address" { |
| 7 | assertOrPanic(@ptrToInt(x.ptr) == 0x1000); | |
| 8 | assertOrPanic(x.len == 0x500); | |
| 7 | expect(@ptrToInt(x.ptr) == 0x1000); | |
| 8 | expect(x.len == 0x500); | |
| 9 | 9 | |
| 10 | assertOrPanic(@ptrToInt(y.ptr) == 0x1100); | |
| 11 | assertOrPanic(y.len == 0x400); | |
| 10 | expect(@ptrToInt(y.ptr) == 0x1100); | |
| 11 | expect(y.len == 0x400); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "slice child property" { |
| 15 | 15 | var array: [5]i32 = undefined; |
| 16 | 16 | var slice = array[0..]; |
| 17 | assertOrPanic(@typeOf(slice).Child == i32); | |
| 17 | expect(@typeOf(slice).Child == i32); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | test "runtime safety lets us slice from len..len" { |
| ... | ... | @@ -23,7 +23,7 @@ test "runtime safety lets us slice from len..len" { |
| 23 | 23 | 2, |
| 24 | 24 | 3, |
| 25 | 25 | }; |
| 26 | assertOrPanic(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), "")); | |
| 26 | expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), "")); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { |
| ... | ... | @@ -36,5 +36,5 @@ test "implicitly cast array of size 0 to slice" { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | fn assertLenIsZero(msg: []const u8) void { |
| 39 | assertOrPanic(msg.len == 0); | |
| 39 | expect(msg.len == 0); | |
| 40 | 40 | } |
test/stage1/behavior/struct.zig+92-92| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| ... | ... | @@ -12,7 +12,7 @@ const empty_global_instance = StructWithNoFields{}; |
| 12 | 12 | |
| 13 | 13 | test "call struct static method" { |
| 14 | 14 | const result = StructWithNoFields.add(3, 4); |
| 15 | assertOrPanic(result == 7); | |
| 15 | expect(result == 7); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "return empty struct instance" { |
| ... | ... | @@ -25,7 +25,7 @@ fn returnEmptyStructInstance() StructWithNoFields { |
| 25 | 25 | const should_be_11 = StructWithNoFields.add(5, 6); |
| 26 | 26 | |
| 27 | 27 | test "invoke static method in global scope" { |
| 28 | assertOrPanic(should_be_11 == 11); | |
| 28 | expect(should_be_11 == 11); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | test "void struct fields" { |
| ... | ... | @@ -34,8 +34,8 @@ test "void struct fields" { |
| 34 | 34 | .b = 1, |
| 35 | 35 | .c = void{}, |
| 36 | 36 | }; |
| 37 | assertOrPanic(foo.b == 1); | |
| 38 | assertOrPanic(@sizeOf(VoidStructFieldsFoo) == 4); | |
| 37 | expect(foo.b == 1); | |
| 38 | expect(@sizeOf(VoidStructFieldsFoo) == 4); | |
| 39 | 39 | } |
| 40 | 40 | const VoidStructFieldsFoo = struct { |
| 41 | 41 | a: void, |
| ... | ... | @@ -50,7 +50,7 @@ test "structs" { |
| 50 | 50 | foo.b = foo.a == 1; |
| 51 | 51 | testFoo(foo); |
| 52 | 52 | testMutation(&foo); |
| 53 | assertOrPanic(foo.c == 100); | |
| 53 | expect(foo.c == 100); | |
| 54 | 54 | } |
| 55 | 55 | const StructFoo = struct { |
| 56 | 56 | a: i32, |
| ... | ... | @@ -58,7 +58,7 @@ const StructFoo = struct { |
| 58 | 58 | c: f32, |
| 59 | 59 | }; |
| 60 | 60 | fn testFoo(foo: StructFoo) void { |
| 61 | assertOrPanic(foo.b); | |
| 61 | expect(foo.b); | |
| 62 | 62 | } |
| 63 | 63 | fn testMutation(foo: *StructFoo) void { |
| 64 | 64 | foo.c = 100; |
| ... | ... | @@ -83,7 +83,7 @@ test "struct point to self" { |
| 83 | 83 | |
| 84 | 84 | root.next = &node; |
| 85 | 85 | |
| 86 | assertOrPanic(node.next.next.next.val.x == 1); | |
| 86 | expect(node.next.next.next.val.x == 1); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "struct byval assign" { |
| ... | ... | @@ -92,18 +92,18 @@ test "struct byval assign" { |
| 92 | 92 | |
| 93 | 93 | foo1.a = 1234; |
| 94 | 94 | foo2.a = 0; |
| 95 | assertOrPanic(foo2.a == 0); | |
| 95 | expect(foo2.a == 0); | |
| 96 | 96 | foo2 = foo1; |
| 97 | assertOrPanic(foo2.a == 1234); | |
| 97 | expect(foo2.a == 1234); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | fn structInitializer() void { |
| 101 | 101 | const val = Val{ .x = 42 }; |
| 102 | assertOrPanic(val.x == 42); | |
| 102 | expect(val.x == 42); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "fn call of struct field" { |
| 106 | assertOrPanic(callStructField(Foo{ .ptr = aFunc }) == 13); | |
| 106 | expect(callStructField(Foo{ .ptr = aFunc }) == 13); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | const Foo = struct { |
| ... | ... | @@ -122,7 +122,7 @@ test "store member function in variable" { |
| 122 | 122 | const instance = MemberFnTestFoo{ .x = 1234 }; |
| 123 | 123 | const memberFn = MemberFnTestFoo.member; |
| 124 | 124 | const result = memberFn(instance); |
| 125 | assertOrPanic(result == 1234); | |
| 125 | expect(result == 1234); | |
| 126 | 126 | } |
| 127 | 127 | const MemberFnTestFoo = struct { |
| 128 | 128 | x: i32, |
| ... | ... | @@ -134,12 +134,12 @@ const MemberFnTestFoo = struct { |
| 134 | 134 | test "call member function directly" { |
| 135 | 135 | const instance = MemberFnTestFoo{ .x = 1234 }; |
| 136 | 136 | const result = MemberFnTestFoo.member(instance); |
| 137 | assertOrPanic(result == 1234); | |
| 137 | expect(result == 1234); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | test "member functions" { |
| 141 | 141 | const r = MemberFnRand{ .seed = 1234 }; |
| 142 | assertOrPanic(r.getSeed() == 1234); | |
| 142 | expect(r.getSeed() == 1234); | |
| 143 | 143 | } |
| 144 | 144 | const MemberFnRand = struct { |
| 145 | 145 | seed: u32, |
| ... | ... | @@ -150,7 +150,7 @@ const MemberFnRand = struct { |
| 150 | 150 | |
| 151 | 151 | test "return struct byval from function" { |
| 152 | 152 | const bar = makeBar(1234, 5678); |
| 153 | assertOrPanic(bar.y == 5678); | |
| 153 | expect(bar.y == 5678); | |
| 154 | 154 | } |
| 155 | 155 | const Bar = struct { |
| 156 | 156 | x: i32, |
| ... | ... | @@ -165,7 +165,7 @@ fn makeBar(x: i32, y: i32) Bar { |
| 165 | 165 | |
| 166 | 166 | test "empty struct method call" { |
| 167 | 167 | const es = EmptyStruct{}; |
| 168 | assertOrPanic(es.method() == 1234); | |
| 168 | expect(es.method() == 1234); | |
| 169 | 169 | } |
| 170 | 170 | const EmptyStruct = struct { |
| 171 | 171 | fn method(es: *const EmptyStruct) i32 { |
| ... | ... | @@ -182,7 +182,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 { |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | test "pass slice of empty struct to fn" { |
| 185 | assertOrPanic(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1); | |
| 185 | expect(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1); | |
| 186 | 186 | } |
| 187 | 187 | fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize { |
| 188 | 188 | return slice.len; |
| ... | ... | @@ -200,7 +200,7 @@ test "packed struct" { |
| 200 | 200 | }; |
| 201 | 201 | foo.y += 1; |
| 202 | 202 | const four = foo.x + foo.y; |
| 203 | assertOrPanic(four == 4); | |
| 203 | expect(four == 4); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | const BitField1 = packed struct { |
| ... | ... | @@ -217,17 +217,17 @@ const bit_field_1 = BitField1{ |
| 217 | 217 | |
| 218 | 218 | test "bit field access" { |
| 219 | 219 | var data = bit_field_1; |
| 220 | assertOrPanic(getA(&data) == 1); | |
| 221 | assertOrPanic(getB(&data) == 2); | |
| 222 | assertOrPanic(getC(&data) == 3); | |
| 223 | comptime assertOrPanic(@sizeOf(BitField1) == 1); | |
| 220 | expect(getA(&data) == 1); | |
| 221 | expect(getB(&data) == 2); | |
| 222 | expect(getC(&data) == 3); | |
| 223 | comptime expect(@sizeOf(BitField1) == 1); | |
| 224 | 224 | |
| 225 | 225 | data.b += 1; |
| 226 | assertOrPanic(data.b == 3); | |
| 226 | expect(data.b == 3); | |
| 227 | 227 | |
| 228 | 228 | data.a += 1; |
| 229 | assertOrPanic(data.a == 2); | |
| 230 | assertOrPanic(data.b == 3); | |
| 229 | expect(data.a == 2); | |
| 230 | expect(data.b == 3); | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | fn getA(data: *const BitField1) u3 { |
| ... | ... | @@ -254,8 +254,8 @@ const Foo96Bits = packed struct { |
| 254 | 254 | |
| 255 | 255 | test "packed struct 24bits" { |
| 256 | 256 | comptime { |
| 257 | assertOrPanic(@sizeOf(Foo24Bits) == 3); | |
| 258 | assertOrPanic(@sizeOf(Foo96Bits) == 12); | |
| 257 | expect(@sizeOf(Foo24Bits) == 3); | |
| 258 | expect(@sizeOf(Foo96Bits) == 12); | |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | var value = Foo96Bits{ |
| ... | ... | @@ -265,28 +265,28 @@ test "packed struct 24bits" { |
| 265 | 265 | .d = 0, |
| 266 | 266 | }; |
| 267 | 267 | value.a += 1; |
| 268 | assertOrPanic(value.a == 1); | |
| 269 | assertOrPanic(value.b == 0); | |
| 270 | assertOrPanic(value.c == 0); | |
| 271 | assertOrPanic(value.d == 0); | |
| 268 | expect(value.a == 1); | |
| 269 | expect(value.b == 0); | |
| 270 | expect(value.c == 0); | |
| 271 | expect(value.d == 0); | |
| 272 | 272 | |
| 273 | 273 | value.b += 1; |
| 274 | assertOrPanic(value.a == 1); | |
| 275 | assertOrPanic(value.b == 1); | |
| 276 | assertOrPanic(value.c == 0); | |
| 277 | assertOrPanic(value.d == 0); | |
| 274 | expect(value.a == 1); | |
| 275 | expect(value.b == 1); | |
| 276 | expect(value.c == 0); | |
| 277 | expect(value.d == 0); | |
| 278 | 278 | |
| 279 | 279 | value.c += 1; |
| 280 | assertOrPanic(value.a == 1); | |
| 281 | assertOrPanic(value.b == 1); | |
| 282 | assertOrPanic(value.c == 1); | |
| 283 | assertOrPanic(value.d == 0); | |
| 280 | expect(value.a == 1); | |
| 281 | expect(value.b == 1); | |
| 282 | expect(value.c == 1); | |
| 283 | expect(value.d == 0); | |
| 284 | 284 | |
| 285 | 285 | value.d += 1; |
| 286 | assertOrPanic(value.a == 1); | |
| 287 | assertOrPanic(value.b == 1); | |
| 288 | assertOrPanic(value.c == 1); | |
| 289 | assertOrPanic(value.d == 1); | |
| 286 | expect(value.a == 1); | |
| 287 | expect(value.b == 1); | |
| 288 | expect(value.c == 1); | |
| 289 | expect(value.d == 1); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | const FooArray24Bits = packed struct { |
| ... | ... | @@ -297,43 +297,43 @@ const FooArray24Bits = packed struct { |
| 297 | 297 | |
| 298 | 298 | test "packed array 24bits" { |
| 299 | 299 | comptime { |
| 300 | assertOrPanic(@sizeOf([9]Foo24Bits) == 9 * 3); | |
| 301 | assertOrPanic(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2); | |
| 300 | expect(@sizeOf([9]Foo24Bits) == 9 * 3); | |
| 301 | expect(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2); | |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1); |
| 305 | 305 | bytes[bytes.len - 1] = 0xaa; |
| 306 | 306 | const ptr = &@bytesToSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; |
| 307 | assertOrPanic(ptr.a == 0); | |
| 308 | assertOrPanic(ptr.b[0].field == 0); | |
| 309 | assertOrPanic(ptr.b[1].field == 0); | |
| 310 | assertOrPanic(ptr.c == 0); | |
| 307 | expect(ptr.a == 0); | |
| 308 | expect(ptr.b[0].field == 0); | |
| 309 | expect(ptr.b[1].field == 0); | |
| 310 | expect(ptr.c == 0); | |
| 311 | 311 | |
| 312 | 312 | ptr.a = maxInt(u16); |
| 313 | assertOrPanic(ptr.a == maxInt(u16)); | |
| 314 | assertOrPanic(ptr.b[0].field == 0); | |
| 315 | assertOrPanic(ptr.b[1].field == 0); | |
| 316 | assertOrPanic(ptr.c == 0); | |
| 313 | expect(ptr.a == maxInt(u16)); | |
| 314 | expect(ptr.b[0].field == 0); | |
| 315 | expect(ptr.b[1].field == 0); | |
| 316 | expect(ptr.c == 0); | |
| 317 | 317 | |
| 318 | 318 | ptr.b[0].field = maxInt(u24); |
| 319 | assertOrPanic(ptr.a == maxInt(u16)); | |
| 320 | assertOrPanic(ptr.b[0].field == maxInt(u24)); | |
| 321 | assertOrPanic(ptr.b[1].field == 0); | |
| 322 | assertOrPanic(ptr.c == 0); | |
| 319 | expect(ptr.a == maxInt(u16)); | |
| 320 | expect(ptr.b[0].field == maxInt(u24)); | |
| 321 | expect(ptr.b[1].field == 0); | |
| 322 | expect(ptr.c == 0); | |
| 323 | 323 | |
| 324 | 324 | ptr.b[1].field = maxInt(u24); |
| 325 | assertOrPanic(ptr.a == maxInt(u16)); | |
| 326 | assertOrPanic(ptr.b[0].field == maxInt(u24)); | |
| 327 | assertOrPanic(ptr.b[1].field == maxInt(u24)); | |
| 328 | assertOrPanic(ptr.c == 0); | |
| 325 | expect(ptr.a == maxInt(u16)); | |
| 326 | expect(ptr.b[0].field == maxInt(u24)); | |
| 327 | expect(ptr.b[1].field == maxInt(u24)); | |
| 328 | expect(ptr.c == 0); | |
| 329 | 329 | |
| 330 | 330 | ptr.c = maxInt(u16); |
| 331 | assertOrPanic(ptr.a == maxInt(u16)); | |
| 332 | assertOrPanic(ptr.b[0].field == maxInt(u24)); | |
| 333 | assertOrPanic(ptr.b[1].field == maxInt(u24)); | |
| 334 | assertOrPanic(ptr.c == maxInt(u16)); | |
| 331 | expect(ptr.a == maxInt(u16)); | |
| 332 | expect(ptr.b[0].field == maxInt(u24)); | |
| 333 | expect(ptr.b[1].field == maxInt(u24)); | |
| 334 | expect(ptr.c == maxInt(u16)); | |
| 335 | 335 | |
| 336 | assertOrPanic(bytes[bytes.len - 1] == 0xaa); | |
| 336 | expect(bytes[bytes.len - 1] == 0xaa); | |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | const FooStructAligned = packed struct { |
| ... | ... | @@ -347,17 +347,17 @@ const FooArrayOfAligned = packed struct { |
| 347 | 347 | |
| 348 | 348 | test "aligned array of packed struct" { |
| 349 | 349 | comptime { |
| 350 | assertOrPanic(@sizeOf(FooStructAligned) == 2); | |
| 351 | assertOrPanic(@sizeOf(FooArrayOfAligned) == 2 * 2); | |
| 350 | expect(@sizeOf(FooStructAligned) == 2); | |
| 351 | expect(@sizeOf(FooArrayOfAligned) == 2 * 2); | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned); |
| 355 | 355 | const ptr = &@bytesToSlice(FooArrayOfAligned, bytes[0..bytes.len])[0]; |
| 356 | 356 | |
| 357 | assertOrPanic(ptr.a[0].a == 0xbb); | |
| 358 | assertOrPanic(ptr.a[0].b == 0xbb); | |
| 359 | assertOrPanic(ptr.a[1].a == 0xbb); | |
| 360 | assertOrPanic(ptr.a[1].b == 0xbb); | |
| 357 | expect(ptr.a[0].a == 0xbb); | |
| 358 | expect(ptr.a[0].b == 0xbb); | |
| 359 | expect(ptr.a[1].a == 0xbb); | |
| 360 | expect(ptr.a[1].b == 0xbb); | |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | test "runtime struct initialization of bitfield" { |
| ... | ... | @@ -370,10 +370,10 @@ test "runtime struct initialization of bitfield" { |
| 370 | 370 | .y = @intCast(u4, x2), |
| 371 | 371 | }; |
| 372 | 372 | |
| 373 | assertOrPanic(s1.x == x1); | |
| 374 | assertOrPanic(s1.y == x1); | |
| 375 | assertOrPanic(s2.x == @intCast(u4, x2)); | |
| 376 | assertOrPanic(s2.y == @intCast(u4, x2)); | |
| 373 | expect(s1.x == x1); | |
| 374 | expect(s1.y == x1); | |
| 375 | expect(s2.x == @intCast(u4, x2)); | |
| 376 | expect(s2.y == @intCast(u4, x2)); | |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | var x1 = u4(1); |
| ... | ... | @@ -400,18 +400,18 @@ test "native bit field understands endianness" { |
| 400 | 400 | @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8); |
| 401 | 401 | var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*; |
| 402 | 402 | |
| 403 | assertOrPanic(bitfields.f1 == 0x1111); | |
| 404 | assertOrPanic(bitfields.f2 == 0x2222); | |
| 405 | assertOrPanic(bitfields.f3 == 0x33); | |
| 406 | assertOrPanic(bitfields.f4 == 0x44); | |
| 407 | assertOrPanic(bitfields.f5 == 0x5); | |
| 408 | assertOrPanic(bitfields.f6 == 0x6); | |
| 409 | assertOrPanic(bitfields.f7 == 0x77); | |
| 403 | expect(bitfields.f1 == 0x1111); | |
| 404 | expect(bitfields.f2 == 0x2222); | |
| 405 | expect(bitfields.f3 == 0x33); | |
| 406 | expect(bitfields.f4 == 0x44); | |
| 407 | expect(bitfields.f5 == 0x5); | |
| 408 | expect(bitfields.f6 == 0x6); | |
| 409 | expect(bitfields.f7 == 0x77); | |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | test "align 1 field before self referential align 8 field as slice return type" { |
| 413 | 413 | const result = alloc(Expr); |
| 414 | assertOrPanic(result.len == 0); | |
| 414 | expect(result.len == 0); | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | const Expr = union(enum) { |
| ... | ... | @@ -434,10 +434,10 @@ test "call method with mutable reference to struct with no fields" { |
| 434 | 434 | }; |
| 435 | 435 | |
| 436 | 436 | var s = S{}; |
| 437 | assertOrPanic(S.doC(&s)); | |
| 438 | assertOrPanic(s.doC()); | |
| 439 | assertOrPanic(S.do(&s)); | |
| 440 | assertOrPanic(s.do()); | |
| 437 | expect(S.doC(&s)); | |
| 438 | expect(s.doC()); | |
| 439 | expect(S.do(&s)); | |
| 440 | expect(s.do()); | |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | test "implicit cast packed struct field to const ptr" { |
| ... | ... | @@ -453,7 +453,7 @@ test "implicit cast packed struct field to const ptr" { |
| 453 | 453 | var lup: LevelUpMove = undefined; |
| 454 | 454 | lup.level = 12; |
| 455 | 455 | const res = LevelUpMove.toInt(lup.level); |
| 456 | assertOrPanic(res == 12); | |
| 456 | expect(res == 12); | |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | test "pointer to packed struct member in a stack variable" { |
| ... | ... | @@ -464,7 +464,7 @@ test "pointer to packed struct member in a stack variable" { |
| 464 | 464 | |
| 465 | 465 | var s = S{ .a = 2, .b = 0 }; |
| 466 | 466 | var b_ptr = &s.b; |
| 467 | assertOrPanic(s.b == 0); | |
| 467 | expect(s.b == 0); | |
| 468 | 468 | b_ptr.* = 2; |
| 469 | assertOrPanic(s.b == 2); | |
| 469 | expect(s.b == 2); | |
| 470 | 470 | } |
test/stage1/behavior/struct_contains_null_ptr_itself.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "struct contains null pointer which contains original struct" { |
| 5 | 5 | var x: ?*NodeLineComment = null; |
| 6 | assertOrPanic(x == null); | |
| 6 | expect(x == null); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | pub const Node = struct { |
test/stage1/behavior/struct_contains_slice_of_itself.zig+13-13| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const Node = struct { |
| 4 | 4 | payload: i32, |
| ... | ... | @@ -39,12 +39,12 @@ test "struct contains slice of itself" { |
| 39 | 39 | .payload = 1234, |
| 40 | 40 | .children = nodes[0..], |
| 41 | 41 | }; |
| 42 | assertOrPanic(root.payload == 1234); | |
| 43 | assertOrPanic(root.children[0].payload == 1); | |
| 44 | assertOrPanic(root.children[1].payload == 2); | |
| 45 | assertOrPanic(root.children[2].payload == 3); | |
| 46 | assertOrPanic(root.children[2].children[0].payload == 31); | |
| 47 | assertOrPanic(root.children[2].children[1].payload == 32); | |
| 42 | expect(root.payload == 1234); | |
| 43 | expect(root.children[0].payload == 1); | |
| 44 | expect(root.children[1].payload == 2); | |
| 45 | expect(root.children[2].payload == 3); | |
| 46 | expect(root.children[2].children[0].payload == 31); | |
| 47 | expect(root.children[2].children[1].payload == 32); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "struct contains aligned slice of itself" { |
| ... | ... | @@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" { |
| 76 | 76 | .payload = 1234, |
| 77 | 77 | .children = nodes[0..], |
| 78 | 78 | }; |
| 79 | assertOrPanic(root.payload == 1234); | |
| 80 | assertOrPanic(root.children[0].payload == 1); | |
| 81 | assertOrPanic(root.children[1].payload == 2); | |
| 82 | assertOrPanic(root.children[2].payload == 3); | |
| 83 | assertOrPanic(root.children[2].children[0].payload == 31); | |
| 84 | assertOrPanic(root.children[2].children[1].payload == 32); | |
| 79 | expect(root.payload == 1234); | |
| 80 | expect(root.children[0].payload == 1); | |
| 81 | expect(root.children[1].payload == 2); | |
| 82 | expect(root.children[2].payload == 3); | |
| 83 | expect(root.children[2].children[0].payload == 31); | |
| 84 | expect(root.children[2].children[1].payload == 32); | |
| 85 | 85 | } |
test/stage1/behavior/switch.zig+33-33| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "switch with numbers" { |
| 4 | 4 | testSwitchWithNumbers(13); |
| ... | ... | @@ -10,14 +10,14 @@ fn testSwitchWithNumbers(x: u32) void { |
| 10 | 10 | 13 => true, |
| 11 | 11 | else => false, |
| 12 | 12 | }; |
| 13 | assertOrPanic(result); | |
| 13 | expect(result); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | test "switch with all ranges" { |
| 17 | assertOrPanic(testSwitchWithAllRanges(50, 3) == 1); | |
| 18 | assertOrPanic(testSwitchWithAllRanges(101, 0) == 2); | |
| 19 | assertOrPanic(testSwitchWithAllRanges(300, 5) == 3); | |
| 20 | assertOrPanic(testSwitchWithAllRanges(301, 6) == 6); | |
| 17 | expect(testSwitchWithAllRanges(50, 3) == 1); | |
| 18 | expect(testSwitchWithAllRanges(101, 0) == 2); | |
| 19 | expect(testSwitchWithAllRanges(300, 5) == 3); | |
| 20 | expect(testSwitchWithAllRanges(301, 6) == 6); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | fn testSwitchWithAllRanges(x: u32, y: u32) u32 { |
| ... | ... | @@ -40,7 +40,7 @@ test "implicit comptime switch" { |
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | 42 | comptime { |
| 43 | assertOrPanic(result + 1 == 14); | |
| 43 | expect(result + 1 == 14); | |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| ... | ... | @@ -71,7 +71,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) void { |
| 71 | 71 | SwitchStatmentFoo.C => 3, |
| 72 | 72 | SwitchStatmentFoo.D => 4, |
| 73 | 73 | }; |
| 74 | assertOrPanic(val == 3); | |
| 74 | expect(val == 3); | |
| 75 | 75 | } |
| 76 | 76 | const SwitchStatmentFoo = enum { |
| 77 | 77 | A, |
| ... | ... | @@ -93,10 +93,10 @@ const SwitchProngWithVarEnum = union(enum) { |
| 93 | 93 | fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void { |
| 94 | 94 | switch (a) { |
| 95 | 95 | SwitchProngWithVarEnum.One => |x| { |
| 96 | assertOrPanic(x == 13); | |
| 96 | expect(x == 13); | |
| 97 | 97 | }, |
| 98 | 98 | SwitchProngWithVarEnum.Two => |x| { |
| 99 | assertOrPanic(x == 13.0); | |
| 99 | expect(x == 13.0); | |
| 100 | 100 | }, |
| 101 | 101 | SwitchProngWithVarEnum.Meh => |x| { |
| 102 | 102 | const v: void = x; |
| ... | ... | @@ -116,7 +116,7 @@ fn testSwitchEnumPtrCapture() void { |
| 116 | 116 | else => unreachable, |
| 117 | 117 | } |
| 118 | 118 | switch (value) { |
| 119 | SwitchProngWithVarEnum.One => |x| assertOrPanic(x == 1235), | |
| 119 | SwitchProngWithVarEnum.One => |x| expect(x == 1235), | |
| 120 | 120 | else => unreachable, |
| 121 | 121 | } |
| 122 | 122 | } |
| ... | ... | @@ -127,7 +127,7 @@ test "switch with multiple expressions" { |
| 127 | 127 | 4, 5, 6 => 2, |
| 128 | 128 | else => i32(3), |
| 129 | 129 | }; |
| 130 | assertOrPanic(x == 2); | |
| 130 | expect(x == 2); | |
| 131 | 131 | } |
| 132 | 132 | fn returnsFive() i32 { |
| 133 | 133 | return 5; |
| ... | ... | @@ -149,12 +149,12 @@ fn returnsFalse() bool { |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | test "switch on const enum with var" { |
| 152 | assertOrPanic(!returnsFalse()); | |
| 152 | expect(!returnsFalse()); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | test "switch on type" { |
| 156 | assertOrPanic(trueIfBoolFalseOtherwise(bool)); | |
| 157 | assertOrPanic(!trueIfBoolFalseOtherwise(i32)); | |
| 156 | expect(trueIfBoolFalseOtherwise(bool)); | |
| 157 | expect(!trueIfBoolFalseOtherwise(i32)); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | fn trueIfBoolFalseOtherwise(comptime T: type) bool { |
| ... | ... | @@ -170,16 +170,16 @@ test "switch handles all cases of number" { |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | fn testSwitchHandleAllCases() void { |
| 173 | assertOrPanic(testSwitchHandleAllCasesExhaustive(0) == 3); | |
| 174 | assertOrPanic(testSwitchHandleAllCasesExhaustive(1) == 2); | |
| 175 | assertOrPanic(testSwitchHandleAllCasesExhaustive(2) == 1); | |
| 176 | assertOrPanic(testSwitchHandleAllCasesExhaustive(3) == 0); | |
| 173 | expect(testSwitchHandleAllCasesExhaustive(0) == 3); | |
| 174 | expect(testSwitchHandleAllCasesExhaustive(1) == 2); | |
| 175 | expect(testSwitchHandleAllCasesExhaustive(2) == 1); | |
| 176 | expect(testSwitchHandleAllCasesExhaustive(3) == 0); | |
| 177 | 177 | |
| 178 | assertOrPanic(testSwitchHandleAllCasesRange(100) == 0); | |
| 179 | assertOrPanic(testSwitchHandleAllCasesRange(200) == 1); | |
| 180 | assertOrPanic(testSwitchHandleAllCasesRange(201) == 2); | |
| 181 | assertOrPanic(testSwitchHandleAllCasesRange(202) == 4); | |
| 182 | assertOrPanic(testSwitchHandleAllCasesRange(230) == 3); | |
| 178 | expect(testSwitchHandleAllCasesRange(100) == 0); | |
| 179 | expect(testSwitchHandleAllCasesRange(200) == 1); | |
| 180 | expect(testSwitchHandleAllCasesRange(201) == 2); | |
| 181 | expect(testSwitchHandleAllCasesRange(202) == 4); | |
| 182 | expect(testSwitchHandleAllCasesRange(230) == 3); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| ... | ... | @@ -207,8 +207,8 @@ test "switch all prongs unreachable" { |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | fn testAllProngsUnreachable() void { |
| 210 | assertOrPanic(switchWithUnreachable(1) == 2); | |
| 211 | assertOrPanic(switchWithUnreachable(2) == 10); | |
| 210 | expect(switchWithUnreachable(1) == 2); | |
| 211 | expect(switchWithUnreachable(2) == 10); | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | fn switchWithUnreachable(x: i32) i32 { |
| ... | ... | @@ -230,7 +230,7 @@ test "capture value of switch with all unreachable prongs" { |
| 230 | 230 | const x = return_a_number() catch |err| switch (err) { |
| 231 | 231 | else => unreachable, |
| 232 | 232 | }; |
| 233 | assertOrPanic(x == 1); | |
| 233 | expect(x == 1); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | test "switching on booleans" { |
| ... | ... | @@ -239,14 +239,14 @@ test "switching on booleans" { |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | fn testSwitchOnBools() void { |
| 242 | assertOrPanic(testSwitchOnBoolsTrueAndFalse(true) == false); | |
| 243 | assertOrPanic(testSwitchOnBoolsTrueAndFalse(false) == true); | |
| 242 | expect(testSwitchOnBoolsTrueAndFalse(true) == false); | |
| 243 | expect(testSwitchOnBoolsTrueAndFalse(false) == true); | |
| 244 | 244 | |
| 245 | assertOrPanic(testSwitchOnBoolsTrueWithElse(true) == false); | |
| 246 | assertOrPanic(testSwitchOnBoolsTrueWithElse(false) == true); | |
| 245 | expect(testSwitchOnBoolsTrueWithElse(true) == false); | |
| 246 | expect(testSwitchOnBoolsTrueWithElse(false) == true); | |
| 247 | 247 | |
| 248 | assertOrPanic(testSwitchOnBoolsFalseWithElse(true) == false); | |
| 249 | assertOrPanic(testSwitchOnBoolsFalseWithElse(false) == true); | |
| 248 | expect(testSwitchOnBoolsFalseWithElse(true) == false); | |
| 249 | expect(testSwitchOnBoolsFalseWithElse(false) == true); | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | fn testSwitchOnBoolsTrueAndFalse(x: bool) bool { |
test/stage1/behavior/switch_prong_err_enum.zig+3-3| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | var read_count: u64 = 0; |
| 4 | 4 | |
| ... | ... | @@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue { |
| 22 | 22 | test "switch prong returns error enum" { |
| 23 | 23 | switch (doThing(17) catch unreachable) { |
| 24 | 24 | FormValue.Address => |payload| { |
| 25 | assertOrPanic(payload == 1); | |
| 25 | expect(payload == 1); | |
| 26 | 26 | }, |
| 27 | 27 | else => unreachable, |
| 28 | 28 | } |
| 29 | assertOrPanic(read_count == 1); | |
| 29 | expect(read_count == 1); | |
| 30 | 30 | } |
test/stage1/behavior/switch_prong_implicit_cast.zig+2-2| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const FormValue = union(enum) { |
| 4 | 4 | One: void, |
| ... | ... | @@ -18,5 +18,5 @@ test "switch prong implicit cast" { |
| 18 | 18 | FormValue.One => false, |
| 19 | 19 | FormValue.Two => |x| x, |
| 20 | 20 | }; |
| 21 | assertOrPanic(result); | |
| 21 | expect(result); | |
| 22 | 22 | } |
test/stage1/behavior/this.zig+4-4| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const module = @This(); |
| 4 | 4 | |
| ... | ... | @@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "this refer to module call private fn" { |
| 23 | assertOrPanic(module.add(1, 2) == 3); | |
| 23 | expect(module.add(1, 2) == 3); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | test "this refer to container" { |
| ... | ... | @@ -29,7 +29,7 @@ test "this refer to container" { |
| 29 | 29 | .y = 34, |
| 30 | 30 | }; |
| 31 | 31 | pt.addOne(); |
| 32 | assertOrPanic(pt.x == 13); | |
| 33 | assertOrPanic(pt.y == 35); | |
| 32 | expect(pt.x == 13); | |
| 33 | expect(pt.y == 35); | |
| 34 | 34 | } |
| 35 | 35 |
test/stage1/behavior/truncate.zig+2-2| ... | ... | @@ -1,8 +1,8 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "truncate u0 to larger integer allowed and has comptime known result" { |
| 5 | 5 | var x: u0 = 0; |
| 6 | 6 | const y = @truncate(u8, x); |
| 7 | comptime assertOrPanic(y == 0); | |
| 7 | comptime expect(y == 0); | |
| 8 | 8 | } |
test/stage1/behavior/try.zig+5-5| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "try on error union" { |
| 4 | 4 | tryOnErrorUnionImpl(); |
| ... | ... | @@ -11,7 +11,7 @@ fn tryOnErrorUnionImpl() void { |
| 11 | 11 | error.CrappedOut => i32(2), |
| 12 | 12 | else => unreachable, |
| 13 | 13 | }; |
| 14 | assertOrPanic(x == 11); | |
| 14 | expect(x == 11); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn returnsTen() anyerror!i32 { |
| ... | ... | @@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 { |
| 20 | 20 | |
| 21 | 21 | test "try without vars" { |
| 22 | 22 | const result1 = if (failIfTrue(true)) 1 else |_| i32(2); |
| 23 | assertOrPanic(result1 == 2); | |
| 23 | expect(result1 == 2); | |
| 24 | 24 | |
| 25 | 25 | const result2 = if (failIfTrue(false)) 1 else |_| i32(2); |
| 26 | assertOrPanic(result2 == 1); | |
| 26 | expect(result2 == 1); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | fn failIfTrue(ok: bool) anyerror!void { |
| ... | ... | @@ -38,6 +38,6 @@ test "try then not executed with assignment" { |
| 38 | 38 | if (failIfTrue(true)) { |
| 39 | 39 | unreachable; |
| 40 | 40 | } else |err| { |
| 41 | assertOrPanic(err == error.ItBroke); | |
| 41 | expect(err == error.ItBroke); | |
| 42 | 42 | } |
| 43 | 43 | } |
test/stage1/behavior/type_info.zig+91-91| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | const TypeInfo = @import("builtin").TypeInfo; |
| 4 | 4 | const TypeId = @import("builtin").TypeId; |
| ... | ... | @@ -9,10 +9,10 @@ test "type info: tag type, void info" { |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | fn testBasic() void { |
| 12 | assertOrPanic(@TagType(TypeInfo) == TypeId); | |
| 12 | expect(@TagType(TypeInfo) == TypeId); | |
| 13 | 13 | const void_info = @typeInfo(void); |
| 14 | assertOrPanic(TypeId(void_info) == TypeId.Void); | |
| 15 | assertOrPanic(void_info.Void == {}); | |
| 14 | expect(TypeId(void_info) == TypeId.Void); | |
| 15 | expect(void_info.Void == {}); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "type info: integer, floating point type info" { |
| ... | ... | @@ -22,13 +22,13 @@ test "type info: integer, floating point type info" { |
| 22 | 22 | |
| 23 | 23 | fn testIntFloat() void { |
| 24 | 24 | const u8_info = @typeInfo(u8); |
| 25 | assertOrPanic(TypeId(u8_info) == TypeId.Int); | |
| 26 | assertOrPanic(!u8_info.Int.is_signed); | |
| 27 | assertOrPanic(u8_info.Int.bits == 8); | |
| 25 | expect(TypeId(u8_info) == TypeId.Int); | |
| 26 | expect(!u8_info.Int.is_signed); | |
| 27 | expect(u8_info.Int.bits == 8); | |
| 28 | 28 | |
| 29 | 29 | const f64_info = @typeInfo(f64); |
| 30 | assertOrPanic(TypeId(f64_info) == TypeId.Float); | |
| 31 | assertOrPanic(f64_info.Float.bits == 64); | |
| 30 | expect(TypeId(f64_info) == TypeId.Float); | |
| 31 | expect(f64_info.Float.bits == 64); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "type info: pointer type info" { |
| ... | ... | @@ -38,12 +38,12 @@ test "type info: pointer type info" { |
| 38 | 38 | |
| 39 | 39 | fn testPointer() void { |
| 40 | 40 | const u32_ptr_info = @typeInfo(*u32); |
| 41 | assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 42 | assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); | |
| 43 | assertOrPanic(u32_ptr_info.Pointer.is_const == false); | |
| 44 | assertOrPanic(u32_ptr_info.Pointer.is_volatile == false); | |
| 45 | assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(u32)); | |
| 46 | assertOrPanic(u32_ptr_info.Pointer.child == u32); | |
| 41 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 42 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); | |
| 43 | expect(u32_ptr_info.Pointer.is_const == false); | |
| 44 | expect(u32_ptr_info.Pointer.is_volatile == false); | |
| 45 | expect(u32_ptr_info.Pointer.alignment == @alignOf(u32)); | |
| 46 | expect(u32_ptr_info.Pointer.child == u32); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "type info: unknown length pointer type info" { |
| ... | ... | @@ -53,12 +53,12 @@ test "type info: unknown length pointer type info" { |
| 53 | 53 | |
| 54 | 54 | fn testUnknownLenPtr() void { |
| 55 | 55 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 56 | assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 57 | assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 58 | assertOrPanic(u32_ptr_info.Pointer.is_const == true); | |
| 59 | assertOrPanic(u32_ptr_info.Pointer.is_volatile == true); | |
| 60 | assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(f64)); | |
| 61 | assertOrPanic(u32_ptr_info.Pointer.child == f64); | |
| 56 | expect(TypeId(u32_ptr_info) == TypeId.Pointer); | |
| 57 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 58 | expect(u32_ptr_info.Pointer.is_const == true); | |
| 59 | expect(u32_ptr_info.Pointer.is_volatile == true); | |
| 60 | expect(u32_ptr_info.Pointer.alignment == @alignOf(f64)); | |
| 61 | expect(u32_ptr_info.Pointer.child == f64); | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | test "type info: slice type info" { |
| ... | ... | @@ -68,12 +68,12 @@ test "type info: slice type info" { |
| 68 | 68 | |
| 69 | 69 | fn testSlice() void { |
| 70 | 70 | const u32_slice_info = @typeInfo([]u32); |
| 71 | assertOrPanic(TypeId(u32_slice_info) == TypeId.Pointer); | |
| 72 | assertOrPanic(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); | |
| 73 | assertOrPanic(u32_slice_info.Pointer.is_const == false); | |
| 74 | assertOrPanic(u32_slice_info.Pointer.is_volatile == false); | |
| 75 | assertOrPanic(u32_slice_info.Pointer.alignment == 4); | |
| 76 | assertOrPanic(u32_slice_info.Pointer.child == u32); | |
| 71 | expect(TypeId(u32_slice_info) == TypeId.Pointer); | |
| 72 | expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); | |
| 73 | expect(u32_slice_info.Pointer.is_const == false); | |
| 74 | expect(u32_slice_info.Pointer.is_volatile == false); | |
| 75 | expect(u32_slice_info.Pointer.alignment == 4); | |
| 76 | expect(u32_slice_info.Pointer.child == u32); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | test "type info: array type info" { |
| ... | ... | @@ -83,9 +83,9 @@ test "type info: array type info" { |
| 83 | 83 | |
| 84 | 84 | fn testArray() void { |
| 85 | 85 | const arr_info = @typeInfo([42]bool); |
| 86 | assertOrPanic(TypeId(arr_info) == TypeId.Array); | |
| 87 | assertOrPanic(arr_info.Array.len == 42); | |
| 88 | assertOrPanic(arr_info.Array.child == bool); | |
| 86 | expect(TypeId(arr_info) == TypeId.Array); | |
| 87 | expect(arr_info.Array.len == 42); | |
| 88 | expect(arr_info.Array.child == bool); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "type info: optional type info" { |
| ... | ... | @@ -95,8 +95,8 @@ test "type info: optional type info" { |
| 95 | 95 | |
| 96 | 96 | fn testOptional() void { |
| 97 | 97 | const null_info = @typeInfo(?void); |
| 98 | assertOrPanic(TypeId(null_info) == TypeId.Optional); | |
| 99 | assertOrPanic(null_info.Optional.child == void); | |
| 98 | expect(TypeId(null_info) == TypeId.Optional); | |
| 99 | expect(null_info.Optional.child == void); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "type info: promise info" { |
| ... | ... | @@ -106,12 +106,12 @@ test "type info: promise info" { |
| 106 | 106 | |
| 107 | 107 | fn testPromise() void { |
| 108 | 108 | const null_promise_info = @typeInfo(promise); |
| 109 | assertOrPanic(TypeId(null_promise_info) == TypeId.Promise); | |
| 110 | assertOrPanic(null_promise_info.Promise.child == null); | |
| 109 | expect(TypeId(null_promise_info) == TypeId.Promise); | |
| 110 | expect(null_promise_info.Promise.child == null); | |
| 111 | 111 | |
| 112 | 112 | const promise_info = @typeInfo(promise->usize); |
| 113 | assertOrPanic(TypeId(promise_info) == TypeId.Promise); | |
| 114 | assertOrPanic(promise_info.Promise.child.? == usize); | |
| 113 | expect(TypeId(promise_info) == TypeId.Promise); | |
| 114 | expect(promise_info.Promise.child.? == usize); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "type info: error set, error union info" { |
| ... | ... | @@ -127,15 +127,15 @@ fn testErrorSet() void { |
| 127 | 127 | }; |
| 128 | 128 | |
| 129 | 129 | const error_set_info = @typeInfo(TestErrorSet); |
| 130 | assertOrPanic(TypeId(error_set_info) == TypeId.ErrorSet); | |
| 131 | assertOrPanic(error_set_info.ErrorSet.errors.len == 3); | |
| 132 | assertOrPanic(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First")); | |
| 133 | assertOrPanic(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third)); | |
| 130 | expect(TypeId(error_set_info) == TypeId.ErrorSet); | |
| 131 | expect(error_set_info.ErrorSet.errors.len == 3); | |
| 132 | expect(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First")); | |
| 133 | expect(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third)); | |
| 134 | 134 | |
| 135 | 135 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 136 | assertOrPanic(TypeId(error_union_info) == TypeId.ErrorUnion); | |
| 137 | assertOrPanic(error_union_info.ErrorUnion.error_set == TestErrorSet); | |
| 138 | assertOrPanic(error_union_info.ErrorUnion.payload == usize); | |
| 136 | expect(TypeId(error_union_info) == TypeId.ErrorUnion); | |
| 137 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); | |
| 138 | expect(error_union_info.ErrorUnion.payload == usize); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "type info: enum info" { |
| ... | ... | @@ -152,13 +152,13 @@ fn testEnum() void { |
| 152 | 152 | }; |
| 153 | 153 | |
| 154 | 154 | const os_info = @typeInfo(Os); |
| 155 | assertOrPanic(TypeId(os_info) == TypeId.Enum); | |
| 156 | assertOrPanic(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); | |
| 157 | assertOrPanic(os_info.Enum.fields.len == 4); | |
| 158 | assertOrPanic(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); | |
| 159 | assertOrPanic(os_info.Enum.fields[3].value == 3); | |
| 160 | assertOrPanic(os_info.Enum.tag_type == u2); | |
| 161 | assertOrPanic(os_info.Enum.defs.len == 0); | |
| 155 | expect(TypeId(os_info) == TypeId.Enum); | |
| 156 | expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); | |
| 157 | expect(os_info.Enum.fields.len == 4); | |
| 158 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); | |
| 159 | expect(os_info.Enum.fields[3].value == 3); | |
| 160 | expect(os_info.Enum.tag_type == u2); | |
| 161 | expect(os_info.Enum.defs.len == 0); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | test "type info: union info" { |
| ... | ... | @@ -168,14 +168,14 @@ test "type info: union info" { |
| 168 | 168 | |
| 169 | 169 | fn testUnion() void { |
| 170 | 170 | const typeinfo_info = @typeInfo(TypeInfo); |
| 171 | assertOrPanic(TypeId(typeinfo_info) == TypeId.Union); | |
| 172 | assertOrPanic(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); | |
| 173 | assertOrPanic(typeinfo_info.Union.tag_type.? == TypeId); | |
| 174 | assertOrPanic(typeinfo_info.Union.fields.len == 25); | |
| 175 | assertOrPanic(typeinfo_info.Union.fields[4].enum_field != null); | |
| 176 | assertOrPanic(typeinfo_info.Union.fields[4].enum_field.?.value == 4); | |
| 177 | assertOrPanic(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); | |
| 178 | assertOrPanic(typeinfo_info.Union.defs.len == 21); | |
| 171 | expect(TypeId(typeinfo_info) == TypeId.Union); | |
| 172 | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); | |
| 173 | expect(typeinfo_info.Union.tag_type.? == TypeId); | |
| 174 | expect(typeinfo_info.Union.fields.len == 25); | |
| 175 | expect(typeinfo_info.Union.fields[4].enum_field != null); | |
| 176 | expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); | |
| 177 | expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); | |
| 178 | expect(typeinfo_info.Union.defs.len == 21); | |
| 179 | 179 | |
| 180 | 180 | const TestNoTagUnion = union { |
| 181 | 181 | Foo: void, |
| ... | ... | @@ -183,22 +183,22 @@ fn testUnion() void { |
| 183 | 183 | }; |
| 184 | 184 | |
| 185 | 185 | const notag_union_info = @typeInfo(TestNoTagUnion); |
| 186 | assertOrPanic(TypeId(notag_union_info) == TypeId.Union); | |
| 187 | assertOrPanic(notag_union_info.Union.tag_type == null); | |
| 188 | assertOrPanic(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); | |
| 189 | assertOrPanic(notag_union_info.Union.fields.len == 2); | |
| 190 | assertOrPanic(notag_union_info.Union.fields[0].enum_field == null); | |
| 191 | assertOrPanic(notag_union_info.Union.fields[1].field_type == u32); | |
| 186 | expect(TypeId(notag_union_info) == TypeId.Union); | |
| 187 | expect(notag_union_info.Union.tag_type == null); | |
| 188 | expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); | |
| 189 | expect(notag_union_info.Union.fields.len == 2); | |
| 190 | expect(notag_union_info.Union.fields[0].enum_field == null); | |
| 191 | expect(notag_union_info.Union.fields[1].field_type == u32); | |
| 192 | 192 | |
| 193 | 193 | const TestExternUnion = extern union { |
| 194 | 194 | foo: *c_void, |
| 195 | 195 | }; |
| 196 | 196 | |
| 197 | 197 | const extern_union_info = @typeInfo(TestExternUnion); |
| 198 | assertOrPanic(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern); | |
| 199 | assertOrPanic(extern_union_info.Union.tag_type == null); | |
| 200 | assertOrPanic(extern_union_info.Union.fields[0].enum_field == null); | |
| 201 | assertOrPanic(extern_union_info.Union.fields[0].field_type == *c_void); | |
| 198 | expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern); | |
| 199 | expect(extern_union_info.Union.tag_type == null); | |
| 200 | expect(extern_union_info.Union.fields[0].enum_field == null); | |
| 201 | expect(extern_union_info.Union.fields[0].field_type == *c_void); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "type info: struct info" { |
| ... | ... | @@ -208,17 +208,17 @@ test "type info: struct info" { |
| 208 | 208 | |
| 209 | 209 | fn testStruct() void { |
| 210 | 210 | const struct_info = @typeInfo(TestStruct); |
| 211 | assertOrPanic(TypeId(struct_info) == TypeId.Struct); | |
| 212 | assertOrPanic(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); | |
| 213 | assertOrPanic(struct_info.Struct.fields.len == 3); | |
| 214 | assertOrPanic(struct_info.Struct.fields[1].offset == null); | |
| 215 | assertOrPanic(struct_info.Struct.fields[2].field_type == *TestStruct); | |
| 216 | assertOrPanic(struct_info.Struct.defs.len == 2); | |
| 217 | assertOrPanic(struct_info.Struct.defs[0].is_pub); | |
| 218 | assertOrPanic(!struct_info.Struct.defs[0].data.Fn.is_extern); | |
| 219 | assertOrPanic(struct_info.Struct.defs[0].data.Fn.lib_name == null); | |
| 220 | assertOrPanic(struct_info.Struct.defs[0].data.Fn.return_type == void); | |
| 221 | assertOrPanic(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void); | |
| 211 | expect(TypeId(struct_info) == TypeId.Struct); | |
| 212 | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); | |
| 213 | expect(struct_info.Struct.fields.len == 3); | |
| 214 | expect(struct_info.Struct.fields[1].offset == null); | |
| 215 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); | |
| 216 | expect(struct_info.Struct.defs.len == 2); | |
| 217 | expect(struct_info.Struct.defs[0].is_pub); | |
| 218 | expect(!struct_info.Struct.defs[0].data.Fn.is_extern); | |
| 219 | expect(struct_info.Struct.defs[0].data.Fn.lib_name == null); | |
| 220 | expect(struct_info.Struct.defs[0].data.Fn.return_type == void); | |
| 221 | expect(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | const TestStruct = packed struct { |
| ... | ... | @@ -238,18 +238,18 @@ test "type info: function type info" { |
| 238 | 238 | |
| 239 | 239 | fn testFunction() void { |
| 240 | 240 | const fn_info = @typeInfo(@typeOf(foo)); |
| 241 | assertOrPanic(TypeId(fn_info) == TypeId.Fn); | |
| 242 | assertOrPanic(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); | |
| 243 | assertOrPanic(fn_info.Fn.is_generic); | |
| 244 | assertOrPanic(fn_info.Fn.args.len == 2); | |
| 245 | assertOrPanic(fn_info.Fn.is_var_args); | |
| 246 | assertOrPanic(fn_info.Fn.return_type == null); | |
| 247 | assertOrPanic(fn_info.Fn.async_allocator_type == null); | |
| 241 | expect(TypeId(fn_info) == TypeId.Fn); | |
| 242 | expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); | |
| 243 | expect(fn_info.Fn.is_generic); | |
| 244 | expect(fn_info.Fn.args.len == 2); | |
| 245 | expect(fn_info.Fn.is_var_args); | |
| 246 | expect(fn_info.Fn.return_type == null); | |
| 247 | expect(fn_info.Fn.async_allocator_type == null); | |
| 248 | 248 | |
| 249 | 249 | const test_instance: TestStruct = undefined; |
| 250 | 250 | const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); |
| 251 | assertOrPanic(TypeId(bound_fn_info) == TypeId.BoundFn); | |
| 252 | assertOrPanic(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); | |
| 251 | expect(TypeId(bound_fn_info) == TypeId.BoundFn); | |
| 252 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | fn foo(comptime a: usize, b: bool, args: ...) usize { |
| ... | ... | @@ -270,7 +270,7 @@ test "type info: vectors" { |
| 270 | 270 | |
| 271 | 271 | fn testVector() void { |
| 272 | 272 | const vec_info = @typeInfo(@Vector(4, i32)); |
| 273 | assertOrPanic(TypeId(vec_info) == TypeId.Vector); | |
| 274 | assertOrPanic(vec_info.Vector.len == 4); | |
| 275 | assertOrPanic(vec_info.Vector.child == i32); | |
| 273 | expect(TypeId(vec_info) == TypeId.Vector); | |
| 274 | expect(vec_info.Vector.len == 4); | |
| 275 | expect(vec_info.Vector.child == i32); | |
| 276 | 276 | } |
test/stage1/behavior/undefined.zig+14-14| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | fn initStaticArray() [10]i32 { |
| ... | ... | @@ -11,16 +11,16 @@ fn initStaticArray() [10]i32 { |
| 11 | 11 | } |
| 12 | 12 | const static_array = initStaticArray(); |
| 13 | 13 | test "init static array to undefined" { |
| 14 | assertOrPanic(static_array[0] == 1); | |
| 15 | assertOrPanic(static_array[4] == 2); | |
| 16 | assertOrPanic(static_array[7] == 3); | |
| 17 | assertOrPanic(static_array[9] == 4); | |
| 14 | expect(static_array[0] == 1); | |
| 15 | expect(static_array[4] == 2); | |
| 16 | expect(static_array[7] == 3); | |
| 17 | expect(static_array[9] == 4); | |
| 18 | 18 | |
| 19 | 19 | comptime { |
| 20 | assertOrPanic(static_array[0] == 1); | |
| 21 | assertOrPanic(static_array[4] == 2); | |
| 22 | assertOrPanic(static_array[7] == 3); | |
| 23 | assertOrPanic(static_array[9] == 4); | |
| 20 | expect(static_array[0] == 1); | |
| 21 | expect(static_array[4] == 2); | |
| 22 | expect(static_array[7] == 3); | |
| 23 | expect(static_array[9] == 4); | |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
| ... | ... | @@ -40,12 +40,12 @@ test "assign undefined to struct" { |
| 40 | 40 | comptime { |
| 41 | 41 | var foo: Foo = undefined; |
| 42 | 42 | setFooX(&foo); |
| 43 | assertOrPanic(foo.x == 2); | |
| 43 | expect(foo.x == 2); | |
| 44 | 44 | } |
| 45 | 45 | { |
| 46 | 46 | var foo: Foo = undefined; |
| 47 | 47 | setFooX(&foo); |
| 48 | assertOrPanic(foo.x == 2); | |
| 48 | expect(foo.x == 2); | |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| ... | ... | @@ -53,17 +53,17 @@ test "assign undefined to struct with method" { |
| 53 | 53 | comptime { |
| 54 | 54 | var foo: Foo = undefined; |
| 55 | 55 | foo.setFooXMethod(); |
| 56 | assertOrPanic(foo.x == 3); | |
| 56 | expect(foo.x == 3); | |
| 57 | 57 | } |
| 58 | 58 | { |
| 59 | 59 | var foo: Foo = undefined; |
| 60 | 60 | foo.setFooXMethod(); |
| 61 | assertOrPanic(foo.x == 3); | |
| 61 | expect(foo.x == 3); | |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | test "type name of undefined" { |
| 66 | 66 | const x = undefined; |
| 67 | assertOrPanic(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)")); | |
| 67 | expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)")); | |
| 68 | 68 | } |
| 69 | 69 |
test/stage1/behavior/underscore.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | test "ignore lval with underscore" { |
| 5 | 5 | _ = false; |
test/stage1/behavior/union.zig+38-38| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const Value = union(enum) { |
| 4 | 4 | Int: u64, |
| ... | ... | @@ -27,11 +27,11 @@ const array = []Value{ |
| 27 | 27 | |
| 28 | 28 | test "unions embedded in aggregate types" { |
| 29 | 29 | switch (array[1]) { |
| 30 | Value.Array => |arr| assertOrPanic(arr[4] == 3), | |
| 30 | Value.Array => |arr| expect(arr[4] == 3), | |
| 31 | 31 | else => unreachable, |
| 32 | 32 | } |
| 33 | 33 | switch ((err catch unreachable).val1) { |
| 34 | Value.Int => |x| assertOrPanic(x == 1234), | |
| 34 | Value.Int => |x| expect(x == 1234), | |
| 35 | 35 | else => unreachable, |
| 36 | 36 | } |
| 37 | 37 | } |
| ... | ... | @@ -43,18 +43,18 @@ const Foo = union { |
| 43 | 43 | |
| 44 | 44 | test "basic unions" { |
| 45 | 45 | var foo = Foo{ .int = 1 }; |
| 46 | assertOrPanic(foo.int == 1); | |
| 46 | expect(foo.int == 1); | |
| 47 | 47 | foo = Foo{ .float = 12.34 }; |
| 48 | assertOrPanic(foo.float == 12.34); | |
| 48 | expect(foo.float == 12.34); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | test "comptime union field access" { |
| 52 | 52 | comptime { |
| 53 | 53 | var foo = Foo{ .int = 0 }; |
| 54 | assertOrPanic(foo.int == 0); | |
| 54 | expect(foo.int == 0); | |
| 55 | 55 | |
| 56 | 56 | foo = Foo{ .float = 42.42 }; |
| 57 | assertOrPanic(foo.float == 42.42); | |
| 57 | expect(foo.float == 42.42); | |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| ... | ... | @@ -62,10 +62,10 @@ test "init union with runtime value" { |
| 62 | 62 | var foo: Foo = undefined; |
| 63 | 63 | |
| 64 | 64 | setFloat(&foo, 12.34); |
| 65 | assertOrPanic(foo.float == 12.34); | |
| 65 | expect(foo.float == 12.34); | |
| 66 | 66 | |
| 67 | 67 | setInt(&foo, 42); |
| 68 | assertOrPanic(foo.int == 42); | |
| 68 | expect(foo.int == 42); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | fn setFloat(foo: *Foo, x: f64) void { |
| ... | ... | @@ -83,9 +83,9 @@ const FooExtern = extern union { |
| 83 | 83 | |
| 84 | 84 | test "basic extern unions" { |
| 85 | 85 | var foo = FooExtern{ .int = 1 }; |
| 86 | assertOrPanic(foo.int == 1); | |
| 86 | expect(foo.int == 1); | |
| 87 | 87 | foo.float = 12.34; |
| 88 | assertOrPanic(foo.float == 12.34); | |
| 88 | expect(foo.float == 12.34); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | const Letter = enum { |
| ... | ... | @@ -105,11 +105,11 @@ test "union with specified enum tag" { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | fn doTest() void { |
| 108 | assertOrPanic(bar(Payload{ .A = 1234 }) == -10); | |
| 108 | expect(bar(Payload{ .A = 1234 }) == -10); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | fn bar(value: Payload) i32 { |
| 112 | assertOrPanic(Letter(value) == Letter.A); | |
| 112 | expect(Letter(value) == Letter.A); | |
| 113 | 113 | return switch (value) { |
| 114 | 114 | Payload.A => |x| return x - 1244, |
| 115 | 115 | Payload.B => |x| if (x == 12.34) i32(20) else 21, |
| ... | ... | @@ -125,8 +125,8 @@ const MultipleChoice = union(enum(u32)) { |
| 125 | 125 | }; |
| 126 | 126 | test "simple union(enum(u32))" { |
| 127 | 127 | var x = MultipleChoice.C; |
| 128 | assertOrPanic(x == MultipleChoice.C); | |
| 129 | assertOrPanic(@enumToInt(@TagType(MultipleChoice)(x)) == 60); | |
| 128 | expect(x == MultipleChoice.C); | |
| 129 | expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | const MultipleChoice2 = union(enum(u32)) { |
| ... | ... | @@ -142,14 +142,14 @@ const MultipleChoice2 = union(enum(u32)) { |
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | 144 | test "union(enum(u32)) with specified and unspecified tag values" { |
| 145 | comptime assertOrPanic(@TagType(@TagType(MultipleChoice2)) == u32); | |
| 145 | comptime expect(@TagType(@TagType(MultipleChoice2)) == u32); | |
| 146 | 146 | testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 147 | 147 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 151 | assertOrPanic(@enumToInt(@TagType(MultipleChoice2)(x)) == 60); | |
| 152 | assertOrPanic(1123 == switch (x) { | |
| 151 | expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60); | |
| 152 | expect(1123 == switch (x) { | |
| 153 | 153 | MultipleChoice2.A => 1, |
| 154 | 154 | MultipleChoice2.B => 2, |
| 155 | 155 | MultipleChoice2.C => |v| i32(1000) + v, |
| ... | ... | @@ -167,7 +167,7 @@ const ExternPtrOrInt = extern union { |
| 167 | 167 | int: u64, |
| 168 | 168 | }; |
| 169 | 169 | test "extern union size" { |
| 170 | comptime assertOrPanic(@sizeOf(ExternPtrOrInt) == 8); | |
| 170 | comptime expect(@sizeOf(ExternPtrOrInt) == 8); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const PackedPtrOrInt = packed union { |
| ... | ... | @@ -175,14 +175,14 @@ const PackedPtrOrInt = packed union { |
| 175 | 175 | int: u64, |
| 176 | 176 | }; |
| 177 | 177 | test "extern union size" { |
| 178 | comptime assertOrPanic(@sizeOf(PackedPtrOrInt) == 8); | |
| 178 | comptime expect(@sizeOf(PackedPtrOrInt) == 8); | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | const ZeroBits = union { |
| 182 | 182 | OnlyField: void, |
| 183 | 183 | }; |
| 184 | 184 | test "union with only 1 field which is void should be zero bits" { |
| 185 | comptime assertOrPanic(@sizeOf(ZeroBits) == 0); | |
| 185 | comptime expect(@sizeOf(ZeroBits) == 0); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | const TheTag = enum { |
| ... | ... | @@ -196,9 +196,9 @@ const TheUnion = union(TheTag) { |
| 196 | 196 | C: i32, |
| 197 | 197 | }; |
| 198 | 198 | test "union field access gives the enum values" { |
| 199 | assertOrPanic(TheUnion.A == TheTag.A); | |
| 200 | assertOrPanic(TheUnion.B == TheTag.B); | |
| 201 | assertOrPanic(TheUnion.C == TheTag.C); | |
| 199 | expect(TheUnion.A == TheTag.A); | |
| 200 | expect(TheUnion.B == TheTag.B); | |
| 201 | expect(TheUnion.C == TheTag.C); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "cast union to tag type of union" { |
| ... | ... | @@ -207,12 +207,12 @@ test "cast union to tag type of union" { |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | fn testCastUnionToTagType(x: TheUnion) void { |
| 210 | assertOrPanic(TheTag(x) == TheTag.B); | |
| 210 | expect(TheTag(x) == TheTag.B); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | test "cast tag type of union to union" { |
| 214 | 214 | var x: Value2 = Letter2.B; |
| 215 | assertOrPanic(Letter2(x) == Letter2.B); | |
| 215 | expect(Letter2(x) == Letter2.B); | |
| 216 | 216 | } |
| 217 | 217 | const Letter2 = enum { |
| 218 | 218 | A, |
| ... | ... | @@ -227,11 +227,11 @@ const Value2 = union(Letter2) { |
| 227 | 227 | |
| 228 | 228 | test "implicit cast union to its tag type" { |
| 229 | 229 | var x: Value2 = Letter2.B; |
| 230 | assertOrPanic(x == Letter2.B); | |
| 230 | expect(x == Letter2.B); | |
| 231 | 231 | giveMeLetterB(x); |
| 232 | 232 | } |
| 233 | 233 | fn giveMeLetterB(x: Letter2) void { |
| 234 | assertOrPanic(x == Value2.B); | |
| 234 | expect(x == Value2.B); | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | pub const PackThis = union(enum) { |
| ... | ... | @@ -244,7 +244,7 @@ test "constant packed union" { |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | fn testConstPackedUnion(expected_tokens: []const PackThis) void { |
| 247 | assertOrPanic(expected_tokens[0].StringLiteral == 1); | |
| 247 | expect(expected_tokens[0].StringLiteral == 1); | |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | test "switch on union with only 1 field" { |
| ... | ... | @@ -256,7 +256,7 @@ test "switch on union with only 1 field" { |
| 256 | 256 | z = PartialInstWithPayload{ .Compiled = 1234 }; |
| 257 | 257 | switch (z) { |
| 258 | 258 | PartialInstWithPayload.Compiled => |x| { |
| 259 | assertOrPanic(x == 1234); | |
| 259 | expect(x == 1234); | |
| 260 | 260 | return; |
| 261 | 261 | }, |
| 262 | 262 | } |
| ... | ... | @@ -282,11 +282,11 @@ test "access a member of tagged union with conflicting enum tag name" { |
| 282 | 282 | const B = void; |
| 283 | 283 | }; |
| 284 | 284 | |
| 285 | comptime assertOrPanic(Bar.A == u8); | |
| 285 | comptime expect(Bar.A == u8); | |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | test "tagged union initialization with runtime void" { |
| 289 | assertOrPanic(testTaggedUnionInit({})); | |
| 289 | expect(testTaggedUnionInit({})); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | const TaggedUnionWithAVoid = union(enum) { |
| ... | ... | @@ -324,9 +324,9 @@ test "union with only 1 field casted to its enum type" { |
| 324 | 324 | |
| 325 | 325 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 326 | 326 | const Tag = @TagType(Expr); |
| 327 | comptime assertOrPanic(@TagType(Tag) == comptime_int); | |
| 327 | comptime expect(@TagType(Tag) == comptime_int); | |
| 328 | 328 | var t = Tag(e); |
| 329 | assertOrPanic(t == Expr.Literal); | |
| 329 | expect(t == Expr.Literal); | |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | test "union with only 1 field casted to its enum type which has enum value specified" { |
| ... | ... | @@ -344,9 +344,9 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 344 | 344 | }; |
| 345 | 345 | |
| 346 | 346 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 347 | comptime assertOrPanic(@TagType(Tag) == comptime_int); | |
| 347 | comptime expect(@TagType(Tag) == comptime_int); | |
| 348 | 348 | var t = Tag(e); |
| 349 | assertOrPanic(t == Expr.Literal); | |
| 350 | assertOrPanic(@enumToInt(t) == 33); | |
| 351 | comptime assertOrPanic(@enumToInt(t) == 33); | |
| 349 | expect(t == Expr.Literal); | |
| 350 | expect(@enumToInt(t) == 33); | |
| 351 | comptime expect(@enumToInt(t) == 33); | |
| 352 | 352 | } |
test/stage1/behavior/var_args.zig+17-17| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | fn add(args: ...) i32 { |
| 4 | 4 | var sum = i32(0); |
| ... | ... | @@ -12,9 +12,9 @@ fn add(args: ...) i32 { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "add arbitrary args" { |
| 15 | assertOrPanic(add(i32(1), i32(2), i32(3), i32(4)) == 10); | |
| 16 | assertOrPanic(add(i32(1234)) == 1234); | |
| 17 | assertOrPanic(add() == 0); | |
| 15 | expect(add(i32(1), i32(2), i32(3), i32(4)) == 10); | |
| 16 | expect(add(i32(1234)) == 1234); | |
| 17 | expect(add() == 0); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | fn readFirstVarArg(args: ...) void { |
| ... | ... | @@ -26,9 +26,9 @@ test "send void arg to var args" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "pass args directly" { |
| 29 | assertOrPanic(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10); | |
| 30 | assertOrPanic(addSomeStuff(i32(1234)) == 1234); | |
| 31 | assertOrPanic(addSomeStuff() == 0); | |
| 29 | expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10); | |
| 30 | expect(addSomeStuff(i32(1234)) == 1234); | |
| 31 | expect(addSomeStuff() == 0); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | fn addSomeStuff(args: ...) i32 { |
| ... | ... | @@ -36,24 +36,24 @@ fn addSomeStuff(args: ...) i32 { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "runtime parameter before var args" { |
| 39 | assertOrPanic(extraFn(10) == 0); | |
| 40 | assertOrPanic(extraFn(10, false) == 1); | |
| 41 | assertOrPanic(extraFn(10, false, true) == 2); | |
| 39 | expect(extraFn(10) == 0); | |
| 40 | expect(extraFn(10, false) == 1); | |
| 41 | expect(extraFn(10, false, true) == 2); | |
| 42 | 42 | |
| 43 | 43 | // TODO issue #313 |
| 44 | 44 | //comptime { |
| 45 | // assertOrPanic(extraFn(10) == 0); | |
| 46 | // assertOrPanic(extraFn(10, false) == 1); | |
| 47 | // assertOrPanic(extraFn(10, false, true) == 2); | |
| 45 | // expect(extraFn(10) == 0); | |
| 46 | // expect(extraFn(10, false) == 1); | |
| 47 | // expect(extraFn(10, false, true) == 2); | |
| 48 | 48 | //} |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | fn extraFn(extra: u32, args: ...) usize { |
| 52 | 52 | if (args.len >= 1) { |
| 53 | assertOrPanic(args[0] == false); | |
| 53 | expect(args[0] == false); | |
| 54 | 54 | } |
| 55 | 55 | if (args.len >= 2) { |
| 56 | assertOrPanic(args[1] == true); | |
| 56 | expect(args[1] == true); | |
| 57 | 57 | } |
| 58 | 58 | return args.len; |
| 59 | 59 | } |
| ... | ... | @@ -71,8 +71,8 @@ fn foo2(args: ...) bool { |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | test "array of var args functions" { |
| 74 | assertOrPanic(foos[0]()); | |
| 75 | assertOrPanic(!foos[1]()); | |
| 74 | expect(foos[0]()); | |
| 75 | expect(!foos[1]()); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "pass zero length array to var args param" { |
test/stage1/behavior/vector.zig+4-4| ... | ... | @@ -1,15 +1,15 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | const assertOrPanic = std.debug.assertOrPanic; | |
| 3 | const expect = std.testing.expect; | |
| 4 | 4 | |
| 5 | 5 | test "vector wrap operators" { |
| 6 | 6 | const S = struct { |
| 7 | 7 | fn doTheTest() void { |
| 8 | 8 | const v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 9 | 9 | const x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; |
| 10 | assertOrPanic(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ 11, 22, 33, 44 })); | |
| 11 | assertOrPanic(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 9, 18, 27, 36 })); | |
| 12 | assertOrPanic(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 10, 40, 90, 160 })); | |
| 10 | expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ 11, 22, 33, 44 })); | |
| 11 | expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 9, 18, 27, 36 })); | |
| 12 | expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 10, 40, 90, 160 })); | |
| 13 | 13 | } |
| 14 | 14 | }; |
| 15 | 15 | S.doTheTest(); |
test/stage1/behavior/void.zig+4-4| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | const Foo = struct { |
| 4 | 4 | a: void, |
| ... | ... | @@ -13,14 +13,14 @@ test "compare void with void compile time known" { |
| 13 | 13 | .b = 1, |
| 14 | 14 | .c = {}, |
| 15 | 15 | }; |
| 16 | assertOrPanic(foo.a == {}); | |
| 16 | expect(foo.a == {}); | |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | test "iterate over a void slice" { |
| 21 | 21 | var j: usize = 0; |
| 22 | 22 | for (times(10)) |_, i| { |
| 23 | assertOrPanic(i == j); | |
| 23 | expect(i == j); | |
| 24 | 24 | j += 1; |
| 25 | 25 | } |
| 26 | 26 | } |
| ... | ... | @@ -31,5 +31,5 @@ fn times(n: usize) []const void { |
| 31 | 31 | |
| 32 | 32 | test "void optional" { |
| 33 | 33 | var x: ?void = {}; |
| 34 | assertOrPanic(x != null); | |
| 34 | expect(x != null); | |
| 35 | 35 | } |
test/stage1/behavior/while.zig+22-22| ... | ... | @@ -1,12 +1,12 @@ |
| 1 | const assertOrPanic = @import("std").debug.assertOrPanic; | |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | 2 | |
| 3 | 3 | test "while loop" { |
| 4 | 4 | var i: i32 = 0; |
| 5 | 5 | while (i < 4) { |
| 6 | 6 | i += 1; |
| 7 | 7 | } |
| 8 | assertOrPanic(i == 4); | |
| 9 | assertOrPanic(whileLoop1() == 1); | |
| 8 | expect(i == 4); | |
| 9 | expect(whileLoop1() == 1); | |
| 10 | 10 | } |
| 11 | 11 | fn whileLoop1() i32 { |
| 12 | 12 | return whileLoop2(); |
| ... | ... | @@ -18,7 +18,7 @@ fn whileLoop2() i32 { |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | test "static eval while" { |
| 21 | assertOrPanic(static_eval_while_number == 1); | |
| 21 | expect(static_eval_while_number == 1); | |
| 22 | 22 | } |
| 23 | 23 | const static_eval_while_number = staticWhileLoop1(); |
| 24 | 24 | fn staticWhileLoop1() i32 { |
| ... | ... | @@ -32,7 +32,7 @@ fn staticWhileLoop2() i32 { |
| 32 | 32 | |
| 33 | 33 | test "continue and break" { |
| 34 | 34 | runContinueAndBreakTest(); |
| 35 | assertOrPanic(continue_and_break_counter == 8); | |
| 35 | expect(continue_and_break_counter == 8); | |
| 36 | 36 | } |
| 37 | 37 | var continue_and_break_counter: i32 = 0; |
| 38 | 38 | fn runContinueAndBreakTest() void { |
| ... | ... | @@ -45,7 +45,7 @@ fn runContinueAndBreakTest() void { |
| 45 | 45 | } |
| 46 | 46 | break; |
| 47 | 47 | } |
| 48 | assertOrPanic(i == 4); | |
| 48 | expect(i == 4); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | test "return with implicit cast from while loop" { |
| ... | ... | @@ -66,7 +66,7 @@ test "while with continue expression" { |
| 66 | 66 | sum += i; |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | assertOrPanic(sum == 40); | |
| 69 | expect(sum == 40); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | test "while with else" { |
| ... | ... | @@ -78,8 +78,8 @@ test "while with else" { |
| 78 | 78 | } else { |
| 79 | 79 | got_else += 1; |
| 80 | 80 | } |
| 81 | assertOrPanic(sum == 10); | |
| 82 | assertOrPanic(got_else == 1); | |
| 81 | expect(sum == 10); | |
| 82 | expect(got_else == 1); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "while with optional as condition" { |
| ... | ... | @@ -88,7 +88,7 @@ test "while with optional as condition" { |
| 88 | 88 | while (getNumberOrNull()) |value| { |
| 89 | 89 | sum += value; |
| 90 | 90 | } |
| 91 | assertOrPanic(sum == 45); | |
| 91 | expect(sum == 45); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "while with optional as condition with else" { |
| ... | ... | @@ -97,12 +97,12 @@ test "while with optional as condition with else" { |
| 97 | 97 | var got_else: i32 = 0; |
| 98 | 98 | while (getNumberOrNull()) |value| { |
| 99 | 99 | sum += value; |
| 100 | assertOrPanic(got_else == 0); | |
| 100 | expect(got_else == 0); | |
| 101 | 101 | } else { |
| 102 | 102 | got_else += 1; |
| 103 | 103 | } |
| 104 | assertOrPanic(sum == 45); | |
| 105 | assertOrPanic(got_else == 1); | |
| 104 | expect(sum == 45); | |
| 105 | expect(got_else == 1); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | test "while with error union condition" { |
| ... | ... | @@ -112,11 +112,11 @@ test "while with error union condition" { |
| 112 | 112 | while (getNumberOrErr()) |value| { |
| 113 | 113 | sum += value; |
| 114 | 114 | } else |err| { |
| 115 | assertOrPanic(err == error.OutOfNumbers); | |
| 115 | expect(err == error.OutOfNumbers); | |
| 116 | 116 | got_else += 1; |
| 117 | 117 | } |
| 118 | assertOrPanic(sum == 45); | |
| 119 | assertOrPanic(got_else == 1); | |
| 118 | expect(sum == 45); | |
| 119 | expect(got_else == 1); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | var numbers_left: i32 = undefined; |
| ... | ... | @@ -138,7 +138,7 @@ test "while on optional with else result follow else prong" { |
| 138 | 138 | break value; |
| 139 | 139 | } else |
| 140 | 140 | i32(2); |
| 141 | assertOrPanic(result == 2); | |
| 141 | expect(result == 2); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "while on optional with else result follow break prong" { |
| ... | ... | @@ -146,7 +146,7 @@ test "while on optional with else result follow break prong" { |
| 146 | 146 | break value; |
| 147 | 147 | } else |
| 148 | 148 | i32(2); |
| 149 | assertOrPanic(result == 10); | |
| 149 | expect(result == 10); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | test "while on error union with else result follow else prong" { |
| ... | ... | @@ -154,7 +154,7 @@ test "while on error union with else result follow else prong" { |
| 154 | 154 | break value; |
| 155 | 155 | } else |err| |
| 156 | 156 | i32(2); |
| 157 | assertOrPanic(result == 2); | |
| 157 | expect(result == 2); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | test "while on error union with else result follow break prong" { |
| ... | ... | @@ -162,7 +162,7 @@ test "while on error union with else result follow break prong" { |
| 162 | 162 | break value; |
| 163 | 163 | } else |err| |
| 164 | 164 | i32(2); |
| 165 | assertOrPanic(result == 10); | |
| 165 | expect(result == 10); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | test "while on bool with else result follow else prong" { |
| ... | ... | @@ -170,7 +170,7 @@ test "while on bool with else result follow else prong" { |
| 170 | 170 | break i32(10); |
| 171 | 171 | } else |
| 172 | 172 | i32(2); |
| 173 | assertOrPanic(result == 2); | |
| 173 | expect(result == 2); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "while on bool with else result follow break prong" { |
| ... | ... | @@ -178,7 +178,7 @@ test "while on bool with else result follow break prong" { |
| 178 | 178 | break i32(10); |
| 179 | 179 | } else |
| 180 | 180 | i32(2); |
| 181 | assertOrPanic(result == 10); | |
| 181 | expect(result == 10); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | test "break from outer while loop" { |
test/stage1/behavior/widening.zig+4-4| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | |
| 5 | 5 | test "integer widening" { |
| ... | ... | @@ -9,13 +9,13 @@ test "integer widening" { |
| 9 | 9 | var d: u64 = c; |
| 10 | 10 | var e: u64 = d; |
| 11 | 11 | var f: u128 = e; |
| 12 | assertOrPanic(f == a); | |
| 12 | expect(f == a); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | test "implicit unsigned integer to signed integer" { |
| 16 | 16 | var a: u8 = 250; |
| 17 | 17 | var b: i16 = a; |
| 18 | assertOrPanic(b == 250); | |
| 18 | expect(b == 250); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "float widening" { |
| ... | ... | @@ -23,6 +23,6 @@ test "float widening" { |
| 23 | 23 | var b: f32 = a; |
| 24 | 24 | var c: f64 = b; |
| 25 | 25 | var d: f128 = c; |
| 26 | assertOrPanic(d == a); | |
| 26 | expect(d == a); | |
| 27 | 27 | } |
| 28 | 28 |
test/stage1/c_abi/main.zig+41-41| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assertOrPanic = std.debug.assertOrPanic; | |
| 2 | const expect = std.testing.expect; | |
| 3 | 3 | |
| 4 | 4 | extern fn run_c_tests() void; |
| 5 | 5 | |
| ... | ... | @@ -33,28 +33,28 @@ test "C ABI integers" { |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | export fn zig_u8(x: u8) void { |
| 36 | assertOrPanic(x == 0xff); | |
| 36 | expect(x == 0xff); | |
| 37 | 37 | } |
| 38 | 38 | export fn zig_u16(x: u16) void { |
| 39 | assertOrPanic(x == 0xfffe); | |
| 39 | expect(x == 0xfffe); | |
| 40 | 40 | } |
| 41 | 41 | export fn zig_u32(x: u32) void { |
| 42 | assertOrPanic(x == 0xfffffffd); | |
| 42 | expect(x == 0xfffffffd); | |
| 43 | 43 | } |
| 44 | 44 | export fn zig_u64(x: u64) void { |
| 45 | assertOrPanic(x == 0xfffffffffffffffc); | |
| 45 | expect(x == 0xfffffffffffffffc); | |
| 46 | 46 | } |
| 47 | 47 | export fn zig_i8(x: i8) void { |
| 48 | assertOrPanic(x == -1); | |
| 48 | expect(x == -1); | |
| 49 | 49 | } |
| 50 | 50 | export fn zig_i16(x: i16) void { |
| 51 | assertOrPanic(x == -2); | |
| 51 | expect(x == -2); | |
| 52 | 52 | } |
| 53 | 53 | export fn zig_i32(x: i32) void { |
| 54 | assertOrPanic(x == -3); | |
| 54 | expect(x == -3); | |
| 55 | 55 | } |
| 56 | 56 | export fn zig_i64(x: i64) void { |
| 57 | assertOrPanic(x == -4); | |
| 57 | expect(x == -4); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | extern fn c_f32(f32) void; |
| ... | ... | @@ -66,10 +66,10 @@ test "C ABI floats" { |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | export fn zig_f32(x: f32) void { |
| 69 | assertOrPanic(x == 12.34); | |
| 69 | expect(x == 12.34); | |
| 70 | 70 | } |
| 71 | 71 | export fn zig_f64(x: f64) void { |
| 72 | assertOrPanic(x == 56.78); | |
| 72 | expect(x == 56.78); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | extern fn c_ptr(*c_void) void; |
| ... | ... | @@ -79,7 +79,7 @@ test "C ABI pointer" { |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | export fn zig_ptr(x: *c_void) void { |
| 82 | assertOrPanic(@ptrToInt(x) == 0xdeadbeef); | |
| 82 | expect(@ptrToInt(x) == 0xdeadbeef); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | extern fn c_bool(bool) void; |
| ... | ... | @@ -89,7 +89,7 @@ test "C ABI bool" { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | export fn zig_bool(x: bool) void { |
| 92 | assertOrPanic(x); | |
| 92 | expect(x); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | extern fn c_array([10]u8) void; |
| ... | ... | @@ -100,7 +100,7 @@ test "C ABI array" { |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | export fn zig_array(x: [10]u8) void { |
| 103 | assertOrPanic(std.mem.eql(u8, x, "1234567890")); | |
| 103 | expect(std.mem.eql(u8, x, "1234567890")); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | const BigStruct = extern struct { |
| ... | ... | @@ -124,11 +124,11 @@ test "C ABI big struct" { |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | export fn zig_big_struct(x: BigStruct) void { |
| 127 | assertOrPanic(x.a == 1); | |
| 128 | assertOrPanic(x.b == 2); | |
| 129 | assertOrPanic(x.c == 3); | |
| 130 | assertOrPanic(x.d == 4); | |
| 131 | assertOrPanic(x.e == 5); | |
| 127 | expect(x.a == 1); | |
| 128 | expect(x.b == 2); | |
| 129 | expect(x.c == 3); | |
| 130 | expect(x.d == 4); | |
| 131 | expect(x.e == 5); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | const BigUnion = extern union { |
| ... | ... | @@ -150,11 +150,11 @@ test "C ABI big union" { |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | export fn zig_big_union(x: BigUnion) void { |
| 153 | assertOrPanic(x.a.a == 1); | |
| 154 | assertOrPanic(x.a.b == 2); | |
| 155 | assertOrPanic(x.a.c == 3); | |
| 156 | assertOrPanic(x.a.d == 4); | |
| 157 | assertOrPanic(x.a.e == 5); | |
| 153 | expect(x.a.a == 1); | |
| 154 | expect(x.a.b == 2); | |
| 155 | expect(x.a.c == 3); | |
| 156 | expect(x.a.d == 4); | |
| 157 | expect(x.a.e == 5); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | const SmallStructInts = extern struct { |
| ... | ... | @@ -176,10 +176,10 @@ test "C ABI small struct of ints" { |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | export fn zig_small_struct_ints(x: SmallStructInts) void { |
| 179 | assertOrPanic(x.a == 1); | |
| 180 | assertOrPanic(x.b == 2); | |
| 181 | assertOrPanic(x.c == 3); | |
| 182 | assertOrPanic(x.d == 4); | |
| 179 | expect(x.a == 1); | |
| 180 | expect(x.b == 2); | |
| 181 | expect(x.c == 3); | |
| 182 | expect(x.d == 4); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | const SplitStructInt = extern struct { |
| ... | ... | @@ -199,9 +199,9 @@ test "C ABI split struct of ints" { |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | export fn zig_split_struct_ints(x: SplitStructInt) void { |
| 202 | assertOrPanic(x.a == 1234); | |
| 203 | assertOrPanic(x.b == 100); | |
| 204 | assertOrPanic(x.c == 1337); | |
| 202 | expect(x.a == 1234); | |
| 203 | expect(x.b == 100); | |
| 204 | expect(x.c == 1337); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | extern fn c_big_struct_both(BigStruct) BigStruct; |
| ... | ... | @@ -215,19 +215,19 @@ test "C ABI sret and byval together" { |
| 215 | 215 | .e = 5, |
| 216 | 216 | }; |
| 217 | 217 | var y = c_big_struct_both(s); |
| 218 | assertOrPanic(y.a == 10); | |
| 219 | assertOrPanic(y.b == 11); | |
| 220 | assertOrPanic(y.c == 12); | |
| 221 | assertOrPanic(y.d == 13); | |
| 222 | assertOrPanic(y.e == 14); | |
| 218 | expect(y.a == 10); | |
| 219 | expect(y.b == 11); | |
| 220 | expect(y.c == 12); | |
| 221 | expect(y.d == 13); | |
| 222 | expect(y.e == 14); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | export fn zig_big_struct_both(x: BigStruct) BigStruct { |
| 226 | assertOrPanic(x.a == 30); | |
| 227 | assertOrPanic(x.b == 31); | |
| 228 | assertOrPanic(x.c == 32); | |
| 229 | assertOrPanic(x.d == 33); | |
| 230 | assertOrPanic(x.e == 34); | |
| 226 | expect(x.a == 30); | |
| 227 | expect(x.b == 31); | |
| 228 | expect(x.c == 32); | |
| 229 | expect(x.d == 33); | |
| 230 | expect(x.e == 34); | |
| 231 | 231 | var s = BigStruct{ |
| 232 | 232 | .a = 20, |
| 233 | 233 | .b = 21, |
test/standalone/brace_expansion/main.zig+3-6| ... | ... | @@ -3,6 +3,7 @@ const io = std.io; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const debug = std.debug; |
| 5 | 5 | const assert = debug.assert; |
| 6 | const testing = std.testing; | |
| 6 | 7 | const Buffer = std.Buffer; |
| 7 | 8 | const ArrayList = std.ArrayList; |
| 8 | 9 | const maxInt = std.math.maxInt; |
| ... | ... | @@ -220,11 +221,7 @@ fn expectError(test_input: []const u8, expected_err: anyerror) void { |
| 220 | 221 | var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable; |
| 221 | 222 | defer output_buf.deinit(); |
| 222 | 223 | |
| 223 | if (expandString(test_input, &output_buf)) { | |
| 224 | unreachable; | |
| 225 | } else |err| { | |
| 226 | assert(expected_err == err); | |
| 227 | } | |
| 224 | testing.expectError(expected_err, expandString(test_input, &output_buf)); | |
| 228 | 225 | } |
| 229 | 226 | |
| 230 | 227 | test "valid inputs" { |
| ... | ... | @@ -256,5 +253,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void { |
| 256 | 253 | |
| 257 | 254 | expandString(test_input, &result) catch unreachable; |
| 258 | 255 | |
| 259 | assert(mem.eql(u8, result.toSlice(), expected_result)); | |
| 256 | testing.expectEqualSlices(u8, expected_result, result.toSlice()); | |
| 260 | 257 | } |
test/standalone/issue_794/main.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const c = @cImport(@cInclude("foo.h")); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | const testing = std.testing; | |
| 4 | 4 | |
| 5 | 5 | test "c import" { |
| 6 | comptime assert(c.NUMBER == 1234); | |
| 6 | comptime testing.expect(c.NUMBER == 1234); | |
| 7 | 7 | } |