mirror of
https://github.com/ziglang/zig.git
synced 2025-02-08 21:50:33 +00:00
Remove redundant test name prefixes now that test names are fully qualified
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
This commit is contained in:
parent
1b79a42da0
commit
16b3d1004e
@ -173,7 +173,7 @@ pub fn fill(self: *Isaac64, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "isaac64 sequence" {
|
||||
test "sequence" {
|
||||
var r = Isaac64.init(0);
|
||||
|
||||
// from reference implementation
|
||||
@ -201,7 +201,7 @@ test "isaac64 sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "isaac64 fill" {
|
||||
test "fill" {
|
||||
var r = Isaac64.init(0);
|
||||
|
||||
// from reference implementation
|
||||
|
@ -72,7 +72,7 @@ pub fn fill(self: *Pcg, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "pcg sequence" {
|
||||
test "sequence" {
|
||||
var r = Pcg.init(0);
|
||||
const s0: u64 = 0x9394bf54ce5d79de;
|
||||
const s1: u64 = 0x84e9c579ef59bbf7;
|
||||
@ -92,7 +92,7 @@ test "pcg sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "pcg fill" {
|
||||
test "fill" {
|
||||
var r = Pcg.init(0);
|
||||
const s0: u64 = 0x9394bf54ce5d79de;
|
||||
const s1: u64 = 0x84e9c579ef59bbf7;
|
||||
|
@ -72,7 +72,7 @@ pub fn fill(self: *RomuTrio, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "RomuTrio sequence" {
|
||||
test "sequence" {
|
||||
// Unfortunately there does not seem to be an official test sequence.
|
||||
var r = RomuTrio.init(0);
|
||||
|
||||
@ -94,7 +94,7 @@ test "RomuTrio sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "RomuTrio fill" {
|
||||
test "fill" {
|
||||
// Unfortunately there does not seem to be an official test sequence.
|
||||
var r = RomuTrio.init(0);
|
||||
|
||||
@ -120,7 +120,7 @@ test "RomuTrio fill" {
|
||||
}
|
||||
}
|
||||
|
||||
test "RomuTrio buf seeding test" {
|
||||
test "buf seeding test" {
|
||||
const buf0 = @as([24]u8, @bitCast([3]u64{ 16294208416658607535, 13964609475759908645, 4703697494102998476 }));
|
||||
const resulting_state = .{ .x = 16294208416658607535, .y = 13964609475759908645, .z = 4703697494102998476 };
|
||||
var r = RomuTrio.init(0);
|
||||
|
@ -70,7 +70,7 @@ pub fn fill(self: *Sfc64, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "Sfc64 sequence" {
|
||||
test "sequence" {
|
||||
// Unfortunately there does not seem to be an official test sequence.
|
||||
var r = Sfc64.init(0);
|
||||
|
||||
@ -98,7 +98,7 @@ test "Sfc64 sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Sfc64 fill" {
|
||||
test "fill" {
|
||||
// Unfortunately there does not seem to be an official test sequence.
|
||||
var r = Sfc64.init(0);
|
||||
|
||||
|
@ -88,7 +88,7 @@ pub fn fill(self: *Xoroshiro128, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "xoroshiro sequence" {
|
||||
test "sequence" {
|
||||
var r = Xoroshiro128.init(0);
|
||||
r.s[0] = 0xaeecf86f7878dd75;
|
||||
r.s[1] = 0x01cd153642e72622;
|
||||
@ -122,7 +122,7 @@ test "xoroshiro sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "xoroshiro fill" {
|
||||
test "fill" {
|
||||
var r = Xoroshiro128.init(0);
|
||||
r.s[0] = 0xaeecf86f7878dd75;
|
||||
r.s[1] = 0x01cd153642e72622;
|
||||
|
@ -88,7 +88,7 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "xoroshiro sequence" {
|
||||
test "sequence" {
|
||||
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
var r = Xoshiro256.init(0);
|
||||
@ -122,7 +122,7 @@ test "xoroshiro sequence" {
|
||||
}
|
||||
}
|
||||
|
||||
test "xoroshiro fill" {
|
||||
test "fill" {
|
||||
var r = Xoshiro256.init(0);
|
||||
|
||||
const seq = [_]u64{
|
||||
|
@ -166,7 +166,7 @@ pub fn format(
|
||||
const expect = std.testing.expect;
|
||||
const expectError = std.testing.expectError;
|
||||
|
||||
test "SemanticVersion format" {
|
||||
test "format" {
|
||||
// Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
|
||||
|
||||
// Valid version strings should be accepted.
|
||||
@ -277,7 +277,7 @@ test "SemanticVersion format" {
|
||||
if (parse(big_invalid)) |ver| std.debug.panic("expected error, found {}", .{ver}) else |_| {}
|
||||
}
|
||||
|
||||
test "SemanticVersion precedence" {
|
||||
test "precedence" {
|
||||
// SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
|
||||
try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
|
||||
try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
|
||||
|
@ -1437,7 +1437,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
|
||||
event.set();
|
||||
}
|
||||
|
||||
test "Thread.join" {
|
||||
test "join" {
|
||||
if (builtin.single_threaded) return error.SkipZigTest;
|
||||
|
||||
var value: usize = 0;
|
||||
@ -1449,7 +1449,7 @@ test "Thread.join" {
|
||||
try std.testing.expectEqual(value, 1);
|
||||
}
|
||||
|
||||
test "Thread.detach" {
|
||||
test "detach" {
|
||||
if (builtin.single_threaded) return error.SkipZigTest;
|
||||
|
||||
var value: usize = 0;
|
||||
|
@ -296,7 +296,7 @@ const FutexImpl = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "Condition - smoke test" {
|
||||
test "smoke test" {
|
||||
var mutex = Mutex{};
|
||||
var cond = Condition{};
|
||||
|
||||
@ -317,7 +317,7 @@ test "Condition - smoke test" {
|
||||
}
|
||||
|
||||
// Inspired from: https://github.com/Amanieu/parking_lot/pull/129
|
||||
test "Condition - wait and signal" {
|
||||
test "wait and signal" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -362,7 +362,7 @@ test "Condition - wait and signal" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Condition - signal" {
|
||||
test "signal" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -429,7 +429,7 @@ test "Condition - signal" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Condition - multi signal" {
|
||||
test "multi signal" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -491,7 +491,7 @@ test "Condition - multi signal" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Condition - broadcasting" {
|
||||
test "broadcasting" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -557,7 +557,7 @@ test "Condition - broadcasting" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Condition - broadcasting - wake all threads" {
|
||||
test "broadcasting - wake all threads" {
|
||||
// Tests issue #12877
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
|
@ -881,7 +881,7 @@ const PosixImpl = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "Futex - smoke test" {
|
||||
test "smoke test" {
|
||||
var value = atomic.Value(u32).init(0);
|
||||
|
||||
// Try waits with invalid values.
|
||||
@ -898,7 +898,7 @@ test "Futex - smoke test" {
|
||||
Futex.wake(&value, std.math.maxInt(u32));
|
||||
}
|
||||
|
||||
test "Futex - signaling" {
|
||||
test "signaling" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -952,7 +952,7 @@ test "Futex - signaling" {
|
||||
for (paddles) |p| try testing.expectEqual(p.current, num_iterations);
|
||||
}
|
||||
|
||||
test "Futex - broadcasting" {
|
||||
test "broadcasting" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -1054,7 +1054,7 @@ pub const Deadline = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "Futex - Deadline" {
|
||||
test "Deadline" {
|
||||
var deadline = Deadline.init(100 * std.time.ns_per_ms);
|
||||
var futex_word = atomic.Value(u32).init(0);
|
||||
|
||||
|
@ -215,7 +215,7 @@ const FutexImpl = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "Mutex - smoke test" {
|
||||
test "smoke test" {
|
||||
var mutex = Mutex{};
|
||||
|
||||
try testing.expect(mutex.tryLock());
|
||||
@ -243,7 +243,7 @@ const NonAtomicCounter = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "Mutex - many uncontended" {
|
||||
test "many uncontended" {
|
||||
// This test requires spawning threads.
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -274,7 +274,7 @@ test "Mutex - many uncontended" {
|
||||
for (runners) |r| try testing.expectEqual(r.counter.get(), num_increments);
|
||||
}
|
||||
|
||||
test "Mutex - many contended" {
|
||||
test "many contended" {
|
||||
// This test requires spawning threads.
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
|
@ -157,7 +157,7 @@ const FutexImpl = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "ResetEvent - smoke test" {
|
||||
test "smoke test" {
|
||||
// make sure the event is unset
|
||||
var event = ResetEvent{};
|
||||
try testing.expectEqual(false, event.isSet());
|
||||
@ -181,7 +181,7 @@ test "ResetEvent - smoke test" {
|
||||
try testing.expectEqual(true, event.isSet());
|
||||
}
|
||||
|
||||
test "ResetEvent - signaling" {
|
||||
test "signaling" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
@ -242,7 +242,7 @@ test "ResetEvent - signaling" {
|
||||
try ctx.input();
|
||||
}
|
||||
|
||||
test "ResetEvent - broadcast" {
|
||||
test "broadcast" {
|
||||
// This test requires spawning threads
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
|
@ -264,7 +264,7 @@ test "DefaultRwLock - internal state" {
|
||||
try testing.expectEqual(rwl, DefaultRwLock{});
|
||||
}
|
||||
|
||||
test "RwLock - smoke test" {
|
||||
test "smoke test" {
|
||||
var rwl = RwLock{};
|
||||
|
||||
rwl.lock();
|
||||
@ -293,7 +293,7 @@ test "RwLock - smoke test" {
|
||||
rwl.unlock();
|
||||
}
|
||||
|
||||
test "RwLock - concurrent access" {
|
||||
test "concurrent access" {
|
||||
if (builtin.single_threaded)
|
||||
return;
|
||||
|
||||
|
@ -71,7 +71,7 @@ pub fn post(sem: *Semaphore) void {
|
||||
sem.cond.signal();
|
||||
}
|
||||
|
||||
test "Thread.Semaphore" {
|
||||
test "Semaphore" {
|
||||
if (builtin.single_threaded) {
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
@ -97,7 +97,7 @@ test "Thread.Semaphore" {
|
||||
try testing.expect(n == num_threads);
|
||||
}
|
||||
|
||||
test "Thread.Semaphore - timedWait" {
|
||||
test "timedWait" {
|
||||
var sem = Semaphore{};
|
||||
try testing.expectEqual(0, sem.permits);
|
||||
|
||||
|
@ -1231,7 +1231,7 @@ fn addOrOom(a: usize, b: usize) error{OutOfMemory}!usize {
|
||||
return result;
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.init" {
|
||||
test "init" {
|
||||
{
|
||||
var list = ArrayList(i32).init(testing.allocator);
|
||||
defer list.deinit();
|
||||
@ -1248,7 +1248,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
|
||||
test "initCapacity" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = try ArrayList(i8).initCapacity(a, 200);
|
||||
@ -1264,7 +1264,7 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.clone" {
|
||||
test "clone" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var array = ArrayList(i32).init(a);
|
||||
@ -1305,7 +1305,7 @@ test "std.ArrayList/ArrayListUnmanaged.clone" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.basic" {
|
||||
test "basic" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1409,7 +1409,7 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
|
||||
test "appendNTimes" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1433,7 +1433,7 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
|
||||
test "appendNTimes with failing allocator" {
|
||||
const a = testing.failing_allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1447,7 +1447,7 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
|
||||
test "orderedRemove" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1519,7 +1519,7 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
|
||||
test "swapRemove" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1575,7 +1575,7 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.insert" {
|
||||
test "insert" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1605,7 +1605,7 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
|
||||
test "insertSlice" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(i32).init(a);
|
||||
@ -1651,7 +1651,7 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
|
||||
test "replaceRange" {
|
||||
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
const a = arena.allocator();
|
||||
@ -1773,7 +1773,7 @@ const ItemUnmanaged = struct {
|
||||
sub_items: ArrayListUnmanaged(ItemUnmanaged),
|
||||
};
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
|
||||
test "ArrayList(T) of struct T" {
|
||||
const a = std.testing.allocator;
|
||||
{
|
||||
var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
|
||||
@ -1789,7 +1789,7 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList(u8)/ArrayListAligned implements writer" {
|
||||
test "ArrayList(u8) implements writer" {
|
||||
const a = testing.allocator;
|
||||
|
||||
{
|
||||
@ -1816,7 +1816,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayListUnmanaged(u8) implements writer" {
|
||||
test "ArrayListUnmanaged(u8) implements writer" {
|
||||
const a = testing.allocator;
|
||||
|
||||
{
|
||||
@ -1883,7 +1883,7 @@ test "shrinkAndFree with a copy" {
|
||||
try testing.expect(mem.eql(i32, list.items, &.{ 3, 3, 3, 3 }));
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
|
||||
test "addManyAsArray" {
|
||||
const a = std.testing.allocator;
|
||||
{
|
||||
var list = ArrayList(u8).init(a);
|
||||
@ -1907,7 +1907,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged growing memory preserves contents" {
|
||||
test "growing memory preserves contents" {
|
||||
// Shrink the list after every insertion to ensure that a memory growth
|
||||
// will be triggered in the next operation.
|
||||
const a = std.testing.allocator;
|
||||
@ -1941,46 +1941,55 @@ test "std.ArrayList/ArrayListUnmanaged growing memory preserves contents" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayList.fromOwnedSliceSentinel" {
|
||||
test "fromOwnedSlice" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var orig_list = ArrayList(u8).init(a);
|
||||
defer orig_list.deinit();
|
||||
try orig_list.appendSlice("foobar");
|
||||
|
||||
var orig_list = ArrayList(u8).init(a);
|
||||
defer orig_list.deinit();
|
||||
try orig_list.appendSlice("foobar");
|
||||
const sentinel_slice = try orig_list.toOwnedSliceSentinel(0);
|
||||
const slice = try orig_list.toOwnedSlice();
|
||||
var list = ArrayList(u8).fromOwnedSlice(a, slice);
|
||||
defer list.deinit();
|
||||
try testing.expectEqualStrings(list.items, "foobar");
|
||||
}
|
||||
{
|
||||
var list = ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
try list.appendSlice("foobar");
|
||||
|
||||
var list = ArrayList(u8).fromOwnedSliceSentinel(a, 0, sentinel_slice);
|
||||
defer list.deinit();
|
||||
try testing.expectEqualStrings(list.items, "foobar");
|
||||
const slice = try list.toOwnedSlice();
|
||||
var unmanaged = ArrayListUnmanaged(u8).fromOwnedSlice(slice);
|
||||
defer unmanaged.deinit(a);
|
||||
try testing.expectEqualStrings(unmanaged.items, "foobar");
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.fromOwnedSlice" {
|
||||
test "fromOwnedSliceSentinel" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var orig_list = ArrayList(u8).init(a);
|
||||
defer orig_list.deinit();
|
||||
try orig_list.appendSlice("foobar");
|
||||
|
||||
var list = ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
try list.appendSlice("foobar");
|
||||
const sentinel_slice = try orig_list.toOwnedSliceSentinel(0);
|
||||
var list = ArrayList(u8).fromOwnedSliceSentinel(a, 0, sentinel_slice);
|
||||
defer list.deinit();
|
||||
try testing.expectEqualStrings(list.items, "foobar");
|
||||
}
|
||||
{
|
||||
var list = ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
try list.appendSlice("foobar");
|
||||
|
||||
const slice = try list.toOwnedSlice();
|
||||
var unmanaged = ArrayListUnmanaged(u8).fromOwnedSlice(slice);
|
||||
defer unmanaged.deinit(a);
|
||||
try testing.expectEqualStrings(unmanaged.items, "foobar");
|
||||
const sentinel_slice = try list.toOwnedSliceSentinel(0);
|
||||
var unmanaged = ArrayListUnmanaged(u8).fromOwnedSliceSentinel(0, sentinel_slice);
|
||||
defer unmanaged.deinit(a);
|
||||
try testing.expectEqualStrings(unmanaged.items, "foobar");
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.fromOwnedSliceSentinel" {
|
||||
const a = testing.allocator;
|
||||
|
||||
var list = ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
try list.appendSlice("foobar");
|
||||
|
||||
const sentinel_slice = try list.toOwnedSliceSentinel(0);
|
||||
var unmanaged = ArrayListUnmanaged(u8).fromOwnedSliceSentinel(0, sentinel_slice);
|
||||
defer unmanaged.deinit(a);
|
||||
try testing.expectEqualStrings(unmanaged.items, "foobar");
|
||||
}
|
||||
|
||||
test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
|
||||
test "toOwnedSliceSentinel" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = ArrayList(u8).init(a);
|
||||
@ -2004,7 +2013,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
|
||||
}
|
||||
}
|
||||
|
||||
test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
|
||||
test "accepts unaligned slices" {
|
||||
const a = testing.allocator;
|
||||
{
|
||||
var list = std.ArrayListAligned(u8, 8).init(a);
|
||||
@ -2028,7 +2037,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.ArrayList(u0)" {
|
||||
test "ArrayList(u0)" {
|
||||
// An ArrayList on zero-sized types should not need to allocate
|
||||
const a = testing.failing_allocator;
|
||||
|
||||
@ -2048,7 +2057,7 @@ test "std.ArrayList(u0)" {
|
||||
try testing.expectEqual(count, 3);
|
||||
}
|
||||
|
||||
test "std.ArrayList(?u32).popOrNull()" {
|
||||
test "ArrayList(?u32).popOrNull()" {
|
||||
const a = testing.allocator;
|
||||
|
||||
var list = ArrayList(?u32).init(a);
|
||||
@ -2065,7 +2074,7 @@ test "std.ArrayList(?u32).popOrNull()" {
|
||||
try testing.expect(list.popOrNull() == null);
|
||||
}
|
||||
|
||||
test "std.ArrayList(u32).getLast()" {
|
||||
test "ArrayList(u32).getLast()" {
|
||||
const a = testing.allocator;
|
||||
|
||||
var list = ArrayList(u32).init(a);
|
||||
@ -2076,7 +2085,7 @@ test "std.ArrayList(u32).getLast()" {
|
||||
try testing.expectEqual(const_list.getLast(), 2);
|
||||
}
|
||||
|
||||
test "std.ArrayList(u32).getLastOrNull()" {
|
||||
test "ArrayList(u32).getLastOrNull()" {
|
||||
const a = testing.allocator;
|
||||
|
||||
var list = ArrayList(u32).init(a);
|
||||
|
@ -101,7 +101,7 @@ pub const BufSet = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "BufSet" {
|
||||
test BufSet {
|
||||
var bufset = BufSet.init(std.testing.allocator);
|
||||
defer bufset.deinit();
|
||||
|
||||
@ -115,7 +115,7 @@ test "BufSet" {
|
||||
try bufset.insert("z");
|
||||
}
|
||||
|
||||
test "BufSet clone" {
|
||||
test "clone" {
|
||||
var original = BufSet.init(testing.allocator);
|
||||
defer original.deinit();
|
||||
try original.insert("x");
|
||||
@ -132,7 +132,7 @@ test "BufSet clone" {
|
||||
);
|
||||
}
|
||||
|
||||
test "BufSet.clone with arena" {
|
||||
test "clone with arena" {
|
||||
const allocator = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||
defer arena.deinit();
|
||||
|
@ -84,7 +84,7 @@ test {
|
||||
_ = inflate;
|
||||
}
|
||||
|
||||
test "flate compress/decompress" {
|
||||
test "compress/decompress" {
|
||||
if (builtin.target.cpu.arch == .wasm32) return error.SkipZigTest;
|
||||
|
||||
var cmp_buf: [64 * 1024]u8 = undefined; // compressed data buffer
|
||||
@ -252,7 +252,7 @@ fn testDecompress(comptime container: Container, compressed: []const u8, expecte
|
||||
try testing.expectEqualSlices(u8, expected_plain, out.items);
|
||||
}
|
||||
|
||||
test "flate don't read past deflate stream's end" {
|
||||
test "don't read past deflate stream's end" {
|
||||
try testDecompress(.zlib, &[_]u8{
|
||||
0x08, 0xd7, 0x63, 0xf8, 0xcf, 0xc0, 0xc0, 0x00, 0xc1, 0xff,
|
||||
0xff, 0x43, 0x30, 0x03, 0x03, 0xc3, 0xff, 0xff, 0xff, 0x01,
|
||||
@ -264,7 +264,7 @@ test "flate don't read past deflate stream's end" {
|
||||
});
|
||||
}
|
||||
|
||||
test "flate zlib header" {
|
||||
test "zlib header" {
|
||||
// Truncated header
|
||||
try testing.expectError(
|
||||
error.EndOfStream,
|
||||
@ -292,7 +292,7 @@ test "flate zlib header" {
|
||||
);
|
||||
}
|
||||
|
||||
test "flate gzip header" {
|
||||
test "gzip header" {
|
||||
// Truncated header
|
||||
try testing.expectError(
|
||||
error.EndOfStream,
|
||||
@ -353,7 +353,7 @@ test "flate gzip header" {
|
||||
}, "");
|
||||
}
|
||||
|
||||
test "flate public interface" {
|
||||
test "public interface" {
|
||||
if (builtin.target.cpu.arch == .wasm32) return error.SkipZigTest;
|
||||
|
||||
const plain_data = [_]u8{ 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0x0a };
|
||||
|
@ -130,7 +130,7 @@ pub fn full(self: *Self) bool {
|
||||
}
|
||||
|
||||
// example from: https://youtu.be/SJPvNi4HrWQ?t=3558
|
||||
test "flate.CircularBuffer writeMatch" {
|
||||
test "writeMatch" {
|
||||
var cb: Self = .{};
|
||||
|
||||
cb.writeAll("a salad; ");
|
||||
@ -140,7 +140,7 @@ test "flate.CircularBuffer writeMatch" {
|
||||
try testing.expectEqualStrings("a salad; a salsal", cb.read());
|
||||
}
|
||||
|
||||
test "flate.CircularBuffer writeMatch overlap" {
|
||||
test "writeMatch overlap" {
|
||||
var cb: Self = .{};
|
||||
|
||||
cb.writeAll("a b c ");
|
||||
@ -150,7 +150,7 @@ test "flate.CircularBuffer writeMatch overlap" {
|
||||
try testing.expectEqualStrings("a b c b c b c d", cb.read());
|
||||
}
|
||||
|
||||
test "flate.CircularBuffer readAtMost" {
|
||||
test "readAtMost" {
|
||||
var cb: Self = .{};
|
||||
|
||||
cb.writeAll("0123456789");
|
||||
@ -165,7 +165,7 @@ test "flate.CircularBuffer readAtMost" {
|
||||
try testing.expectEqualStrings("", cb.read());
|
||||
}
|
||||
|
||||
test "flate.CircularBuffer" {
|
||||
test "CircularBuffer" {
|
||||
var cb: Self = .{};
|
||||
|
||||
const data = "0123456789abcdef" ** (1024 / 16);
|
||||
@ -201,7 +201,7 @@ test "flate.CircularBuffer" {
|
||||
try testing.expectEqual(@as(usize, 200), cb.read().len); // read the rest
|
||||
}
|
||||
|
||||
test "flate.CircularBuffer write overlap" {
|
||||
test "write overlap" {
|
||||
var cb: Self = .{};
|
||||
cb.wp = cb.buffer.len - 15;
|
||||
cb.rp = cb.wp;
|
||||
@ -218,7 +218,7 @@ test "flate.CircularBuffer write overlap" {
|
||||
try testing.expect(cb.wp == cb.rp);
|
||||
}
|
||||
|
||||
test "flate.CircularBuffer writeMatch/read overlap" {
|
||||
test "writeMatch/read overlap" {
|
||||
var cb: Self = .{};
|
||||
cb.wp = cb.buffer.len - 15;
|
||||
cb.rp = cb.wp;
|
||||
|
@ -83,7 +83,7 @@ fn hashu(v: u32) u32 {
|
||||
return @intCast((v *% prime4) >> consts.lookup.shift);
|
||||
}
|
||||
|
||||
test "flate.Lookup add/prev" {
|
||||
test "add/prev" {
|
||||
const data = [_]u8{
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
@ -107,7 +107,7 @@ test "flate.Lookup add/prev" {
|
||||
try expect(h.chain[2 + 8] == 2);
|
||||
}
|
||||
|
||||
test "flate.Lookup bulkAdd" {
|
||||
test "bulkAdd" {
|
||||
const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
||||
|
||||
// one by one
|
||||
|
@ -122,7 +122,7 @@ pub fn tokensBuffer(self: *Self) ?[]const u8 {
|
||||
return self.buffer[@intCast(self.fp)..self.rp];
|
||||
}
|
||||
|
||||
test "flate.SlidingWindow match" {
|
||||
test "match" {
|
||||
const data = "Blah blah blah blah blah!";
|
||||
var win: Self = .{};
|
||||
try expect(win.write(data) == data.len);
|
||||
@ -142,7 +142,7 @@ test "flate.SlidingWindow match" {
|
||||
try expect(win.match(15, 20, 4) == 0);
|
||||
}
|
||||
|
||||
test "flate.SlidingWindow slide" {
|
||||
test "slide" {
|
||||
var win: Self = .{};
|
||||
win.wp = Self.buffer_len - 11;
|
||||
win.rp = Self.buffer_len - 111;
|
||||
|
@ -275,12 +275,12 @@ const match_distances = [_]MatchDistance{
|
||||
.{ .extra_bits = 13, .base_scaled = 0x6000, .code = 29, .base = 24577 },
|
||||
};
|
||||
|
||||
test "flate.Token size" {
|
||||
test "size" {
|
||||
try expect(@sizeOf(Token) == 4);
|
||||
}
|
||||
|
||||
// testing table https://datatracker.ietf.org/doc/html/rfc1951#page-12
|
||||
test "flate.Token MatchLength" {
|
||||
test "MatchLength" {
|
||||
var c = Token.initMatch(1, 4).lengthEncoding();
|
||||
try expect(c.code == 258);
|
||||
try expect(c.extra_bits == 0);
|
||||
@ -302,7 +302,7 @@ test "flate.Token MatchLength" {
|
||||
try expect(c.extra_length == 130 - 115);
|
||||
}
|
||||
|
||||
test "flate.Token MatchDistance" {
|
||||
test "MatchDistance" {
|
||||
var c = Token.initMatch(1, 4).distanceEncoding();
|
||||
try expect(c.code == 0);
|
||||
try expect(c.extra_bits == 0);
|
||||
@ -314,7 +314,7 @@ test "flate.Token MatchDistance" {
|
||||
try expect(c.extra_distance == 192 - 129);
|
||||
}
|
||||
|
||||
test "flate.Token match_lengths" {
|
||||
test "match_lengths" {
|
||||
for (match_lengths, 0..) |ml, i| {
|
||||
try expect(@as(u16, ml.base_scaled) + 3 == ml.base);
|
||||
try expect(i + 257 == ml.code);
|
||||
|
@ -218,7 +218,7 @@ pub fn BitReader(comptime ReaderType: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
test "flate.BitReader" {
|
||||
test "BitReader" {
|
||||
var fbs = std.io.fixedBufferStream(&[_]u8{ 0xf3, 0x48, 0xcd, 0xc9, 0x00, 0x00 });
|
||||
var br = bitReader(fbs.reader());
|
||||
const F = BitReader(@TypeOf(fbs.reader())).flag;
|
||||
@ -253,7 +253,7 @@ test "flate.BitReader" {
|
||||
try testing.expectEqual(@as(u16, 0xc), try br.readN(4, 0));
|
||||
}
|
||||
|
||||
test "flate.BitReader read block type 1 data" {
|
||||
test "read block type 1 data" {
|
||||
const data = [_]u8{
|
||||
0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, // deflate data block type 1
|
||||
0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00,
|
||||
@ -277,7 +277,7 @@ test "flate.BitReader read block type 1 data" {
|
||||
try testing.expectEqual(@as(u16, 0xddcc), try br.readF(u16, 0));
|
||||
}
|
||||
|
||||
test "flate.BitReader init" {
|
||||
test "init" {
|
||||
const data = [_]u8{
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
@ -302,7 +302,7 @@ test "flate.BitReader init" {
|
||||
try testing.expectEqual(@as(u64, 0x00_00_00_00_00_08_07_06), br.bits);
|
||||
}
|
||||
|
||||
test "flate.BitReader readAll" {
|
||||
test "readAll" {
|
||||
const data = [_]u8{
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
@ -320,7 +320,7 @@ test "flate.BitReader readAll" {
|
||||
try testing.expectEqualSlices(u8, data[0..16], &out);
|
||||
}
|
||||
|
||||
test "flate.BitReader readFixedCode" {
|
||||
test "readFixedCode" {
|
||||
const fixed_codes = @import("huffman_encoder.zig").fixed_codes;
|
||||
|
||||
var fbs = std.io.fixedBufferStream(&fixed_codes);
|
||||
|
@ -596,20 +596,20 @@ const TestCase = @import("testdata/block_writer.zig").TestCase;
|
||||
const testCases = @import("testdata/block_writer.zig").testCases;
|
||||
|
||||
// tests if the writeBlock encoding has changed.
|
||||
test "flate.BlockWriter write" {
|
||||
test "write" {
|
||||
inline for (0..testCases.len) |i| {
|
||||
try testBlock(testCases[i], .write_block);
|
||||
}
|
||||
}
|
||||
|
||||
// tests if the writeBlockDynamic encoding has changed.
|
||||
test "flate.BlockWriter dynamicBlock" {
|
||||
test "dynamicBlock" {
|
||||
inline for (0..testCases.len) |i| {
|
||||
try testBlock(testCases[i], .write_dyn_block);
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.BlockWriter huffmanBlock" {
|
||||
test "huffmanBlock" {
|
||||
inline for (0..testCases.len) |i| {
|
||||
try testBlock(testCases[i], .write_huffman_block);
|
||||
}
|
||||
|
@ -93,7 +93,6 @@ fn HuffmanDecoder(
|
||||
var code: u16 = 0;
|
||||
var idx: u16 = 0;
|
||||
for (&self.symbols, 0..) |*sym, pos| {
|
||||
//print("sym: {}\n", .{sym});
|
||||
if (sym.code_bits == 0) continue; // skip unused
|
||||
sym.code = code;
|
||||
|
||||
@ -116,7 +115,6 @@ fn HuffmanDecoder(
|
||||
idx = next_idx;
|
||||
code = next_code;
|
||||
}
|
||||
//print("decoder generate, code: {d}, idx: {d}\n", .{ code, idx });
|
||||
}
|
||||
|
||||
/// Given the list of code lengths check that it represents a canonical
|
||||
@ -176,7 +174,7 @@ fn HuffmanDecoder(
|
||||
};
|
||||
}
|
||||
|
||||
test "flate.HuffmanDecoder init/find" {
|
||||
test "init/find" {
|
||||
// example data from: https://youtu.be/SJPvNi4HrWQ?t=8423
|
||||
const code_lens = [_]u4{ 4, 3, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2 };
|
||||
var h: CodegenDecoder = .{};
|
||||
@ -252,11 +250,7 @@ test "flate.HuffmanDecoder init/find" {
|
||||
try testing.expectEqual(16, (try h.find(@intCast(c))).symbol);
|
||||
}
|
||||
|
||||
const print = std.debug.print;
|
||||
const assert = std.debug.assert;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
test "flate.HuffmanDecoder encode/decode literals" {
|
||||
test "encode/decode literals" {
|
||||
const LiteralEncoder = @import("huffman_encoder.zig").LiteralEncoder;
|
||||
|
||||
for (1..286) |j| { // for all different number of codes
|
||||
@ -292,7 +286,7 @@ test "flate.HuffmanDecoder encode/decode literals" {
|
||||
};
|
||||
|
||||
const c = enc.codes[symbol];
|
||||
try expect(c.code == c_code);
|
||||
try testing.expect(c.code == c_code);
|
||||
}
|
||||
|
||||
// find each symbol by code
|
||||
@ -301,8 +295,8 @@ test "flate.HuffmanDecoder encode/decode literals" {
|
||||
|
||||
const s_code: u15 = @bitReverse(@as(u15, @intCast(c.code)));
|
||||
const s = try dec.find(s_code);
|
||||
try expect(s.code == s_code);
|
||||
try expect(s.code_bits == c.len);
|
||||
try testing.expect(s.code == s_code);
|
||||
try testing.expect(s.code_bits == c.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ fn byFreq(context: void, a: LiteralNode, b: LiteralNode) bool {
|
||||
return a.freq < b.freq;
|
||||
}
|
||||
|
||||
test "flate.HuffmanEncoder generate a Huffman code from an array of frequencies" {
|
||||
test "generate a Huffman code from an array of frequencies" {
|
||||
var freqs: [19]u16 = [_]u16{
|
||||
8, // 0
|
||||
1, // 1
|
||||
@ -421,7 +421,7 @@ test "flate.HuffmanEncoder generate a Huffman code from an array of frequencies"
|
||||
try testing.expectEqual(@as(u16, 0x3f), enc.codes[16].code);
|
||||
}
|
||||
|
||||
test "flate.HuffmanEncoder generate a Huffman code for the fixed literal table specific to Deflate" {
|
||||
test "generate a Huffman code for the fixed literal table specific to Deflate" {
|
||||
const enc = fixedLiteralEncoder();
|
||||
for (enc.codes) |c| {
|
||||
switch (c.len) {
|
||||
@ -443,7 +443,7 @@ test "flate.HuffmanEncoder generate a Huffman code for the fixed literal table s
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.HuffmanEncoder generate a Huffman code for the 30 possible relative distances (LZ77 distances) of Deflate" {
|
||||
test "generate a Huffman code for the 30 possible relative distances (LZ77 distances) of Deflate" {
|
||||
const enc = fixedDistanceEncoder();
|
||||
for (enc.codes) |c| {
|
||||
const v = @bitReverse(@as(u5, @intCast(c.code)));
|
||||
@ -458,7 +458,7 @@ fn bitReverse(comptime T: type, value: T, n: usize) T {
|
||||
return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n));
|
||||
}
|
||||
|
||||
test "flate bitReverse" {
|
||||
test "bitReverse" {
|
||||
const ReverseBitsTest = struct {
|
||||
in: u16,
|
||||
bit_count: u5,
|
||||
@ -482,7 +482,7 @@ test "flate bitReverse" {
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.HuffmanEncoder fixedLiteralEncoder codes" {
|
||||
test "fixedLiteralEncoder codes" {
|
||||
var al = std.ArrayList(u8).init(testing.allocator);
|
||||
defer al.deinit();
|
||||
var bw = std.io.bitWriter(.little, al.writer());
|
||||
|
@ -342,7 +342,7 @@ pub fn Inflate(comptime container: Container, comptime ReaderType: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
test "flate.Inflate decompress" {
|
||||
test "decompress" {
|
||||
const cases = [_]struct {
|
||||
in: []const u8,
|
||||
out: []const u8,
|
||||
@ -383,7 +383,7 @@ test "flate.Inflate decompress" {
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.Inflate gzip decompress" {
|
||||
test "gzip decompress" {
|
||||
const cases = [_]struct {
|
||||
in: []const u8,
|
||||
out: []const u8,
|
||||
@ -440,7 +440,7 @@ test "flate.Inflate gzip decompress" {
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.Inflate zlib decompress" {
|
||||
test "zlib decompress" {
|
||||
const cases = [_]struct {
|
||||
in: []const u8,
|
||||
out: []const u8,
|
||||
@ -466,7 +466,7 @@ test "flate.Inflate zlib decompress" {
|
||||
}
|
||||
}
|
||||
|
||||
test "flate.Inflate fuzzing tests" {
|
||||
test "fuzzing tests" {
|
||||
const cases = [_]struct {
|
||||
input: []const u8,
|
||||
out: []const u8 = "",
|
||||
@ -529,7 +529,7 @@ test "flate.Inflate fuzzing tests" {
|
||||
}
|
||||
}
|
||||
|
||||
test "flate bug 18966" {
|
||||
test "bug 18966" {
|
||||
const input = @embedFile("testdata/fuzz/bug_18966.input");
|
||||
const expect = @embedFile("testdata/fuzz/bug_18966.expect");
|
||||
|
||||
|
@ -21,7 +21,7 @@ fn testDecompressError(expected: anyerror, compressed: []const u8) !void {
|
||||
return std.testing.expectError(expected, testDecompress(compressed));
|
||||
}
|
||||
|
||||
test "LZMA: decompress empty world" {
|
||||
test "decompress empty world" {
|
||||
try testDecompressEqual(
|
||||
"",
|
||||
&[_]u8{
|
||||
@ -31,7 +31,7 @@ test "LZMA: decompress empty world" {
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: decompress hello world" {
|
||||
test "decompress hello world" {
|
||||
try testDecompressEqual(
|
||||
"Hello world\n",
|
||||
&[_]u8{
|
||||
@ -42,7 +42,7 @@ test "LZMA: decompress hello world" {
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: decompress huge dict" {
|
||||
test "decompress huge dict" {
|
||||
try testDecompressEqual(
|
||||
"Hello world\n",
|
||||
&[_]u8{
|
||||
@ -53,35 +53,35 @@ test "LZMA: decompress huge dict" {
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: unknown size with end of payload marker" {
|
||||
test "unknown size with end of payload marker" {
|
||||
try testDecompressEqual(
|
||||
"Hello\nWorld!\n",
|
||||
@embedFile("testdata/good-unknown_size-with_eopm.lzma"),
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: known size without end of payload marker" {
|
||||
test "known size without end of payload marker" {
|
||||
try testDecompressEqual(
|
||||
"Hello\nWorld!\n",
|
||||
@embedFile("testdata/good-known_size-without_eopm.lzma"),
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: known size with end of payload marker" {
|
||||
test "known size with end of payload marker" {
|
||||
try testDecompressEqual(
|
||||
"Hello\nWorld!\n",
|
||||
@embedFile("testdata/good-known_size-with_eopm.lzma"),
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: too big uncompressed size in header" {
|
||||
test "too big uncompressed size in header" {
|
||||
try testDecompressError(
|
||||
error.CorruptInput,
|
||||
@embedFile("testdata/bad-too_big_size-with_eopm.lzma"),
|
||||
);
|
||||
}
|
||||
|
||||
test "LZMA: too small uncompressed size in header" {
|
||||
test "too small uncompressed size in header" {
|
||||
try testDecompressError(
|
||||
error.CorruptInput,
|
||||
@embedFile("testdata/bad-too_small_size-without_eopm-3.lzma"),
|
||||
|
@ -49,7 +49,7 @@ const testing = std.testing;
|
||||
const expectEqualSlices = std.testing.expectEqualSlices;
|
||||
const expectError = std.testing.expectError;
|
||||
|
||||
test "Vec2D.init" {
|
||||
test "init" {
|
||||
const allocator = testing.allocator;
|
||||
var vec2d = try Vec2D(i32).init(allocator, 1, .{ 2, 3 });
|
||||
defer vec2d.deinit(allocator);
|
||||
@ -58,7 +58,7 @@ test "Vec2D.init" {
|
||||
try expectEqualSlices(i32, &.{ 1, 1, 1 }, try vec2d.get(1));
|
||||
}
|
||||
|
||||
test "Vec2D.init overflow" {
|
||||
test "init overflow" {
|
||||
const allocator = testing.allocator;
|
||||
try expectError(
|
||||
error.Overflow,
|
||||
@ -66,7 +66,7 @@ test "Vec2D.init overflow" {
|
||||
);
|
||||
}
|
||||
|
||||
test "Vec2D.fill" {
|
||||
test "fill" {
|
||||
const allocator = testing.allocator;
|
||||
var vec2d = try Vec2D(i32).init(allocator, 0, .{ 2, 3 });
|
||||
defer vec2d.deinit(allocator);
|
||||
@ -77,7 +77,7 @@ test "Vec2D.fill" {
|
||||
try expectEqualSlices(i32, &.{ 7, 7, 7 }, try vec2d.get(1));
|
||||
}
|
||||
|
||||
test "Vec2D.get" {
|
||||
test "get" {
|
||||
var data = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
const vec2d = Vec2D(i32){
|
||||
.data = &data,
|
||||
@ -90,7 +90,7 @@ test "Vec2D.get" {
|
||||
try expectEqualSlices(i32, &.{ 6, 7 }, try vec2d.get(3));
|
||||
}
|
||||
|
||||
test "Vec2D.getMut" {
|
||||
test "getMut" {
|
||||
var data = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
var vec2d = Vec2D(i32){
|
||||
.data = &data,
|
||||
@ -107,7 +107,7 @@ test "Vec2D.getMut" {
|
||||
try expectEqualSlices(i32, &.{ 6, 7 }, try vec2d.get(3));
|
||||
}
|
||||
|
||||
test "Vec2D.get multiplication overflow" {
|
||||
test "get multiplication overflow" {
|
||||
const allocator = testing.allocator;
|
||||
var matrix = try Vec2D(i32).init(allocator, 0, .{ 3, 4 });
|
||||
defer matrix.deinit(allocator);
|
||||
@ -117,7 +117,7 @@ test "Vec2D.get multiplication overflow" {
|
||||
try expectError(error.Overflow, matrix.getMut(row));
|
||||
}
|
||||
|
||||
test "Vec2D.get addition overflow" {
|
||||
test "get addition overflow" {
|
||||
const allocator = testing.allocator;
|
||||
var matrix = try Vec2D(i32).init(allocator, 0, .{ 3, 5 });
|
||||
defer matrix.deinit(allocator);
|
||||
|
@ -222,7 +222,7 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
|
||||
try std.testing.expectEqualSlices(u8, expected, buf);
|
||||
}
|
||||
|
||||
test "zstandard decompression" {
|
||||
test "decompression" {
|
||||
const uncompressed = @embedFile("testdata/rfc8478.txt");
|
||||
const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");
|
||||
const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");
|
||||
@ -239,7 +239,7 @@ test "zstandard decompression" {
|
||||
try std.testing.expectEqualSlices(u8, uncompressed, buffer);
|
||||
}
|
||||
|
||||
test "zstandard streaming decompression" {
|
||||
test "streaming decompression" {
|
||||
// default stack size for wasm32 is too low for Decompressor - slightly
|
||||
// over 1MiB stack space is needed via the --stack CLI flag
|
||||
if (@import("builtin").target.cpu.arch == .wasm32) return error.SkipZigTest;
|
||||
|
@ -142,7 +142,7 @@ const TestEnum = enum {
|
||||
E,
|
||||
};
|
||||
|
||||
test "ComptimeStringMap list literal of list literals" {
|
||||
test "list literal of list literals" {
|
||||
const map = ComptimeStringMap(TestEnum, .{
|
||||
.{ "these", .D },
|
||||
.{ "have", .A },
|
||||
@ -157,7 +157,7 @@ test "ComptimeStringMap list literal of list literals" {
|
||||
try std.testing.expect(null == map.get("NOTHING"));
|
||||
}
|
||||
|
||||
test "ComptimeStringMap array of structs" {
|
||||
test "array of structs" {
|
||||
const KV = struct { []const u8, TestEnum };
|
||||
const map = ComptimeStringMap(TestEnum, [_]KV{
|
||||
.{ "these", .D },
|
||||
@ -170,7 +170,7 @@ test "ComptimeStringMap array of structs" {
|
||||
try testMap(map);
|
||||
}
|
||||
|
||||
test "ComptimeStringMap slice of structs" {
|
||||
test "slice of structs" {
|
||||
const KV = struct { []const u8, TestEnum };
|
||||
const slice: []const KV = &[_]KV{
|
||||
.{ "these", .D },
|
||||
@ -198,7 +198,7 @@ fn testMap(comptime map: anytype) !void {
|
||||
try std.testing.expect(null == map.get("averylongstringthathasnomatches"));
|
||||
}
|
||||
|
||||
test "ComptimeStringMap void value type, slice of structs" {
|
||||
test "void value type, slice of structs" {
|
||||
const KV = struct { []const u8 };
|
||||
const slice: []const KV = &[_]KV{
|
||||
.{"these"},
|
||||
@ -215,7 +215,7 @@ test "ComptimeStringMap void value type, slice of structs" {
|
||||
try std.testing.expect(null == map.get("NOTHING"));
|
||||
}
|
||||
|
||||
test "ComptimeStringMap void value type, list literal of list literals" {
|
||||
test "void value type, list literal of list literals" {
|
||||
const map = ComptimeStringMap(void, .{
|
||||
.{"these"},
|
||||
.{"have"},
|
||||
@ -258,7 +258,7 @@ test "ComptimeStringMapWithEql" {
|
||||
try std.testing.expect(map.has("ThESe"));
|
||||
}
|
||||
|
||||
test "ComptimeStringMap empty" {
|
||||
test "empty" {
|
||||
const m1 = ComptimeStringMap(usize, .{});
|
||||
try std.testing.expect(null == m1.get("anything"));
|
||||
|
||||
@ -266,7 +266,7 @@ test "ComptimeStringMap empty" {
|
||||
try std.testing.expect(null == m2.get("anything"));
|
||||
}
|
||||
|
||||
test "ComptimeStringMap redundant entries" {
|
||||
test "redundant entries" {
|
||||
const map = ComptimeStringMap(TestEnum, .{
|
||||
.{ "redundant", .D },
|
||||
.{ "theNeedle", .A },
|
||||
@ -284,7 +284,7 @@ test "ComptimeStringMap redundant entries" {
|
||||
try std.testing.expectEqual(TestEnum.A, map.get("theNeedle").?);
|
||||
}
|
||||
|
||||
test "ComptimeStringMap redundant insensitive" {
|
||||
test "redundant insensitive" {
|
||||
const map = ComptimeStringMapWithEql(TestEnum, .{
|
||||
.{ "redundant", .D },
|
||||
.{ "theNeedle", .A },
|
||||
@ -300,7 +300,7 @@ test "ComptimeStringMap redundant insensitive" {
|
||||
try std.testing.expectEqual(TestEnum.A, map.get("theNeedle").?);
|
||||
}
|
||||
|
||||
test "ComptimeStringMap comptime-only value" {
|
||||
test "comptime-only value" {
|
||||
const map = std.ComptimeStringMap(type, .{
|
||||
.{ "a", struct {
|
||||
pub const foo = 1;
|
||||
|
@ -137,7 +137,7 @@ test "non-affine edwards25519 to curve25519 projection" {
|
||||
try std.testing.expectEqualSlices(u8, &xp.toBytes(), &expected);
|
||||
}
|
||||
|
||||
test "curve25519 small order check" {
|
||||
test "small order check" {
|
||||
var s: [32]u8 = [_]u8{1} ++ [_]u8{0} ** 31;
|
||||
const small_order_ss: [7][32]u8 = .{
|
||||
.{
|
||||
|
@ -482,7 +482,7 @@ pub const Ed25519 = struct {
|
||||
};
|
||||
};
|
||||
|
||||
test "ed25519 key pair creation" {
|
||||
test "key pair creation" {
|
||||
var seed: [32]u8 = undefined;
|
||||
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
|
||||
const key_pair = try Ed25519.KeyPair.create(seed);
|
||||
@ -491,7 +491,7 @@ test "ed25519 key pair creation" {
|
||||
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key.toBytes())}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
|
||||
}
|
||||
|
||||
test "ed25519 signature" {
|
||||
test "signature" {
|
||||
var seed: [32]u8 = undefined;
|
||||
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
|
||||
const key_pair = try Ed25519.KeyPair.create(seed);
|
||||
@ -503,7 +503,7 @@ test "ed25519 signature" {
|
||||
try std.testing.expectError(error.SignatureVerificationFailed, sig.verify("TEST", key_pair.public_key));
|
||||
}
|
||||
|
||||
test "ed25519 batch verification" {
|
||||
test "batch verification" {
|
||||
var i: usize = 0;
|
||||
while (i < 100) : (i += 1) {
|
||||
const key_pair = try Ed25519.KeyPair.create(null);
|
||||
@ -532,7 +532,7 @@ test "ed25519 batch verification" {
|
||||
}
|
||||
}
|
||||
|
||||
test "ed25519 test vectors" {
|
||||
test "test vectors" {
|
||||
const Vec = struct {
|
||||
msg_hex: *const [64:0]u8,
|
||||
public_key_hex: *const [64:0]u8,
|
||||
@ -634,7 +634,7 @@ test "ed25519 test vectors" {
|
||||
}
|
||||
}
|
||||
|
||||
test "ed25519 with blind keys" {
|
||||
test "with blind keys" {
|
||||
const BlindKeyPair = Ed25519.key_blinding.BlindKeyPair;
|
||||
|
||||
// Create a standard Ed25519 key pair
|
||||
@ -657,7 +657,7 @@ test "ed25519 with blind keys" {
|
||||
try std.testing.expectEqualSlices(u8, &pk.toBytes(), &kp.public_key.toBytes());
|
||||
}
|
||||
|
||||
test "ed25519 signatures with streaming" {
|
||||
test "signatures with streaming" {
|
||||
const kp = try Ed25519.KeyPair.create(null);
|
||||
|
||||
var signer = try kp.signer(null);
|
||||
@ -673,7 +673,7 @@ test "ed25519 signatures with streaming" {
|
||||
try verifier.verify();
|
||||
}
|
||||
|
||||
test "ed25519 key pair from secret key" {
|
||||
test "key pair from secret key" {
|
||||
const kp = try Ed25519.KeyPair.create(null);
|
||||
const kp2 = try Ed25519.KeyPair.fromSecretKey(kp.secret_key);
|
||||
try std.testing.expectEqualSlices(u8, &kp.secret_key.toBytes(), &kp2.secret_key.toBytes());
|
||||
|
@ -493,7 +493,7 @@ pub const Edwards25519 = struct {
|
||||
|
||||
const htest = @import("../test.zig");
|
||||
|
||||
test "edwards25519 packing/unpacking" {
|
||||
test "packing/unpacking" {
|
||||
const s = [_]u8{170} ++ [_]u8{0} ** 31;
|
||||
var b = Edwards25519.basePoint;
|
||||
const pk = try b.mul(s);
|
||||
@ -529,7 +529,7 @@ test "edwards25519 packing/unpacking" {
|
||||
}
|
||||
}
|
||||
|
||||
test "edwards25519 point addition/subtraction" {
|
||||
test "point addition/subtraction" {
|
||||
var s1: [32]u8 = undefined;
|
||||
var s2: [32]u8 = undefined;
|
||||
crypto.random.bytes(&s1);
|
||||
@ -543,7 +543,7 @@ test "edwards25519 point addition/subtraction" {
|
||||
try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
|
||||
}
|
||||
|
||||
test "edwards25519 uniform-to-point" {
|
||||
test "uniform-to-point" {
|
||||
var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
|
||||
var p = Edwards25519.fromUniform(r);
|
||||
try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
|
||||
@ -554,7 +554,7 @@ test "edwards25519 uniform-to-point" {
|
||||
}
|
||||
|
||||
// Test vectors from draft-irtf-cfrg-hash-to-curve-12
|
||||
test "edwards25519 hash-to-curve operation" {
|
||||
test "hash-to-curve operation" {
|
||||
var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");
|
||||
try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895839a", p.toBytes()[0..]);
|
||||
|
||||
@ -562,7 +562,7 @@ test "edwards25519 hash-to-curve operation" {
|
||||
try htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d7367", p.toBytes()[0..]);
|
||||
}
|
||||
|
||||
test "edwards25519 implicit reduction of invalid scalars" {
|
||||
test "implicit reduction of invalid scalars" {
|
||||
const s = [_]u8{0} ** 31 ++ [_]u8{255};
|
||||
const p1 = try Edwards25519.basePoint.mulPublic(s);
|
||||
const p2 = try Edwards25519.basePoint.mul(s);
|
||||
|
@ -81,7 +81,7 @@ pub const X25519 = struct {
|
||||
|
||||
const htest = @import("../test.zig");
|
||||
|
||||
test "x25519 public key calculation from secret key" {
|
||||
test "public key calculation from secret key" {
|
||||
var sk: [32]u8 = undefined;
|
||||
var pk_expected: [32]u8 = undefined;
|
||||
_ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
|
||||
@ -90,7 +90,7 @@ test "x25519 public key calculation from secret key" {
|
||||
try std.testing.expectEqual(pk_calculated, pk_expected);
|
||||
}
|
||||
|
||||
test "x25519 rfc7748 vector1" {
|
||||
test "rfc7748 vector1" {
|
||||
const secret_key = [32]u8{ 0xa5, 0x46, 0xe3, 0x6b, 0xf0, 0x52, 0x7c, 0x9d, 0x3b, 0x16, 0x15, 0x4b, 0x82, 0x46, 0x5e, 0xdd, 0x62, 0x14, 0x4c, 0x0a, 0xc1, 0xfc, 0x5a, 0x18, 0x50, 0x6a, 0x22, 0x44, 0xba, 0x44, 0x9a, 0xc4 };
|
||||
const public_key = [32]u8{ 0xe6, 0xdb, 0x68, 0x67, 0x58, 0x30, 0x30, 0xdb, 0x35, 0x94, 0xc1, 0xa4, 0x24, 0xb1, 0x5f, 0x7c, 0x72, 0x66, 0x24, 0xec, 0x26, 0xb3, 0x35, 0x3b, 0x10, 0xa9, 0x03, 0xa6, 0xd0, 0xab, 0x1c, 0x4c };
|
||||
|
||||
@ -100,7 +100,7 @@ test "x25519 rfc7748 vector1" {
|
||||
try std.testing.expectEqual(output, expected_output);
|
||||
}
|
||||
|
||||
test "x25519 rfc7748 vector2" {
|
||||
test "rfc7748 vector2" {
|
||||
const secret_key = [32]u8{ 0x4b, 0x66, 0xe9, 0xd4, 0xd1, 0xb4, 0x67, 0x3c, 0x5a, 0xd2, 0x26, 0x91, 0x95, 0x7d, 0x6a, 0xf5, 0xc1, 0x1b, 0x64, 0x21, 0xe0, 0xea, 0x01, 0xd4, 0x2c, 0xa4, 0x16, 0x9e, 0x79, 0x18, 0xba, 0x0d };
|
||||
const public_key = [32]u8{ 0xe5, 0x21, 0x0f, 0x12, 0x78, 0x68, 0x11, 0xd3, 0xf4, 0xb7, 0x95, 0x9d, 0x05, 0x38, 0xae, 0x2c, 0x31, 0xdb, 0xe7, 0x10, 0x6f, 0xc0, 0x3c, 0x3e, 0xfc, 0x4c, 0xd5, 0x49, 0xc7, 0x15, 0xa4, 0x93 };
|
||||
|
||||
@ -110,7 +110,7 @@ test "x25519 rfc7748 vector2" {
|
||||
try std.testing.expectEqual(output, expected_output);
|
||||
}
|
||||
|
||||
test "x25519 rfc7748 one iteration" {
|
||||
test "rfc7748 one iteration" {
|
||||
const initial_value = [32]u8{ 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
const expected_output = [32]u8{ 0x42, 0x2c, 0x8e, 0x7a, 0x62, 0x27, 0xd7, 0xbc, 0xa1, 0x35, 0x0b, 0x3e, 0x2b, 0xb7, 0x27, 0x9f, 0x78, 0x97, 0xb8, 0x7b, 0xb6, 0x85, 0x4b, 0x78, 0x3c, 0x60, 0xe8, 0x03, 0x11, 0xae, 0x30, 0x79 };
|
||||
|
||||
@ -127,7 +127,7 @@ test "x25519 rfc7748 one iteration" {
|
||||
try std.testing.expectEqual(k, expected_output);
|
||||
}
|
||||
|
||||
test "x25519 rfc7748 1,000 iterations" {
|
||||
test "rfc7748 1,000 iterations" {
|
||||
// These iteration tests are slow so we always skip them. Results have been verified.
|
||||
if (true) {
|
||||
return error.SkipZigTest;
|
||||
@ -149,7 +149,7 @@ test "x25519 rfc7748 1,000 iterations" {
|
||||
try std.testing.expectEqual(k, expected_output);
|
||||
}
|
||||
|
||||
test "x25519 rfc7748 1,000,000 iterations" {
|
||||
test "rfc7748 1,000,000 iterations" {
|
||||
if (true) {
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
@ -758,7 +758,7 @@ fn XChaChaPoly1305(comptime rounds_nb: usize) type {
|
||||
};
|
||||
}
|
||||
|
||||
test "chacha20 AEAD API" {
|
||||
test "AEAD API" {
|
||||
const aeads = [_]type{ ChaCha20Poly1305, XChaCha20Poly1305 };
|
||||
const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
|
||||
const ad = "Additional data";
|
||||
@ -779,7 +779,7 @@ test "chacha20 AEAD API" {
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7539#section-2.4.2
|
||||
test "crypto.chacha20 test vector sunscreen" {
|
||||
test "test vector sunscreen" {
|
||||
const expected_result = [_]u8{
|
||||
0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80,
|
||||
0x41, 0xba, 0x07, 0x28, 0xdd, 0x0d, 0x69, 0x81,
|
||||
@ -820,7 +820,7 @@ test "crypto.chacha20 test vector sunscreen" {
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
|
||||
test "crypto.chacha20 test vector 1" {
|
||||
test "test vector 1" {
|
||||
const expected_result = [_]u8{
|
||||
0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90,
|
||||
0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28,
|
||||
@ -854,7 +854,7 @@ test "crypto.chacha20 test vector 1" {
|
||||
try testing.expectEqualSlices(u8, &expected_result, &result);
|
||||
}
|
||||
|
||||
test "crypto.chacha20 test vector 2" {
|
||||
test "test vector 2" {
|
||||
const expected_result = [_]u8{
|
||||
0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96,
|
||||
0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96,
|
||||
@ -888,7 +888,7 @@ test "crypto.chacha20 test vector 2" {
|
||||
try testing.expectEqualSlices(u8, &expected_result, &result);
|
||||
}
|
||||
|
||||
test "crypto.chacha20 test vector 3" {
|
||||
test "test vector 3" {
|
||||
const expected_result = [_]u8{
|
||||
0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5,
|
||||
0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a,
|
||||
@ -922,7 +922,7 @@ test "crypto.chacha20 test vector 3" {
|
||||
try testing.expectEqualSlices(u8, &expected_result, &result);
|
||||
}
|
||||
|
||||
test "crypto.chacha20 test vector 4" {
|
||||
test "test vector 4" {
|
||||
const expected_result = [_]u8{
|
||||
0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb,
|
||||
0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80,
|
||||
@ -956,7 +956,7 @@ test "crypto.chacha20 test vector 4" {
|
||||
try testing.expectEqualSlices(u8, &expected_result, &result);
|
||||
}
|
||||
|
||||
test "crypto.chacha20 test vector 5" {
|
||||
test "test vector 5" {
|
||||
const expected_result = [_]u8{
|
||||
0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69,
|
||||
0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75,
|
||||
@ -1142,7 +1142,7 @@ test "open" {
|
||||
}
|
||||
}
|
||||
|
||||
test "crypto.xchacha20" {
|
||||
test "xchacha20" {
|
||||
const key = [_]u8{69} ** 32;
|
||||
const nonce = [_]u8{42} ** 24;
|
||||
const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
|
||||
|
@ -371,7 +371,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
test "ECDSA - Basic operations over EcdsaP384Sha384" {
|
||||
test "Basic operations over EcdsaP384Sha384" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const Scheme = EcdsaP384Sha384;
|
||||
@ -387,7 +387,7 @@ test "ECDSA - Basic operations over EcdsaP384Sha384" {
|
||||
try sig2.verify(msg, kp.public_key);
|
||||
}
|
||||
|
||||
test "ECDSA - Basic operations over Secp256k1" {
|
||||
test "Basic operations over Secp256k1" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const Scheme = EcdsaSecp256k1Sha256oSha256;
|
||||
@ -403,7 +403,7 @@ test "ECDSA - Basic operations over Secp256k1" {
|
||||
try sig2.verify(msg, kp.public_key);
|
||||
}
|
||||
|
||||
test "ECDSA - Basic operations over EcdsaP384Sha256" {
|
||||
test "Basic operations over EcdsaP384Sha256" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256);
|
||||
@ -419,7 +419,7 @@ test "ECDSA - Basic operations over EcdsaP384Sha256" {
|
||||
try sig2.verify(msg, kp.public_key);
|
||||
}
|
||||
|
||||
test "ECDSA - Verifying a existing signature with EcdsaP384Sha256" {
|
||||
test "Verifying a existing signature with EcdsaP384Sha256" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256);
|
||||
@ -463,7 +463,7 @@ const TestVector = struct {
|
||||
result: enum { valid, invalid, acceptable },
|
||||
};
|
||||
|
||||
test "ECDSA - Test vectors from Project Wycheproof" {
|
||||
test "Test vectors from Project Wycheproof" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const vectors = [_]TestVector{
|
||||
@ -877,7 +877,7 @@ fn tvTry(vector: TestVector) !void {
|
||||
try sig.verify(msg, pk);
|
||||
}
|
||||
|
||||
test "ECDSA - Sec1 encoding/decoding" {
|
||||
test "Sec1 encoding/decoding" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
|
||||
const Scheme = EcdsaP384Sha384;
|
||||
|
@ -76,7 +76,7 @@ pub fn Hmac(comptime Hash: type) type {
|
||||
|
||||
const htest = @import("test.zig");
|
||||
|
||||
test "hmac md5" {
|
||||
test "md5" {
|
||||
var out: [HmacMd5.mac_length]u8 = undefined;
|
||||
HmacMd5.create(out[0..], "", "");
|
||||
try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
|
||||
@ -85,7 +85,7 @@ test "hmac md5" {
|
||||
try htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
|
||||
}
|
||||
|
||||
test "hmac sha1" {
|
||||
test "sha1" {
|
||||
var out: [HmacSha1.mac_length]u8 = undefined;
|
||||
HmacSha1.create(out[0..], "", "");
|
||||
try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
|
||||
@ -94,7 +94,7 @@ test "hmac sha1" {
|
||||
try htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
|
||||
}
|
||||
|
||||
test "hmac sha256" {
|
||||
test "sha256" {
|
||||
var out: [sha2.HmacSha256.mac_length]u8 = undefined;
|
||||
sha2.HmacSha256.create(out[0..], "", "");
|
||||
try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
|
||||
|
@ -232,7 +232,7 @@ pub const Md5 = struct {
|
||||
|
||||
const htest = @import("test.zig");
|
||||
|
||||
test "md5 single" {
|
||||
test "single" {
|
||||
try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
|
||||
try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
|
||||
try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
|
||||
@ -242,7 +242,7 @@ test "md5 single" {
|
||||
try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
}
|
||||
|
||||
test "md5 streaming" {
|
||||
test "streaming" {
|
||||
var h = Md5.init(.{});
|
||||
var out: [16]u8 = undefined;
|
||||
|
||||
@ -263,7 +263,7 @@ test "md5 streaming" {
|
||||
try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
|
||||
}
|
||||
|
||||
test "md5 aligned final" {
|
||||
test "aligned final" {
|
||||
var block = [_]u8{0} ** Md5.block_length;
|
||||
var out: [Md5.digest_length]u8 = undefined;
|
||||
|
||||
|
@ -195,7 +195,7 @@ pub const Poly1305 = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "poly1305 rfc7439 vector1" {
|
||||
test "rfc7439 vector1" {
|
||||
const expected_mac = "\xa8\x06\x1d\xc1\x30\x51\x36\xc6\xc2\x2b\x8b\xaf\x0c\x01\x27\xa9";
|
||||
|
||||
const msg = "Cryptographic Forum Research Group";
|
||||
@ -208,7 +208,7 @@ test "poly1305 rfc7439 vector1" {
|
||||
try std.testing.expectEqualSlices(u8, expected_mac, &mac);
|
||||
}
|
||||
|
||||
test "poly1305 requiring a final reduction" {
|
||||
test "requiring a final reduction" {
|
||||
const expected_mac = [_]u8{ 25, 13, 249, 42, 164, 57, 99, 60, 149, 181, 74, 74, 13, 63, 121, 6 };
|
||||
const msg = [_]u8{ 253, 193, 249, 146, 70, 6, 214, 226, 131, 213, 241, 116, 20, 24, 210, 224, 65, 151, 255, 104, 133 };
|
||||
const key = [_]u8{ 190, 63, 95, 57, 155, 103, 77, 170, 7, 98, 106, 44, 117, 186, 90, 185, 109, 118, 184, 24, 69, 41, 166, 243, 119, 132, 151, 61, 52, 43, 64, 250 };
|
||||
|
@ -138,7 +138,7 @@ pub inline fn secureZero(comptime T: type, s: []T) void {
|
||||
@memset(@as([]volatile T, s), 0);
|
||||
}
|
||||
|
||||
test "crypto.utils.timingSafeEql" {
|
||||
test "timingSafeEql" {
|
||||
var a: [100]u8 = undefined;
|
||||
var b: [100]u8 = undefined;
|
||||
random.bytes(a[0..]);
|
||||
@ -148,7 +148,7 @@ test "crypto.utils.timingSafeEql" {
|
||||
try testing.expect(timingSafeEql([100]u8, a, b));
|
||||
}
|
||||
|
||||
test "crypto.utils.timingSafeEql (vectors)" {
|
||||
test "timingSafeEql (vectors)" {
|
||||
if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
||||
|
||||
var a: [100]u8 = undefined;
|
||||
@ -162,7 +162,7 @@ test "crypto.utils.timingSafeEql (vectors)" {
|
||||
try testing.expect(timingSafeEql(@Vector(100, u8), v1, v3));
|
||||
}
|
||||
|
||||
test "crypto.utils.timingSafeCompare" {
|
||||
test "timingSafeCompare" {
|
||||
var a = [_]u8{10} ** 32;
|
||||
var b = [_]u8{10} ** 32;
|
||||
try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq);
|
||||
@ -175,7 +175,7 @@ test "crypto.utils.timingSafeCompare" {
|
||||
try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt);
|
||||
}
|
||||
|
||||
test "crypto.utils.timingSafe{Add,Sub}" {
|
||||
test "timingSafe{Add,Sub}" {
|
||||
const len = 32;
|
||||
var a: [len]u8 = undefined;
|
||||
var b: [len]u8 = undefined;
|
||||
@ -195,7 +195,7 @@ test "crypto.utils.timingSafe{Add,Sub}" {
|
||||
}
|
||||
}
|
||||
|
||||
test "crypto.utils.secureZero" {
|
||||
test "secureZero" {
|
||||
var a = [_]u8{0xfe} ** 8;
|
||||
var b = [_]u8{0xfe} ** 8;
|
||||
|
||||
|
@ -120,7 +120,7 @@ pub fn directEnumArray(
|
||||
return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);
|
||||
}
|
||||
|
||||
test "std.enums.directEnumArray" {
|
||||
test "directEnumArray" {
|
||||
const E = enum(i4) { a = 4, b = 6, c = 2 };
|
||||
var runtime_false: bool = false;
|
||||
_ = &runtime_false;
|
||||
@ -163,7 +163,7 @@ pub fn directEnumArrayDefault(
|
||||
return result;
|
||||
}
|
||||
|
||||
test "std.enums.directEnumArrayDefault" {
|
||||
test "directEnumArrayDefault" {
|
||||
const E = enum(i4) { a = 4, b = 6, c = 2 };
|
||||
var runtime_false: bool = false;
|
||||
_ = &runtime_false;
|
||||
@ -178,7 +178,7 @@ test "std.enums.directEnumArrayDefault" {
|
||||
try testing.expectEqual(false, array[2]);
|
||||
}
|
||||
|
||||
test "std.enums.directEnumArrayDefault slice" {
|
||||
test "directEnumArrayDefault slice" {
|
||||
const E = enum(i4) { a = 4, b = 6, c = 2 };
|
||||
var runtime_b = "b";
|
||||
_ = &runtime_b;
|
||||
@ -214,7 +214,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
|
||||
};
|
||||
}
|
||||
|
||||
test "std.enums.nameCast" {
|
||||
test "nameCast" {
|
||||
const A = enum(u1) { a = 0, b = 1 };
|
||||
const B = enum(u1) { a = 1, b = 0 };
|
||||
try testing.expectEqual(A.a, nameCast(A, .a));
|
||||
@ -983,7 +983,7 @@ test "pure EnumSet fns" {
|
||||
try testing.expect(full.differenceWith(black).eql(red));
|
||||
}
|
||||
|
||||
test "std.enums.EnumSet empty" {
|
||||
test "EnumSet empty" {
|
||||
const E = enum {};
|
||||
const empty = EnumSet(E).initEmpty();
|
||||
const full = EnumSet(E).initFull();
|
||||
@ -994,7 +994,7 @@ test "std.enums.EnumSet empty" {
|
||||
try std.testing.expect(empty.eql(full.complement()));
|
||||
}
|
||||
|
||||
test "std.enums.EnumSet const iterator" {
|
||||
test "EnumSet const iterator" {
|
||||
const Direction = enum { up, down, left, right };
|
||||
const diag_move = init: {
|
||||
var move = EnumSet(Direction).initEmpty();
|
||||
@ -1298,7 +1298,7 @@ pub fn ensureIndexer(comptime T: type) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.enums.ensureIndexer" {
|
||||
test "ensureIndexer" {
|
||||
ensureIndexer(struct {
|
||||
pub const Key = u32;
|
||||
pub const count: comptime_int = 8;
|
||||
@ -1463,7 +1463,7 @@ test "EnumIndexer non-exhaustive" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.enums.EnumIndexer dense zeroed" {
|
||||
test "EnumIndexer dense zeroed" {
|
||||
const E = enum(u2) { b = 1, a = 0, c = 2 };
|
||||
const Indexer = EnumIndexer(E);
|
||||
ensureIndexer(Indexer);
|
||||
@ -1479,7 +1479,7 @@ test "std.enums.EnumIndexer dense zeroed" {
|
||||
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
|
||||
}
|
||||
|
||||
test "std.enums.EnumIndexer dense positive" {
|
||||
test "EnumIndexer dense positive" {
|
||||
const E = enum(u4) { c = 6, a = 4, b = 5 };
|
||||
const Indexer = EnumIndexer(E);
|
||||
ensureIndexer(Indexer);
|
||||
@ -1495,7 +1495,7 @@ test "std.enums.EnumIndexer dense positive" {
|
||||
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
|
||||
}
|
||||
|
||||
test "std.enums.EnumIndexer dense negative" {
|
||||
test "EnumIndexer dense negative" {
|
||||
const E = enum(i4) { a = -6, c = -4, b = -5 };
|
||||
const Indexer = EnumIndexer(E);
|
||||
ensureIndexer(Indexer);
|
||||
@ -1511,7 +1511,7 @@ test "std.enums.EnumIndexer dense negative" {
|
||||
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
|
||||
}
|
||||
|
||||
test "std.enums.EnumIndexer sparse" {
|
||||
test "EnumIndexer sparse" {
|
||||
const E = enum(i4) { a = -2, c = 6, b = 4 };
|
||||
const Indexer = EnumIndexer(E);
|
||||
ensureIndexer(Indexer);
|
||||
@ -1527,7 +1527,7 @@ test "std.enums.EnumIndexer sparse" {
|
||||
try testing.expectEqual(E.c, Indexer.keyForIndex(2));
|
||||
}
|
||||
|
||||
test "std.enums.EnumIndexer empty" {
|
||||
test "EnumIndexer empty" {
|
||||
const E = enum {};
|
||||
const Indexer = EnumIndexer(E);
|
||||
ensureIndexer(Indexer);
|
||||
|
@ -12,7 +12,7 @@ const epsilon = 1e-7;
|
||||
|
||||
// See https://github.com/tiehuis/parse-number-fxx-test-data for a wider-selection of test-data.
|
||||
|
||||
test "fmt.parseFloat" {
|
||||
test "parseFloat" {
|
||||
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
|
||||
try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
|
||||
try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
|
||||
@ -68,7 +68,7 @@ test "fmt.parseFloat" {
|
||||
}
|
||||
}
|
||||
|
||||
test "fmt.parseFloat nan and inf" {
|
||||
test "nan and inf" {
|
||||
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
|
||||
const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
|
||||
|
||||
@ -78,24 +78,24 @@ test "fmt.parseFloat nan and inf" {
|
||||
}
|
||||
}
|
||||
|
||||
test "fmt.parseFloat largest normals" {
|
||||
test "largest normals" {
|
||||
try expectEqual(@as(u16, @bitCast(try parseFloat(f16, "65504"))), 0x7bff);
|
||||
try expectEqual(@as(u32, @bitCast(try parseFloat(f32, "3.4028234664E38"))), 0x7f7f_ffff);
|
||||
try expectEqual(@as(u64, @bitCast(try parseFloat(f64, "1.7976931348623157E308"))), 0x7fef_ffff_ffff_ffff);
|
||||
try expectEqual(@as(u128, @bitCast(try parseFloat(f128, "1.1897314953572317650857593266280070162E4932"))), 0x7ffe_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
|
||||
}
|
||||
|
||||
test "fmt.parseFloat #11169" {
|
||||
test "#11169" {
|
||||
try expectEqual(try parseFloat(f128, "9007199254740993.0"), 9007199254740993.0);
|
||||
}
|
||||
|
||||
test "fmt.parseFloat hex.special" {
|
||||
test "hex.special" {
|
||||
try testing.expect(math.isNan(try parseFloat(f32, "nAn")));
|
||||
try testing.expect(math.isPositiveInf(try parseFloat(f32, "iNf")));
|
||||
try testing.expect(math.isPositiveInf(try parseFloat(f32, "+Inf")));
|
||||
try testing.expect(math.isNegativeInf(try parseFloat(f32, "-iNf")));
|
||||
}
|
||||
test "fmt.parseFloat hex.zero" {
|
||||
test "hex.zero" {
|
||||
try testing.expectEqual(@as(f32, 0.0), try parseFloat(f32, "0x0"));
|
||||
try testing.expectEqual(@as(f32, 0.0), try parseFloat(f32, "-0x0"));
|
||||
try testing.expectEqual(@as(f32, 0.0), try parseFloat(f32, "0x0p42"));
|
||||
@ -103,7 +103,7 @@ test "fmt.parseFloat hex.zero" {
|
||||
try testing.expectEqual(@as(f32, 0.0), try parseFloat(f32, "0x0.00000p666"));
|
||||
}
|
||||
|
||||
test "fmt.parseFloat hex.f16" {
|
||||
test "hex.f16" {
|
||||
try testing.expectEqual(try parseFloat(f16, "0x1p0"), 1.0);
|
||||
try testing.expectEqual(try parseFloat(f16, "-0x1p-1"), -0.5);
|
||||
try testing.expectEqual(try parseFloat(f16, "0x10p+10"), 16384.0);
|
||||
@ -119,7 +119,7 @@ test "fmt.parseFloat hex.f16" {
|
||||
try testing.expectEqual(try parseFloat(f16, "-0x1p-24"), -math.floatTrueMin(f16));
|
||||
}
|
||||
|
||||
test "fmt.parseFloat hex.f32" {
|
||||
test "hex.f32" {
|
||||
try testing.expectError(error.InvalidCharacter, parseFloat(f32, "0x"));
|
||||
try testing.expectEqual(try parseFloat(f32, "0x1p0"), 1.0);
|
||||
try testing.expectEqual(try parseFloat(f32, "-0x1p-1"), -0.5);
|
||||
@ -138,7 +138,7 @@ test "fmt.parseFloat hex.f32" {
|
||||
try testing.expectEqual(try parseFloat(f32, "-0x1P-149"), -math.floatTrueMin(f32));
|
||||
}
|
||||
|
||||
test "fmt.parseFloat hex.f64" {
|
||||
test "hex.f64" {
|
||||
try testing.expectEqual(try parseFloat(f64, "0x1p0"), 1.0);
|
||||
try testing.expectEqual(try parseFloat(f64, "-0x1p-1"), -0.5);
|
||||
try testing.expectEqual(try parseFloat(f64, "0x10p+10"), 16384.0);
|
||||
@ -153,7 +153,7 @@ test "fmt.parseFloat hex.f64" {
|
||||
try testing.expectEqual(try parseFloat(f64, "0x1p-1074"), math.floatTrueMin(f64));
|
||||
try testing.expectEqual(try parseFloat(f64, "-0x1p-1074"), -math.floatTrueMin(f64));
|
||||
}
|
||||
test "fmt.parseFloat hex.f128" {
|
||||
test "hex.f128" {
|
||||
try testing.expectEqual(try parseFloat(f128, "0x1p0"), 1.0);
|
||||
try testing.expectEqual(try parseFloat(f128, "-0x1p-1"), -0.5);
|
||||
try testing.expectEqual(try parseFloat(f128, "0x10p+10"), 16384.0);
|
||||
|
@ -1612,7 +1612,7 @@ const testing = std.testing;
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "std.hash_map basic usage" {
|
||||
test "basic usage" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1640,7 +1640,7 @@ test "std.hash_map basic usage" {
|
||||
try expectEqual(total, sum);
|
||||
}
|
||||
|
||||
test "std.hash_map ensureTotalCapacity" {
|
||||
test "ensureTotalCapacity" {
|
||||
var map = AutoHashMap(i32, i32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1655,7 +1655,7 @@ test "std.hash_map ensureTotalCapacity" {
|
||||
try testing.expect(initial_capacity == map.capacity());
|
||||
}
|
||||
|
||||
test "std.hash_map ensureUnusedCapacity with tombstones" {
|
||||
test "ensureUnusedCapacity with tombstones" {
|
||||
var map = AutoHashMap(i32, i32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1667,7 +1667,7 @@ test "std.hash_map ensureUnusedCapacity with tombstones" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map clearRetainingCapacity" {
|
||||
test "clearRetainingCapacity" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1692,7 +1692,7 @@ test "std.hash_map clearRetainingCapacity" {
|
||||
try expect(!map.contains(1));
|
||||
}
|
||||
|
||||
test "std.hash_map grow" {
|
||||
test "grow" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1718,7 +1718,7 @@ test "std.hash_map grow" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map clone" {
|
||||
test "clone" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1756,7 +1756,7 @@ test "std.hash_map clone" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map ensureTotalCapacity with existing elements" {
|
||||
test "ensureTotalCapacity with existing elements" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1769,7 +1769,7 @@ test "std.hash_map ensureTotalCapacity with existing elements" {
|
||||
try expectEqual(map.capacity(), 128);
|
||||
}
|
||||
|
||||
test "std.hash_map ensureTotalCapacity satisfies max load factor" {
|
||||
test "ensureTotalCapacity satisfies max load factor" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1777,7 +1777,7 @@ test "std.hash_map ensureTotalCapacity satisfies max load factor" {
|
||||
try expectEqual(map.capacity(), 256);
|
||||
}
|
||||
|
||||
test "std.hash_map remove" {
|
||||
test "remove" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1809,7 +1809,7 @@ test "std.hash_map remove" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map reverse removes" {
|
||||
test "reverse removes" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1831,7 +1831,7 @@ test "std.hash_map reverse removes" {
|
||||
try expectEqual(map.count(), 0);
|
||||
}
|
||||
|
||||
test "std.hash_map multiple removes on same metadata" {
|
||||
test "multiple removes on same metadata" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1868,7 +1868,7 @@ test "std.hash_map multiple removes on same metadata" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map put and remove loop in random order" {
|
||||
test "put and remove loop in random order" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1900,7 +1900,7 @@ test "std.hash_map put and remove loop in random order" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map remove one million elements in random order" {
|
||||
test "remove one million elements in random order" {
|
||||
const Map = AutoHashMap(u32, u32);
|
||||
const n = 1000 * 1000;
|
||||
var map = Map.init(std.heap.page_allocator);
|
||||
@ -1930,7 +1930,7 @@ test "std.hash_map remove one million elements in random order" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map put" {
|
||||
test "put" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1955,7 +1955,7 @@ test "std.hash_map put" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map putAssumeCapacity" {
|
||||
test "putAssumeCapacity" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -1985,7 +1985,7 @@ test "std.hash_map putAssumeCapacity" {
|
||||
try expectEqual(sum, 20);
|
||||
}
|
||||
|
||||
test "std.hash_map repeat putAssumeCapacity/remove" {
|
||||
test "repeat putAssumeCapacity/remove" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2017,7 +2017,7 @@ test "std.hash_map repeat putAssumeCapacity/remove" {
|
||||
try expectEqual(map.unmanaged.count(), limit);
|
||||
}
|
||||
|
||||
test "std.hash_map getOrPut" {
|
||||
test "getOrPut" {
|
||||
var map = AutoHashMap(u32, u32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2040,7 +2040,7 @@ test "std.hash_map getOrPut" {
|
||||
try expectEqual(sum, 30);
|
||||
}
|
||||
|
||||
test "std.hash_map basic hash map usage" {
|
||||
test "basic hash map usage" {
|
||||
var map = AutoHashMap(i32, i32).init(std.testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2085,7 +2085,7 @@ test "std.hash_map basic hash map usage" {
|
||||
try testing.expect(map.remove(3) == true);
|
||||
}
|
||||
|
||||
test "std.hash_map getOrPutAdapted" {
|
||||
test "getOrPutAdapted" {
|
||||
const AdaptedContext = struct {
|
||||
fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
|
||||
_ = self;
|
||||
@ -2134,7 +2134,7 @@ test "std.hash_map getOrPutAdapted" {
|
||||
}
|
||||
}
|
||||
|
||||
test "std.hash_map ensureUnusedCapacity" {
|
||||
test "ensureUnusedCapacity" {
|
||||
var map = AutoHashMap(u64, u64).init(testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2147,7 +2147,7 @@ test "std.hash_map ensureUnusedCapacity" {
|
||||
try testing.expectEqual(capacity, map.capacity());
|
||||
}
|
||||
|
||||
test "std.hash_map removeByPtr" {
|
||||
test "removeByPtr" {
|
||||
var map = AutoHashMap(i32, u64).init(testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2173,7 +2173,7 @@ test "std.hash_map removeByPtr" {
|
||||
try testing.expect(map.count() == 0);
|
||||
}
|
||||
|
||||
test "std.hash_map removeByPtr 0 sized key" {
|
||||
test "removeByPtr 0 sized key" {
|
||||
var map = AutoHashMap(u0, u64).init(testing.allocator);
|
||||
defer map.deinit();
|
||||
|
||||
@ -2191,7 +2191,7 @@ test "std.hash_map removeByPtr 0 sized key" {
|
||||
try testing.expect(map.count() == 0);
|
||||
}
|
||||
|
||||
test "std.hash_map repeat fetchRemove" {
|
||||
test "repeat fetchRemove" {
|
||||
var map = AutoHashMapUnmanaged(u64, void){};
|
||||
defer map.deinit(testing.allocator);
|
||||
|
||||
|
@ -246,7 +246,7 @@ pub const ArenaAllocator = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "ArenaAllocator (reset with preheating)" {
|
||||
test "reset with preheating" {
|
||||
var arena_allocator = ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena_allocator.deinit();
|
||||
// provides some variance in the allocated data
|
||||
@ -269,7 +269,7 @@ test "ArenaAllocator (reset with preheating)" {
|
||||
}
|
||||
}
|
||||
|
||||
test "ArenaAllocator (reset while retaining a buffer)" {
|
||||
test "reset while retaining a buffer" {
|
||||
var arena_allocator = ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena_allocator.deinit();
|
||||
const a = arena_allocator.allocator();
|
||||
|
@ -145,7 +145,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type
|
||||
};
|
||||
}
|
||||
|
||||
test "memory pool: basic" {
|
||||
test "basic" {
|
||||
var pool = MemoryPool(u32).init(std.testing.allocator);
|
||||
defer pool.deinit();
|
||||
|
||||
@ -165,7 +165,7 @@ test "memory pool: basic" {
|
||||
try std.testing.expect(p2 == p4);
|
||||
}
|
||||
|
||||
test "memory pool: preheating (success)" {
|
||||
test "preheating (success)" {
|
||||
var pool = try MemoryPool(u32).initPreheated(std.testing.allocator, 4);
|
||||
defer pool.deinit();
|
||||
|
||||
@ -174,12 +174,12 @@ test "memory pool: preheating (success)" {
|
||||
_ = try pool.create();
|
||||
}
|
||||
|
||||
test "memory pool: preheating (failure)" {
|
||||
test "preheating (failure)" {
|
||||
const failer = std.testing.failing_allocator;
|
||||
try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5));
|
||||
}
|
||||
|
||||
test "memory pool: growable" {
|
||||
test "growable" {
|
||||
var pool = try MemoryPoolExtra(u32, .{ .growable = false }).initPreheated(std.testing.allocator, 4);
|
||||
defer pool.deinit();
|
||||
|
||||
@ -191,7 +191,7 @@ test "memory pool: growable" {
|
||||
try std.testing.expectError(error.OutOfMemory, pool.create());
|
||||
}
|
||||
|
||||
test "memory pool: greater than pointer default alignment" {
|
||||
test "greater than pointer default alignment" {
|
||||
const Foo = struct {
|
||||
data: u64 align(16),
|
||||
};
|
||||
@ -203,7 +203,7 @@ test "memory pool: greater than pointer default alignment" {
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
test "memory pool: greater than pointer manual alignment" {
|
||||
test "greater than pointer manual alignment" {
|
||||
const Foo = struct {
|
||||
data: u64,
|
||||
};
|
||||
|
@ -15,14 +15,14 @@ test "Reader" {
|
||||
try testing.expectError(error.EndOfStream, reader.readByte());
|
||||
}
|
||||
|
||||
test "Reader.isBytes" {
|
||||
test "isBytes" {
|
||||
var fis = std.io.fixedBufferStream("foobar");
|
||||
const reader = fis.reader();
|
||||
try testing.expectEqual(true, try reader.isBytes("foo"));
|
||||
try testing.expectEqual(false, try reader.isBytes("qux"));
|
||||
}
|
||||
|
||||
test "Reader.skipBytes" {
|
||||
test "skipBytes" {
|
||||
var fis = std.io.fixedBufferStream("foobar");
|
||||
const reader = fis.reader();
|
||||
try reader.skipBytes(3, .{});
|
||||
@ -31,7 +31,7 @@ test "Reader.skipBytes" {
|
||||
try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterArrayList returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
test "readUntilDelimiterArrayList returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
const a = std.testing.allocator;
|
||||
var list = std.ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
@ -46,7 +46,7 @@ test "Reader.readUntilDelimiterArrayList returns ArrayLists with bytes read unti
|
||||
try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiterArrayList(&list, '\n', 5));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterArrayList returns an empty ArrayList" {
|
||||
test "readUntilDelimiterArrayList returns an empty ArrayList" {
|
||||
const a = std.testing.allocator;
|
||||
var list = std.ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
@ -58,7 +58,7 @@ test "Reader.readUntilDelimiterArrayList returns an empty ArrayList" {
|
||||
try std.testing.expectEqualStrings("", list.items);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterArrayList returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
test "readUntilDelimiterArrayList returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
const a = std.testing.allocator;
|
||||
var list = std.ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
@ -72,7 +72,7 @@ test "Reader.readUntilDelimiterArrayList returns StreamTooLong, then an ArrayLis
|
||||
try std.testing.expectEqualStrings("67", list.items);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterArrayList returns EndOfStream" {
|
||||
test "readUntilDelimiterArrayList returns EndOfStream" {
|
||||
const a = std.testing.allocator;
|
||||
var list = std.ArrayList(u8).init(a);
|
||||
defer list.deinit();
|
||||
@ -84,7 +84,7 @@ test "Reader.readUntilDelimiterArrayList returns EndOfStream" {
|
||||
try std.testing.expectEqualStrings("1234", list.items);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
test "readUntilDelimiterAlloc returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("0000\n1234\n");
|
||||
@ -105,7 +105,7 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th
|
||||
try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiterAlloc(a, '\n', 5));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {
|
||||
test "readUntilDelimiterAlloc returns an empty ArrayList" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("\n");
|
||||
@ -118,7 +118,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
test "readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("1234567\n");
|
||||
@ -131,7 +131,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi
|
||||
try std.testing.expectEqualStrings("67", result);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterAlloc returns EndOfStream" {
|
||||
test "readUntilDelimiterAlloc returns EndOfStream" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("1234");
|
||||
@ -140,7 +140,7 @@ test "Reader.readUntilDelimiterAlloc returns EndOfStream" {
|
||||
try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiterAlloc(a, '\n', 5));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns bytes read until the delimiter" {
|
||||
test "readUntilDelimiter returns bytes read until the delimiter" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("0000\n1234\n");
|
||||
const reader = fis.reader();
|
||||
@ -148,14 +148,14 @@ test "Reader.readUntilDelimiter returns bytes read until the delimiter" {
|
||||
try std.testing.expectEqualStrings("1234", try reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns an empty string" {
|
||||
test "readUntilDelimiter returns an empty string" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("\n");
|
||||
const reader = fis.reader();
|
||||
try std.testing.expectEqualStrings("", try reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns StreamTooLong, then an empty string" {
|
||||
test "readUntilDelimiter returns StreamTooLong, then an empty string" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("12345\n");
|
||||
const reader = fis.reader();
|
||||
@ -163,7 +163,7 @@ test "Reader.readUntilDelimiter returns StreamTooLong, then an empty string" {
|
||||
try std.testing.expectEqualStrings("", try reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns StreamTooLong, then bytes read until the delimiter" {
|
||||
test "readUntilDelimiter returns StreamTooLong, then bytes read until the delimiter" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234567\n");
|
||||
const reader = fis.reader();
|
||||
@ -171,7 +171,7 @@ test "Reader.readUntilDelimiter returns StreamTooLong, then bytes read until the
|
||||
try std.testing.expectEqualStrings("67", try reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns EndOfStream" {
|
||||
test "readUntilDelimiter returns EndOfStream" {
|
||||
{
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("");
|
||||
@ -186,7 +186,7 @@ test "Reader.readUntilDelimiter returns EndOfStream" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfStream" {
|
||||
test "readUntilDelimiter returns bytes read until delimiter, then EndOfStream" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234\n");
|
||||
const reader = fis.reader();
|
||||
@ -194,7 +194,7 @@ test "Reader.readUntilDelimiter returns bytes read until delimiter, then EndOfSt
|
||||
try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter returns StreamTooLong, then EndOfStream" {
|
||||
test "readUntilDelimiter returns StreamTooLong, then EndOfStream" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("12345");
|
||||
const reader = fis.reader();
|
||||
@ -202,7 +202,7 @@ test "Reader.readUntilDelimiter returns StreamTooLong, then EndOfStream" {
|
||||
try std.testing.expectError(error.EndOfStream, reader.readUntilDelimiter(&buf, '\n'));
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiter writes all bytes read to the output buffer" {
|
||||
test "readUntilDelimiter writes all bytes read to the output buffer" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("0000\n12345");
|
||||
const reader = fis.reader();
|
||||
@ -212,7 +212,7 @@ test "Reader.readUntilDelimiter writes all bytes read to the output buffer" {
|
||||
try std.testing.expectEqualStrings("12345", &buf);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
test "readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read until the delimiter, then EndOfStream" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("0000\n1234\n");
|
||||
@ -233,7 +233,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt
|
||||
try std.testing.expect((try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)) == null);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
|
||||
test "readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("\n");
|
||||
@ -246,7 +246,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
|
||||
}
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
test "readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayList with bytes read until the delimiter" {
|
||||
const a = std.testing.allocator;
|
||||
|
||||
var fis = std.io.fixedBufferStream("1234567\n");
|
||||
@ -259,7 +259,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi
|
||||
try std.testing.expectEqualStrings("67", result);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns bytes read until the delimiter" {
|
||||
test "readUntilDelimiterOrEof returns bytes read until the delimiter" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("0000\n1234\n");
|
||||
const reader = fis.reader();
|
||||
@ -267,14 +267,14 @@ test "Reader.readUntilDelimiterOrEof returns bytes read until the delimiter" {
|
||||
try std.testing.expectEqualStrings("1234", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns an empty string" {
|
||||
test "readUntilDelimiterOrEof returns an empty string" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("\n");
|
||||
const reader = fis.reader();
|
||||
try std.testing.expectEqualStrings("", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then an empty string" {
|
||||
test "readUntilDelimiterOrEof returns StreamTooLong, then an empty string" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("12345\n");
|
||||
const reader = fis.reader();
|
||||
@ -282,7 +282,7 @@ test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then an empty string
|
||||
try std.testing.expectEqualStrings("", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then bytes read until the delimiter" {
|
||||
test "readUntilDelimiterOrEof returns StreamTooLong, then bytes read until the delimiter" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234567\n");
|
||||
const reader = fis.reader();
|
||||
@ -290,14 +290,14 @@ test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then bytes read unti
|
||||
try std.testing.expectEqualStrings("67", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns null" {
|
||||
test "readUntilDelimiterOrEof returns null" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("");
|
||||
const reader = fis.reader();
|
||||
try std.testing.expect((try reader.readUntilDelimiterOrEof(&buf, '\n')) == null);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns bytes read until delimiter, then null" {
|
||||
test "readUntilDelimiterOrEof returns bytes read until delimiter, then null" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234\n");
|
||||
const reader = fis.reader();
|
||||
@ -305,14 +305,14 @@ test "Reader.readUntilDelimiterOrEof returns bytes read until delimiter, then nu
|
||||
try std.testing.expect((try reader.readUntilDelimiterOrEof(&buf, '\n')) == null);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns bytes read until end-of-stream" {
|
||||
test "readUntilDelimiterOrEof returns bytes read until end-of-stream" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234");
|
||||
const reader = fis.reader();
|
||||
try std.testing.expectEqualStrings("1234", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then bytes read until end-of-stream" {
|
||||
test "readUntilDelimiterOrEof returns StreamTooLong, then bytes read until end-of-stream" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("1234567");
|
||||
const reader = fis.reader();
|
||||
@ -320,7 +320,7 @@ test "Reader.readUntilDelimiterOrEof returns StreamTooLong, then bytes read unti
|
||||
try std.testing.expectEqualStrings("67", (try reader.readUntilDelimiterOrEof(&buf, '\n')).?);
|
||||
}
|
||||
|
||||
test "Reader.readUntilDelimiterOrEof writes all bytes read to the output buffer" {
|
||||
test "readUntilDelimiterOrEof writes all bytes read to the output buffer" {
|
||||
var buf: [5]u8 = undefined;
|
||||
var fis = std.io.fixedBufferStream("0000\n12345");
|
||||
const reader = fis.reader();
|
||||
@ -330,7 +330,7 @@ test "Reader.readUntilDelimiterOrEof writes all bytes read to the output buffer"
|
||||
try std.testing.expectEqualStrings("12345", &buf);
|
||||
}
|
||||
|
||||
test "Reader.streamUntilDelimiter writes all bytes without delimiter to the output" {
|
||||
test "streamUntilDelimiter writes all bytes without delimiter to the output" {
|
||||
const input_string = "some_string_with_delimiter!";
|
||||
var input_fbs = std.io.fixedBufferStream(input_string);
|
||||
const reader = input_fbs.reader();
|
||||
@ -349,7 +349,7 @@ test "Reader.streamUntilDelimiter writes all bytes without delimiter to the outp
|
||||
try std.testing.expectError(error.StreamTooLong, reader.streamUntilDelimiter(writer, '!', 5));
|
||||
}
|
||||
|
||||
test "Reader.readBoundedBytes correctly reads into a new bounded array" {
|
||||
test "readBoundedBytes correctly reads into a new bounded array" {
|
||||
const test_string = "abcdefg";
|
||||
var fis = std.io.fixedBufferStream(test_string);
|
||||
const reader = fis.reader();
|
||||
@ -358,7 +358,7 @@ test "Reader.readBoundedBytes correctly reads into a new bounded array" {
|
||||
try testing.expectEqualStrings(array.slice(), test_string);
|
||||
}
|
||||
|
||||
test "Reader.readIntoBoundedBytes correctly reads into a provided bounded array" {
|
||||
test "readIntoBoundedBytes correctly reads into a provided bounded array" {
|
||||
const test_string = "abcdefg";
|
||||
var fis = std.io.fixedBufferStream(test_string);
|
||||
const reader = fis.reader();
|
||||
|
@ -53,7 +53,7 @@ pub fn bufferedReaderSize(comptime size: usize, reader: anytype) BufferedReader(
|
||||
return .{ .unbuffered_reader = reader };
|
||||
}
|
||||
|
||||
test "io.BufferedReader OneByte" {
|
||||
test "OneByte" {
|
||||
const OneByteReadReader = struct {
|
||||
str: []const u8,
|
||||
curr: usize,
|
||||
@ -96,7 +96,7 @@ test "io.BufferedReader OneByte" {
|
||||
fn smallBufferedReader(underlying_stream: anytype) BufferedReader(8, @TypeOf(underlying_stream)) {
|
||||
return .{ .unbuffered_reader = underlying_stream };
|
||||
}
|
||||
test "io.BufferedReader Block" {
|
||||
test "Block" {
|
||||
const BlockReader = struct {
|
||||
block: []const u8,
|
||||
reads_allowed: usize,
|
||||
|
@ -146,7 +146,7 @@ fn bufferedReader(reader: anytype) BufferedReader(4096, @TypeOf(reader)) {
|
||||
};
|
||||
}
|
||||
|
||||
test "io.BufferedTee io.BufferedReader OneByte" {
|
||||
test "OneByte" {
|
||||
const OneByteReadReader = struct {
|
||||
str: []const u8,
|
||||
curr: usize,
|
||||
@ -186,7 +186,7 @@ test "io.BufferedTee io.BufferedReader OneByte" {
|
||||
try testing.expectEqualSlices(u8, str, res);
|
||||
}
|
||||
|
||||
test "io.BufferedTee io.BufferedReader Block" {
|
||||
test "Block" {
|
||||
const BlockReader = struct {
|
||||
block: []const u8,
|
||||
reads_allowed: usize,
|
||||
@ -289,7 +289,7 @@ test "io.BufferedTee io.BufferedReader Block" {
|
||||
}
|
||||
}
|
||||
|
||||
test "io.BufferedTee with zero lookahead" {
|
||||
test "with zero lookahead" {
|
||||
// output has same bytes as consumer
|
||||
const data = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ** 12;
|
||||
var in = io.fixedBufferStream(&data);
|
||||
@ -308,7 +308,7 @@ test "io.BufferedTee with zero lookahead" {
|
||||
}
|
||||
}
|
||||
|
||||
test "io.BufferedTee with lookahead" {
|
||||
test "with lookahead" {
|
||||
// output is lookahead bytes behind consumer
|
||||
inline for (1..8) |lookahead| {
|
||||
const data = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ** 12;
|
||||
@ -333,7 +333,7 @@ test "io.BufferedTee with lookahead" {
|
||||
}
|
||||
}
|
||||
|
||||
test "io.BufferedTee internal state" {
|
||||
test "internal state" {
|
||||
const data = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ** 2;
|
||||
var in = io.fixedBufferStream(&data);
|
||||
var out = std.ArrayList(u8).init(testing.allocator);
|
||||
|
@ -27,7 +27,7 @@ pub fn countingReader(reader: anytype) CountingReader(@TypeOf(reader)) {
|
||||
return .{ .child_reader = reader };
|
||||
}
|
||||
|
||||
test "io.CountingReader" {
|
||||
test CountingReader {
|
||||
const bytes = "yay" ** 100;
|
||||
var fbs = io.fixedBufferStream(bytes);
|
||||
|
||||
|
@ -29,7 +29,7 @@ pub fn countingWriter(child_stream: anytype) CountingWriter(@TypeOf(child_stream
|
||||
return .{ .bytes_written = 0, .child_stream = child_stream };
|
||||
}
|
||||
|
||||
test "io.CountingWriter" {
|
||||
test CountingWriter {
|
||||
var counting_stream = countingWriter(std.io.null_writer);
|
||||
const stream = counting_stream.writer();
|
||||
|
||||
|
@ -132,7 +132,7 @@ fn Slice(comptime T: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
test "FixedBufferStream output" {
|
||||
test "output" {
|
||||
var buf: [255]u8 = undefined;
|
||||
var fbs = fixedBufferStream(&buf);
|
||||
const stream = fbs.writer();
|
||||
@ -141,7 +141,7 @@ test "FixedBufferStream output" {
|
||||
try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
|
||||
}
|
||||
|
||||
test "FixedBufferStream output at comptime" {
|
||||
test "output at comptime" {
|
||||
comptime {
|
||||
var buf: [255]u8 = undefined;
|
||||
var fbs = fixedBufferStream(&buf);
|
||||
@ -152,7 +152,7 @@ test "FixedBufferStream output at comptime" {
|
||||
}
|
||||
}
|
||||
|
||||
test "FixedBufferStream output 2" {
|
||||
test "output 2" {
|
||||
var buffer: [10]u8 = undefined;
|
||||
var fbs = fixedBufferStream(&buffer);
|
||||
|
||||
@ -175,7 +175,7 @@ test "FixedBufferStream output 2" {
|
||||
try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("H"));
|
||||
}
|
||||
|
||||
test "FixedBufferStream input" {
|
||||
test "input" {
|
||||
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
|
||||
var fbs = fixedBufferStream(&bytes);
|
||||
|
||||
|
@ -99,11 +99,11 @@ pub const StreamSource = union(enum) {
|
||||
}
|
||||
};
|
||||
|
||||
test "StreamSource (refs)" {
|
||||
test "refs" {
|
||||
std.testing.refAllDecls(StreamSource);
|
||||
}
|
||||
|
||||
test "StreamSource (mutable buffer)" {
|
||||
test "mutable buffer" {
|
||||
var buffer: [64]u8 = undefined;
|
||||
var source = StreamSource{ .buffer = std.io.fixedBufferStream(&buffer) };
|
||||
|
||||
@ -114,7 +114,7 @@ test "StreamSource (mutable buffer)" {
|
||||
try std.testing.expectEqualStrings("Hello, World!", source.buffer.getWritten());
|
||||
}
|
||||
|
||||
test "StreamSource (const buffer)" {
|
||||
test "const buffer" {
|
||||
const buffer: [64]u8 = "Hello, World!".* ++ ([1]u8{0xAA} ** 51);
|
||||
var source = StreamSource{ .const_buffer = std.io.fixedBufferStream(&buffer) };
|
||||
|
||||
|
@ -35,7 +35,7 @@ fn expectPeekNext(scanner_or_reader: anytype, expected_token_type: TokenType, ex
|
||||
try expectEqualTokens(expected_token, try scanner_or_reader.next());
|
||||
}
|
||||
|
||||
test "json.token" {
|
||||
test "token" {
|
||||
var scanner = JsonScanner.initCompleteInput(std.testing.allocator, example_document_str);
|
||||
defer scanner.deinit();
|
||||
|
||||
@ -153,7 +153,7 @@ test "peek all types" {
|
||||
try testAllTypes(&tiny_json_reader, false);
|
||||
}
|
||||
|
||||
test "json.token mismatched close" {
|
||||
test "token mismatched close" {
|
||||
var scanner = JsonScanner.initCompleteInput(std.testing.allocator, "[102, 111, 111 }");
|
||||
defer scanner.deinit();
|
||||
try expectNext(&scanner, .array_begin);
|
||||
@ -163,7 +163,7 @@ test "json.token mismatched close" {
|
||||
try std.testing.expectError(error.SyntaxError, scanner.next());
|
||||
}
|
||||
|
||||
test "json.token premature object close" {
|
||||
test "token premature object close" {
|
||||
var scanner = JsonScanner.initCompleteInput(std.testing.allocator, "{ \"key\": }");
|
||||
defer scanner.deinit();
|
||||
try expectNext(&scanner, .object_begin);
|
||||
@ -353,7 +353,7 @@ test "BufferUnderrun" {
|
||||
}
|
||||
}
|
||||
|
||||
test "json.validate" {
|
||||
test "validate" {
|
||||
try std.testing.expectEqual(true, try validate(std.testing.allocator, "{}"));
|
||||
try std.testing.expectEqual(true, try validate(std.testing.allocator, "[]"));
|
||||
try std.testing.expectEqual(false, try validate(std.testing.allocator, "[{[[[[{}]]]]}]"));
|
||||
|
@ -1298,7 +1298,7 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T) {
|
||||
return log2_val + 1;
|
||||
}
|
||||
|
||||
test "std.math.log2_int_ceil" {
|
||||
test log2_int_ceil {
|
||||
try testing.expect(log2_int_ceil(u32, 1) == 0);
|
||||
try testing.expect(log2_int_ceil(u32, 2) == 1);
|
||||
try testing.expect(log2_int_ceil(u32, 3) == 2);
|
||||
|
@ -148,12 +148,12 @@ fn acos64(x: f64) f64 {
|
||||
return 2 * (df + w);
|
||||
}
|
||||
|
||||
test "math.acos" {
|
||||
test "acos" {
|
||||
try expect(acos(@as(f32, 0.0)) == acos32(0.0));
|
||||
try expect(acos(@as(f64, 0.0)) == acos64(0.0));
|
||||
}
|
||||
|
||||
test "math.acos32" {
|
||||
test "acos32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
|
||||
@ -164,7 +164,7 @@ test "math.acos32" {
|
||||
try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
|
||||
}
|
||||
|
||||
test "math.acos64" {
|
||||
test "acos64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
|
||||
@ -175,12 +175,12 @@ test "math.acos64" {
|
||||
try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
|
||||
}
|
||||
|
||||
test "math.acos32.special" {
|
||||
test "acos32.special" {
|
||||
try expect(math.isNan(acos32(-2)));
|
||||
try expect(math.isNan(acos32(1.5)));
|
||||
}
|
||||
|
||||
test "math.acos64.special" {
|
||||
test "acos64.special" {
|
||||
try expect(math.isNan(acos64(-2)));
|
||||
try expect(math.isNan(acos64(1.5)));
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ fn acosh64(x: f64) f64 {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.acosh" {
|
||||
test "acosh" {
|
||||
try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
|
||||
try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
|
||||
}
|
||||
|
||||
test "math.acosh32" {
|
||||
test "acosh32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
|
||||
@ -73,7 +73,7 @@ test "math.acosh32" {
|
||||
try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
|
||||
}
|
||||
|
||||
test "math.acosh64" {
|
||||
test "acosh64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
|
||||
@ -82,12 +82,12 @@ test "math.acosh64" {
|
||||
try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
|
||||
}
|
||||
|
||||
test "math.acosh32.special" {
|
||||
test "acosh32.special" {
|
||||
try expect(math.isNan(acosh32(math.nan(f32))));
|
||||
try expect(math.isNan(acosh32(0.5)));
|
||||
}
|
||||
|
||||
test "math.acosh64.special" {
|
||||
test "acosh64.special" {
|
||||
try expect(math.isNan(acosh64(math.nan(f64))));
|
||||
try expect(math.isNan(acosh64(0.5)));
|
||||
}
|
||||
|
@ -141,12 +141,12 @@ fn asin64(x: f64) f64 {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.asin" {
|
||||
test "asin" {
|
||||
try expect(asin(@as(f32, 0.0)) == asin32(0.0));
|
||||
try expect(asin(@as(f64, 0.0)) == asin64(0.0));
|
||||
}
|
||||
|
||||
test "math.asin32" {
|
||||
test "asin32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
|
||||
@ -157,7 +157,7 @@ test "math.asin32" {
|
||||
try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
|
||||
}
|
||||
|
||||
test "math.asin64" {
|
||||
test "asin64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
|
||||
@ -168,14 +168,14 @@ test "math.asin64" {
|
||||
try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
|
||||
}
|
||||
|
||||
test "math.asin32.special" {
|
||||
test "asin32.special" {
|
||||
try expect(math.isPositiveZero(asin32(0.0)));
|
||||
try expect(math.isNegativeZero(asin32(-0.0)));
|
||||
try expect(math.isNan(asin32(-2)));
|
||||
try expect(math.isNan(asin32(1.5)));
|
||||
}
|
||||
|
||||
test "math.asin64.special" {
|
||||
test "asin64.special" {
|
||||
try expect(math.isPositiveZero(asin64(0.0)));
|
||||
try expect(math.isNegativeZero(asin64(-0.0)));
|
||||
try expect(math.isNan(asin64(-2)));
|
||||
|
@ -80,12 +80,12 @@ fn asinh64(x: f64) f64 {
|
||||
return if (s != 0) -rx else rx;
|
||||
}
|
||||
|
||||
test "math.asinh" {
|
||||
test "asinh" {
|
||||
try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
|
||||
try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
|
||||
}
|
||||
|
||||
test "math.asinh32" {
|
||||
test "asinh32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
|
||||
@ -98,7 +98,7 @@ test "math.asinh32" {
|
||||
try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
|
||||
}
|
||||
|
||||
test "math.asinh64" {
|
||||
test "asinh64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
|
||||
@ -111,7 +111,7 @@ test "math.asinh64" {
|
||||
try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
|
||||
}
|
||||
|
||||
test "math.asinh32.special" {
|
||||
test "asinh32.special" {
|
||||
try expect(math.isPositiveZero(asinh32(0.0)));
|
||||
try expect(math.isNegativeZero(asinh32(-0.0)));
|
||||
try expect(math.isPositiveInf(asinh32(math.inf(f32))));
|
||||
@ -119,7 +119,7 @@ test "math.asinh32.special" {
|
||||
try expect(math.isNan(asinh32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.asinh64.special" {
|
||||
test "asinh64.special" {
|
||||
try expect(math.isPositiveZero(asinh64(0.0)));
|
||||
try expect(math.isNegativeZero(asinh64(-0.0)));
|
||||
try expect(math.isPositiveInf(asinh64(math.inf(f64))));
|
||||
|
@ -212,12 +212,12 @@ fn atan64(x_: f64) f64 {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.atan" {
|
||||
test "atan" {
|
||||
try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));
|
||||
try expect(atan(@as(f64, 0.2)) == atan64(0.2));
|
||||
}
|
||||
|
||||
test "math.atan32" {
|
||||
test "atan32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
|
||||
@ -227,7 +227,7 @@ test "math.atan32" {
|
||||
try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan64" {
|
||||
test "atan64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
|
||||
@ -237,7 +237,7 @@ test "math.atan64" {
|
||||
try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan32.special" {
|
||||
test "atan32.special" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(atan32(0.0)));
|
||||
@ -246,7 +246,7 @@ test "math.atan32.special" {
|
||||
try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan64.special" {
|
||||
test "atan64.special" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(atan64(0.0)));
|
||||
|
@ -214,7 +214,7 @@ fn atan2_64(y: f64, x: f64) f64 {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.atan2" {
|
||||
test "atan2" {
|
||||
const y32: f32 = 0.2;
|
||||
const x32: f32 = 0.21;
|
||||
const y64: f64 = 0.2;
|
||||
@ -223,7 +223,7 @@ test "math.atan2" {
|
||||
try expect(atan2(y64, x64) == atan2_64(0.2, 0.21));
|
||||
}
|
||||
|
||||
test "math.atan2_32" {
|
||||
test "atan2_32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
|
||||
@ -235,7 +235,7 @@ test "math.atan2_32" {
|
||||
try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan2_64" {
|
||||
test "atan2_64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
|
||||
@ -247,7 +247,7 @@ test "math.atan2_64" {
|
||||
try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan2_32.special" {
|
||||
test "atan2_32.special" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
|
||||
@ -271,7 +271,7 @@ test "math.atan2_32.special" {
|
||||
try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
|
||||
}
|
||||
|
||||
test "math.atan2_64.special" {
|
||||
test "atan2_64.special" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
|
||||
|
@ -84,12 +84,12 @@ fn atanh_64(x: f64) f64 {
|
||||
return if (s != 0) -y else y;
|
||||
}
|
||||
|
||||
test "math.atanh" {
|
||||
test "atanh" {
|
||||
try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
|
||||
try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
|
||||
}
|
||||
|
||||
test "math.atanh_32" {
|
||||
test "atanh_32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
|
||||
@ -97,7 +97,7 @@ test "math.atanh_32" {
|
||||
try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
|
||||
}
|
||||
|
||||
test "math.atanh_64" {
|
||||
test "atanh_64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
|
||||
@ -105,7 +105,7 @@ test "math.atanh_64" {
|
||||
try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
|
||||
}
|
||||
|
||||
test "math.atanh32.special" {
|
||||
test "atanh32.special" {
|
||||
try expect(math.isPositiveInf(atanh_32(1)));
|
||||
try expect(math.isNegativeInf(atanh_32(-1)));
|
||||
try expect(math.isNan(atanh_32(1.5)));
|
||||
@ -113,7 +113,7 @@ test "math.atanh32.special" {
|
||||
try expect(math.isNan(atanh_32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.atanh64.special" {
|
||||
test "atanh64.special" {
|
||||
try expect(math.isPositiveInf(atanh_64(1)));
|
||||
try expect(math.isNegativeInf(atanh_64(-1)));
|
||||
try expect(math.isNan(atanh_64(1.5)));
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -493,7 +493,7 @@ fn extractLowBits(a: Int, comptime T: type) T {
|
||||
}
|
||||
}
|
||||
|
||||
test "big.rational extractLowBits" {
|
||||
test "extractLowBits" {
|
||||
var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);
|
||||
defer a.deinit();
|
||||
|
||||
@ -513,7 +513,7 @@ test "big.rational extractLowBits" {
|
||||
try testing.expect(a5 == 0x11112222333344441234567887654321);
|
||||
}
|
||||
|
||||
test "big.rational set" {
|
||||
test "set" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -542,7 +542,7 @@ test "big.rational set" {
|
||||
try testing.expect((try a.q.to(i32)) == 1);
|
||||
}
|
||||
|
||||
test "big.rational setFloat" {
|
||||
test "setFloat" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -567,7 +567,7 @@ test "big.rational setFloat" {
|
||||
try testing.expect((try a.q.to(u128)) == 70368744177664);
|
||||
}
|
||||
|
||||
test "big.rational setFloatString" {
|
||||
test "setFloatString" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -578,7 +578,7 @@ test "big.rational setFloatString" {
|
||||
try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
|
||||
}
|
||||
|
||||
test "big.rational toFloat" {
|
||||
test "toFloat" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -591,7 +591,7 @@ test "big.rational toFloat" {
|
||||
try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
|
||||
}
|
||||
|
||||
test "big.rational set/to Float round-trip" {
|
||||
test "set/to Float round-trip" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var prng = std.Random.DefaultPrng.init(0x5EED);
|
||||
@ -604,7 +604,7 @@ test "big.rational set/to Float round-trip" {
|
||||
}
|
||||
}
|
||||
|
||||
test "big.rational copy" {
|
||||
test "copy" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -634,7 +634,7 @@ test "big.rational copy" {
|
||||
try testing.expect((try a.q.to(u32)) == 1);
|
||||
}
|
||||
|
||||
test "big.rational negate" {
|
||||
test "negate" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -651,7 +651,7 @@ test "big.rational negate" {
|
||||
try testing.expect((try a.q.to(i32)) == 1);
|
||||
}
|
||||
|
||||
test "big.rational abs" {
|
||||
test "abs" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
||||
@ -668,7 +668,7 @@ test "big.rational abs" {
|
||||
try testing.expect((try a.q.to(i32)) == 1);
|
||||
}
|
||||
|
||||
test "big.rational swap" {
|
||||
test "swap" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -692,7 +692,7 @@ test "big.rational swap" {
|
||||
try testing.expect((try b.q.to(u32)) == 23);
|
||||
}
|
||||
|
||||
test "big.rational order" {
|
||||
test "order" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -707,7 +707,7 @@ test "big.rational order" {
|
||||
try testing.expect((try a.order(b)) == .eq);
|
||||
}
|
||||
|
||||
test "big.rational order/orderAbs with negative" {
|
||||
test "order/orderAbs with negative" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -719,7 +719,7 @@ test "big.rational order/orderAbs with negative" {
|
||||
try testing.expect((try a.orderAbs(b)) == .lt);
|
||||
}
|
||||
|
||||
test "big.rational add single-limb" {
|
||||
test "add single-limb" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -734,7 +734,7 @@ test "big.rational add single-limb" {
|
||||
try testing.expect((try a.order(b)) == .eq);
|
||||
}
|
||||
|
||||
test "big.rational add" {
|
||||
test "add" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -750,7 +750,7 @@ test "big.rational add" {
|
||||
try testing.expect((try a.order(r)) == .eq);
|
||||
}
|
||||
|
||||
test "big.rational sub" {
|
||||
test "sub" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -766,7 +766,7 @@ test "big.rational sub" {
|
||||
try testing.expect((try a.order(r)) == .eq);
|
||||
}
|
||||
|
||||
test "big.rational mul" {
|
||||
test "mul" {
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
var b = try Rational.init(testing.allocator);
|
||||
@ -782,7 +782,7 @@ test "big.rational mul" {
|
||||
try testing.expect((try a.order(r)) == .eq);
|
||||
}
|
||||
|
||||
test "big.rational div" {
|
||||
test "div" {
|
||||
{
|
||||
var a = try Rational.init(testing.allocator);
|
||||
defer a.deinit();
|
||||
|
@ -119,12 +119,12 @@ fn cbrt64(x: f64) f64 {
|
||||
return t + t * q;
|
||||
}
|
||||
|
||||
test "math.cbrt" {
|
||||
test "cbrt" {
|
||||
try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
|
||||
try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
|
||||
}
|
||||
|
||||
test "math.cbrt32" {
|
||||
test "cbrt32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(cbrt32(0.0)));
|
||||
@ -135,7 +135,7 @@ test "math.cbrt32" {
|
||||
try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
|
||||
}
|
||||
|
||||
test "math.cbrt64" {
|
||||
test "cbrt64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(cbrt64(0.0)));
|
||||
@ -146,7 +146,7 @@ test "math.cbrt64" {
|
||||
try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
|
||||
}
|
||||
|
||||
test "math.cbrt.special" {
|
||||
test "cbrt.special" {
|
||||
try expect(math.isPositiveZero(cbrt32(0.0)));
|
||||
try expect(@as(u32, @bitCast(cbrt32(-0.0))) == @as(u32, 0x80000000));
|
||||
try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
|
||||
@ -154,7 +154,7 @@ test "math.cbrt.special" {
|
||||
try expect(math.isNan(cbrt32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.cbrt64.special" {
|
||||
test "cbrt64.special" {
|
||||
try expect(math.isPositiveZero(cbrt64(0.0)));
|
||||
try expect(math.isNegativeZero(cbrt64(-0.0)));
|
||||
try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
|
||||
|
@ -120,7 +120,7 @@ pub fn Complex(comptime T: type) type {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.add" {
|
||||
test "add" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const b = Complex(f32).init(2, 7);
|
||||
const c = a.add(b);
|
||||
@ -128,7 +128,7 @@ test "complex.add" {
|
||||
try testing.expect(c.re == 7 and c.im == 10);
|
||||
}
|
||||
|
||||
test "complex.sub" {
|
||||
test "sub" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const b = Complex(f32).init(2, 7);
|
||||
const c = a.sub(b);
|
||||
@ -136,7 +136,7 @@ test "complex.sub" {
|
||||
try testing.expect(c.re == 3 and c.im == -4);
|
||||
}
|
||||
|
||||
test "complex.mul" {
|
||||
test "mul" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const b = Complex(f32).init(2, 7);
|
||||
const c = a.mul(b);
|
||||
@ -144,7 +144,7 @@ test "complex.mul" {
|
||||
try testing.expect(c.re == -11 and c.im == 41);
|
||||
}
|
||||
|
||||
test "complex.div" {
|
||||
test "div" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const b = Complex(f32).init(2, 7);
|
||||
const c = a.div(b);
|
||||
@ -153,28 +153,28 @@ test "complex.div" {
|
||||
math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
|
||||
}
|
||||
|
||||
test "complex.conjugate" {
|
||||
test "conjugate" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.conjugate();
|
||||
|
||||
try testing.expect(c.re == 5 and c.im == -3);
|
||||
}
|
||||
|
||||
test "complex.neg" {
|
||||
test "neg" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.neg();
|
||||
|
||||
try testing.expect(c.re == -5 and c.im == -3);
|
||||
}
|
||||
|
||||
test "complex.mulbyi" {
|
||||
test "mulbyi" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.mulbyi();
|
||||
|
||||
try testing.expect(c.re == -3 and c.im == 5);
|
||||
}
|
||||
|
||||
test "complex.reciprocal" {
|
||||
test "reciprocal" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.reciprocal();
|
||||
|
||||
@ -182,7 +182,7 @@ test "complex.reciprocal" {
|
||||
math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
|
||||
}
|
||||
|
||||
test "complex.magnitude" {
|
||||
test "magnitude" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.magnitude();
|
||||
|
||||
|
@ -11,7 +11,7 @@ pub fn abs(z: anytype) @TypeOf(z.re, z.im) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.cabs" {
|
||||
test abs {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = abs(a);
|
||||
try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
|
||||
|
@ -13,7 +13,7 @@ pub fn acos(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.cacos" {
|
||||
test acos {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = acos(a);
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub fn acosh(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.cacosh" {
|
||||
test acosh {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = acosh(a);
|
||||
|
||||
|
@ -11,7 +11,7 @@ pub fn arg(z: anytype) @TypeOf(z.re, z.im) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.carg" {
|
||||
test arg {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = arg(a);
|
||||
try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
|
||||
|
@ -19,7 +19,7 @@ pub fn asin(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.casin" {
|
||||
test asin {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = asin(a);
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn asinh(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.casinh" {
|
||||
test asinh {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = asinh(a);
|
||||
|
||||
|
@ -120,7 +120,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.catan32" {
|
||||
test "atan32" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = atan(a);
|
||||
|
||||
@ -128,7 +128,7 @@ test "complex.catan32" {
|
||||
try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
|
||||
}
|
||||
|
||||
test "complex.catan64" {
|
||||
test "atan64" {
|
||||
const a = Complex(f64).init(5, 3);
|
||||
const c = atan(a);
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn atanh(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.catanh" {
|
||||
test "atanh" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = atanh(a);
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub fn conj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
return Complex(T).init(z.re, -z.im);
|
||||
}
|
||||
|
||||
test "complex.conj" {
|
||||
test "onj" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = a.conjugate();
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.ccos" {
|
||||
test "cos" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = cos(a);
|
||||
|
||||
|
@ -155,7 +155,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.ccosh32" {
|
||||
test "cosh32" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = cosh(a);
|
||||
|
||||
@ -163,7 +163,7 @@ test "complex.ccosh32" {
|
||||
try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
|
||||
}
|
||||
|
||||
test "complex.ccosh64" {
|
||||
test "cosh64" {
|
||||
const a = Complex(f64).init(5, 3);
|
||||
const c = cosh(a);
|
||||
|
||||
|
@ -119,7 +119,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
|
||||
}
|
||||
}
|
||||
|
||||
test "complex.cexp32" {
|
||||
test "exp32" {
|
||||
const tolerance_f32 = @sqrt(math.floatEps(f32));
|
||||
|
||||
{
|
||||
@ -139,7 +139,7 @@ test "complex.cexp32" {
|
||||
}
|
||||
}
|
||||
|
||||
test "complex.cexp64" {
|
||||
test "exp64" {
|
||||
const tolerance_f64 = @sqrt(math.floatEps(f64));
|
||||
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.clog" {
|
||||
test "log" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = log(a);
|
||||
|
||||
|
@ -11,7 +11,7 @@ pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.cpow" {
|
||||
test "pow" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const b = Complex(f32).init(2.3, -1.3);
|
||||
const c = pow(a, b);
|
||||
|
@ -17,7 +17,7 @@ pub fn proj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.cproj" {
|
||||
test "proj" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = proj(a);
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.csin" {
|
||||
test "sin" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = sin(a);
|
||||
|
||||
|
@ -154,7 +154,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.csinh32" {
|
||||
test "sinh32" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = sinh(a);
|
||||
|
||||
@ -162,7 +162,7 @@ test "complex.csinh32" {
|
||||
try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
|
||||
}
|
||||
|
||||
test "complex.csinh64" {
|
||||
test "sinh64" {
|
||||
const a = Complex(f64).init(5, 3);
|
||||
const c = sinh(a);
|
||||
|
||||
|
@ -129,7 +129,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.csqrt32" {
|
||||
test "sqrt32" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = sqrt(a);
|
||||
|
||||
@ -137,7 +137,7 @@ test "complex.csqrt32" {
|
||||
try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
|
||||
}
|
||||
|
||||
test "complex.csqrt64" {
|
||||
test "sqrt64" {
|
||||
const a = Complex(f64).init(5, 3);
|
||||
const c = sqrt(a);
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn tan(z: anytype) Complex(@TypeOf(z.re, z.im)) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.ctan" {
|
||||
test "tan" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = tan(a);
|
||||
|
||||
|
@ -103,7 +103,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
|
||||
|
||||
const epsilon = 0.0001;
|
||||
|
||||
test "complex.ctanh32" {
|
||||
test "tanh32" {
|
||||
const a = Complex(f32).init(5, 3);
|
||||
const c = tanh(a);
|
||||
|
||||
@ -111,7 +111,7 @@ test "complex.ctanh32" {
|
||||
try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
|
||||
}
|
||||
|
||||
test "complex.ctanh64" {
|
||||
test "tanh64" {
|
||||
const a = Complex(f64).init(5, 3);
|
||||
const c = tanh(a);
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude)
|
||||
return @as(T, @bitCast(mag | sgn));
|
||||
}
|
||||
|
||||
test "math.copysign" {
|
||||
test copysign {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
try expect(copysign(@as(T, 1.0), @as(T, 1.0)) == 1.0);
|
||||
try expect(copysign(@as(T, 2.0), @as(T, -2.0)) == -2.0);
|
||||
|
@ -86,12 +86,12 @@ fn cosh64(x: f64) f64 {
|
||||
return expo2(ax);
|
||||
}
|
||||
|
||||
test "math.cosh" {
|
||||
test "cosh" {
|
||||
try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
|
||||
try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
|
||||
}
|
||||
|
||||
test "math.cosh32" {
|
||||
test "cosh32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
|
||||
@ -104,7 +104,7 @@ test "math.cosh32" {
|
||||
try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
|
||||
}
|
||||
|
||||
test "math.cosh64" {
|
||||
test "cosh64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
|
||||
@ -117,7 +117,7 @@ test "math.cosh64" {
|
||||
try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
|
||||
}
|
||||
|
||||
test "math.cosh32.special" {
|
||||
test "cosh32.special" {
|
||||
try expect(cosh32(0.0) == 1.0);
|
||||
try expect(cosh32(-0.0) == 1.0);
|
||||
try expect(math.isPositiveInf(cosh32(math.inf(f32))));
|
||||
@ -125,7 +125,7 @@ test "math.cosh32.special" {
|
||||
try expect(math.isNan(cosh32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.cosh64.special" {
|
||||
test "cosh64.special" {
|
||||
try expect(cosh64(0.0) == 1.0);
|
||||
try expect(cosh64(-0.0) == 1.0);
|
||||
try expect(math.isPositiveInf(cosh64(math.inf(f64))));
|
||||
|
@ -286,12 +286,12 @@ fn expm1_64(x_: f64) f64 {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.exp1m" {
|
||||
test "exp1m" {
|
||||
try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
|
||||
try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
|
||||
}
|
||||
|
||||
test "math.expm1_32" {
|
||||
test "expm1_32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(expm1_32(0.0)));
|
||||
@ -301,7 +301,7 @@ test "math.expm1_32" {
|
||||
try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
|
||||
}
|
||||
|
||||
test "math.expm1_64" {
|
||||
test "expm1_64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.isPositiveZero(expm1_64(0.0)));
|
||||
@ -311,13 +311,13 @@ test "math.expm1_64" {
|
||||
try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
|
||||
}
|
||||
|
||||
test "math.expm1_32.special" {
|
||||
test "expm1_32.special" {
|
||||
try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
|
||||
try expect(expm1_32(-math.inf(f32)) == -1.0);
|
||||
try expect(math.isNan(expm1_32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.expm1_64.special" {
|
||||
test "expm1_64.special" {
|
||||
try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
|
||||
try expect(expm1_64(-math.inf(f64)) == -1.0);
|
||||
try expect(math.isNan(expm1_64(math.nan(f64))));
|
||||
|
@ -132,7 +132,7 @@ test "float bits" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.inf" {
|
||||
test "inf" {
|
||||
const inf_u16: u16 = 0x7C00;
|
||||
const inf_u32: u32 = 0x7F800000;
|
||||
const inf_u64: u64 = 0x7FF0000000000000;
|
||||
@ -145,7 +145,7 @@ test "math.inf" {
|
||||
try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128))));
|
||||
}
|
||||
|
||||
test "math.nan" {
|
||||
test "nan" {
|
||||
const qnan_u16: u16 = 0x7E00;
|
||||
const qnan_u32: u32 = 0x7FC00000;
|
||||
const qnan_u64: u64 = 0x7FF8000000000000;
|
||||
@ -158,7 +158,7 @@ test "math.nan" {
|
||||
try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));
|
||||
}
|
||||
|
||||
test "math.snan" {
|
||||
test "snan" {
|
||||
// TODO: https://github.com/ziglang/zig/issues/14366
|
||||
if (builtin.zig_backend == .stage2_llvm and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
|
||||
|
||||
|
@ -240,7 +240,7 @@ const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const expectApproxEqRel = std.testing.expectApproxEqRel;
|
||||
|
||||
test "math.gamma" {
|
||||
test "gamma" {
|
||||
inline for (&.{ f32, f64 }) |T| {
|
||||
const eps = @sqrt(std.math.floatEps(T));
|
||||
try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps);
|
||||
@ -261,7 +261,7 @@ test "math.gamma" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.gamma.special" {
|
||||
test "gamma.special" {
|
||||
inline for (&.{ f32, f64 }) |T| {
|
||||
try expect(std.math.isNan(gamma(T, -std.math.nan(T))));
|
||||
try expect(std.math.isNan(gamma(T, std.math.nan(T))));
|
||||
@ -286,7 +286,7 @@ test "math.gamma.special" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.lgamma" {
|
||||
test "lgamma" {
|
||||
inline for (&.{ f32, f64 }) |T| {
|
||||
const eps = @sqrt(std.math.floatEps(T));
|
||||
try expectApproxEqRel(@as(T, @log(24.0)), lgamma(T, 5), eps);
|
||||
@ -307,7 +307,7 @@ test "math.lgamma" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.lgamma.special" {
|
||||
test "lgamma.special" {
|
||||
inline for (&.{ f32, f64 }) |T| {
|
||||
try expect(std.math.isNan(lgamma(T, -std.math.nan(T))));
|
||||
try expect(std.math.isNan(lgamma(T, std.math.nan(T))));
|
||||
|
@ -124,7 +124,7 @@ fn hypot64(x: f64, y: f64) f64 {
|
||||
return z * @sqrt(ly + lx + hy + hx);
|
||||
}
|
||||
|
||||
test "math.hypot" {
|
||||
test "hypot" {
|
||||
const x32: f32 = 0.0;
|
||||
const y32: f32 = -1.2;
|
||||
const x64: f64 = 0.0;
|
||||
@ -133,7 +133,7 @@ test "math.hypot" {
|
||||
try expect(hypot(x64, y64) == hypot64(0.0, -1.2));
|
||||
}
|
||||
|
||||
test "math.hypot32" {
|
||||
test "hypot32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
|
||||
@ -145,7 +145,7 @@ test "math.hypot32" {
|
||||
try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
|
||||
}
|
||||
|
||||
test "math.hypot64" {
|
||||
test "hypot64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
|
||||
@ -157,7 +157,7 @@ test "math.hypot64" {
|
||||
try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
|
||||
}
|
||||
|
||||
test "math.hypot32.special" {
|
||||
test "hypot32.special" {
|
||||
try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
|
||||
try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
|
||||
try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
|
||||
@ -166,7 +166,7 @@ test "math.hypot32.special" {
|
||||
try expect(math.isNan(hypot32(0.0, math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.hypot64.special" {
|
||||
test "hypot64.special" {
|
||||
try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
|
||||
try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
|
||||
try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
|
||||
|
@ -10,7 +10,7 @@ pub fn isFinite(x: anytype) bool {
|
||||
return @as(TBits, @bitCast(x)) & remove_sign < @as(TBits, @bitCast(math.inf(T)));
|
||||
}
|
||||
|
||||
test "math.isFinite" {
|
||||
test isFinite {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
// normals
|
||||
try expect(isFinite(@as(T, 1.0)));
|
||||
|
@ -20,7 +20,7 @@ pub inline fn isNegativeInf(x: anytype) bool {
|
||||
return x == -math.inf(@TypeOf(x));
|
||||
}
|
||||
|
||||
test "math.isInf" {
|
||||
test isInf {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
try expect(!isInf(@as(T, 0.0)));
|
||||
try expect(!isInf(@as(T, -0.0)));
|
||||
@ -31,7 +31,7 @@ test "math.isInf" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.isPositiveInf" {
|
||||
test isPositiveInf {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
try expect(!isPositiveInf(@as(T, 0.0)));
|
||||
try expect(!isPositiveInf(@as(T, -0.0)));
|
||||
@ -42,7 +42,7 @@ test "math.isPositiveInf" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.isNegativeInf" {
|
||||
test isNegativeInf {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
try expect(!isNegativeInf(@as(T, 0.0)));
|
||||
try expect(!isNegativeInf(@as(T, -0.0)));
|
||||
|
@ -17,7 +17,7 @@ pub fn isSignalNan(x: anytype) bool {
|
||||
return isNan(x) and (@as(U, @bitCast(x)) & quiet_signal_bit_mask == 0);
|
||||
}
|
||||
|
||||
test "math.isNan" {
|
||||
test isNan {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| {
|
||||
try expect(isNan(math.nan(T)));
|
||||
try expect(isNan(-math.nan(T)));
|
||||
@ -27,7 +27,7 @@ test "math.isNan" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.isSignalNan" {
|
||||
test isSignalNan {
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| {
|
||||
// TODO: Signalling NaN values get converted to quiet NaN values in
|
||||
// some cases where they shouldn't such that this can fail.
|
||||
|
@ -19,7 +19,7 @@ pub fn isNormal(x: anytype) bool {
|
||||
return value & remove_sign >= (increment_exp << 1);
|
||||
}
|
||||
|
||||
test "math.isNormal" {
|
||||
test isNormal {
|
||||
// TODO add `c_longdouble' when math.inf(T) supports it
|
||||
inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
|
||||
const TBits = std.meta.Int(.unsigned, @bitSizeOf(T));
|
||||
|
@ -66,7 +66,7 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.ldexp" {
|
||||
test ldexp {
|
||||
// subnormals
|
||||
try expect(ldexp(@as(f16, 0x1.1FFp14), -14 - 9 - 15) == math.floatTrueMin(f16));
|
||||
try expect(ldexp(@as(f32, 0x1.3FFFFFp-1), -126 - 22) == math.floatTrueMin(f32));
|
||||
|
@ -47,7 +47,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.log integer" {
|
||||
test "log integer" {
|
||||
try expect(log(u8, 2, 0x1) == 0);
|
||||
try expect(log(u8, 2, 0x2) == 1);
|
||||
try expect(log(u16, 2, 0x72) == 6);
|
||||
@ -55,7 +55,7 @@ test "math.log integer" {
|
||||
try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
|
||||
}
|
||||
|
||||
test "math.log float" {
|
||||
test "log float" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
|
||||
@ -63,7 +63,7 @@ test "math.log float" {
|
||||
try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
|
||||
}
|
||||
|
||||
test "math.log float_special" {
|
||||
test "log float_special" {
|
||||
try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
|
||||
try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
|
||||
|
||||
|
@ -182,12 +182,12 @@ fn log1p_64(x: f64) f64 {
|
||||
return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
|
||||
}
|
||||
|
||||
test "math.log1p" {
|
||||
test "log1p" {
|
||||
try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
|
||||
try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
|
||||
}
|
||||
|
||||
test "math.log1p_32" {
|
||||
test "log1p_32" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
|
||||
@ -199,7 +199,7 @@ test "math.log1p_32" {
|
||||
try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
|
||||
}
|
||||
|
||||
test "math.log1p_64" {
|
||||
test "log1p_64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
|
||||
@ -211,7 +211,7 @@ test "math.log1p_64" {
|
||||
try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
|
||||
}
|
||||
|
||||
test "math.log1p_32.special" {
|
||||
test "log1p_32.special" {
|
||||
try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
|
||||
try expect(math.isPositiveZero(log1p_32(0.0)));
|
||||
try expect(math.isNegativeZero(log1p_32(-0.0)));
|
||||
@ -220,7 +220,7 @@ test "math.log1p_32.special" {
|
||||
try expect(math.isNan(log1p_32(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "math.log1p_64.special" {
|
||||
test "log1p_64.special" {
|
||||
try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
|
||||
try expect(math.isPositiveZero(log1p_64(0.0)));
|
||||
try expect(math.isNegativeZero(log1p_64(-0.0)));
|
||||
|
@ -60,7 +60,7 @@ pub fn log_int(comptime T: type, base: T, x: T) Log2Int(T) {
|
||||
return exponent;
|
||||
}
|
||||
|
||||
test "math.log_int" {
|
||||
test "log_int" {
|
||||
// Test all unsigned integers with 2, 3, ..., 64 bits.
|
||||
// We cannot test 0 or 1 bits since base must be > 1.
|
||||
inline for (2..64 + 1) |bits| {
|
||||
@ -92,7 +92,7 @@ test "math.log_int" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.log_int vs math.log2" {
|
||||
test "log_int vs math.log2" {
|
||||
const types = [_]type{ u2, u3, u4, u8, u16 };
|
||||
inline for (types) |T| {
|
||||
var n: T = 0;
|
||||
@ -105,7 +105,7 @@ test "math.log_int vs math.log2" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.log_int vs math.log10" {
|
||||
test "log_int vs math.log10" {
|
||||
const types = [_]type{ u4, u5, u6, u8, u16 };
|
||||
inline for (types) |T| {
|
||||
var n: T = 0;
|
||||
@ -118,7 +118,7 @@ test "math.log_int vs math.log10" {
|
||||
}
|
||||
}
|
||||
|
||||
test "math.log_int at comptime" {
|
||||
test "log_int at comptime" {
|
||||
const x = 59049; // 9 ** 5;
|
||||
comptime {
|
||||
if (math.log_int(comptime_int, 9, x) != 5) {
|
||||
|
@ -123,14 +123,14 @@ fn modf64(x: f64) modf64_result {
|
||||
return result;
|
||||
}
|
||||
|
||||
test "math.modf" {
|
||||
test "modf" {
|
||||
const a = modf(@as(f32, 1.0));
|
||||
const b = modf32(1.0);
|
||||
// NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
|
||||
try expectEqual(a, b);
|
||||
}
|
||||
|
||||
test "math.modf32" {
|
||||
test "modf32" {
|
||||
const epsilon = 0.000001;
|
||||
var r: modf32_result = undefined;
|
||||
|
||||
@ -155,7 +155,7 @@ test "math.modf32" {
|
||||
try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
|
||||
}
|
||||
|
||||
test "math.modf64" {
|
||||
test "modf64" {
|
||||
const epsilon = 0.000001;
|
||||
var r: modf64_result = undefined;
|
||||
|
||||
@ -180,7 +180,7 @@ test "math.modf64" {
|
||||
try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
|
||||
}
|
||||
|
||||
test "math.modf32.special" {
|
||||
test "modf32.special" {
|
||||
var r: modf32_result = undefined;
|
||||
|
||||
r = modf32(math.inf(f32));
|
||||
@ -193,7 +193,7 @@ test "math.modf32.special" {
|
||||
try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
|
||||
}
|
||||
|
||||
test "math.modf64.special" {
|
||||
test "modf64.special" {
|
||||
var r: modf64_result = undefined;
|
||||
|
||||
r = modf64(math.inf(f64));
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user