/[sudobot]/trunk/tests/framework/streams/Stream.test.ts
ViewVC logotype

Contents of /trunk/tests/framework/streams/Stream.test.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (show annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1566 byte(s)
chore: add trunk
1 import Stream from "@framework/streams/Stream";
2 import { beforeEach, describe, expect, it } from "vitest";
3
4 describe("Stream", () => {
5 let stream: Stream<number>;
6
7 beforeEach(() => {
8 stream = new Stream([1, 2, 3, 4, 5]);
9 });
10
11 it("should create a new Stream instance", () => {
12 expect(stream).toBeInstanceOf(Stream);
13 });
14
15 it("should filter items correctly", () => {
16 const filteredStream = stream.filter(item => item > 2);
17 expect(Array.from(filteredStream)).toEqual([3, 4, 5]);
18 });
19
20 it("should map items correctly", () => {
21 const mappedStream = stream.map(item => item * 2);
22 expect(Array.from(mappedStream)).toEqual([2, 4, 6, 8, 10]);
23 });
24
25 it("should return correct item at index", () => {
26 expect(stream.at(2)).toEqual(3);
27 });
28
29 it("should concatenate streams correctly", () => {
30 const additionalStream = new Stream([6, 7, 8]);
31 const concatenatedStream = stream.concat(additionalStream);
32 expect(Array.from(concatenatedStream)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
33 });
34
35 it("should slice streams correctly", () => {
36 const slicedStream = stream.slice(1, 3);
37 expect(Array.from(slicedStream)).toEqual([2, 3]);
38 });
39
40 it("should reduce streams correctly", () => {
41 const reducedStream = stream.reduce((acc, item) => acc + item, 0);
42 expect(reducedStream.get()).toEqual(15);
43 });
44
45 it("should convert to array correctly", () => {
46 expect(stream.toArray()).toEqual([1, 2, 3, 4, 5]);
47 });
48 });

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26