Skip to content

Commit

Permalink
fix: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Jul 1, 2024
1 parent a1da66e commit 8a718a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
14 changes: 10 additions & 4 deletions lib/src/slice/slice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ final class Slice<T> implements Iterable<T> {

/// Returns an iterator over all contiguous windows of length size. The windows overlap.
/// If the array is shorter than size, the iterator returns no values.
/// Panics if size is zero or less.
RIterator<Arr<T>> arrayWindows(int size) {
RangeError.checkNotNegative(size);
if(size <= 0){
panic("window size must be non-zero");
}
return RIterator.fromIterable(_arrayWindowsHelper(size));
}

Expand Down Expand Up @@ -210,7 +213,7 @@ final class Slice<T> implements Iterable<T> {
// contains: Implemented by Iterable.contains

/// Copies the elements from src into self.
/// The length of src must be the same as self.
/// The length of src must be the same as this.
void copyFromSlice(Slice<T> src) {
final length = len();
final srcLength = src.len();
Expand Down Expand Up @@ -833,10 +836,13 @@ final class Slice<T> implements Iterable<T> {
// trim_ascii_end: Will not implement, not possible in Dart
// trim_ascii_start: Will not implement, not possible in Dart

/// Returns an iterator over all contiguous windows of length size. The windows overlap.
/// Returns an iterator of slices of this slice over all contiguous windows of length size. The windows overlap.
/// If the slice is shorter than size, the iterator returns no values.
/// Panics if size is zero or less.
RIterator<Slice<T>> windows(int size) {
RangeError.checkNotNegative(size);
if(size <= 0){
panic("window size must be non-zero");
}
return RIterator.fromIterable(_windowsHelper(size));
}

Expand Down
22 changes: 14 additions & 8 deletions test/slice/slice_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ main() {

list = [1, 2, 3, 4, 5];
slice = Slice(list, 1, 4);
expect(() => slice.windows(0), throwsA(isA<Object>()));
expect(() => slice.windows(-1), throwsA(isA<Object>()));
expect(() => slice.arrayWindows(0), throwsA(isA<Panic>()));
expect(() => slice.arrayWindows(-1), throwsA(isA<Panic>()));
});

test("asChunks", () {
Expand Down Expand Up @@ -334,15 +334,21 @@ main() {
dstList = [6, 7, 8, 9, 10];
src = Slice(srcList, 0, 5);
dst = Slice(dstList, 1, 4);
expect(() => dst.copyFromSlice(src), throwsA(isA<Panic>()));

srcList = [1, 2, 3, 4, 5];
dstList = [6, 7, 8, 9, 10];
src = Slice(srcList, 1, 5);
dst = Slice(dstList, 0, 4);
dst.copyFromSlice(src);
expect(dstList, [6, 1, 2, 3, 10]);
expect(dstList, [2, 3, 4, 5, 10]);

srcList = [1, 2, 3, 4, 5];
dstList = [6, 7, 8, 9, 10];
src = Slice(srcList, 1, 4);
dst = Slice(dstList, 0, 5);
src = Slice(srcList, 0, 4);
dst = Slice(dstList, 1, 5);
dst.copyFromSlice(src);
expect(dstList, [2, 3, 4, 9, 10]);
expect(dstList, [6, 1, 2, 3, 4]);
});

test("copyWithin", () {
Expand Down Expand Up @@ -923,7 +929,7 @@ main() {

list = [1, 2, 3, 4, 5];
slice = Slice(list, 1, 4);
expect(() => slice.windows(0), throwsA(isA<Object>()));
expect(() => slice.windows(-1), throwsA(isA<Object>()));
expect(() => slice.windows(0), throwsA(isA<Panic>()));
expect(() => slice.windows(-1), throwsA(isA<Panic>()));
});
}

0 comments on commit 8a718a5

Please sign in to comment.