1const builtin = @import("builtin");
2const std = @import("std");
3
4const c = std.c;
5const testing = std.testing;
6
7test "erand48" {
8 if (builtin.target.os.tag == .windows) return; // no erand48
9
10 var xsubi: [3]c_ushort = .{ 37174, 64810, 11603 };
11
12 try testing.expectApproxEqAbs(0.8965, c.erand48(&xsubi), 0.0005);
13 try testing.expectEqualSlices(c_ushort, &.{ 22537, 47966, 58735 }, &xsubi);
14
15 try testing.expectApproxEqAbs(0.3375, c.erand48(&xsubi), 0.0005);
16 try testing.expectEqualSlices(c_ushort, &.{ 37344, 32911, 22119 }, &xsubi);
17
18 try testing.expectApproxEqAbs(0.6475, c.erand48(&xsubi), 0.0005);
19 try testing.expectEqualSlices(c_ushort, &.{ 23659, 29872, 42445 }, &xsubi);
20
21 try testing.expectApproxEqAbs(0.5005, c.erand48(&xsubi), 0.0005);
22 try testing.expectEqualSlices(c_ushort, &.{ 31642, 7875, 32802 }, &xsubi);
23
24 try testing.expectApproxEqAbs(0.5065, c.erand48(&xsubi), 0.0005);
25 try testing.expectEqualSlices(c_ushort, &.{ 64669, 14399, 33170 }, &xsubi);
26}
27
28test "jrand48" {
29 if (builtin.target.os.tag == .windows) return; // no jrand48
30
31 if (builtin.target.os.tag == .openbsd) return error.SkipZigTest; // TODO
32
33 var xsubi: [3]c_ushort = .{ 25175, 11052, 45015 };
34
35 try testing.expectEqual(1699503220, c.jrand48(&xsubi));
36 try testing.expectEqualSlices(c_ushort, &.{ 2326, 23668, 25932 }, &xsubi);
37
38 try testing.expectEqual(-992276007, c.jrand48(&xsubi));
39 try testing.expectEqualSlices(c_ushort, &.{ 41577, 4569, 50395 }, &xsubi);
40
41 try testing.expectEqual(-19535776, c.jrand48(&xsubi));
42 try testing.expectEqualSlices(c_ushort, &.{ 31936, 59488, 65237 }, &xsubi);
43
44 try testing.expectEqual(79438377, c.jrand48(&xsubi));
45 try testing.expectEqualSlices(c_ushort, &.{ 40395, 8745, 1212 }, &xsubi);
46
47 try testing.expectEqual(-1258917728, c.jrand48(&xsubi));
48 try testing.expectEqualSlices(c_ushort, &.{ 37242, 28832, 46326 }, &xsubi);
49}
50
51test "nrand48" {
52 if (builtin.target.os.tag == .windows) return; // no nrand48
53
54 var xsubi: [3]c_ushort = .{ 546, 33817, 23389 };
55
56 try testing.expectEqual(914920692, c.nrand48(&xsubi));
57 try testing.expectEqualSlices(c_ushort, &.{ 29829, 10728, 27921 }, &xsubi);
58
59 try testing.expectEqual(754104482, c.nrand48(&xsubi));
60 try testing.expectEqualSlices(c_ushort, &.{ 6828, 28997, 23013 }, &xsubi);
61
62 try testing.expectEqual(609453945, c.nrand48(&xsubi));
63 try testing.expectEqualSlices(c_ushort, &.{ 58183, 3826, 18599 }, &xsubi);
64
65 try testing.expectEqual(1878644360, c.nrand48(&xsubi));
66 try testing.expectEqualSlices(c_ushort, &.{ 36678, 44304, 57331 }, &xsubi);
67
68 try testing.expectEqual(2114923686, c.nrand48(&xsubi));
69 try testing.expectEqualSlices(c_ushort, &.{ 58585, 22861, 64542 }, &xsubi);
70}