net: Add missing public imports, move tests

This commit is contained in:
2019-03-19 08:47:39 +01:00
parent 484cb13317
commit 20c7e47ff7
36 changed files with 1447 additions and 1364 deletions

View File

@ -107,11 +107,7 @@ struct Integer
/// ditto
this(shared Allocator allocator) @nogc nothrow pure @safe
in
{
assert(allocator !is null);
}
do
in (allocator !is null)
{
this.allocator_ = allocator;
}
@ -867,11 +863,7 @@ struct Integer
/// ditto
ref Integer opOpAssign(string op : "/")(auto ref const Integer operand)
in
{
assert(operand.length > 0, "Division by zero.");
}
do
in (operand.length > 0, "Division by zero.")
{
divide(operand, this);
return this;
@ -879,37 +871,12 @@ struct Integer
/// ditto
ref Integer opOpAssign(string op : "%")(auto ref const Integer operand)
in
{
assert(operand.length > 0, "Division by zero.");
}
do
in (operand.length > 0, "Division by zero")
{
divide(operand, null, this);
return this;
}
@nogc nothrow pure @safe unittest
{
auto h1 = Integer(18);
auto h2 = Integer(4);
h1 %= h2;
assert(h1 == 2);
h1 = 8;
h1 %= h2;
assert(h1 == 0);
h1 = 7;
h1 %= h2;
assert(h1 == 3);
h1 = 56088;
h2 = 456;
h1 /= h2;
assert(h1 == 123);
}
/// ditto
ref Integer opOpAssign(string op : ">>")(const size_t operand)
{
@ -1055,7 +1022,7 @@ struct Integer
return this;
}
//
///
@nogc nothrow pure @safe unittest
{
auto h1 = Integer(79);
@ -1162,11 +1129,7 @@ struct Integer
/// ditto
Integer opBinary(string op)(const auto ref Integer operand) const
if (op == "/" || op == "%")
in
{
assert(operand.length > 0, "Division by zero.");
}
do
in (operand.length > 0, "Division by zero")
{
mixin("return Integer(this, allocator) " ~ op ~ "= operand;");
}
@ -1281,11 +1244,7 @@ struct Integer
if ((is(Q : typeof(null))
|| (is(Q : Integer) && __traits(isRef, quotient)))
&& (ARGS.length == 0 || (ARGS.length == 1 && is(ARGS[0] : Integer))))
in
{
assert(divisor != 0, "Division by zero.");
}
do
in (divisor != 0, "Division by zero")
{
if (compare(divisor) < 0)
{
@ -1526,46 +1485,5 @@ struct Integer
}
}
@nogc nothrow pure @safe unittest
{
{
Integer integer;
assert(integer.toArray().length == 0);
}
{
auto integer = Integer(0x03);
ubyte[1] expected = [ 0x03 ];
auto array = integer.toArray();
assert(equal(array[], expected[]));
}
{
ubyte[63] expected = [
0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x39, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
];
auto integer = Integer(Sign.positive, expected[]);
auto array = integer.toArray();
assert(equal(array[], expected[]));
}
{
ubyte[14] expected = [
0x22, 0x33, 0x44, 0x55, 0x05, 0x06, 0x07,
0x08, 0x3a, 0x3b, 0x00, 0x61, 0x62, 0x63,
];
auto integer = Integer(Sign.positive, expected[]);
auto array = integer.toArray();
assert(equal(array[], expected[]));
}
}
mixin DefaultAllocator;
}

View File

@ -254,21 +254,6 @@ if (isFloatingPoint!F)
assert(classify(-real.infinity) == FloatingPointClass.infinite);
}
@nogc nothrow pure @safe unittest
{
static if (ieeePrecision!float == IEEEPrecision.doubleExtended)
{
assert(classify(1.68105e-10) == FloatingPointClass.normal);
assert(classify(1.68105e-4932L) == FloatingPointClass.subnormal);
// Emulate unnormals, because they aren't generated anymore since i386
FloatBits!real unnormal;
unnormal.exp = 0x123;
unnormal.mantissa = 0x1;
assert(classify(unnormal) == FloatingPointClass.subnormal);
}
}
/**
* Determines whether $(D_PARAM x) is a finite number.
*
@ -581,11 +566,7 @@ if (isFloatingPoint!F)
*/
H pow(I, G, H)(in auto ref I x, in auto ref G y, in auto ref H z)
if (isIntegral!I && isIntegral!G && isIntegral!H)
in
{
assert(z > 0, "Division by zero.");
}
do
in (z > 0, "Division by zero")
{
G mask = G.max / 2 + 1;
H result;
@ -622,11 +603,7 @@ do
/// ditto
I pow(I)(const auto ref I x, const auto ref I y, const auto ref I z)
if (is(I == Integer))
in
{
assert(z.length > 0, "Division by zero.");
}
do
in (z.length > 0, "Division by zero")
{
size_t i;
auto tmp1 = Integer(x, x.allocator);
@ -708,33 +685,3 @@ bool isPseudoprime(ulong x) @nogc nothrow pure @safe
assert(15485867.isPseudoprime);
assert(!15485868.isPseudoprime);
}
@nogc nothrow pure @safe unittest
{
assert(74653.isPseudoprime);
assert(74687.isPseudoprime);
assert(74699.isPseudoprime);
assert(74707.isPseudoprime);
assert(74713.isPseudoprime);
assert(74717.isPseudoprime);
assert(74719.isPseudoprime);
assert(74747.isPseudoprime);
assert(74759.isPseudoprime);
assert(74761.isPseudoprime);
assert(74771.isPseudoprime);
assert(74779.isPseudoprime);
assert(74797.isPseudoprime);
assert(74821.isPseudoprime);
assert(74827.isPseudoprime);
assert(9973.isPseudoprime);
assert(49979693.isPseudoprime);
assert(104395303.isPseudoprime);
assert(593441861.isPseudoprime);
assert(104729.isPseudoprime);
assert(15485867.isPseudoprime);
assert(49979693.isPseudoprime);
assert(104395303.isPseudoprime);
assert(593441861.isPseudoprime);
assert(899809363.isPseudoprime);
assert(982451653.isPseudoprime);
}

View File

@ -324,13 +324,3 @@ else version (Windows)
}
}
}
static if (is(PlatformEntropySource)) @nogc @system unittest
{
import tanya.memory.smartref : unique;
auto source = defaultAllocator.unique!PlatformEntropySource();
assert(source.threshold == 32);
assert(source.strong);
}