Konoha

Finished
1import { describe, expect, test, xtest } from '@jest/globals';
2import { List } from './main.js';
3
4describe('append', () => {
5 test('appends two empty lists', () => {
6 const list1 = new List();
7 const list2 = new List();
8 expect(list1.append(list2)).toEqual(new List());
9 });
10
11 test('appends an empty list to a non-empty list', () => {
12 const list1 = new List([1, 2, 3]);
13 const list2 = new List();
14 expect(list1.append(list2)).toEqual(new List([1, 2, 3]));
15 });
16
17 test('appends a non-empty list to an empty list', () => {
18 const list1 = new List();
19 const list2 = new List([1, 2, 3]);
20 expect(list1.append(list2)).toEqual(new List([1, 2, 3]));
21 });
22
23 test('appends two non-empty lists', () => {
24 const list1 = new List([1, 2]);
25 const list2 = new List([3, 4]);
26 expect(list1.append(list2)).toEqual(new List([1, 2, 3, 4]));
27 });
28});
29
30describe('concat', () => {
31 test('concatenates an empty list', () => {
32 const list1 = new List();
33 const list2 = new List();
34 expect(list1.concat(list2)).toEqual(new List());
35 });
36
37 test('concatenates a list with an empty list', () => {
38 const list1 = new List([1, 2, 3]);
39 const list2 = new List();
40 expect(list1.concat(list2)).toEqual(new List([1, 2, 3]));
41 });
42
43 test('concatenates two lists', () => {
44 const list1 = new List([1, 2, 3]);
45 const list2 = new List([4, 5, 6]);
46 expect(list1.concat(list2)).toEqual(new List([1, 2, 3, 4, 5, 6]));
47 });
48
49 test('concatenates multiple lists', () => {
50 const list1 = new List([1, 2]);
51 const list2 = new List([3, 4]);
52 const list3 = new List([5, 6]);
53 const list4 = new List([7, 8]);
54 expect(list1.concat(list2).concat(list3).concat(list4)).toEqual(
55 new List([1, 2, 3, 4, 5, 6, 7, 8]),
56 );
57 });
58});
59
60describe('filter', () => {
61 test('filters an empty list', () => {
62 const list = new List();
63 expect(list.filter((el) => el % 2 === 1)).toEqual(new List());
64 });
65
66 test('filters a list', () => {
67 const list = new List([1, 2, 3, 4, 5]);
68 expect(list.filter((el) => el % 2 === 1)).toEqual(new List([1, 3, 5]));
69 });
70});
71
72describe('length', () => {
73 test('gets the length of an empty list', () => {
74 const list = new List();
75 expect(list.length()).toBe(0);
76 });
77
78 test('gets the length of a non-empty list', () => {
79 const list = new List([1, 2, 3, 4]);
80 expect(list.length()).toBe(4);
81 });
82});
83
84describe('map', () => {
85 test('maps an empty list', () => {
86 const list = new List();
87 expect(list.map((el) => el + 1)).toEqual(new List());
88 });
89
90 test('maps a list', () => {
91 const list = new List([1, 3, 5, 7]);
92 expect(list.map((el) => el + 1)).toEqual(new List([2, 4, 6, 8]));
93 });
94});
95
96describe('foldl', () => {
97 test('folds an empty list from the left', () => {
98 const list = new List();
99 expect(list.foldl((acc, el) => el * acc, 2)).toBe(2);
100 });
101
102 test('folds a list from the left', () => {
103 const list = new List([1, 2, 3, 4]);
104 expect(list.foldl((acc, el) => el + acc, 5)).toBe(15);
105 });
106
107 test('folds a list from the left with a function that returns a string', () => {
108 const list = new List([1, 2, 3, 4]);
109 expect(list.foldl((acc, el) => `${acc}${el}`, '5')).toBe('51234');
110 });
111});
112
113describe('foldr', () => {
114 test('folds an empty list from the right', () => {
115 const list = new List();
116 expect(list.foldr((acc, el) => el * acc, 2)).toBe(2);
117 });
118
119 test('folds a list from the right', () => {
120 const list = new List([1, 2, 3, 4]);
121 expect(list.foldr((acc, el) => el + acc, 5)).toBe(15);
122 });
123
124 test('folds a list from the right with a function that returns a string', () => {
125 const list = new List([1, 2, 3, 4]);
126 expect(list.foldr((acc, el) => `${acc}${el}`, '5')).toBe('54321');
127 });
128});
129
130describe('reverse', () => {
131 test('reverses an empty list', () => {
132 const list = new List();
133 expect(list.reverse()).toEqual(new List());
134 });
135
136 test('reverses a non-empty list', () => {
137 const list = new List([1, 3, 5, 7]);
138 expect(list.reverse()).toEqual(new List([7, 5, 3, 1]));
139 });
140
141 test('reverses a list with duplicate elements', () => {
142 const list = new List([1, 1, 2, 2]);
143 expect(list.reverse()).toEqual(new List([2, 2, 1, 1]));
144 });
145});
Test NameStatus
list of lists
Fail
list of nested lists
Fail
empty lists
Pass
list to empty list
Pass
empty list to list
Pass
non-empty lists
Pass
empty list
Pass
empty list
Pass
non empty list
Pass
empty list
Pass
non-empty list
Pass
empty list
Pass
non-empty list
Pass
empty list
Pass
direction independent function applied to non-empty list
Pass
direction dependent function applied to non-empty list
Pass
empty list
Pass
direction independent function applied to non-empty list
Pass
direction dependent function applied to non-empty list
Pass
empty list
Pass
non-empty list
Pass
list of lists is not flattened
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.