-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Expect, Equal } from "type-testing"; | ||
|
||
type StringToNumber<T> = T extends `${infer N extends number}` ? N : never; | ||
|
||
type FindSanta<Forest extends unknown[][]> = { | ||
[Row in keyof Forest]: { | ||
[Column in keyof Forest[Row]]: Forest[Row][Column] extends "π πΌ" | ||
? [StringToNumber<Row>, StringToNumber<Column>] | ||
: never; | ||
}[keyof Forest[Row]]; | ||
}[number]; | ||
|
||
// ------------------- Test section --------------------- | ||
|
||
type Forest0 = [ | ||
["π πΌ", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
]; | ||
type test_0_actual = FindSanta<Forest0>; | ||
// ^? | ||
type test_0_expected = [0, 0]; | ||
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>; | ||
|
||
type Forest1 = [ | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π πΌ", "π", "π"], | ||
]; | ||
type test_1_actual = FindSanta<Forest1>; | ||
// ^? | ||
type test_1_expected = [3, 1]; | ||
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>; | ||
|
||
type Forest2 = [ | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π", "π πΌ", "π"], | ||
["π", "π", "π", "π"], | ||
]; | ||
type test_2_actual = FindSanta<Forest2>; | ||
// ^? | ||
type test_2_expected = [2, 2]; | ||
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>; | ||
|
||
type Forest3 = [ | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π πΌ", "π", "π"], | ||
["π", "π", "π", "π"], | ||
]; | ||
type test_3_actual = FindSanta<Forest3>; | ||
// ^? | ||
type test_3_expected = [2, 1]; | ||
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>; | ||
|
||
type Forest4 = [ | ||
["π", "π", "π", "π"], | ||
["π", "π", "π πΌ", "π"], | ||
["π", "π", "π", "π"], | ||
["π", "π", "π", "π"], | ||
]; | ||
type test_4_actual = FindSanta<Forest4>; | ||
// ^? | ||
type test_4_expected = [1, 2]; | ||
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Expect, Equal } from "type-testing"; | ||
|
||
type RockPaperScissors = "ππ»" | "ππΎ" | "βπ½"; | ||
type RockPaperScissorsWin = ["ππ»", "ππΎ"] | ["ππΎ", "βπ½"] | ["βπ½", "ππ»"]; | ||
|
||
type WhoWins< | ||
Player1 extends RockPaperScissors, | ||
Player2 extends RockPaperScissors, | ||
> = Player1 extends Player2 | ||
? "draw" | ||
: [Player1, Player2] extends RockPaperScissorsWin | ||
? "win" | ||
: "lose"; | ||
|
||
// ------------------- Test section --------------------- | ||
|
||
type test_0_actual = WhoWins<"ππ»", "ππΎ">; | ||
// ^? | ||
type test_0_expected = "win"; | ||
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>; | ||
|
||
type test_1_actual = WhoWins<"ππ»", "βπ½">; | ||
// ^? | ||
type test_1_expected = "lose"; | ||
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>; | ||
|
||
type test_2_actual = WhoWins<"ππ»", "ππ»">; | ||
// ^? | ||
type test_2_expected = "draw"; | ||
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>; | ||
|
||
type test_3_actual = WhoWins<"ππΎ", "ππ»">; | ||
// ^? | ||
type test_3_expected = "lose"; | ||
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>; | ||
|
||
type test_4_actual = WhoWins<"ππΎ", "βπ½">; | ||
// ^? | ||
type test_4_expected = "win"; | ||
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>; | ||
|
||
type test_5_actual = WhoWins<"ππΎ", "ππΎ">; | ||
// ^? | ||
type test_5_expected = "draw"; | ||
type test_5 = Expect<Equal<test_5_expected, test_5_actual>>; | ||
|
||
type test_6_actual = WhoWins<"βπ½", "ππ»">; | ||
// ^? | ||
type test_6_expected = "win"; | ||
type test_6 = Expect<Equal<test_6_expected, test_6_actual>>; | ||
|
||
type test_7_actual = WhoWins<"βπ½", "βπ½">; | ||
// ^? | ||
type test_7_expected = "draw"; | ||
type test_7 = Expect<Equal<test_7_expected, test_7_actual>>; | ||
|
||
type test_8_actual = WhoWins<"βπ½", "ππΎ">; | ||
// ^? | ||
type test_8_expected = "lose"; | ||
type test_8 = Expect<Equal<test_8_expected, test_8_actual>>; |