Skip to content

Commit

Permalink
add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 26, 2016
1 parent ca0b6fd commit a5502af
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions std/experimental/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,24 @@ struct Slice(size_t _N, _Range)
assert(slice(indexP) == 4); // Math & Fortran order
}

static if (doUnittest)
pure nothrow unittest
{
// check with different PureN
import std.experimental.ndslice.selection: pack, iotaSlice;
auto pElements = iotaSlice(2, 3, 4, 5).pack!2;
import std.range: iota;
import std.algorithm.comparison: equal;

// D & C order
assert(pElements[$-1, $-1][$-1].equal([5].iotaSlice(115)));
assert(pElements[[1, 2]][$-1].equal([5].iotaSlice(115)));

// Math & Fortran
assert(pElements(2, 1)[$-1].equal([5].iotaSlice(115)));
assert(pElements([2, 1])[$-1].equal([5].iotaSlice(115)));
}

/++
$(BLUE Partially or fully defined slice).
+/
Expand Down Expand Up @@ -2761,6 +2779,12 @@ private auto ptrShell(Range)(Range range, sizediff_t shift = 0)
assert(ptr[0] == save0 + 11);
(ptr + 5)[2] = 333;
assert(range[7] == 333);

auto ptrCopy = ptr.save;
ptrCopy._range.popFront;
ptr[1] = 2;
assert(ptr[0] == save0 + 11);
assert(ptrCopy[0] == 2);
}
}

Expand All @@ -2783,6 +2807,17 @@ pure nothrow unittest
}
}

unittest
{
int[] arr = [1, 2, 3];
auto ptr = arr.ptrShell;
assert(ptr[0] == 1);
auto ptrCopy = ptr.save;
ptrCopy._range.popFront;
assert(ptr[0] == 1);
assert(ptrCopy[0] == 2);
}

private enum isSlicePointer(T) = isPointer!T || is(T : PtrShell!R, R);

private struct LikePtr {}
Expand Down

0 comments on commit a5502af

Please sign in to comment.