mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
std: add tests for std.atomic.Int
This commit is contained in:
parent
8fa29bc0a2
commit
d89d6374be
@ -4,7 +4,9 @@
|
||||
// The MIT license requires this copyright notice to be included in all copies
|
||||
// and substantial portions of the software.
|
||||
|
||||
const builtin = @import("std").builtin;
|
||||
const std = @import("std");
|
||||
const builtin = std.builtin;
|
||||
const testing = std.testing;
|
||||
|
||||
/// Thread-safe, lock-free integer
|
||||
pub fn Int(comptime T: type) type {
|
||||
@ -61,3 +63,15 @@ pub fn Int(comptime T: type) type {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test "std.atomic.Int" {
|
||||
var a = Int(u8).init(0);
|
||||
testing.expectEqual(@as(u8, 0), a.incr());
|
||||
testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
|
||||
a.store(42, .SeqCst);
|
||||
testing.expectEqual(@as(u8, 42), a.decr());
|
||||
testing.expectEqual(@as(u8, 41), a.xchg(100));
|
||||
testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
|
||||
testing.expectEqual(@as(u8, 105), a.get());
|
||||
a.set(200);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user