authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-11-19 00:57:54+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-11-19 00:57:54+11:00
logd89d6374bed73683fa92d3c409016fb3f260a7c1
tree66906b5c649d2cb07c1ca9305521f0c4c5df5aed
parent8fa29bc0a235fb123c02e89936d0699906831a37
signaturelock-open Commit is signed but in an unrecognized format.

std: add tests for std.atomic.Int


1 files changed, 15 insertions(+), 1 deletions(-)

lib/std/atomic/int.zig+15-1
...@@ -4,7 +4,9 @@...@@ -4,7 +4,9 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
66
7const builtin = @import("std").builtin;7const std = @import("std");
8const builtin = std.builtin;
9const testing = std.testing;
810
9/// Thread-safe, lock-free integer11/// Thread-safe, lock-free integer
10pub fn Int(comptime T: type) type {12pub fn Int(comptime T: type) type {
...@@ -61,3 +63,15 @@ pub fn Int(comptime T: type) type {...@@ -61,3 +63,15 @@ pub fn Int(comptime T: type) type {
61 }63 }
62 };64 };
63}65}
66
67test "std.atomic.Int" {
68 var a = Int(u8).init(0);
69 testing.expectEqual(@as(u8, 0), a.incr());
70 testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
71 a.store(42, .SeqCst);
72 testing.expectEqual(@as(u8, 42), a.decr());
73 testing.expectEqual(@as(u8, 41), a.xchg(100));
74 testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
75 testing.expectEqual(@as(u8, 105), a.get());
76 a.set(200);
77}