| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn OneSmallerInt(comptime T: type) type { |
| 6 | const info = @typeInfo(T).int; |
| 7 | return @Int(info.signedness, info.bits - 1); |
| 8 | } |
| 9 | |
| 10 | test { |
| 11 | try std.testing.expect(OneSmallerInt(u1) == u0); |
| 12 | } |
| 13 | test { |
| 14 | try std.testing.expect(OneSmallerInt(u2) == u1); |
| 15 | } |
| 16 | test { |
| 17 | try std.testing.expect(OneSmallerInt(u3) == u2); |
| 18 | } |
| 19 | test { |
| 20 | try std.testing.expect(OneSmallerInt(u4) == u3); |
| 21 | } |
| 22 | test { |
| 23 | try std.testing.expect(OneSmallerInt(u5) == u4); |
| 24 | } |
| 25 | test { |
| 26 | try std.testing.expect(OneSmallerInt(i1) == i0); |
| 27 | } |
| 28 | test { |
| 29 | try std.testing.expect(OneSmallerInt(i2) == i1); |
| 30 | } |
| 31 | test { |
| 32 | try std.testing.expect(OneSmallerInt(i3) == i2); |
| 33 | } |
| 34 | test { |
| 35 | try std.testing.expect(OneSmallerInt(i4) == i3); |
| 36 | } |
| 37 | test { |
| 38 | try std.testing.expect(OneSmallerInt(i5) == i4); |
| 39 | } |