Skip to content

Commit b238a19

Browse files
committed
add test for shuffle transform
1 parent 776b93d commit b238a19

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/lib/transforms/sort.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2-
import { sort } from './sort.js';
2+
import { sort, shuffle } from './sort.js';
33
import type { DataRecord } from '$lib/types.js';
44

55
const data: DataRecord[] = [
@@ -43,3 +43,13 @@ describe('sort transform', () => {
4343
);
4444
});
4545
});
46+
47+
describe('shuffle transform', () => {
48+
it('shuffles the data', () => {
49+
const shuffled = shuffle({ data }, { seed: 1 });
50+
expect(shuffled.sort).toBe(null);
51+
expect(shuffled.data).toHaveLength(data.length);
52+
expect(shuffled.data).not.toStrictEqual(data);
53+
expect(shuffled.data.sort((a, b) => a.A - b.A)).toStrictEqual(sortedByA);
54+
});
55+
});

src/lib/transforms/sort.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function sort(
6363
}
6464

6565
/**
66-
* reverses the data row order
66+
* shuffles the data row order
6767
*/
6868
export function shuffle(
6969
{ data, ...channels }: TransformArg<DataRow[]>,
@@ -76,7 +76,8 @@ export function shuffle(
7676
...channels,
7777
// set the sort channel to null to disable the implicit
7878
// alphabetical ordering of ordinal domains
79-
sort: null
79+
sort: null,
80+
[IS_SORTED]: true
8081
};
8182
}
8283

@@ -89,6 +90,7 @@ export function reverse({ data, ...channels }: TransformArg<DataRow[]>) {
8990
...channels,
9091
// set the sort channel to null to disable the implicit
9192
// alphabetical ordering of ordinal domains
92-
sort: null
93+
sort: null,
94+
[IS_SORTED]: true
9395
};
9496
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy