std: add tests for std.atomic.Int

This commit is contained in:
daurnimator 2020-11-19 00:57:54 +11:00
parent 8fa29bc0a2
commit d89d6374be
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A

View File

@ -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);
}