diff --git a/get.ts b/get.ts new file mode 100644 index 0000000..d9d955b --- /dev/null +++ b/get.ts @@ -0,0 +1,33 @@ +namespace GetTests { + export function run(): boolean { + let allPassed: boolean = true + let test: TernaryStringSet = new TernaryStringSet() + + // Get() on an empty set will be null. + if (test.get(0) !== null) { + game.splash("Get test 1 failed.") + allPassed = false + } + + test.add("") + if (test.get(0) !== "") { + game.splash("Get test 2 failed.") + allPassed = false + } + + test.clear() + test.addAll(ShortEnglishList.words) + console.log("Get random words from short word list.") + for (let count: number = 0; count < 100; count++) { + let index: number = randint(0, test.size - 1) + let word: string = test.get(index) + console.log(word) + if (word.length == 0) { + game.splash(`Get test 3 count ${count} failed; index = ${index}.`) + allPassed = false + } + } + + return allPassed + } +} \ No newline at end of file diff --git a/main.ts b/main.ts index 3f1d567..57ddfa3 100644 --- a/main.ts +++ b/main.ts @@ -15,6 +15,7 @@ let tests: (() => boolean)[] = [ Balance.run, Compact.run, Serialization.run, + GetTests.run, ] for (let t of tests) { diff --git a/pxt.json b/pxt.json index c83f14b..297839d 100644 --- a/pxt.json +++ b/pxt.json @@ -19,7 +19,8 @@ "compact.ts", "common.ts", "serialization.ts", - "serialized-short-list.ts" + "serialized-short-list.ts", + "get.ts" ], "testDependencies": {}, "targetVersions": {