Skip to content

Commit 43cb2f5

Browse files
author
Kanchalai Tanglertsampan
committed
Add tests
1 parent f55167e commit 43cb2f5

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// @module: commonjs
2+
// @target: es6
3+
// @noImplicitAny: true
4+
5+
export interface StrategicState {
6+
lastStrategyApplied?: string;
7+
}
8+
9+
export function strategy<T extends StrategicState>(stratName: string, gen: (a: T) => IterableIterator<T | undefined>): (a: T) => IterableIterator<T | undefined> {
10+
return function*(state) {
11+
for (const next of gen(state)) {
12+
if (next) {
13+
next.lastStrategyApplied = stratName;
14+
}
15+
yield next;
16+
}
17+
}
18+
}
19+
20+
export interface Strategy<T> {
21+
(a: T): IterableIterator<T | undefined>;
22+
}
23+
24+
export interface State extends StrategicState {
25+
foo: number;
26+
}
27+
28+
export const Nothing1: Strategy<State> = strategy("Nothing", function*(state: State) {
29+
return state;
30+
});
31+
32+
export const Nothing2: Strategy<State> = strategy("Nothing", function*(state: State) {
33+
yield state;
34+
});
35+
36+
export const Nothing3: Strategy<State> = strategy("Nothing", function* (state: State) {
37+
yield ;
38+
return state;
39+
});
40+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// @module: commonjs
2+
// @target: es6
3+
// @noImplicitAny: true
4+
5+
export interface StrategicState {
6+
lastStrategyApplied?: string;
7+
}
8+
9+
export function strategy<T extends StrategicState>(stratName: string, gen: (a: T) => IterableIterator<T | undefined>): (a: T) => IterableIterator<T | undefined> {
10+
return function*(state) {
11+
for (const next of gen(state)) {
12+
if (next) {
13+
next.lastStrategyApplied = stratName;
14+
}
15+
yield next;
16+
}
17+
}
18+
}
19+
20+
export interface Strategy<T> {
21+
(a: T): IterableIterator<T | undefined>;
22+
}
23+
24+
export interface State extends StrategicState {
25+
foo: number;
26+
}
27+
28+
export const Nothing: Strategy<State> = strategy("Nothing", function* (state: State) {
29+
yield 1;
30+
return state;
31+
});
32+
33+
export const Nothing1: Strategy<State> = strategy("Nothing", function* (state: State) {
34+
});
35+
36+
export const Nothing2: Strategy<State> = strategy("Nothing", function* (state: State) {
37+
return 1;
38+
});
39+
40+
export const Nothing3: Strategy<State> = strategy("Nothing", function* (state: State) {
41+
yield state;
42+
return 1;
43+
});

0 commit comments

Comments
 (0)